Exemplo n.º 1
0
        public bool RequestOwnership(GameObject obj)
        {
            OwnableObject ownershipManager = obj.GetComponent <OwnableObject>();

            if (ownershipManager != null)
            {
                return(ownershipManager.Take());
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public GameObject InstantiateOwnedObject(string prefabName)
        {
            GameObject localObj = InstantiateLocally(prefabName);

            if (localObj != null)
            {
                RaiseInstantiateEventHandler(localObj);
                int[] whiteListIDs = new int[1];
                whiteListIDs[0] = PhotonNetwork.player.ID;
                //UnityEngine.Debug.Log("About to raise restriction event.");
                OwnableObject ownershipManager = localObj.GetComponent <OwnableObject>();
                ownershipManager.SetRestrictions(true, whiteListIDs);
                RaiseObjectOwnershipRestrictionEventHandler(localObj, true, whiteListIDs);
            }
            return(localObj);
        }
Exemplo n.º 3
0
        public bool Destroy(GameObject go)
        {
            if (go == null)
            {
                return(true);
            }
            else
            {
                OwnableObject ownershipManager = go.GetComponent <OwnableObject>();
                if (ownershipManager.Take())
                {
                    UnityEngine.GameObject.Destroy(go);
                    // Calling Unity's Destroy mechanism kills the object by triggering an OnDestroy call in the ObjectManager
                }

                return(true);
            }
        }
Exemplo n.º 4
0
        public bool RestrictOwnership(GameObject obj, List <int> whiteListIDs)
        {
            OwnableObject ownershipManager = obj.GetComponent <OwnableObject>();
            List <int>    returnValue      = ownershipManager.RestrictToYourself();

            if (returnValue != null)
            {
                if (whiteListIDs != null)
                {
                    ownershipManager.WhiteListPlayerID(whiteListIDs);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        private void HandleSyncObjectOwnershipRestriction(ExitGames.Client.Photon.Hashtable eventData)
        {
            string objectName = (string)eventData[(byte)0];
            int    viewID     = (int)eventData[(byte)1];
            bool   restricted = (bool)eventData[(byte)2];

            int[] ownableIDs      = (int[])eventData[(byte)3];
            int   serverTimeStamp = (int)eventData[(byte)4];

            //UnityEngine.Debug.Log("restricted = " + ((restricted) ? "true" : "false"));

            GameObject[] objs = GameObject.FindObjectsOfType <GameObject>();
            GameObject   go   = null;

            foreach (GameObject obj in objs)
            {
                if (obj.name.Equals(objectName))
                {
                    PhotonView pv = obj.GetComponent <PhotonView>();
                    if (pv == null)
                    {
                        continue;
                    }
                    else if (pv.viewID == viewID)
                    {
                        go = obj;
                        break;
                    }
                }
            }

            if (go != null)
            {
                OwnableObject ownershipManager = go.GetComponent <OwnableObject>();
                ownershipManager.SetRestrictions(restricted, ownableIDs);
            }
        }
Exemplo n.º 6
0
        private void HandleSyncSceneEvent(ExitGames.Client.Photon.Hashtable eventData)
        {
            int targetPlayerID = (int)eventData[(byte)0];

            if (PhotonNetwork.player.ID == targetPlayerID)
            {
                string  prefabName = (string)eventData[(byte)1];
                Vector3 position   = Vector3.zero;
                Vector3 scale      = Vector3.one;
                if (eventData.ContainsKey((byte)2))
                {
                    position = (Vector3)eventData[(byte)2];
                }
                Quaternion rotation = Quaternion.identity;
                if (eventData.ContainsKey((byte)3))
                {
                    rotation = (Quaternion)eventData[(byte)3];
                }
                scale = (Vector3)eventData[(byte)4];

                int[] viewIDs = (int[])eventData[(byte)5];
                if (eventData.ContainsKey((byte)6))
                {
                    uint currentLevelPrefix = (uint)eventData[(byte)6];
                }

                int serverTimeStamp = (int)eventData[(byte)7];
                int instantiationID = (int)eventData[(byte)8];

                GameObject go = InstantiateLocally(prefabName, viewIDs, position, rotation, scale);

                OwnableObject ownershipManager      = go.GetComponent <OwnableObject>();
                bool          isOwnershipRestricted = (bool)eventData[(byte)9];
                int[]         whiteListIDs          = (int[])eventData[(byte)10];
                ownershipManager.SetRestrictions(isOwnershipRestricted, whiteListIDs);
            }
        }
Exemplo n.º 7
0
        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;
                    }
                    syncSceneData[(byte)4] = go.transform.localScale;

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

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

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

                    OwnableObject ownershipManager = go.GetComponent <OwnableObject>();
                    syncSceneData[(byte)9] = ownershipManager.IsOwnershipRestricted;
                    List <int> whiteListIDs = ownershipManager.OwnablePlayerIDs;
                    int[]      idList       = new int[whiteListIDs.Count];
                    whiteListIDs.CopyTo(idList);
                    syncSceneData[(byte)10] = idList;

                    //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);
                }
            }
        }
Exemplo n.º 8
0
        public bool UnRestrictOwnership(GameObject obj)
        {
            OwnableObject ownershipManager = obj.GetComponent <OwnableObject>();

            return(ownershipManager.UnRestrict());
        }