void UpdateComponentEditors(TimelineControl obj) { MonoBehaviour[] components = null; if (obj != null) { components = obj.gameObject.GetComponents <MonoBehaviour>(); } int numComponents = (components == null) ? 0 : components.Length; int numEditors = (m_editors == null) ? 0 : m_editors.Length; if (m_cachedReferenceObject != obj || (numComponents + 1) != numEditors) { DestroyComponentEditors(); m_cachedReferenceObject = obj; if (obj != null) { m_editors = new UnityEditor.Editor[components.Length + 1]; CreateCachedEditor(obj.gameObject.GetComponent <Transform>(), null, ref m_editors[0]); for (int i = 0; i < components.Length; ++i) { CreateCachedEditor(components[i], null, ref m_editors[i + 1]); } } } }
public override void OnInspectorGUI() { TimelineControl obj = m_controlProperty.exposedReferenceValue as TimelineControl; if (obj == null) { serializedObject.Update(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(m_controlProperty, kTimelineControlLabel, GUILayout.ExpandWidth(true)); obj = m_controlProperty.exposedReferenceValue as TimelineControl; //if ((obj == null) && GUILayout.Button(new GUIContent("Create"), GUILayout.ExpandWidth(false))) //{ // TimelineControl vcam = CinemachineMenu.CreateDefaultVirtualCamera(); // mControlProperty.exposedReferenceValue = vcam; //} EditorGUILayout.EndHorizontal(); serializedObject.ApplyModifiedProperties(); } else { serializedObject.Update(); DrawPropertiesExcluding(serializedObject, m_excludeFields); // Create an editor for each of the cinemachine virtual cam and its components UpdateComponentEditors(obj); if (m_editors != null) { foreach (UnityEditor.Editor e in m_editors) { EditorGUILayout.Separator(); if (e.target.GetType() != typeof(Transform)) { GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); EditorGUILayout.LabelField(e.target.GetType().Name, EditorStyles.boldLabel); } e.OnInspectorGUI(); } } EditorGUILayout.Separator(); GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); EditorGUILayout.LabelField("Event", EditorStyles.boldLabel); var graphStartEvents = m_behaivorProperty.FindPropertyRelative("graphStartEvents"); var graphEndEvents = m_behaivorProperty.FindPropertyRelative("graphEndEvents"); var behaviorStartEvents = m_behaivorProperty.FindPropertyRelative("behaviorStartEvents"); var behaviorEndEvents = m_behaivorProperty.FindPropertyRelative("behaviorEndEvents"); var behaviorUpdateEvents = m_behaivorProperty.FindPropertyRelative("behaviorUpdateEvents"); UpdateEvents(graphStartEvents, "GraphStart"); UpdateEvents(graphEndEvents, "GraphEnd"); UpdateEvents(behaviorStartEvents, "BehaviorStart"); UpdateEvents(behaviorEndEvents, "BehaviorEnd"); UpdateEvents(behaviorUpdateEvents, "BehaviorUpdate"); serializedObject.ApplyModifiedProperties(); } }
void DestroyComponentEditors() { m_cachedReferenceObject = null; if (m_editors != null) { for (int i = 0; i < m_editors.Length; ++i) { if (m_editors[i] != null) { UnityEngine.Object.DestroyImmediate(m_editors[i]); } m_editors[i] = null; } m_editors = null; } }