/// <summary> /// Create new DynamicBlockerObject 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 DynamicBlockerObject Create(GridCell parent, DynamicBlockerData oData, bool addCollider, bool isTrigger, Action <int> TargetCollectEvent) { if (!parent || oData == null) { return(null); } GameObject gO = null; SpriteRenderer sR = null; DynamicBlockerObject gridObject = null; sR = Creator.CreateSprite(parent.transform, oData.ObjectImage, parent.transform.position); gO = sR.gameObject; gridObject = gO.GetOrAddComponent <DynamicBlockerObject>(); if (addCollider) { BoxCollider2D cC = gridObject.gameObject.GetOrAddComponent <BoxCollider2D>(); cC.isTrigger = isTrigger; } #if UNITY_EDITOR gO.name = "dynamic blocker " + parent.ToString(); #endif gridObject.SetData(oData); gridObject.SRenderer = sR; gridObject.TargetCollectEvent = TargetCollectEvent; return(gridObject); }
internal void SetDynamicBlockerObject(DynamicBlockerData mObjectData) { if (mObjectData == null || IsDisabled || Blocked) { return; } // Debug.Log("set dynamic blocker: " + mObjectData.ID); if (DynamicObject) { GameObject old = DynamicObject; DestroyImmediate(old); } if (StaticBlocker) { GameObject old = StaticBlocker.gameObject; DestroyImmediate(old); } DynamicBlockerObject.Create(this, mObjectData, false, true, MBoard.TargetCollectEventHandler); DynamicBlocker.SetToFront(false); }