예제 #1
0
        /// <summary>
        /// Create new MainObject for gridcell
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="oData"></param>
        /// <param name="addCollider"></param>
        /// <param name="radius"></param>
        /// <param name="isTrigger"></param>
        /// <returns></returns>
        public static FallingObject Create(GridCell parent, FallingObjectData oData, bool addCollider, bool isTrigger, Action <int> TargetCollectEvent)
        {
            if (!parent || oData == null)
            {
                return(null);
            }
            SpriteRenderer sR         = Creator.CreateSprite(parent.transform, oData.ObjectImage, parent.transform.position);
            GameObject     gO         = sR.gameObject;
            FallingObject  gridObject = gO.AddComponent <FallingObject>();

            if (addCollider)
            {
                BoxCollider2D cC = gridObject.gameObject.GetOrAddComponent <BoxCollider2D>();
                cC.isTrigger = isTrigger;
            }

            if (oData.iddleAnimPrefab)
            {
                Creator.InstantiatePrefab(oData.iddleAnimPrefab, gridObject.transform, gridObject.transform.position, 0, SortingOrder.MainToFront);
            }

            gridObject.SRenderer          = sR;
            gridObject.TargetCollectEvent = TargetCollectEvent;
            gridObject.SetData(oData);
            return(gridObject);
        }
예제 #2
0
        internal virtual void SetData(FallingObjectData oData)
        {
            SRenderer = GetComponent <SpriteRenderer>();
            if (SRenderer)
            {
                SRenderer.sprite = (oData != null) ? oData.ObjectImage : null;
            }
            OData = oData;
#if UNITY_EDITOR
            gameObject.name = (oData != null) ? "Falling: " + GetID() + "(" + SRenderer.sprite.name + ")" : "none";
#endif
            SetToFront(false);
        }
예제 #3
0
 internal void SetFalling(FallingObjectData mObjectData)
 {
     if (mObjectData == null || IsDisabled || Blocked)
     {
         return;
     }
     //  Debug.Log("set falling: " + mObjectData.ID);
     if (DynamicObject)
     {
         GameObject old = DynamicObject;
         DestroyImmediate(old);
     }
     if (StaticBlocker)
     {
         GameObject old = StaticBlocker.gameObject;
         DestroyImmediate(old);
     }
     FallingObject.Create(this, mObjectData, false, true, MBoard.TargetCollectEventHandler);//.gameObject;
     Falling.SetToFront(false);
 }