Esempio n. 1
0
    public void Setup()
    {
        // Get references to the components.
        m_Movement = m_Instance.GetComponent <TankMovement>();
        m_Shooting = m_Instance.GetComponent <TankShooting>();
        m_Health   = m_Instance.GetComponent <TankHealth>();
        m_Setup    = m_Instance.GetComponent <TankSetup>();

        // Get references to the child objects.
        m_TankRenderers = m_Health.m_TankRenderers;

        //Set a reference to that amanger in the health script, to disable control when dying
        m_Health.m_Manager = this;

        // Set the player numbers to be consistent across the scripts.
        m_Movement.m_PlayerNumber = m_PlayerNumber;
        m_Movement.m_LocalID      = m_LocalPlayerID;

        m_Shooting.m_PlayerNumber = m_PlayerNumber;
        m_Shooting.m_localID      = m_LocalPlayerID;

        //setup is use for diverse Network Related sync
        m_Setup.m_Color        = m_PlayerColor;
        m_Setup.m_PlayerName   = m_PlayerName;
        m_Setup.m_PlayerNumber = m_PlayerNumber;
        m_Setup.m_LocalID      = m_LocalPlayerID;
    }
Esempio n. 2
0
    // This is called whenever the tank takes damage.
    public void Damage(float amount, TankSetup m_playerOriginTankSetup)
    {
        // Reduce current health by the amount of damage done.
        m_CurrentHealth -= amount;

        // If the current health is at or below zero and it has not yet been registered, call OnZeroHealth.
        if (m_CurrentHealth <= 0f && !m_ZeroHealthHappened)
        {
            OnZeroHealth();
            if (m_TankSetup.m_AccountID == m_playerOriginTankSetup.m_AccountID)
            {
                m_TankSetup.CmdSetScore(-1);
                Debug.Log("You killed yourself!");
            }
            else
            {
                m_playerOriginTankSetup.CmdSetScore(1);
                Debug.Log($"{m_playerOriginTankSetup.m_PlayerDisplayName} killed {m_TankSetup.m_PlayerDisplayName}!");
            }
        }
        else
        {
            if (m_TankSetup.m_AccountID == m_playerOriginTankSetup.m_AccountID)
            {
                Debug.Log("You have taken damaged from: yourself!");
            }
            else
            {
                Debug.Log($"You have taken damaged from: {m_playerOriginTankSetup.m_PlayerDisplayName}!");
            }
        }
    }
Esempio n. 3
0
    private IEnumerator WaitForTankSetupInSceneByAccountId(string accountID, GameObject newRosterObject)
    {
        TankSetup tankSetup = null;

        while (tankSetup == null)
        {
            yield return(new WaitForSeconds((float)0.1));

            tankSetup = VivoxTankHelper.FindTankSetupInSceneByAccountId(accountID);
        }

        tankSetup.m_RosterItem = newRosterObject;
        newRosterObject.GetComponent <RectTransform>().sizeDelta = new Vector2(250, 100);
        var rosterItemText = newRosterObject.GetComponentInChildren <Text>();

        rosterItemText.text     = tankSetup.m_PlayerDisplayName;
        rosterItemText.color    = Color.white;
        rosterItemText.fontSize = 32;

        newRosterObject.GetComponent <RosterItem>().ChatStateImage.GetComponent <Image>().color = Color.white;
        var backgroundColor = newRosterObject.GetComponent <Image>();
        var bgColor         = tankSetup.m_TeamID == TeamColor.Blue ? Color.blue : Color.red;

        bgColor.a             = 0.25f;
        backgroundColor.color = bgColor;
    }
Esempio n. 4
0
    public void Setup()
    {
        // Get references to the components.
        m_Movement = m_Instance.GetComponent<TankMovement>();
        m_Shooting = m_Instance.GetComponent<TankShooting>();
        m_Health = m_Instance.GetComponent<TankHealth>();
        m_Setup = m_Instance.GetComponent<TankSetup>();

        // Get references to the child objects.
        m_TankRenderers = m_Health.m_TankRenderers;

        //Set a reference to that amanger in the health script, to disable control when dying
        m_Health.m_Manager = this;

        // Set the player numbers to be consistent across the scripts.
        m_Movement.m_PlayerNumber = m_PlayerNumber;
        m_Movement.m_LocalID = m_LocalPlayerID;

        m_Shooting.m_PlayerNumber = m_PlayerNumber;
        m_Shooting.m_localID = m_LocalPlayerID;

        //setup is use for diverse Network Related sync
        m_Setup.m_Color = m_PlayerColor;
        m_Setup.m_PlayerName = m_PlayerName;
        m_Setup.m_PlayerNumber = m_PlayerNumber;
        m_Setup.m_LocalID = m_LocalPlayerID;
    }
