Ejemplo n.º 1
0
        /// <summary>
        /// Internal method which spawns the object over the network. This does not instantiate a new object on the local client.
        /// </summary>
        /// <param name="original">The object that the object was instantiated from.</param>
        /// <param name="instanceObject">The object that was instantiated from the original object.</param>
        protected override void NetworkSpawnInternal(GameObject original, GameObject instanceObject)
        {
            int index;

            if (!m_SpawnableGameObjectIDMap.TryGetValue(original, out index))
            {
                Debug.LogError("Error: Unable to spawn " + original.name + " on the network. Ensure the object has been added to the PunObjectPool.");
                return;
            }

            m_ActiveGameObjects.Add(instanceObject, instanceObject.GetCachedComponent <ISpawnDataObject>());
            if (!m_SpawnedGameObjects.Contains(instanceObject))
            {
                m_SpawnedGameObjects.Add(instanceObject);
            }

            var photonView = instanceObject.GetCachedComponent <PhotonView>();

            if (photonView.ViewID != 0 || PhotonNetwork.AllocateSceneViewID(photonView))
            {
                // The pooled object can optionally provide initialization spawn data.
                var      spawnDataObject = instanceObject.GetCachedComponent <ISpawnDataObject>();
                object[] spawnData       = null;
                if (spawnDataObject != null)
                {
                    spawnData = spawnDataObject.SpawnData();
                }
                var data = new object[]
                {
                    index, instanceObject.transform.position, instanceObject.transform.rotation, photonView.ViewID, spawnData
                };

                PhotonNetwork.RaiseEvent(PhotonEventIDs.ObjectInstantiation, data, m_RaisedEventOptions, m_ReliableSendOptions);
            }
        }
Ejemplo n.º 2
0
        // Token: 0x06000005 RID: 5 RVA: 0x000021B0 File Offset: 0x000003B0
        public static GameObject SetupTrainerServerSide()
        {
            string     text       = UID.Generate().ToString();
            int        num        = PhotonNetwork.AllocateSceneViewID();
            GameObject gameObject = CustomCharacters.CreateCharacter(JuggernautTrainer.TrainerLocation, text, "SL_Character", false, null);
            Character  component  = gameObject.GetComponent <Character>();

            At.SetValue <CharacterManager.CharacterInstantiationTypes>(CharacterManager.CharacterInstantiationTypes.Item, typeof(Character), component, "m_instantiationType");
            foreach (int itemID in JuggernautTrainer.TrainerEquipment)
            {
                component.Inventory.Equipment.EquipInstantiate(ResourcesPrefabManager.Instance.GetItemPrefab(itemID) as Equipment);
            }
            component.ChangeFaction(Character.Factions.NONE, true);
            gameObject.SetActive(true);
            bool offlineMode = PhotonNetwork.offlineMode;

            if (offlineMode)
            {
                JuggernautTrainer.SetupTrainerClientSide(gameObject, num);
            }
            else
            {
                RPCManager.Instance.photonView.RPC("GetJuggernautTrainerFromServer", 0, new object[]
                {
                    text.ToString(),
                    num,
                    0
                });
            }
            return(gameObject);
        }
Ejemplo n.º 3
0
 private void SpawnSceneObjects(PhotonView photonVIew)
 {
     if (PhotonNetwork.AllocateSceneViewID(photonView))
     {
         Debug.Log("[PhotonGameManager] Allocated scene view id");
     }
 }
