public override void OnInspectorGUI() { base.OnInspectorGUI(); if (Application.isPlaying) { EditorGUILayout.HelpBox("Editing is disabled in play mode.", MessageType.Info); return; } PhotonRigidbody2DView view = (PhotonRigidbody2DView)target; view.m_TeleportEnabled = PhotonGUI.ContainerHeaderToggle("Enable teleport for large distances", view.m_TeleportEnabled); if (view.m_TeleportEnabled) { Rect rect = PhotonGUI.ContainerBody(20.0f); view.m_TeleportIfDistanceGreaterThan = EditorGUI.FloatField(rect, "Teleport if distance greater than", view.m_TeleportIfDistanceGreaterThan); } view.m_SynchronizeVelocity = PhotonGUI.ContainerHeaderToggle("Synchronize Velocity", view.m_SynchronizeVelocity); view.m_SynchronizeAngularVelocity = PhotonGUI.ContainerHeaderToggle("Synchronize Angular Velocity", view.m_SynchronizeAngularVelocity); if (GUI.changed) { EditorUtility.SetDirty(view); } }
public override void OnInspectorGUI() { if (Application.isPlaying) { EditorGUILayout.HelpBox("Editing is disabled in play mode.", MessageType.Info); return; } PhotonRigidbody2DView view = (PhotonRigidbody2DView)target; view.m_SynchronizeVelocity = PhotonGUI.ContainerHeaderToggle("Synchronize Velocity", view.m_SynchronizeVelocity); view.m_SynchronizeAngularVelocity = PhotonGUI.ContainerHeaderToggle("Synchronize Angular Velocity", view.m_SynchronizeAngularVelocity); }
private void DrawObservedComponentsList() { GUILayout.Space(5); SerializedProperty listProperty = this.serializedObject.FindProperty("ObservedComponents"); if (listProperty == null) { return; } float containerElementHeight = 22; float containerHeight = listProperty.arraySize * containerElementHeight; bool isOpen = PhotonGUI.ContainerHeaderFoldout("Observed Components (" + this.GetObservedComponentsCount() + ")", this.serializedObject.FindProperty("ObservedComponentsFoldoutOpen").boolValue); this.serializedObject.FindProperty("ObservedComponentsFoldoutOpen").boolValue = isOpen; if (isOpen == false) { containerHeight = 0; } //Texture2D statsIcon = AssetDatabase.LoadAssetAtPath( "Assets/Photon Unity Networking/Editor/PhotonNetwork/PhotonViewStats.png", typeof( Texture2D ) ) as Texture2D; Rect containerRect = PhotonGUI.ContainerBody(containerHeight); bool wasObservedComponentsEmpty = this.m_Target.ObservedComponents.FindAll(item => item != null).Count == 0; if (isOpen == true) { for (int i = 0; i < listProperty.arraySize; ++i) { Rect elementRect = new Rect(containerRect.xMin, containerRect.yMin + containerElementHeight * i, containerRect.width, containerElementHeight); { Rect texturePosition = new Rect(elementRect.xMin + 6, elementRect.yMin + elementRect.height / 2f - 1, 9, 5); ReorderableListResources.DrawTexture(texturePosition, ReorderableListResources.texGrabHandle); Rect propertyPosition = new Rect(elementRect.xMin + 20, elementRect.yMin + 3, elementRect.width - 45, 16); // keep track of old type to catch when a new type is observed Type _oldType = listProperty.GetArrayElementAtIndex(i).objectReferenceValue != null?listProperty.GetArrayElementAtIndex(i).objectReferenceValue.GetType() : null; EditorGUI.PropertyField(propertyPosition, listProperty.GetArrayElementAtIndex(i), new GUIContent()); // new type, could be different from old type Type _newType = listProperty.GetArrayElementAtIndex(i).objectReferenceValue != null?listProperty.GetArrayElementAtIndex(i).objectReferenceValue.GetType() : null; // the user dropped a Transform, we must change it by adding a PhotonTransformView and observe that instead if (_oldType != _newType) { if (_newType == typeof(PhotonView)) { listProperty.GetArrayElementAtIndex(i).objectReferenceValue = null; Debug.LogError("PhotonView Detected you dropped a PhotonView, this is not allowed. \n It's been removed from observed field."); } else if (_newType == typeof(Transform)) { // try to get an existing PhotonTransformView ( we don't want any duplicates...) PhotonTransformView _ptv = this.m_Target.gameObject.GetComponent <PhotonTransformView>(); if (_ptv == null) { // no ptv yet, we create one and enable position and rotation, no scaling, as it's too rarely needed to take bandwidth for nothing _ptv = Undo.AddComponent <PhotonTransformView>(this.m_Target.gameObject); } // switch observe from transform to _ptv listProperty.GetArrayElementAtIndex(i).objectReferenceValue = _ptv; Debug.Log("PhotonView has detected you dropped a Transform. Instead it's better to observe a PhotonTransformView for better control and performances"); } else if (_newType == typeof(Rigidbody)) { Rigidbody _rb = listProperty.GetArrayElementAtIndex(i).objectReferenceValue as Rigidbody; // try to get an existing PhotonRigidbodyView ( we don't want any duplicates...) PhotonRigidbodyView _prbv = _rb.gameObject.GetComponent <PhotonRigidbodyView>(); if (_prbv == null) { // no _prbv yet, we create one _prbv = Undo.AddComponent <PhotonRigidbodyView>(_rb.gameObject); } // switch observe from transform to _prbv listProperty.GetArrayElementAtIndex(i).objectReferenceValue = _prbv; Debug.Log("PhotonView has detected you dropped a RigidBody. Instead it's better to observe a PhotonRigidbodyView for better control and performances"); } else if (_newType == typeof(Rigidbody2D)) { // try to get an existing PhotonRigidbody2DView ( we don't want any duplicates...) PhotonRigidbody2DView _prb2dv = this.m_Target.gameObject.GetComponent <PhotonRigidbody2DView>(); if (_prb2dv == null) { // no _prb2dv yet, we create one _prb2dv = Undo.AddComponent <PhotonRigidbody2DView>(this.m_Target.gameObject); } // switch observe from transform to _prb2dv listProperty.GetArrayElementAtIndex(i).objectReferenceValue = _prb2dv; Debug.Log("PhotonView has detected you dropped a Rigidbody2D. Instead it's better to observe a PhotonRigidbody2DView for better control and performances"); } else if (_newType == typeof(Animator)) { // try to get an existing PhotonAnimatorView ( we don't want any duplicates...) PhotonAnimatorView _pav = this.m_Target.gameObject.GetComponent <PhotonAnimatorView>(); if (_pav == null) { // no _pav yet, we create one _pav = Undo.AddComponent <PhotonAnimatorView>(this.m_Target.gameObject); } // switch observe from transform to _prb2dv listProperty.GetArrayElementAtIndex(i).objectReferenceValue = _pav; Debug.Log("PhotonView has detected you dropped a Animator, so we switched to PhotonAnimatorView so that you can serialized the Animator variables"); } else if (!typeof(IPunObservable).IsAssignableFrom(_newType)) { bool _ignore = false; #if PLAYMAKER _ignore = _newType == typeof(PlayMakerFSM);// Photon Integration for PlayMaker will swap at runtime to a proxy using iPunObservable. #endif if (_newType == null || _newType == typeof(Rigidbody) || _newType == typeof(Rigidbody2D)) { _ignore = true; } if (!_ignore) { listProperty.GetArrayElementAtIndex(i).objectReferenceValue = null; Debug.LogError("PhotonView Detected you dropped a Component missing IPunObservable Interface,\n You dropped a <" + _newType + "> instead. It's been removed from observed field."); } } } //Debug.Log( listProperty.GetArrayElementAtIndex( i ).objectReferenceValue.GetType() ); //Rect statsPosition = new Rect( propertyPosition.xMax + 7, propertyPosition.yMin, statsIcon.width, statsIcon.height ); //ReorderableListResources.DrawTexture( statsPosition, statsIcon ); Rect removeButtonRect = new Rect(elementRect.xMax - PhotonGUI.DefaultRemoveButtonStyle.fixedWidth, elementRect.yMin + 2, PhotonGUI.DefaultRemoveButtonStyle.fixedWidth, PhotonGUI.DefaultRemoveButtonStyle.fixedHeight); GUI.enabled = listProperty.arraySize > 1; if (GUI.Button(removeButtonRect, new GUIContent(ReorderableListResources.texRemoveButton), PhotonGUI.DefaultRemoveButtonStyle)) { listProperty.DeleteArrayElementAtIndex(i); } GUI.enabled = true; if (i < listProperty.arraySize - 1) { texturePosition = new Rect(elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1); PhotonGUI.DrawSplitter(texturePosition); } } } } if (PhotonGUI.AddButton()) { listProperty.InsertArrayElementAtIndex(Mathf.Max(0, listProperty.arraySize - 1)); } this.serializedObject.ApplyModifiedProperties(); bool isObservedComponentsEmpty = this.m_Target.ObservedComponents.FindAll(item => item != null).Count == 0; if (wasObservedComponentsEmpty == true && isObservedComponentsEmpty == false && this.m_Target.Synchronization == ViewSynchronization.Off) { Undo.RecordObject(this.m_Target, "Change PhotonView"); this.m_Target.Synchronization = ViewSynchronization.UnreliableOnChange; this.serializedObject.Update(); } if (wasObservedComponentsEmpty == false && isObservedComponentsEmpty == true) { Undo.RecordObject(this.m_Target, "Change PhotonView"); this.m_Target.Synchronization = ViewSynchronization.Off; this.serializedObject.Update(); } }