Esempio n. 5
0
    private BoxCollider m_Collider;                 // Used so that the tank doesn't collide with anything when it's dead.

    private void Awake()
    {
        m_Collider     = GetComponent <BoxCollider>();
        m_gameManager  = FindObjectOfType <GameManager>();
        m_TankMovement = GetComponent <TankMovement>();
        m_TankSetup    = GetComponent <TankSetup>();
        OnCurrentHealthChanged(m_StartingHealth);
    }
 private void Awake()
 {
     // Set up the references.
     m_Rigidbody   = GetComponent <Rigidbody>();
     m_gameManager = FindObjectOfType <GameManager>();
     m_tankSetup   = GetComponent <TankSetup>();
     if (!m_gameManager)
     {
         Debug.LogError("Unable to find GameManager object.");
     }
     m_AimSlider.minValue = m_MinLaunchForce;
     m_AimSlider.maxValue = m_MaxLaunchForce;
 }
Esempio n. 7
0
    public void AssignTeam(TankSetup player)
    {
        TeamColor team;

        if (BlueTeam.Count() == RedTeam.Count())
        {
            team = (TeamColor)UnityEngine.Random.Range(1, Enum.GetValues(typeof(TeamColor)).Length);
        }
        else
        {
            team = BlueTeam.Count > RedTeam.Count ? TeamColor.Red : TeamColor.Blue;
        }
        player.m_TeamID = team;
    }
Esempio n. 8
0
    private void ClearRoster(TankSetup player = null)
    {
        var uiElements = transform.GetComponentsInChildren <RectTransform>();

        if (uiElements.Length > 0)
        {
            foreach (var element in uiElements)
            {
                if (element.gameObject != this.gameObject)
                {
                    Destroy(element.gameObject);
                }
            }
        }
    }
Esempio n. 9
0
 private void OnPlayerListUpdated(TankSetup joiningPlayer)
 {
     if (TeamManager.Instance.LocalTeamID == joiningPlayer.m_TeamID)
     {
         ClearRoster();
         var teammates = TeamManager.Instance.LocalTeamID == TeamColor.Blue ? TeamManager.Instance.BlueTeam : TeamManager.Instance.RedTeam;
         if (teammates.Count() > 0)
         {
             foreach (var teammate in teammates)
             {
                 InstantiateTeammateUIElement(teammate);
             }
         }
     }
     // Don't do anything if the player joining isn't on the same team as the local player.
 }
Esempio n. 10
0
    private void InstantiateTeammateUIElement(TankSetup player)
    {
        GameObject newRosterObject = Instantiate(playerFab, this.gameObject.transform);

        StartCoroutine(WaitForTankSetupInSceneByAccountId(player.m_AccountID, newRosterObject));
    }
Esempio n. 11
0
    /// <summary>
    /// This is fired on all clients when the "Players" SyncList is updated on the server.
    /// </summary>
    private void OnPlayerListUpdated(SyncList <TankSetup> .Operation op, int itemIndex, TankSetup item)
    {
        switch (op)
        {
        case global::Mirror.SyncList <global::TankSetup> .Operation.OP_ADD:
        {
            OnPlayerAdded?.Invoke(item);
        }
        break;

        case global::Mirror.SyncList <global::TankSetup> .Operation.OP_CLEAR:
            break;

        case global::Mirror.SyncList <global::TankSetup> .Operation.OP_INSERT:
            break;

        case global::Mirror.SyncList <global::TankSetup> .Operation.OP_REMOVE:
        {
            OnPlayerRemoved?.Invoke(item);
        }
        break;

        case global::Mirror.SyncList <global::TankSetup> .Operation.OP_REMOVEAT:
            break;

        case global::Mirror.SyncList <global::TankSetup> .Operation.OP_SET:
            break;

        case global::Mirror.SyncList <global::TankSetup> .Operation.OP_DIRTY:
            break;

        default:
            break;
        }
    }