Ejemplo n.º 4
0
    void OnJoinedRoom()
    {
        myPhotonView = this.GetComponent <PhotonView> ();

        if (PhotonNetwork.isMasterClient)
        {
            myPhotonView.viewID = PhotonNetwork.AllocateSceneViewID();
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Instantiates a new ship into the game world for the given team on the given node
    /// </summary>
    /// <param name="node">the node to place the ship</param>
    /// <param name="team">the team the ship is assigned to</param>
    /// <returns>A reference to the newly created ship</returns>
    public Ship spawnShip(Node node, Team team)
    {
        GameObject parent = GameObject.Find("Ships");

        if (parent == null)
        {
            parent      = Instantiate(new GameObject());
            parent.name = "Ships";
        }
        GameObject shipPrefab = Resources.Load("Prefabs/Ship") as GameObject;

        GameObject spawn = Instantiate(shipPrefab, node.getRealPos(), Quaternion.identity);

        Ship ship = spawn.GetComponent <Ship>();

        PhotonView          pv  = spawn.AddComponent <PhotonView>();
        PhotonTransformView ptv = spawn.AddComponent <PhotonTransformView>();

        pv.ObservedComponents = new List <Component>();
        pv.ObservedComponents.Add(ptv);
        pv.OwnershipTransfer = OwnershipOption.Takeover;
        pv.Synchronization   = ViewSynchronization.Unreliable;
        //pv.ViewID = (int)(team.TeamFaction+1) * 100 + (ship.Id+1) * 10;

        if (PhotonNetwork.IsConnected)
        {
            if (PhotonNetwork.IsMasterClient)
            {
                if (!PhotonNetwork.AllocateSceneViewID(pv))
                {
                    Debug.LogError("Failed to allocated viewID for ship");
                }
            }
            else
            {
                pv.TransferOwnership(PhotonNetwork.MasterClient);
            }
        }

        //    Debug.Log((int)(team.TeamFaction + 1) * 100 + (ship.Id + 1) * 10);
        //Debug.Log(pv.ViewID);

        if (PhotonNetwork.IsConnected && !PhotonNetwork.IsMasterClient)
        {
            pv.TransferOwnership(PhotonNetwork.MasterClient);
            //spawn = PhotonNetwork.Instantiate("Prefabs/Ship",node.getRealPos(),Quaternion.identity);
        }

        spawn.transform.parent = parent.transform;

        ship.intialize(team, node);
        ship.name = team.TeamFaction.ToString() + " ship " + ship.Id;

        return(ship);
    }
Ejemplo n.º 6
0
 public void Init()
 {
     if (PhotonNetwork.IsMasterClient)
     {
         foreach (var view in views)
         {
             PhotonNetwork.AllocateSceneViewID(view);
             viewIDs.Add(view.ViewID);
         }
         photonView.RPC("SetChildViewID", RpcTarget.Others, viewIDs.ToArray());
     }
 }
Ejemplo n.º 7
0
        public (GameObject gameObject, int viewId) RpcInstantiate(string prefabName, Vector3 position, Quaternion rotation, ViewIdAllocationMethod method, int existingViewId)
        {
            var gameObject = UnityEngine.Object.Instantiate(Resources.Load <GameObject>(prefabName), position, rotation);

            gameObject.AddComponent <SpawnedObject>().ResourceName = prefabName;

            if (method != ViewIdAllocationMethod.Static)
            {
                var photonView = gameObject.GetComponent <PhotonView>();
                if (photonView)
                {
                    switch (method)
                    {
                    case ViewIdAllocationMethod.Specific:
                        photonView.ViewID = existingViewId;
                        break;

                    case ViewIdAllocationMethod.Local:
                        PhotonNetwork.AllocateViewID(photonView);
                        existingViewId = photonView.ViewID;
                        break;

                    case ViewIdAllocationMethod.Scene:
                        PhotonNetwork.AllocateSceneViewID(photonView);
                        existingViewId = photonView.ViewID;
                        break;
                    }
                }
                else
                {
                    Debug.LogWarning("== Instantiated object has no PhotonView and will not be networked.");
                }

                var networkedObject = gameObject.GetComponent <INetworkedObject>();
                if (!(networkedObject == null || networkedObject.Equals(null)))
                {
                    NetworkManager.Register(networkedObject);
                }
            }

            return(gameObject, existingViewId);
        }