您的位置:首页 > 编程语言

OT源代码的分析,OrtHello 迟早攻破你 (二)OT的基本属性和基本流程

2011-12-05 14:56 351 查看
OT三大基本物体:



首先我们看OT:它继承了最基本的MonoBehaviour,它是放置在场景中的,提供一些基本的属性

它的4大功能:

Check if framework is initialized (isValid)

Find your objects, animations, (sprite)containers and materials programmaticly.

Set your default solid/transparent and additive material. (这点大概是最重要的,不用设置繁琐的材质了)

Create a sprite programmaticly.

属性有:

objectPrototypes,就是我们在unity看到的预设的5个种类的物体,materials就是预设的材质了



以下是全局变量了-,-

public static bool dirtyChecks = true; 检查每一个物体的肢体是否绑定成功 ,会花费10fps (very rough estimate).

public static bool objectPooling = true; 创建和销毁物体的时候会 Pooling 放到缓冲池-,-暂定

public static bool debug = false;

public static bool isValid (在updata会检查)

public static float fps 返回fps

public static int objectCount

public static int containerCount 注册的containers 数量

public static int animationCount 注册的animation 数量

public static OTView view //摄像机的控制

public static bool Over(GameObject g)

public static bool Over(OTObject o) 划过一个物体

public static bool Clicked(GameObject g, int button) 是否我们的mouse点下了一个sprite

public static bool Clicked(GameObject g)

public static bool Clicked(OTObject o)

public static bool Touched(GameObject g) 物体是否可touch

public static bool Touched(OTObject o)

GetMaterial(string name) 和一些列材质的函数

查找函数

ContainerByName(string name) 返回OTContainer

AnimationByName(string name) 返回OTAnimation

ObjectByName(string name) 返回OTObject

public static void PreFabricate(string objectPrototype, int numberOfInstances) 创建一个物体缓冲池

public static GameObject CreateObject(string objectPrototype) 创建物体 (放入缓冲池中)

public static void DestroyObject(OTObject o) 销毁物体 (放入缓冲池中)

public static void DestroyContainer(OTContainer container)

public static void DestroyAnimation(OTAnimation animation)

public static void RemoveObject(OTObject o)

public static void RemoveAnimation(OTAnimation o)

public static void RemoveContainer(OTContainer o) //一系列重载

public static OTObject[] ObjectsUnderPoint(Vector2 screenPoint, OTObject[] checkObjects, OTObject[] ignoreObjects)

//Get all orthello objects under a specific point 是不是用来做某些检测用的,有一系列重载

public static OTController Controller(string controllerType, string name)

它自己的updata函数

void Update()
{
if (instance == null) instance = this;

if (Application.isEditor)
{
if (!Vector3.Equals(transform.position, Vector3.zero))
transform.position = Vector3.zero;
}

// check for clicks
if (inputObjects.Count > 0)
{
if (Input.touchCount > 0 ||
Input.GetMouseButton(0) ||
Input.GetMouseButton(1) ||
Input.GetMouseButton(2) ||
Input.GetMouseButtonDown(0) ||
Input.GetMouseButtonDown(1) ||
Input.GetMouseButtonDown(2) ||
Input.GetMouseButtonUp(0) ||
Input.GetMouseButtonUp(1) ||
Input.GetMouseButtonUp(2))
{
if (Input.touchCount > 0)
HandleInput(Input.touches[0].position);
else
HandleInput(Input.mousePosition);
}
}

// calculate fps every 100ms
fpsTime += Time.deltaTime;
if (fpsTime >= 0.1f)
{
_fps = 1 / Time.deltaTime;
fpsTime = 0;
}

if (controllers.Count > 0)
{
for (int c = 0; c < controllers.Count; c++)
{
OTController co = controllers[c];
if (co.enabled)
co.Update(Time.deltaTime);
}
}

}
OT就是酱紫了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