Beispiel #1
0
        /// <summary>
        /// spawn all heroes
        /// </summary>
        private void SpawnHeroes()
        {
            int         playerCounter = 1;
            List <Team> teamList      = GameManager.GetInstance().GetAllTeams();

            for (int i = 0; i < teamList.Count; i++)
            {
                List <Hero> heroList = teamList[i].GetHeroTeamMembers();

                for (int j = 0; j < heroList.Count; j++)
                {
                    Hero h = heroList[j];
                    h          = ((GameObject)Instantiate(h.gameObject)).GetComponent <Hero>();
                    h.PlayerNo = playerCounter;
                    playerCounter++;
                    h.Type        = heroList[j].Type;
                    h.DisplayName = heroList[j].DisplayName;
                    h.name        = "Hero" + h.PlayerNo;
                    teamList[i].RemoveMember(heroList[j]);
                    teamList[i].AddMember(h);
                    h.SpecialRespawn();
                }
            }

            for (int k = 0; k < GameManager.GetInstance().HeroCount; k++)
            {
                Debug.Log("[CharacterSelection.cs] Add AI hero");
                Hero choosenCharacter = ((GameObject)Instantiate(Datasheet.Heroes()[0])).GetComponent <Hero>();
                choosenCharacter.name = "Hero" + playerCounter + "KI";
                playerCounter++;
                choosenCharacter.Type = Hero.Types.AI;

                Debug.Log("Spawn AI: " + choosenCharacter.name);
                choosenCharacter.SpecialRespawn();

                if (GameManager.GetInstance().TeamCount == 1)
                {
                    teamList[0].AddMember(choosenCharacter);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Instantiates Heroes over Network
        /// </summary>
        private void NetworkHeroSpawning()
        {
            // Get hero components
            int  teamNo = _net.TeamNumber;
            Team myTeam = GameManager.GetInstance().GetTeam(teamNo);

            UnityEngine.Object prefab = Resources.Load("Heroes/" + _net.Character);

            // initialise
            Hero hero = ((GameObject)Network.Instantiate(prefab, Vector3.zero, Quaternion.identity, 0)).GetComponent <Hero>();

            // set/prepare defaults
            string oldName = hero.name;

            hero.PlayerNo = 1;
            hero.Type     = Character.Types.HUMAN;
            string objectName;

            if (_net.IsServer)
            {
                objectName = "HeroServer";
            }
            else
            {
                objectName = "HeroClient" + _net.ClientNumber;
            }

            string displayName = (!_net.Username.Equals(string.Empty)) ? _net.Username : hero.DisplayName;

            hero.DisplayName = displayName;
            hero.name        = objectName;

            // set team
            myTeam.AddMember(hero);
            hero.Team = myTeam;

            // synchronize
            networkView.RPC("AddHero", RPCMode.Others, oldName, hero.name, teamNo, displayName);
            hero.SpecialRespawn();
        }