OT源代碼的分析,OrtHello 遲早攻破你 (三)OTObjectType 和OTMatRef 和OTObject

先說說最簡單的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.
    };


    public enum ColliderType
    {
        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

  

發佈了32 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章