private void Start() { if (floorPanel == null) { floorPanel = FloorPanel.Instance; } }
void OnTriggerExit(Collider other) { if (other.tag != "Floor") { return; } currentGround = null; }
void OnTriggerStay(Collider other) { if (other.tag != "Floor") { return; } currentGround = other.gameObject.GetComponent <FloorPanel>(); }
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); } }
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()); }
// 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 }