Пример #1
0
        public GameObject GetPrefab()
        {
            if (prefab == null || currentRoleID != oldRoleID) //create a new prefab if either the prefab has not been originally created yet or the roleID has changed (currentRoleID != oldRoleID)
            {
                if (prefab != null)                           //destroy the old prefab
                {
                    if (Application.isPlaying)                //are we in play mode
                    {
                        GameObject.Destroy(prefab);
                    }
                    else
                    {
                        GameObject.DestroyImmediate(prefab);
                    }
                }

                prefab = new GameObject(faceName); Debug.Log("Creating a " + faceName + " prefab.");
                prefab.SetActive(false);
                SpriteRenderer sRen = prefab.AddComponent <SpriteRenderer> ();
                sRen.sprite         = mainSprite;
                sRen.sortingLayerID = SortingLayer.NameToID(spriteSortingLayerName);
                switch (currentRoleID)
                {
                case TileRoleID.FullWall:
                    prefab.AddComponent <BoxCollider2D> ();
                    break;

                case TileRoleID.PlainFloor:
                    break;
                }
                oldRoleID = currentRoleID;
            }

            return(prefab);
        }
Пример #2
0
 //will return null if a tiletype with the specified role cannot be found
 public TileType FindRole(TileRoleID roleID)
 {
     return(tileTypes.Find((tType) => tType.currentRoleID == roleID));
 }