private void RaiseSyncSceneEventHandler(int otherPlayerID, bool forceSync)
        {
            if (PhotonNetwork.isMasterClient || forceSync)
            {
                List <GameObject> ASLObjectList = GrabAllASLObjects();

                NetworkingPeer peer = PhotonNetwork.networkingPeer;
                foreach (GameObject go in ASLObjectList)
                {
                    if (nonSyncItems.Contains(go))
                    {
                        continue;
                    }

                    ExitGames.Client.Photon.Hashtable syncSceneData = new ExitGames.Client.Photon.Hashtable();

                    syncSceneData[(byte)0] = otherPlayerID;

#if UNITY_EDITOR
                    string prefabName = UnityEditor.PrefabUtility.GetPrefabParent(go).name;
#else
                    //string prefabName = go.name;
                    string prefabName = ObjectInstantiationDatabase.GetPrefabName(go);
#endif
                    UnityEngine.Debug.Log("Prefab name = " + prefabName);
                    syncSceneData[(byte)1] = prefabName;

                    if (go.transform.position != Vector3.zero)
                    {
                        syncSceneData[(byte)2] = go.transform.position;
                    }

                    if (go.transform.rotation != Quaternion.identity)
                    {
                        syncSceneData[(byte)3] = go.transform.rotation;
                    }

                    int[] viewIDs = ExtractPhotonViewIDs(go);
                    syncSceneData[(byte)4] = viewIDs;

                    if (peer.currentLevelPrefix > 0)
                    {
                        syncSceneData[(byte)5] = peer.currentLevelPrefix;
                    }

                    syncSceneData[(byte)6] = PhotonNetwork.ServerTimestamp;
                    syncSceneData[(byte)7] = go.GetPhotonView().instantiationId;

                    //RaiseEventOptions options = new RaiseEventOptions();
                    //options.CachingOption = (isGlobalObject) ? EventCaching.AddToRoomCacheGlobal : EventCaching.AddToRoomCache;

                    //Debug.Log("All items packed. Attempting to literally raise event now.");

                    RaiseEventOptions options = new RaiseEventOptions();
                    options.Receivers = ReceiverGroup.Others;
                    PhotonNetwork.RaiseEvent(ASLEventCode.EV_SYNCSCENE, syncSceneData, true, options);
                }
            }
        }
Esempio n. 2
0
        private void RaiseInstantiateEventHandler(GameObject go)
        {
            //Debug.Log("Attempting to raise event for instantiation");

            NetworkingPeer peer = PhotonNetwork.networkingPeer;

            byte[] content = new byte[2];
            ExitGames.Client.Photon.Hashtable instantiateEvent = new ExitGames.Client.Photon.Hashtable();
#if UNITY_EDITOR
            string prefabName = UnityEditor.PrefabUtility.GetPrefabParent(go).name;
#else
            //string prefabName = go.name;
            string prefabName = ObjectInstantiationDatabase.GetPrefabName(go);
#endif
            instantiateEvent[(byte)0] = prefabName;

            if (go.transform.position != Vector3.zero)
            {
                instantiateEvent[(byte)1] = go.transform.position;
            }

            if (go.transform.rotation != Quaternion.identity)
            {
                instantiateEvent[(byte)2] = go.transform.rotation;
            }

            instantiateEvent[(byte)3] = go.transform.localScale;

            int[] viewIDs = ExtractPhotonViewIDs(go);
            instantiateEvent[(byte)4] = viewIDs;

            if (peer.currentLevelPrefix > 0)
            {
                instantiateEvent[(byte)5] = peer.currentLevelPrefix;
            }

            instantiateEvent[(byte)6] = PhotonNetwork.ServerTimestamp;
            instantiateEvent[(byte)7] = go.GetPhotonView().instantiationId;

            //RaiseEventOptions options = new RaiseEventOptions();
            //options.CachingOption = (isGlobalObject) ? EventCaching.AddToRoomCacheGlobal : EventCaching.AddToRoomCache;

            //Debug.Log("All items packed. Attempting to literally raise event now.");

            RaiseEventOptions options = new RaiseEventOptions();
            options.Receivers = ReceiverGroup.Others;
            PhotonNetwork.RaiseEvent(ASLEventCode.EV_INSTANTIATE, instantiateEvent, true, options);

            //peer.OpRaiseEvent(EV_INSTANTIATE, instantiateEvent, true, null);
        }
Esempio n. 3
0
 private void RegisterObjectDeletion(GameObject go, string goName)
 {
     ObjectInstantiationDatabase.Remove(go, goName);
 }
Esempio n. 4
0
 private void RegisterObjectCreation(GameObject go, string prefabName)
 {
     ObjectInstantiationDatabase.Add(prefabName, go);
 }