コード例 #1
0
 public void UpdateButton(Unit unitForButton)
 {
     if (buttons.ContainsKey(unitForButton.unitName))
     {
         buttonSelection.UpdateButton(unitForButton);
     }
 }
コード例 #2
0
ファイル: GameMaster.cs プロジェクト: hines-r/pixel-chaos
    void LoadUnits(GameData data)
    {
        Dictionary <string, UnitButton> unitButtons = unitSelectionUI.buttons;

        for (int i = 0; i < data.unlockedUnits.Count; i++)
        {
            // Gets the unit that needs to be loaded in and sets appropriate level and active status
            string unitName = data.unlockedUnits[i];

            Unit unitToLoad = null;

            if (!UnitManager.instance.unlockedUnits.ContainsKey(unitName))
            {
                // If the standard unit name from the button doesn't match, it is an awoken unit
                if (unitButtons[unitName].unit.unitName != unitName)
                {
                    // Searches available awoken units to find correct name
                    // Sets the awoken unit to the unit to be loaded
                    foreach (AwokenUnit awokenUnit in unitButtons[unitName].awokenUnitOptions)
                    {
                        if (unitName == awokenUnit.unitName)
                        {
                            unitToLoad = Instantiate(awokenUnit);
                            break;
                        }
                    }
                }
                else
                {
                    unitToLoad = Instantiate(unitButtons[unitName].unit);
                }

                unitToLoad.SetLevel(data.unitLevels[i]);
                unitToLoad.gameObject.SetActive(data.unitActiveStatuses[i]);
                unitToLoad.unitAI           = data.unitActiveAI[i];
                unitToLoad.transform.parent = UnitManager.instance.transform;
                UnitManager.instance.UnlockUnit(unitToLoad);

                // Updates the button within unit selection panel with original unit status
                UnitButton buttonToUpdate = unitButtons[unitName];
                buttonToUpdate.UnlockButton();
                buttonToUpdate.UpdateButton(unitToLoad);

                if (data.nodeUnitNames.Contains(unitName))
                {
                    int  nodeIndex    = data.nodeUnitNames.IndexOf(unitName);
                    Node nodeWithUnit = UnitManager.instance.nodes[nodeIndex];
                    nodeWithUnit.PlaceUnit(unitToLoad);
                }
            }
        }
    }