Esempio n. 1
0
        /// <summary>
        /// Create new OverlayObject 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 StaticBlockerObject Create(GridCell parent, StaticBlockerData oData, bool addCollider, bool isTrigger, Action <int> TargetCollectEvent)
        {
            if (!parent || oData == null)
            {
                return(null);
            }
            GameObject          gO         = null;
            SpriteRenderer      sR         = null;
            StaticBlockerObject gridObject = null;

            sR = Creator.CreateSprite(parent.transform, oData.ObjectImage, parent.transform.position);
            gO = sR.gameObject;

            gridObject = gO.GetOrAddComponent <StaticBlockerObject>();

            if (addCollider)
            {
                BoxCollider2D cC = gridObject.gameObject.GetOrAddComponent <BoxCollider2D>();
                cC.isTrigger = isTrigger;
            }
#if UNITY_EDITOR
            gO.name = "static blocker " + parent.ToString();
#endif
            gridObject.SetData(oData);
            gridObject.SRenderer          = sR;
            gridObject.TargetCollectEvent = TargetCollectEvent;
            return(gridObject);
        }
Esempio n. 2
0
        internal void SetStaticBlockerObject(StaticBlockerData mObjectData)
        {
            if (mObjectData == null || IsDisabled || Blocked)
            {
                return;
            }
            // Debug.Log("set static blocker: " + mObjectData.ID);
            if (DynamicObject)
            {
                GameObject old = DynamicObject;
                DestroyImmediate(old);
            }
            if (StaticBlocker)
            {
                GameObject old = StaticBlocker.gameObject;
                DestroyImmediate(old);
            }

            StaticBlockerObject.Create(this, mObjectData, false, true, MBoard.TargetCollectEventHandler);
            StaticBlocker.SetToFront(false);
        }