コード例 #1
0
 // Constructs default ability data for each ability named in BattleMode.
 // Used only in case of read error.
 void SetAbilityDataDefaultValues()
 {
     abilityStatData.Clear();
     foreach (BattleMode name in BattleMode.GetValues(typeof(BattleMode)))
     {
         abilityStatData.Add(name, new BattleAbility(name));
     }
 }
コード例 #2
0
    // Called just before being set active. Called by BattleManager.Click_Magic()
    // Used once in whole, but subsequently only sets HeroType.
    // Requires a HeroType to know what spells to set.
    public void Initialize(HeroType type)
    {
        // Set type before setting active.
        this.type = type;

        // The rest is only performed once.
        if (!initialized)
        {
            initialized = true;

            // Collect height from template
            float height = spellText.rectTransform.rect.height * spellText.rectTransform.localScale.y;

            // define 6 positions based on height and onset, for later use
            positions[0] = spellText.transform.localPosition;
            positions[1] = new Vector2(positions[0].x, positions[0].y - height);
            positions[2] = new Vector2(positions[0].x, positions[0].y - (2 * height));
            positions[3] = new Vector2(positions[0].x + SecondColumnXOffset, positions[0].y);
            positions[4] = new Vector2(positions[0].x + SecondColumnXOffset, positions[0].y - height);
            positions[5] = new Vector2(positions[0].x + SecondColumnXOffset, positions[0].y - (2 * height));

            // Store reference to parentTransform
            Transform parentTransform = spellText.transform.parent.transform;

            // Create a text object for each spell in the BattleMode enum, using spellText as template
            foreach (BattleMode mode in BattleMode.GetValues(typeof(BattleMode)))
            {
                if (mode.ToString().StartsWith("Magic_"))
                {
                    string name = mode.ToString().Substring(6);

                    GameObject newText = GameObject.Instantiate(spellText.gameObject);
                    newText.transform.SetParent(parentTransform);
                    newText.transform.localScale       = spellText.transform.localScale;
                    newText.GetComponent <Text>().text = name;

                    newText.GetComponent <SpellClick>().SetMode(mode, this);

                    spellTexts.Add(newText.GetComponent <Text>());
                }
            }

            // Destroy template
            Destroy(spellText.gameObject);

            // Place ALL spellTexts using 6 positions
            for (int i = 0; i < spellTexts.Count; i++)
            {
                spellText.transform.localPosition = positions[i];
            }
        }
    }