public ComponentRef(GameObjectRef.eSourceType sourceType, Component component) { GameObject gameObject = component != null ? component.gameObject : null; _gameObject = new GameObjectRef(sourceType, gameObject); _componentIndex = 0; _component = component as T; _editorCollapsed = false; if (component != null) { Component[] components = gameObject.GetComponents <Component>(); int index = 0; for (int i = 0; i < components.Length; i++) { if (components[i] is T) { if (components[i] == component) { _componentIndex = index; break; } index++; } } } }
public ComponentRef(GameObjectRef.eSourceType sourceType) { _gameObject = new GameObjectRef(sourceType); _componentIndex = 0; _component = null; _editorCollapsed = false; }
public static object PropertyField(object obj, GUIContent label, ref bool dataChanged, GUIStyle style, params GUILayoutOption[] options) { GameObjectRef gameObjectRef = (GameObjectRef)obj; if (label == null) { label = new GUIContent(); } label.text += " (" + gameObjectRef + ")"; bool editorCollapsed = !EditorGUILayout.Foldout(!gameObjectRef._editorCollapsed, label); if (editorCollapsed != gameObjectRef._editorCollapsed) { gameObjectRef._editorCollapsed = editorCollapsed; dataChanged = true; } if (!editorCollapsed) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; //Show drop down GameObjectRef.eSourceType sourceType = SerializationEditorGUILayout.ObjectField(gameObjectRef.GetSourceType(), "Source Type", ref dataChanged); if (sourceType != gameObjectRef.GetSourceType()) { gameObjectRef = new GameObjectRef(sourceType); dataChanged = true; } switch (sourceType) { case GameObjectRef.eSourceType.Scene: { RenderSceneGameObjectField(ref gameObjectRef, ref dataChanged); } break; case GameObjectRef.eSourceType.Prefab: { RenderPrefabGameObjectField(ref gameObjectRef, ref dataChanged); } break; case GameObjectRef.eSourceType.Loaded: { RenderLoadedGameObjectField(ref gameObjectRef, ref dataChanged); } break; } EditorGUI.indentLevel = origIndent; } return(gameObjectRef); }
public ComponentRef(GameObjectRef.eSourceType sourceType, Component component, int componentIndex) { GameObject gameObject = component != null ? component.gameObject : null; _gameObject = new GameObjectRef(sourceType, gameObject); _componentIndex = componentIndex; _component = component as T; _editorCollapsed = false; }
private static ComponentRef <T> ComponentField <T>(ComponentRef <T> componentRef, GUIContent label, ref bool dataChanged) where T : class { if (label == null) { label = new GUIContent(); } label.text += " (" + componentRef + ")"; bool editorCollapsed = !EditorGUILayout.Foldout(!componentRef._editorCollapsed, label); if (editorCollapsed != componentRef._editorCollapsed) { componentRef._editorCollapsed = editorCollapsed; dataChanged = true; } if (!editorCollapsed) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; //Show drop down for gameobject type. GameObjectRef.eSourceType sourceType = SerializationEditorGUILayout.ObjectField(componentRef.GetGameObjectRef().GetSourceType(), "Source Type", ref dataChanged); if (sourceType != componentRef.GetGameObjectRef().GetSourceType()) { componentRef = new ComponentRef <T>(sourceType); dataChanged = true; } switch (sourceType) { case GameObjectRef.eSourceType.Scene: RenderSceneObjectField(ref componentRef, ref dataChanged); break; case GameObjectRef.eSourceType.Prefab: RenderPrefabObjectField(ref componentRef, ref dataChanged); break; case GameObjectRef.eSourceType.Loaded: RenderLoadedObjectField(ref componentRef, ref dataChanged); break; } EditorGUI.indentLevel = origIndent; } return(componentRef); }
public bool RenderObjectProperties(GUIContent label) { bool dataChanged = false; if (label == null) { label = new GUIContent(); } label.text += " (" + this + ")"; _editorFoldout = EditorGUILayout.Foldout(_editorFoldout, label); if (_editorFoldout) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; //Show drop down GameObjectRef.eSourceType prevType = _gameObject._sourceType; _gameObject._sourceType = SerializedObjectEditorGUILayout.ObjectField(_gameObject._sourceType, "Source Type", out dataChanged); if (prevType != _gameObject._sourceType) { ClearComponent(); dataChanged = true; } switch (_gameObject._sourceType) { case GameObjectRef.eSourceType.Scene: dataChanged |= RenderSceneObjectProperties(); break; case GameObjectRef.eSourceType.Prefab: dataChanged |= RenderPrefabProperties(); break; case GameObjectRef.eSourceType.Loaded: dataChanged |= RenderLoadedObjectProperties(); break; } EditorGUI.indentLevel = origIndent; } return(dataChanged); }
public void SetComponent(Component component, GameObjectRef.eSourceType gameObjectType) { GameObject gameObject = component != null ? component.gameObject : null; switch (gameObjectType) { case GameObjectRef.eSourceType.Scene: _gameObject.SetSceneGameObject(gameObject); break; case GameObjectRef.eSourceType.Prefab: _gameObject.SetPrefabGameObject(gameObject); break; case GameObjectRef.eSourceType.Loaded: _gameObject.SetLoadedGameObject(gameObject); break; } _editorComponent = component; _componentIndex = 0; if (component != null) { Component[] components = gameObject.GetComponents <Component>(); int index = 0; for (int i = 0; i < components.Length; i++) { if (components[i] is T) { if (components[i] == component) { _componentIndex = index; break; } index++; } } } }