Ejemplo n.º 1
0
        public void OnValidate()
        {
            if (ObservedComponents == null)
            {
                ObservedComponents = new List <Component>();
            }

            var c = ObservedComponents.Sum(x => x?.GetHashCode() ?? 0);

            var observables = GetComponents <IPunObservable>();

            ObservedComponents.Clear();
            ObservedComponents.AddRange(observables.Select(x => x as Component));

            if (!SyncTransforms)
            {
                ObservedComponents.Remove(this);
            }

            if (c != ObservedComponents.Sum(x => x.GetHashCode()))
            {
                UnityEditor.EditorUtility.SetDirty(gameObject);
            }

            if (GetComponent <INetworkTakeover>() != null && ownershipTransfer != OwnershipOption.Takeover)
            {
                ownershipTransfer = OwnershipOption.Takeover;
                UnityEditor.EditorUtility.SetDirty(gameObject);
            }

            if (GetComponent <INetworkTakeover>() == null && ownershipTransfer != OwnershipOption.Fixed)
            {
                ownershipTransfer = OwnershipOption.Fixed;
                UnityEditor.EditorUtility.SetDirty(gameObject);
            }

            if (ObservedComponents.Count > 0 && synchronization != ViewSynchronization.UnreliableOnChange)
            {
                synchronization = ViewSynchronization.UnreliableOnChange;
                UnityEditor.EditorUtility.SetDirty(gameObject);
            }

            if (ObservedComponents.Count == 0 && synchronization != ViewSynchronization.Off)
            {
                synchronization = ViewSynchronization.Off;
                UnityEditor.EditorUtility.SetDirty(gameObject);
            }

            if (SyncTransforms && GetComponent <INetworkStatic>() != null)
            {
                SyncTransforms = false;
                UnityEditor.EditorUtility.SetDirty(gameObject);
            }
        }
Ejemplo n.º 2
0
        public static void SetPhotonViewSync(Transform trans, ViewSynchronization sync)
        {
            var comp = trans.gameObject.GetComponent <PhotonView>();

            if (comp != null)
            {
                comp.Synchronization = sync;
            }
            foreach (PhotonView c in trans.gameObject.GetComponentsInChildren(typeof(PhotonView), true))
            {
                comp.Synchronization = sync;
            }
        }
Ejemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        #if UNITY_3_5
        EditorGUIUtility.LookLikeInspector();
        #endif
        EditorGUI.indentLevel = 1;

        PhotonView mp = (PhotonView)this.target;
        bool       isProjectPrefab = EditorUtility.IsPersistent(mp.gameObject);



        // Owner
        if (isProjectPrefab)
        {
            EditorGUILayout.LabelField("Owner:", "Set at runtime");
        }
        else if (mp.isSceneView)
        {
            EditorGUILayout.LabelField("Owner:", "Scene");
        }
        else
        {
            PhotonPlayer owner     = mp.owner;
            string       ownerInfo = (owner != null) ? owner.name : "<no PhotonPlayer found>";

            if (string.IsNullOrEmpty(ownerInfo))
            {
                ownerInfo = "<no playername set>";
            }

            EditorGUILayout.LabelField("Owner:", "[" + mp.ownerId + "] " + ownerInfo);
        }



        // View ID
        if (isProjectPrefab)
        {
            EditorGUILayout.LabelField("View ID", "Set at runtime");
        }
        else if (EditorApplication.isPlaying)
        {
            EditorGUILayout.LabelField("View ID", mp.viewID.ToString());
        }
        else
        {
            int idValue = EditorGUILayout.IntField("View ID [0.." + (PhotonNetwork.MAX_VIEW_IDS - 1) + "]", mp.viewID);
            mp.viewID = idValue;
        }



        // Locally Controlled
        if (EditorApplication.isPlaying)
        {
            string masterClientHint = PhotonNetwork.isMasterClient ? "(master)" : "";
            EditorGUILayout.Toggle("Controlled locally: " + masterClientHint, mp.isMine);
        }



        // Observed Item
        EditorGUILayout.BeginHorizontal();

        // Using a lower version then 3.4? Remove the TRUE in the next line to fix an compile error
        string typeOfObserved = string.Empty;
        if (mp.observed != null)
        {
            int firstBracketPos = mp.observed.ToString().LastIndexOf('(');
            if (firstBracketPos > 0)
            {
                typeOfObserved = mp.observed.ToString().Substring(firstBracketPos);
            }
        }


        Component componenValue = (Component)EditorGUILayout.ObjectField("Observe: " + typeOfObserved, mp.observed, typeof(Component), true);
        if (mp.observed != componenValue)
        {
            if (mp.observed == null)
            {
                mp.synchronization = ViewSynchronization.UnreliableOnChange;    // if we didn't observe anything yet. use unreliable on change as default
            }
            if (componenValue == null)
            {
                mp.synchronization = ViewSynchronization.Off;
            }

            mp.observed = componenValue;
        }

        EditorGUILayout.EndHorizontal();



        // ViewSynchronization (reliability)
        if (mp.synchronization == ViewSynchronization.Off)
        {
            GUI.color = Color.grey;
        }

        ViewSynchronization vsValue = (ViewSynchronization)EditorGUILayout.EnumPopup("Observe option:", mp.synchronization);
        if (vsValue != mp.synchronization)
        {
            mp.synchronization = vsValue;
            if (mp.synchronization != ViewSynchronization.Off && mp.observed == null)
            {
                EditorUtility.DisplayDialog("Warning", "Setting the synchronization option only makes sense if you observe something.", "OK, I will fix it.");
            }
        }



        // Serialization
        // show serialization options only if something is observed
        if (mp.observed != null)
        {
            Type type = mp.observed.GetType();
            if (type == typeof(Transform))
            {
                mp.onSerializeTransformOption = (OnSerializeTransform)EditorGUILayout.EnumPopup("Serialization:", mp.onSerializeTransformOption);
            }
            else if (type == typeof(Rigidbody))
            {
                mp.onSerializeRigidBodyOption = (OnSerializeRigidBody)EditorGUILayout.EnumPopup("Serialization:", mp.onSerializeRigidBodyOption);
            }
        }



        // Cleanup: save and fix look
        if (GUI.changed)
        {
            EditorUtility.SetDirty(mp);
            PhotonViewHandler.HierarchyChange();  // TODO: check if needed
        }

        GUI.color = Color.white;
        EditorGUIUtility.LookLikeControls();
    }