Exemplo n.º 1
0
 private void Start()
 {
     if (floorPanel == null)
     {
         floorPanel = FloorPanel.Instance;
     }
 }
Exemplo n.º 2
0
 void OnTriggerExit(Collider other)
 {
     if (other.tag != "Floor")
     {
         return;
     }
     currentGround = null;
 }
Exemplo n.º 3
0
 void OnTriggerStay(Collider other)
 {
     if (other.tag != "Floor")
     {
         return;
     }
     currentGround = other.gameObject.GetComponent <FloorPanel>();
 }
Exemplo n.º 4
0
 public void GenerateFloorButtons(int floors, Action <int, FloorPanel.Direction> onFloorPanelClicked)
 {
     for (int i = 0; i < floors; i++)
     {
         FloorPanel newPanel = Instantiate(FloorPanelPrefab, Vector3.zero, Quaternion.identity, FloorPanelsContent).GetComponent <FloorPanel>();
         newPanel.InitFloor(i, onFloorPanelClicked, i == floors - 1, i == 0);
         _panels.Add(newPanel);
     }
 }
Exemplo n.º 5
0
 public void Init(int floors, Action <int, FloorPanel.Direction> onFloorPanelClicked)
 {
     for (int i = 0; i < floors; i++)
     {
         FloorPanel newPanel = Instantiate(ShaftPanelPrefab, Vector3.zero, Quaternion.identity, FloorsParent).GetComponent <FloorPanel>();
         newPanel.InitFloor(i, onFloorPanelClicked, i == floors - 1, i == 0);
         _panels.Add(newPanel);
         newPanel.transform.SetAsFirstSibling();
     }
     Cabin.SetAsLastSibling();
     Cabin.sizeDelta = _floorSize * Vector2.one;
     ChangePosition(0);
     StartCoroutine(MoveToBottom());
 }
Exemplo n.º 6
0
        // Loading into level editor
        public static void DeserializeDungeonToEditor(
            string json,
            EntitiesPanel entitiesPanel,
            GameObject boosterPrefab,
            GameObject enemyPrefab,
            PlayerPanel playerPanel,
            FloorPanel floorPanel,
            GameObject floorListingPrefab,
            GameObject floorPrefab,
            GameObject elementPrefab,
            GameObject upStairsPrefab,
            GameObject downStairsPrefab
            )
        {
            Dungeon dungeon = JsonUtility.FromJson <Dungeon>(json);

            // setup starting values
            StartingValues values = dungeon.StartingValues;

            playerPanel.Init(
                values.Life,
                values.Power,
                values.Defense,
                values.Stars,
                values.GoldKeys,
                values.BlueKeys,
                values.RedKeys);

            // setup entities
            Transform tileHolder = entitiesPanel.TileHolder;

            Addable[] addables = dungeon.Addables;
            foreach (Addable addable in addables)
            {
                GameObject  go;
                AddableTile at;
                switch (addable.AddableType)
                {
                case AddableType.BOOSTER:
                    BoosterData booster = addable.BoosterData;
                    go = GameObject.Instantiate(boosterPrefab, tileHolder);
                    at = go.GetComponent <AddableTile>();
                    at.ChooseBoostedStat(booster.StatToBoost);
                    at.BoostedAmount = booster.AmountBoosted;
                    at.SetSprite(booster.SpriteID, AddableType.BOOSTER);
                    break;

                case AddableType.ENEMY:
                    EnemyData enemy = addable.EnemyData;
                    go = GameObject.Instantiate(enemyPrefab, tileHolder);
                    at = go.GetComponent <AddableTile>();
                    at.SetSprite(enemy.SpriteID, AddableType.ENEMY);
                    at.InitEnemy(enemy.Life, enemy.Power, enemy.Defense, enemy.Stars);
                    break;
                }
            }

            AddableTile[] addableTiles      = tileHolder.GetComponentsInChildren <AddableTile>();
            FloorListing  firstFloorListing = null;

            // setup floors
            Floor[] floors = dungeon.Floors;
            for (int i = 0; i < floors.Length; i++)
            {
                Floor         floor          = floors[i];
                GameObject    floorGo        = GameObject.Instantiate(floorPrefab, floorPanel.FloorParent);
                GameObject    floorListingGo = GameObject.Instantiate(floorListingPrefab, floorPanel.FloorListingParent);
                FloorListing  floorListing   = floorListingGo.GetComponent <FloorListing>();
                EditableFloor editableFloor  = floorGo.GetComponent <EditableFloor>();
                floorListing.Init(i, editableFloor);

                if (i == 0)   // first floor
                {
                    firstFloorListing = floorListing;
                }

                EditableTile[] tiles   = floorGo.GetComponentsInChildren <EditableTile>(true);
                int[]          indices = floor.Indices;
                // same range as serialized array
                for (int j = 0; j < tiles.Length; j++)
                {
                    EditableTile tile  = tiles[j];
                    int          index = indices[j];
                    if (index != NO_ELEMENT)
                    {
                        AddableTile source       = addableTiles[index];
                        GameObject  chosenPrefab = null;

                        // up and down stairs use a special prefab
                        if (source.TileType == TileType.UP_STAIRS)
                        {
                            chosenPrefab = upStairsPrefab;
                        }
                        else if (source.TileType == TileType.DOWN_STAIRS)
                        {
                            chosenPrefab = downStairsPrefab;
                        }
                        else
                        {
                            chosenPrefab = elementPrefab;
                        }
                        GameObject elementGo = GameObject.Instantiate(chosenPrefab, tile.transform);
                        elementGo.GetComponent <Element>().Init(source);
                    }
                }
            }
            floorPanel.Selected = firstFloorListing; // do this last so the other floors are properly disabled
        }