Example #1
0
        /// <summary>
        /// Called after switching to a new MasterClient when the current one leaves.
        /// Here the new master has to decide whether to enable the object in the scene.
        /// </summary>
        public override void OnMasterClientSwitched(Photon.Realtime.Player newMaster)
        {
            //only execute on the new master client
            if (PhotonNetwork.LocalPlayer != newMaster)
            {
                return;
            }

            //defining cases in which the SpawnRoutine should be skipped
            switch (colType)
            {
            case CollectionType.Use:
                //the object is already active thus do not trigger a respawn coroutine
                if (obj != null && obj.activeInHierarchy)
                {
                    return;
                }
                break;

            case CollectionType.Pickup:
                //in addition to the check above, here we check for the current state too
                //if the item is not being carried around and at the home base we can skip the respawn
                if (obj != null && obj.activeInHierarchy &&
                    obj.transform.parent == PoolManager.GetPool(obj).transform&&
                    obj.transform.position == transform.position)
                {
                    return;
                }
                break;
            }

            StartCoroutine(SpawnRoutine());
        }
Example #2
0
        public void Drop(Vector3 position)
        {
            //in case this method call is received over the network earlier than the
            //spawner instantiation, here we make sure to catch up and instantiate it directly
            if (obj == null)
            {
                Instantiate();
            }

            //re-parent object to this spawner
            obj.transform.parent   = PoolManager.GetPool(obj).transform;
            obj.transform.position = position;

            //reset carrier
            Collectible colItem = obj.GetComponent <Collectible>();

            if (colItem != null)
            {
                colItem.carrierId = -1;
                colItem.OnDrop();
            }

            //update respawn counter for a future point in time
            SetRespawn();
            //if the respawn mechanic is selected, trigger a new coroutine
            if (PhotonNetwork.IsMasterClient && respawn)
            {
                StopAllCoroutines();
                StartCoroutine(SpawnRoutine());
            }
        }
Example #3
0
        public void Return()
        {
            //re-parent object to this spawner
            obj.transform.parent   = PoolManager.GetPool(obj).transform;
            obj.transform.position = transform.position;

            //reset carrier
            Collectible colItem = obj.GetComponent <Collectible>();

            if (colItem != null)
            {
                colItem.carrierId = -1;
                colItem.OnReturn();
            }

            //cancel return timer as the object is now back at its base position
            if (PhotonNetwork.IsMasterClient)
            {
                StopAllCoroutines();
            }
        }
Example #4
0
        /// <summary>
        /// Returns the object back to this spawner's position. E.g. in Capture The Flag mode this
        /// can occur if a team collects its own flag, or a flag timed out after being dropped.
        /// </summary>
        public void Return()
        {
            //re-parent object to this spawner
            obj.transform.parent   = PoolManager.GetPool(obj).transform;
            obj.transform.position = transform.position;
            obj.transform.rotation = Quaternion.identity;

            //reset carrier
            Collectible colItem = obj.GetComponent <Collectible>();

            if (colItem != null)
            {
                colItem.carrierId = new NetworkInstanceId(0);
                colItem.OnReturn();
            }

            //cancel return timer as the object is now back at its base position
            if (isServer)
            {
                StopAllCoroutines();
            }
        }
Example #5
0
        /// <summary>
        /// Synchronizes current active state of the object to joining players.
        /// </summary>
        public override void OnPlayerEnteredRoom(Photon.Realtime.Player player)
        {
            //don't execute as a non-master, but also don't execute it for the master itself
            if (!PhotonNetwork.IsMasterClient || player.IsMasterClient)
            {
                return;
            }

            //the object is active in the scene on the master. Thus send an instantiate call
            //to the joining player so the object gets enabled/instantiated on that client too
            if (obj != null && obj.activeInHierarchy)
            {
                this.photonView.RPC("Instantiate", player);
            }

            //defining cases in which the SetRespawn method should be called instead
            switch (colType)
            {
            case CollectionType.Use:
                //on the master the object is not active in the scene. As a client we have to know the
                //remaining respawn time so we are able to take over in a host migration scenario
                if (obj == null || !obj.activeInHierarchy)
                {
                    this.photonView.RPC("SetRespawn", player, nextSpawn);
                }
                break;

            case CollectionType.Pickup:
                //in addition to the check above, here we check for the current state too
                //if the item got dropped, the master should send an updated respawn time as well
                if (obj == null || !obj.activeInHierarchy ||
                    (obj.transform.parent != PoolManager.GetPool(obj).transform&& obj.transform.position != transform.position))
                {
                    this.photonView.RPC("SetRespawn", player, nextSpawn);
                }
                break;
            }
        }