Ejemplo n.º 1
0
        /// <summary>
        /// Sets the character info.
        /// </summary>
        /// <param name="info">The character info.</param>
        public void SetCharacterInfo(Demo_CharacterInfo info)
        {
            if (info == null)
            {
                return;
            }

            if (this.m_NameText != null)
            {
                this.m_NameText.text = info.name.ToUpper();
            }
            if (this.m_LevelText != null)
            {
                this.m_LevelText.text = info.level.ToString();
            }
            if (this.m_RaceText != null)
            {
                this.m_RaceText.text = info.raceString;
            }
            if (this.m_ClassText != null)
            {
                this.m_ClassText.text = info.classString;
            }

            // Set the character info
            this.m_CharacterInfo = info;
        }
        protected void Start()
        {
            // Add characters for the demo
            if (this.m_IsDemo && this.m_CharacterPrefab)
            {
                for (int i = 0; i < this.m_AddCharacters; i++)
                {
                    string[] names = new string[10] {
                        "Annika", "Evita", "Herb", "Thad", "Myesha", "Lucile", "Sharice", "Tatiana", "Isis", "Allen"
                    };
                    string[] races = new string[5] {
                        "Human", "Elf", "Orc", "Undead", "Programmer"
                    };
                    string[] classes = new string[5] {
                        "Warrior", "Mage", "Hunter", "Priest", "Designer"
                    };

                    Demo_CharacterInfo info = new Demo_CharacterInfo();
                    info.name        = names[Random.Range(0, 10)];
                    info.raceString  = races[Random.Range(0, 5)];
                    info.classString = classes[Random.Range(0, 5)];
                    info.level       = (int)Random.Range(1, 61);

                    this.AddCharacter(info, this.m_CharacterPrefab, i);
                }
            }

            // Select the first character
            this.SelectFirstAvailable();
        }
        /// <summary>
        /// Adds a character to the slot at the specified index.
        /// </summary>
        /// <param name="info">The character info.</param>
        /// <param name="modelPrefab">The character model prefab.</param>
        /// <param name="index">Slot index.</param>
        public void AddCharacter(Demo_CharacterInfo info, GameObject modelPrefab, int index)
        {
            if (this.m_Slots.Count == 0 || this.m_Slots.Count < (index + 1))
            {
                return;
            }

            if (modelPrefab == null)
            {
                return;
            }

            // Get the slot
            Transform slotTrans = this.m_Slots[index];

            // Make sure we have a slot transform
            if (slotTrans == null)
            {
                return;
            }

            // Get the character script
            Demo_CharacterSelectSlot csc = slotTrans.gameObject.GetComponent <Demo_CharacterSelectSlot>();

            // Set the character info
            if (csc != null)
            {
                csc.info  = info;
                csc.index = index;
            }

            // Remove any child objects
            foreach (Transform child in slotTrans)
            {
                Destroy(child.gameObject);
            }

            // Add the character model
            GameObject model = Instantiate <GameObject>(modelPrefab);

            model.layer = slotTrans.gameObject.layer;
            model.transform.SetParent(slotTrans, false);
            model.transform.localScale    = modelPrefab.transform.localScale;
            model.transform.localPosition = modelPrefab.transform.localPosition;
            model.transform.localRotation = modelPrefab.transform.localRotation;
        }
        /// <summary>
        /// Adds a character to the character list.
        /// </summary>
        /// <param name="info">The character info.</param>
        /// <param name="selected">In the character should be selected.</param>
        public void AddCharacter(Demo_CharacterInfo info, bool selected)
        {
            if (this.m_CharacterPrefab == null || this.m_CharactersContainer == null)
            {
                return;
            }

            // Add the character
            GameObject model = Instantiate <GameObject>(this.m_CharacterPrefab);

            model.layer = this.m_CharactersContainer.gameObject.layer;
            model.transform.SetParent(this.m_CharactersContainer, false);
            model.transform.localScale    = this.m_CharacterPrefab.transform.localScale;
            model.transform.localPosition = this.m_CharacterPrefab.transform.localPosition;
            model.transform.localRotation = this.m_CharacterPrefab.transform.localRotation;

            // Get the character component
            Demo_CharacterSelectList_Character character = model.GetComponent <Demo_CharacterSelectList_Character>();

            if (character != null)
            {
                // Set the info
                character.SetCharacterInfo(info);

                // Set the toggle group
                character.SetToggleGroup(this.m_ToggleGroup);

                // Set the selected state
                character.SetSelected(selected);

                // Add on select listener
                character.AddOnSelectListener(OnCharacterSelected);

                // Add on delete listener
                character.AddOnDeleteListener(OnCharacterDeleteRequested);
            }
        }
        protected void Start()
        {
            // Clear the characters container
            if (this.m_CharactersContainer != null)
            {
                foreach (Transform t in this.m_CharactersContainer)
                {
                    Destroy(t.gameObject);
                }
            }

            // Add characters for the demo
            if (this.m_IsDemo && this.m_CharacterPrefab)
            {
                for (int i = 0; i < this.m_AddCharacters; i++)
                {
                    string[] names = new string[10] {
                        "Annika", "Evita", "Herb", "Thad", "Myesha", "Lucile", "Sharice", "Tatiana", "Isis", "Allen"
                    };
                    string[] races = new string[5] {
                        "Human", "Elf", "Orc", "Undead", "Programmer"
                    };
                    string[] classes = new string[5] {
                        "Warrior", "Mage", "Hunter", "Priest", "Designer"
                    };

                    Demo_CharacterInfo info = new Demo_CharacterInfo();
                    info.name        = names[Random.Range(0, 10)];
                    info.raceString  = races[Random.Range(0, 5)];
                    info.classString = classes[Random.Range(0, 5)];
                    info.level       = (int)Random.Range(1, 61);

                    this.AddCharacter(info, (i == 0));
                }
            }
        }