示例#1
0
        /// <summary>
        /// Determines the location to respawn the object to and then does the respawn.
        /// </summary>
        public void Respawn()
        {
            m_ScheduledRespawnEvent = null;

            if (m_PositioningMode != SpawnPositioningMode.None)
            {
                Vector3    position;
                Quaternion rotation;
                if (m_PositioningMode == SpawnPositioningMode.SpawnPoint)
                {
                    position = m_Transform.position;
                    rotation = m_Transform.rotation;
                    // If the object can't be spawned then try again in the future.
                    if (!SpawnPointManager.GetPlacement(m_GameObject, m_Grouping, ref position, ref rotation))
                    {
                        m_ScheduledRespawnEvent = Scheduler.Schedule(Random.Range(m_MinRespawnTime, m_MaxRespawnTime), Respawn);
                        return;
                    }
                }
                else     // Spawn Location.
                {
                    position = m_StartPosition;
                    rotation = m_StartRotation;
                }

                Respawn(position, rotation, true);
            }
            else
            {
                Respawn(m_Transform.position, m_Transform.rotation, false);
            }
        }
示例#2
0
        /// <summary>
        /// Activates the specified demo zone.
        /// </summary>
        /// <param name="demoZone">The demo zone to active.</param>
        /// <param name="teleport">Should the character be teleported to the demo zone?</param>
        private void ActiveDemoZone(DemoZone demoZone, bool teleport)
        {
            // The ride ability should be force stopped.
            var ride = m_CharacterLocomotion.GetAbility <UltimateCharacterController.Character.Abilities.Ride>();

            if (ride != null && ride.IsActive)
            {
                m_CharacterLocomotion.TryStopAbility(ride, true);
            }
            if (m_ActiveZoneIndices.Count == 0 || m_ActiveZoneIndices[m_ActiveZoneIndices.Count - 1] != demoZone.Index)
            {
                m_ActiveZoneIndices.Add(demoZone.Index);
            }
            m_LastZoneIndex = demoZone.Index;
            ShowText(demoZone.Header, demoZone.Description, demoZone.Action);
            if (m_PreviousZoneArrow != null)
            {
                m_PreviousZoneArrow.SetActive(demoZone.Index != 0);
            }
            if (m_NextZoneArrow != null)
            {
                m_NextZoneArrow.SetActive(demoZone.Index != m_DemoZones.Length - 1);
            }
            m_EnterFrame = Time.frameCount;
            for (int i = 0; i < demoZone.EnableObjects.Length; ++i)
            {
                demoZone.EnableObjects[i].enabled = true;
            }
            for (int i = 0; i < demoZone.ToggleObjects.Length; ++i)
            {
                demoZone.ToggleObjects[i].SetActive(true);
            }

            // When the character reaches the outside section all doors should be unlocked.
            if (!m_AddOnDemoManager && !m_FullAccess && demoZone.Index >= m_DemoZones.Length - 6)
            {
                for (int i = 0; i < m_Doors.Count; ++i)
                {
                    m_Doors[i].CloseOnTriggerExit = false;
                    m_Doors[i].OpenClose(true, true, false);
                }
                m_FullAccess = true;
            }

            if (teleport)
            {
                var position = Vector3.zero;
                var rotation = Quaternion.identity;
                SpawnPointManager.GetPlacement(m_Character, demoZone.Index, ref position, ref rotation);
                m_CharacterLocomotion.SetPositionAndRotation(position, rotation, true);
            }

            // Set the group after the state so the default state doesn't override the grouping value.
            m_CharacterRespawner.Grouping = demoZone.Index;
        }
示例#3
0
        /// <summary>
        /// Spawns the character within the room. A manual spawn method is used to have complete control over the spawn location.
        /// </summary>
        /// <param name="newPlayer">The player that entered the room.</param>
        public void SpawnPlayer(Player newPlayer)
        {
            // Only the master client can spawn new players.
            if (!PhotonNetwork.IsMasterClient)
            {
                return;
            }

            // Spawn the new player based on the spawn mode.
            var spawnPosition = Vector3.zero;
            var spawnRotation = Quaternion.identity;

            //determines spawn location based on team
            m_SpawnPointGrouping = isMonster(newPlayer) ? 1 : 0;
            if (!SpawnPointManager.GetPlacement(null, m_SpawnPointGrouping, ref spawnPosition, ref spawnRotation))
            {
                Debug.LogWarning("Warning: The Spawn Point Manager is unable to determine a spawn location for grouping " + m_SpawnPointGrouping + ". " +
                                 "Consider adding more spawn points.");
            }
            spawnPosition += m_PlayerCount * m_SpawnLocationOffset;


            // Instantiate the player and let the PhotonNetwork know of the new character.
            var player     = GameObject.Instantiate(GetCharacterPrefab(newPlayer), spawnPosition, spawnRotation);
            var photonView = player.GetComponent <PhotonView>();

            photonView.ViewID = PhotonNetwork.AllocateViewID(newPlayer.ActorNumber);
            if (photonView.ViewID > 0)
            {
                // The character has been created. All other clients need to instantiate the character as well.
                var data = new object[]
                {
                    player.transform.position, player.transform.rotation, photonView.ViewID
                };
                m_RaiseEventOptions.TargetActors = null;
                PhotonNetwork.RaiseEvent(PhotonEventIDs.PlayerInstantiation, data, m_RaiseEventOptions, m_ReliableSendOption);

                // The new player should instantiate all existing characters in addition to their character.
                if (newPlayer != PhotonNetwork.LocalPlayer)
                {
                    // Deactivate the character until the remote machine has the chance to create it. This will prevent the character from
                    // being active on the Master Client without being able to be controlled.
                    player.SetActive(false);

                    data = new object[m_PlayerCount * 3];
                    for (int i = 0; i < m_PlayerCount; ++i)
                    {
                        data[i * 3]     = m_Players[i].transform.position;
                        data[i * 3 + 1] = m_Players[i].transform.rotation;
                        data[i * 3 + 2] = m_Players[i].ViewID;
                    }
                    m_RaiseEventOptions.TargetActors = new int[] { newPlayer.ActorNumber };
                    PhotonNetwork.RaiseEvent(PhotonEventIDs.PlayerInstantiation, data, m_RaiseEventOptions, m_ReliableSendOption);
                }

                AddPhotonView(photonView);
                EventHandler.ExecuteEvent("OnPlayerEnteredRoom", photonView.Owner, photonView.gameObject);
            }
            else
            {
                Debug.LogError("Failed to allocate a ViewId.");
                Destroy(player);
            }
        }