Пример #1
0
    /// <summary>
    /// Selects the previous character.
    /// </summary>
    public void SelectPrevious()
    {
        Demo_CharacterSelectChar prev = this.GetCharacterInDirection(-1f);

        if (prev != null)
        {
            this.SelectCharacter(prev);
        }
    }
Пример #2
0
    /// <summary>
    /// Selects the next character.
    /// </summary>
    public void SelectNext()
    {
        Demo_CharacterSelectChar next = this.GetCharacterInDirection(1f);

        if (next != null)
        {
            this.SelectCharacter(next);
        }
    }
Пример #3
0
    /// <summary>
    /// Gets the character in the specified direction (1 or -1).
    /// </summary>
    /// <param name="direction">The direction 1 or -1.</param>
    /// <returns></returns>
    public Demo_CharacterSelectChar GetCharacterInDirection(float direction)
    {
        if (this.m_Slots.Count == 0)
        {
            return(null);
        }

        if (this.m_SelectedTransform == null)
        {
            return(this.m_Slots[0].gameObject.GetComponent <Demo_CharacterSelectChar>());
        }

        Transform closest      = null;
        float     lastDistance = 0f;

        foreach (Transform trans in this.m_Slots)
        {
            // Skip the selected one
            if (trans.Equals(this.m_SelectedTransform))
            {
                continue;
            }

            float curDirection = trans.position.x - this.m_SelectedTransform.position.x;

            // Check direction
            if (direction > 0f && curDirection > 0f || direction < 0f && curDirection < 0f)
            {
                // If we have no closest assigned yet
                if (closest == null)
                {
                    closest      = trans;
                    lastDistance = Vector3.Distance(this.m_SelectedTransform.position, trans.position);
                    continue;
                }

                // Comapre distance
                if (Vector3.Distance(this.m_SelectedTransform.position, trans.position) <= lastDistance)
                {
                    closest      = trans;
                    lastDistance = Vector3.Distance(this.m_SelectedTransform.position, trans.position);
                }
            }
        }

        if (closest != null)
        {
            Demo_CharacterSelectChar character = closest.GetComponent <Demo_CharacterSelectChar>();

            if (character != null)
            {
                return(character);
            }
        }

        return(null);
    }
Пример #4
0
    /// <summary>
    /// Remove the character at the given index.
    /// </summary>
    /// <param name="index">The index.</param>
    public void RemoveCharacter(int index)
    {
        if (this.m_Slots.Count == 0)
        {
            return;
        }

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

        if (slotTrans == null)
        {
            return;
        }

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

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

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

        // Unset the character info texts
        if (index == this.m_SelectedIndex)
        {
            if (this.m_NameText != null)
            {
                this.m_NameText.text = "";
            }
            if (this.m_LevelText != null)
            {
                this.m_LevelText.text = "";
            }
            if (this.m_RaceClassText != null)
            {
                this.m_RaceClassText.text = "";
            }
        }
    }
Пример #5
0
    /// <summary>
    /// Selects the character.
    /// </summary>
    /// <param name="character">The character component.</param>
    public void SelectCharacter(Demo_CharacterSelectChar character)
    {
        // Check if already selected
        if (this.m_SelectedIndex == character.index)
        {
            return;
        }

        // Set the selected
        this.m_SelectedIndex     = character.index;
        this.m_SelectedTransform = character.transform;

        if (character.info != null)
        {
            // Set the texts
            if (this.m_NameText != null)
            {
                this.m_NameText.text = character.info.name;
            }
            if (this.m_LevelText != null)
            {
                this.m_LevelText.text = "Level " + character.info.level.ToString();
            }
            if (this.m_RaceClassText != null)
            {
                this.m_RaceClassText.text = character.info.raceString + " " + character.info.classString;
            }
        }
        else
        {
            if (this.m_NameText != null)
            {
                this.m_NameText.text = "";
            }
            if (this.m_LevelText != null)
            {
                this.m_LevelText.text = "";
            }
            if (this.m_RaceClassText != null)
            {
                this.m_RaceClassText.text = "";
            }
        }
    }
Пример #6
0
    /// <summary>
    /// Adds a character to the character select.
    /// </summary>
    /// <param name="info">The character info.</param>
    /// <param name="modelPrefab">The character model prefab.</param>
    /// <param name="index">Index.</param>
    public void AddCharacter(Demo_CharacterInfo info, GameObject modelPrefab, int index)
    {
        if (this.m_Slots.Count == 0)
        {
            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_CharacterSelectChar csc = slotTrans.gameObject.GetComponent <Demo_CharacterSelectChar>();

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

        // 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;
    }
Пример #7
0
    /// <summary>
    /// Selects the character at the given index.
    /// </summary>
    /// <param name="index"></param>
    public void SelectCharacter(int index)
    {
        if (this.m_Slots.Count == 0)
        {
            return;
        }

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

        if (slotTrans == null)
        {
            return;
        }

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

        // Select the character
        if (csc != null)
        {
            this.SelectCharacter(csc);
        }
    }