先说说最简单的OTMatRef,它就是用来存材质的相关数据
public class OTMatRef {
public string name = "";
public string fieldColorTint = "";
public string fieldAlphaChannel = "";
public string fieldAlphaColor = "";
public Material material;
}
public class OTObjectType {
public string name = "";
public GameObject prototype;
public static Dictionary<string, GameObject> lookup = new Dictionary<string, GameObject>();
public static string Sprite
public static string FilledSprite
public static string AnimatingSprite
public static string Animation
public static string SpriteSheet
public static string SpriteBatch
public static string SpriteAtlas
}
最后是最重要的OTObject : MonoBehaviour
public enum Pivot 对齐的中心点 ,可设置的值有
TopLeft, Top, TopRight,
Left, Center, Right,
BottomLeft, Bottom, BottomRight,
Custom //自定义
public enum Physics
{
Trigger, /// For input capture or custom collision detection
NoGravity, /// Physical floating object
RigidBody, /// Physical rigid body
StaticBody, /// Physical static body that collides with all
StaticRigidBody, /// Physical static body that has a collison size of 10
Custom /// custom adding/removing/configration of colliders and physical components.
};
{
Box,
Sphere
};
public bool draggable = false; ///Makes this OTObject draggable
public int dragButton = 0; /// Mousebutton that will activate dragging the sprite.
public Rect worldBounds //世界边界,如果设置了的话会限制物体离开世界边界,Rect(0,0,0,0) 设置的话会以无边界处理
public bool dirtyChecks // 当 playing 时检查和设置处理的改变 , 会花费10fps,一般来说在项目开始之初才会用到
public delegate void ObjectDelegate(OTObject owner); //使用委托发送的一个消息
下面开始都是这样子的委托消息
public ObjectDelegate onInput = null;
public ObjectDelegate onOutOfView = null; 当物体移动过视野时响应
public ObjectDelegate onIntoView = null; 当物体进入视野时响应
/// To drag an object you must set <see cref="draggable" /> to true on the object that you want to drag.
public ObjectDelegate onDragStart = null; //开始委托这个物体时
<see cref="dropTarget" /> will contain the sprite where this one was dropped upon.
public ObjectDelegate onDragEnd = null; //委托这个物体之后时
/// This receiving object must have <see cref="registerInput" /> set to true. To drag an object you must set <see cref="draggable" /> to true on the object that you want to drag. /// <see cref="dropTarget" /> will contain the sprite that was dropped upon this one.
public ObjectDelegate onReceiveDrop = null; //另一个物体委托这个物体时
public ObjectDelegate onMouseMoveOT = null; /// Orthello mouse movement handler
public ObjectDelegate onMouseEnterOT = null; /// Orthello mouse enter handler
public ObjectDelegate onMouseExitOT = null; /// Orthello mouse exit handler
/// The onCollision delegate will be called if this object 'collidable' setting is set to true and if the
/// this OTObject collides with another 'collidable' OTObject.
public ObjectDelegate onCollision = null; /// Delegate to check collisions
/// The onEnter delegate will be called if this object 'collidable' setting is set to true and if the
/// this OTObject enters (starts to overlap) another 'collidable' OTObject.
public ObjectDelegate onEnter = null; /// Collision 'enter' delegate
public ObjectDelegate onExit = null; /// Collision 'exit' delegate
/// The onStay delegate will be called if this object 'collidable' setting is set to true and if the
/// this OTObject is overlapping another 'collidable' OTObject.
public ObjectDelegate onStay = null; /// Collision 'stay' delegate
public ObjectDelegate onDragEnd = null;
/// This receiving object must have <see cref="registerInput" /> set to true. To drag an object you must set <see cref="draggable" /> to true on the object that you want to drag.
/// <see cref="dropTarget" /> will contain the sprite that was dropped upon this one.
public ObjectDelegate onReceiveDrop = null; /// Is called when another object is drag'n dropped on this object
public ObjectDelegate onMouseMoveOT = null; /// Orthello mouse movement handler
public ObjectDelegate onMouseEnterOT = null; /// Orthello mouse enter handler
public ObjectDelegate onMouseExitOT = null; /// Orthello mouse exit handler
/// The onCollision delegate will be called if this object 'collidable' setting is set to true and if the
/// this OTObject collides with another 'collidable' OTObject.
public ObjectDelegate onCollision = null; /// Delegate to check collisions
/// The onEnter delegate will be called if this object 'collidable' setting is set to true and if the
/// this OTObject enters (starts to overlap) another 'collidable' OTObject.
public ObjectDelegate onEnter = null; /// Collision 'enter' delegate
public ObjectDelegate onExit = null; /// Collision 'exit' delegate
/// The onStay delegate will be called if this object 'collidable' setting is set to true and if the
/// this OTObject is overlapping another 'collidable' OTObject.
public ObjectDelegate onStay = null; /// Collision 'stay' delegate
有这些消息就可以进行回调函数了orz
public int collisionDepth /// Depth of collision layer 只有两个碰撞器处于同一层才会进行碰撞
public float collisionSize /// Depth (z) size of physical collider
public bool registerInput
public bool collidable
public ColliderType colliderType
public OTObject collisionObject
public Vector2 hitPoint ///这个点是一个相对的坐标点
public OTObject dropTarget ///
下面是Update
// Update is called once per frame
protected virtual void Update()
{
if (!OT.isValid || transform == null || gameObject == null) return;
if (!Application.isPlaying || dirtyChecks || OT.dirtyChecks)
{
if (registerInput != _registerInput_ && !registerInput && draggable)
draggable = false;
if (draggable && !registerInput)
_registerInput = true;
if (!RecordMode())
{
CheckSettings();
CheckDirty();
}
}
if (meshDirty)
{
transform.localScale = Vector3.one;
MeshFilter mf = GetComponent<MeshFilter>();
Mesh m = null;
if (Application.isPlaying)
{
m = mf.mesh;
mesh = GetMesh();
if (mesh != null)
mf.mesh = mesh;
}
else
{
m = mf.sharedMesh;
mesh = GetMesh();
if (mesh != null)
mf.sharedMesh = mesh;
}
if (mesh != null)
{
if (m != null && !isCopy)
{
if (Application.isPlaying)
Destroy(m);
else
DestroyImmediate(m);
}
meshDirty = false;
AfterMesh();
}
}
if (isDirty)
Clean();
if (isCopy)
isCopy = false;
if (controllers.Count > 0)
{
for (int c = 0; c < controllers.Count; c++)
{
OTController co = controllers[c];
if (co.enabled)
co.Update(Time.deltaTime);
}
}
}
又坑完一个orz