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); } }
public override void OnInspectorGUI() { this.m_Target = (PhotonView)target; bool isProjectPrefab = EditorUtility.IsPersistent(this.m_Target.gameObject); if (this.m_Target.ObservedComponents == null) { this.m_Target.ObservedComponents = new System.Collections.Generic.List <Component>(); } if (this.m_Target.ObservedComponents.Count == 0) { this.m_Target.ObservedComponents.Add(null); } EditorGUILayout.BeginHorizontal(); // Owner if (isProjectPrefab) { EditorGUILayout.LabelField("Owner:", "Set at runtime"); } else if (!this.m_Target.isOwnerActive) { EditorGUILayout.LabelField("Owner", "Scene"); } else { PhotonPlayer owner = this.m_Target.owner; string ownerInfo = (owner != null) ? owner.name : "<no PhotonPlayer found>"; if (string.IsNullOrEmpty(ownerInfo)) { ownerInfo = "<no playername set>"; } EditorGUILayout.LabelField("Owner", "[" + this.m_Target.ownerId + "] " + ownerInfo); } // ownership requests EditorGUI.BeginDisabledGroup(Application.isPlaying); OwnershipOption own = (OwnershipOption)EditorGUILayout.EnumPopup(this.m_Target.ownershipTransfer, GUILayout.Width(100)); if (own != this.m_Target.ownershipTransfer) { // jf: fixed 5 and up prefab not accepting changes if you quit Unity straight after change. // not touching the define nor the rest of the code to avoid bringing more problem than solving. EditorUtility.SetDirty(this.m_Target); Undo.RecordObject(this.m_Target, "Change PhotonView Ownership Transfer"); this.m_Target.ownershipTransfer = own; } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); // View ID if (isProjectPrefab) { EditorGUILayout.LabelField("View ID", "Set at runtime"); } else if (EditorApplication.isPlaying) { EditorGUILayout.LabelField("View ID", this.m_Target.viewID.ToString()); } else { int idValue = EditorGUILayout.IntField("View ID [1.." + (PhotonNetwork.MAX_VIEW_IDS - 1) + "]", this.m_Target.viewID); if (this.m_Target.viewID != idValue) { Undo.RecordObject(this.m_Target, "Change PhotonView viewID"); this.m_Target.viewID = idValue; } } // Locally Controlled if (EditorApplication.isPlaying) { string masterClientHint = PhotonNetwork.isMasterClient ? "(master)" : ""; EditorGUILayout.Toggle("Controlled locally: " + masterClientHint, this.m_Target.isMine); } //DrawOldObservedItem(); ConvertOldObservedItemToObservedList(); // ViewSynchronization (reliability) if (this.m_Target.synchronization == ViewSynchronization.Off) { GUI.color = Color.grey; } EditorGUILayout.PropertyField(serializedObject.FindProperty("synchronization"), new GUIContent("Observe option:")); if (this.m_Target.synchronization != ViewSynchronization.Off && this.m_Target.ObservedComponents.FindAll(item => item != null).Count == 0) { GUILayout.BeginVertical(GUI.skin.box); GUILayout.Label("Warning", EditorStyles.boldLabel); GUILayout.Label("Setting the synchronization option only makes sense if you observe something."); GUILayout.EndVertical(); } /*ViewSynchronization vsValue = (ViewSynchronization)EditorGUILayout.EnumPopup("Observe option:", m_Target.synchronization); * if (vsValue != m_Target.synchronization) * { * m_Target.synchronization = vsValue; * if (m_Target.synchronization != ViewSynchronization.Off && m_Target.observed == null) * { * EditorUtility.DisplayDialog("Warning", "Setting the synchronization option only makes sense if you observe something.", "OK, I will fix it."); * } * }*/ DrawSpecificTypeSerializationOptions(); GUI.color = Color.white; DrawObservedComponentsList(); // Cleanup: save and fix look if (GUI.changed) { #if !UNITY_MIN_5_3 EditorUtility.SetDirty(this.m_Target); #endif PhotonViewHandler.HierarchyChange(); // TODO: check if needed } GUI.color = Color.white; #if !UNITY_MIN_5_3 EditorGUIUtility.LookLikeControls(); #endif }
public override void OnInspectorGUI() { this.m_Target = (PhotonView)this.target; bool isProjectPrefab = PhotonEditorUtils.IsPrefab(this.m_Target.gameObject); if (this.m_Target.ObservedComponents == null) { this.m_Target.ObservedComponents = new System.Collections.Generic.List <Component>(); } if (this.m_Target.ObservedComponents.Count == 0) { this.m_Target.ObservedComponents.Add(null); } EditorGUILayout.BeginHorizontal(); // Owner if (isProjectPrefab) { EditorGUILayout.LabelField("Owner", "<i>Set at runtime</i>", new GUIStyle("Label") { richText = true }, GUILayout.MinWidth(120)); } else if (!this.m_Target.IsOwnerActive) { EditorGUILayout.LabelField("Owner", "Scene", GUILayout.MinWidth(120)); } else { Player owner = this.m_Target.Owner; string ownerInfo = (owner != null) ? owner.NickName : "<no Player found>"; if (string.IsNullOrEmpty(ownerInfo)) { ownerInfo = "<no playername set>"; } EditorGUILayout.LabelField("Owner [" + this.m_Target.OwnerActorNr + "] " + ownerInfo, GUILayout.MinWidth(120)); } // ownership requests EditorGUI.BeginDisabledGroup(Application.isPlaying); OwnershipOption own = (OwnershipOption)EditorGUILayout.EnumPopup(this.m_Target.OwnershipTransfer, GUILayout.MaxWidth(68), GUILayout.MinWidth(68)); if (own != this.m_Target.OwnershipTransfer) { // jf: fixed 5 and up prefab not accepting changes if you quit Unity straight after change. // not touching the define nor the rest of the code to avoid bringing more problem than solving. EditorUtility.SetDirty(this.m_Target); Undo.RecordObject(this.m_Target, "Change PhotonView Ownership Transfer"); this.m_Target.OwnershipTransfer = own; } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); // View ID if (isProjectPrefab) { EditorGUILayout.LabelField("View ID", "<i>Set at runtime</i>", new GUIStyle("Label") { richText = true }); } else if (EditorApplication.isPlaying) { EditorGUILayout.LabelField("View ID", this.m_Target.ViewID.ToString()); } else { int idValue = EditorGUILayout.IntField("View ID [1.." + (PhotonNetwork.MAX_VIEW_IDS - 1) + "]", this.m_Target.ViewID); if (this.m_Target.ViewID != idValue) { Undo.RecordObject(this.m_Target, "Change PhotonView viewID"); this.m_Target.ViewID = idValue; } } // Locally Controlled if (EditorApplication.isPlaying) { string masterClientHint = PhotonNetwork.IsMasterClient ? "(master)" : ""; EditorGUILayout.Toggle("Controlled locally: " + masterClientHint, this.m_Target.IsMine); } // ViewSynchronization (reliability) if (this.m_Target.Synchronization == ViewSynchronization.Off) { GUI.color = Color.grey; } EditorGUILayout.PropertyField(this.serializedObject.FindProperty("Synchronization"), new GUIContent("Observe option")); if (this.m_Target.Synchronization != ViewSynchronization.Off && this.m_Target.ObservedComponents.FindAll(item => item != null).Count == 0) { EditorGUILayout.HelpBox("Setting the synchronization option only makes sense if you observe something.", MessageType.Warning); } GUI.color = Color.white; this.DrawObservedComponentsList(); // Cleanup: save and fix look if (GUI.changed) { PhotonViewHandler.OnHierarchyChanged(); // TODO: check if needed } GUI.color = Color.white; }
public override void OnInspectorGUI() { this.m_Target = (PhotonView)this.target; bool isProjectPrefab = PhotonEditorUtils.IsPrefab(this.m_Target.gameObject); bool multiSelected = Selection.gameObjects.Length > 1; if (this.m_Target.ObservedComponents == null) { this.m_Target.ObservedComponents = new System.Collections.Generic.List <Component>(); } if (this.m_Target.ObservedComponents.Count == 0) { this.m_Target.ObservedComponents.Add(null); } GUILayout.Space(5); EditorGUILayout.BeginVertical((GUIStyle)"HelpBox"); // View ID - Hide if we are multi-selected if (!multiSelected) { if (isProjectPrefab) { EditorGUILayout.LabelField("View ID", "<i>Set at runtime</i>", new GUIStyle("Label") { richText = true }); } else if (EditorApplication.isPlaying) { EditorGUILayout.LabelField("View ID", this.m_Target.ViewID.ToString()); } else { // this is an object in a scene, modified at edit-time. we can store this as sceneViewId int idValue = EditorGUILayout.IntField("View ID [1.." + (PhotonNetwork.MAX_VIEW_IDS - 1) + "]", this.m_Target.sceneViewId); if (this.m_Target.sceneViewId != idValue) { Undo.RecordObject(this.m_Target, "Change PhotonView viewID"); this.m_Target.sceneViewId = idValue; } } } // Locally Controlled if (EditorApplication.isPlaying) { string masterClientHint = PhotonNetwork.IsMasterClient ? " (master)" : ""; EditorGUILayout.LabelField("IsMine:", this.m_Target.IsMine.ToString() + masterClientHint); Room room = PhotonNetwork.CurrentRoom; int cretrId = this.m_Target.CreatorActorNr; Player cretr = (room != null) ? room.GetPlayer(cretrId) : null; Player owner = this.m_Target.Owner; Player ctrlr = this.m_Target.Controller; EditorGUILayout.LabelField("Controller:", (ctrlr != null ? ("[" + ctrlr.ActorNumber + "] '" + ctrlr.NickName + "' " + (ctrlr.IsMasterClient ? " (master)" : "")) : "[0] <null>")); EditorGUILayout.LabelField("Owner:", (owner != null ? ("[" + owner.ActorNumber + "] '" + owner.NickName + "' " + (owner.IsMasterClient ? " (master)" : "")) : "[0] <null>")); EditorGUILayout.LabelField("Creator:", (cretr != null ? ("[" + cretrId + "] '" + cretr.NickName + "' " + (cretr.IsMasterClient ? " (master)" : "")) : "[0] <null>")); } EditorGUILayout.EndVertical(); EditorGUI.BeginDisabledGroup(Application.isPlaying); GUILayout.Space(5); // Ownership section EditorGUILayout.LabelField("Ownership", (GUIStyle)"BoldLabel"); OwnershipOption own = (OwnershipOption)EditorGUILayout.EnumPopup(ownerTransferGuiContent, this.m_Target.OwnershipTransfer /*, GUILayout.MaxWidth(68), GUILayout.MinWidth(68)*/); if (own != this.m_Target.OwnershipTransfer) { // jf: fixed 5 and up prefab not accepting changes if you quit Unity straight after change. // not touching the define nor the rest of the code to avoid bringing more problem than solving. EditorUtility.SetDirty(this.m_Target); Undo.RecordObject(this.m_Target, "Change PhotonView Ownership Transfer"); this.m_Target.OwnershipTransfer = own; } GUILayout.Space(5); // Observables section EditorGUILayout.LabelField("Observables", (GUIStyle)"BoldLabel"); EditorGUILayout.PropertyField(this.serializedObject.FindProperty("Synchronization"), syncronizationGuiContent); if (this.m_Target.Synchronization == ViewSynchronization.Off) { // Show warning if there are any observables. The null check is because the list allows nulls. var observed = m_Target.ObservedComponents; if (observed.Count > 0) { for (int i = 0, cnt = observed.Count; i < cnt; ++i) { if (observed[i] != null) { EditorGUILayout.HelpBox("Synchronization is set to Off. Select a Synchronization setting in order to sync the listed Observables.", MessageType.Warning); break; } } } } PhotonView.ObservableSearch autoFindObservables = (PhotonView.ObservableSearch)EditorGUILayout.EnumPopup(observableSearchGuiContent, m_Target.observableSearch); if (m_Target.observableSearch != autoFindObservables) { Undo.RecordObject(this.m_Target, "Change Auto Find Observables Toggle"); m_Target.observableSearch = autoFindObservables; } m_Target.FindObservables(); if (!multiSelected) { bool disableList = Application.isPlaying || autoFindObservables != PhotonView.ObservableSearch.Manual; if (disableList) { EditorGUI.BeginDisabledGroup(true); } this.DrawObservedComponentsList(disableList); if (disableList) { EditorGUI.EndDisabledGroup(); } } // Cleanup: save and fix look if (GUI.changed) { PhotonViewHandler.OnHierarchyChanged(); // TODO: check if needed } EditorGUI.EndDisabledGroup(); }
public static GameObject ConvertToBasicNetObject(GameObject selection = null, OwnershipOption ownershipOption = OwnershipOption.Fixed) { if (selection == null) { selection = Selection.activeGameObject; } if (selection == null) { Debug.LogWarning("No selected GameObject. Creating a dummy Player/NPC."); selection = new GameObject("Empty Player"); selection.CreateChildStatePlaceholders(Space_XD.SPACE_3D, Dynamics.Variable, 2); //return null; } #if PUN_2_OR_NEWER var pv = selection.EnsureComponentExists <PhotonView>(); pv.OwnershipTransfer = ownershipOption; #endif selection.EnsureComponentExists <NetObject>(); return(selection); }