//bool bUnfolded = false; /// <summary> /// Draws the component. /// </summary> /// <param name="com">COM.</param> void DrawComponent(IZComponent com) { int iconSize = (int)EditorGUIUtility.singleLineHeight; //draw component member Rect rect = EditorGUILayout.BeginVertical(entityStyle); Type ty = com.GetType(); var memberInfos = ty.GetPublicMemberInfos(); bool bUnfolded = poolConfig.unfoldMap.IsUnfold(curEntity.Name + ty.Name); //SerializedProperty unfoledObj = serializedObject.FindProperty ("unfoldMap"); //draw component file info EditorGUILayout.BeginHorizontal(); { if (memberInfos.Count == 0) { EditorGUILayout.LabelField(" " + ty.Name, EditorStyles.boldLabel); } else { bool bNewUnfold = EditorLayout.Foldout(bUnfolded, ty.Name, iconSize + 10); //EditorGUILayout.LabelField(ty.Name, EditorStyles.boldLabel); if (bNewUnfold != bUnfolded) { poolConfig.unfoldMap.SetUnfold(curEntity.Name + ty.Name, bNewUnfold); // unfoldObj.Update(); // unfoldObj.ApplyModifiedProperties (); } } if (EditorLayout.MiniButton("-")) { //entity.RemoveComponent(index); curEntity.DelComponent(com); } } EditorGUILayout.EndHorizontal(); //Draw the icon if (ComponentsPool <IZComponent> .IsSystem(com)) { GUI.DrawTexture(new Rect(rect.x + 1, rect.y + 1, iconSize - 2, iconSize - 2), IconHelper.SystemsHierarchyIcon); } else { GUI.DrawTexture(new Rect(rect.x + 1, rect.y + 1, iconSize - 2, iconSize - 2), IconHelper.EntityHierarchyIcon); } if (bUnfolded) { InspectorDrawer.DrawObjectMember(com); } EditorGUILayout.EndVertical(); }
/// <summary> /// Initializes the <see cref="ZECSEditor.ComponentsPool`1"/> class. /// </summary> static ComponentsPool() { if (componentInfos == null) { componentInfos = InspectorDrawer.GetTypes <T> () .Where((info) => { var comAttribute = info.GetType().GetCustomAttributes(typeof(DontShowInComponentsAttribute), false); return(comAttribute == null || comAttribute.Count() <= 0); }).ToArray(); } }
internal override void DrawMember() { if (m_fieldType.IsDefined(CustomDrawerType, true)) { if (m_classDrawer == null) { m_classDrawer = InspectorDrawer.Create(m_fieldInfo.GetValue(DeclaringObject), SerializedProperty.Copy(), false); m_classDrawerAccordion = new SimpleAccordion(DisplayName, () => { m_classDrawer.OnEnable(); m_classDrawer.OnInspectorGUI(); }); m_classDrawerAccordion.IsExpanded = SerializedProperty.isExpanded; m_classDrawerAccordion.expandStateChangeCallback = acc => SerializedProperty.isExpanded = acc.IsExpanded; m_classDrawerAccordion.drawHeaderCallback = () => SimpleAccordion.DrawDefaultAccordionHeader(m_classDrawerAccordion, FA.code, 14, 8); } DrawMember(m_classDrawerAccordion.OnGUI); return; } if (IsListOrArray(m_fieldType)) { if (m_reordableAttribute != null) { if (m_reorderableList == null) { m_reorderableList = CreateReordableList(SerializedProperty.serializedObject, SerializedProperty); } DrawMember(m_reorderableList.DoLayoutList); } else { DrawMember(DrawCollection); } } else { DrawMember(DrawPropertyField); } }
public virtual void OnEnable() { targetType = target.GetType(); shouldOverrideInspector = targetType.IsDefined(typeof(OverrideInspectorAttribute), true); if (!shouldOverrideInspector) { return; } shouldBeDrawed = !DontDrawInspectorIfAttribute.TryFindInvalidAttribute(target, out dontDrawAttribute); if (!shouldBeDrawed) { return; } inspectorDrawer = InspectorDrawer.Create(target, serializedObject.GetIterator()); inspectorDrawer.OnEnable(); EditorApplication.update += Repaint; }
/// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary> /// <param name="position"> Rect describing the size and position of the inspector. </param> /// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary> /// <param name="anyInspectorPartMouseovered"> True if any inspector part is currently mouseovered. </param> /// <param name="scrollable"> True if inspector should be drawn as a scrollable view. This might be false e.g. if the inspector drawer handles creating the scroll view. </param> public void OnGUI(Rect position, bool anyInspectorPartMouseovered, bool scrollable) { UnityEngine.Profiling.Profiler.BeginSample("SimpleInspector.OnGUI"); #if DEV_MODE Debug.Assert(InspectorDrawer.Manager.ActiveInstances.Contains(this)); #endif InspectorUtility.BeginInspector(this, ref anyInspectorPartMouseovered); var currentEvent = Event.current; switch (currentEvent.type) { case EventType.Layout: State.nextUpdateCachedValues--; if (State.nextUpdateCachedValues <= 0) { UpdateCachedValuesFromFields(); } OnCursorPositionOrLayoutChanged(); break; case EventType.MouseMove: case EventType.MouseDrag: case EventType.DragUpdated: if (IgnoreViewportMouseInputs()) { break; } OnCursorPositionOrLayoutChanged(); InspectorDrawer.RefreshView(); break; } bool dirty = false; if (scrollable) { BeginScrollView(position); } if (DrawViewport()) { dirty = true; } if (scrollable) { GUI.EndScrollView(); } if (dirty) { InspectorDrawer.RefreshView(); } InspectorUtility.EndInspector(this); UnityEngine.Profiling.Profiler.EndSample(); }
/// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary> /// <param name="inspectorDimensions"> The position and bounds for where the inspecto should be drawn. </param> /// <param name="anyInspectorPartMouseovered"> True if any inspector part is currently mouseovered. </param> public override void OnGUI(Rect inspectorDimensions, bool anyInspectorPartMouseovered) { UnityEngine.Profiling.Profiler.BeginSample("OnGUI"); #if DEV_MODE && DEBUG_CLICK var e = Event.current; if (e.rawType == EventType.MouseDown) { Debug.Log(StringUtils.ToColorizedString(ToString() + " Event=", e, ", e.type=", e.type, ", button=", e.button, ", mousePos=", e.mousePosition, ", GUIUtility.hotControl=", GUIUtility.hotControl)); } #endif //this can happen e.g. if the preferences file gets reimported due to being altered outside of Unity if (Preferences == null) { Preferences = GetPreferences(); } #if DEV_MODE && DEBUG_MOUSEOVERED_PART if (State.drawer.VisibleMembers.Length > 0 && DrawGUI.IsUnityObjectDrag) { Debug.Log(StringUtils.ToColorizedString(ToString(), ".OnGUI with mouseoveredPart=", MouseoveredPart, ", Event=" + StringUtils.ToString(Event.current), ", ignoreAllMouseInputs=", InspectorDrawer.Manager.IgnoreAllMouseInputs, "´, ObjectPickerIsOpen=", ObjectPicker.IsOpen, ", anyInspectorPartMouseovered=", anyInspectorPartMouseovered, ", InspectorDrawer.MouseIsOver=", InspectorDrawer.MouseIsOver, ", DrawGUI.CanRequestMousePosition=", Cursor.CanRequestLocalPosition)); } #endif InspectorUtility.BeginInspector(this, ref anyInspectorPartMouseovered); Rect toolbarRect; Rect viewportRect; Rect previewAreaRect; GetDrawPositions(inspectorDimensions, out toolbarRect, out viewportRect, out previewAreaRect); // trying to fix a bug where the default inspector layout gets wacky if both it and this window are open // by making sure all values that could affect it are restored back to normal // var indentLevelWas = EditorGUI.indentLevel; #if UNITY_EDITOR var labelWidthWas = EditorGUIUtility.labelWidth; #endif var matrixWas = GUI.matrix; var currentEvent = Event.current; switch (currentEvent.type) { case EventType.Layout: State.nextUpdateCachedValues--; if (State.nextUpdateCachedValues <= 0) { UpdateCachedValuesFromFields(); } OnCursorPositionOrLayoutChanged(); break; case EventType.MouseMove: case EventType.MouseDrag: case EventType.DragUpdated: if (IgnoreViewportMouseInputs()) { #if DEV_MODE //Debug.Log("ignoring "+ currentEvent.type+"..."); #endif break; } OnCursorPositionOrLayoutChanged(); InspectorDrawer.RefreshView(); break; } bool dirty; try { dirty = DrawViewport(viewportRect); } catch (Exception e) { if (ExitGUIUtility.ShouldRethrowException(e)) { NowDrawingPart = InspectorPart.None; DrawGUI.IndentLevel = 0; #if UNITY_EDITOR EditorGUIUtility.labelWidth = labelWidthWas; #endif GUI.skin = null; GUI.matrix = matrixWas; throw; } #if DEV_MODE Debug.LogWarning(ToString() + " " + e); #endif dirty = true; } #if !POWER_INSPECTOR_LITE NowDrawingPart = InspectorPart.Toolbar; { Toolbar.Draw(toolbarRect); } #endif NowDrawingPart = InspectorPart.Other; //TO DO: Move to EndInspector if these are needed? //trying to fix a bug where the default inspector layout gets wacky if both it and this window are open //by making sure all values that could affect it are restored back to normal DrawGUI.IndentLevel = 0; #if UNITY_EDITOR EditorGUIUtility.labelWidth = labelWidthWas; #endif GUI.skin = null; GUI.matrix = matrixWas; if (dirty) { InspectorDrawer.RefreshView(); } InspectorUtility.EndInspector(this); UnityEngine.Profiling.Profiler.EndSample(); }
/// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary> /// <param name="inspectorDimensions"> The position and bounds for where the inspecto should be drawn. </param> /// <param name="anyInspectorPartMouseovered"> True if any inspector part is currently mouseovered. </param> public override void OnGUI(Rect inspectorDimensions, bool anyInspectorPartMouseovered) { UnityEngine.Profiling.Profiler.BeginSample("OnGUI"); #if DEV_MODE && DEBUG_CLICK var ev = Event.current; if (ev.rawType == EventType.MouseDown) { Debug.Log(StringUtils.ToColorizedString(ToString() + " Event=", ev, ", e.type=", ev.type, ", button=", ev.button, ", mousePos=", ev.mousePosition, ", GUIUtility.hotControl=", GUIUtility.hotControl)); } #endif #if DEV_MODE && PI_ASSERTATIONS if (inspectorDimensions.width <= 0f) { Debug.LogError(GetType().Name + ".OnGUI inspectorDimensions.width <= 0f: " + inspectorDimensions); } #endif //this can happen e.g. if the preferences file gets reimported due to being altered outside of Unity if (Preferences == null) { Preferences = GetPreferences(); } #if DEV_MODE && DEBUG_MOUSEOVERED_PART if (State.drawer.VisibleMembers.Length > 0 && DrawGUI.IsUnityObjectDrag) { Debug.Log(StringUtils.ToColorizedString(ToString(), ".OnGUI with mouseoveredPart=", MouseoveredPart, ", Event=" + StringUtils.ToString(Event.current), ", ignoreAllMouseInputs=", InspectorDrawer.Manager.IgnoreAllMouseInputs, "´, ObjectPickerIsOpen=", ObjectPicker.IsOpen, ", anyInspectorPartMouseovered=", anyInspectorPartMouseovered, ", InspectorDrawer.MouseIsOver=", InspectorDrawer.MouseIsOver, ", DrawGUI.CanRequestMousePosition=", Cursor.CanRequestLocalPosition)); } #endif InspectorUtility.BeginInspector(this, ref anyInspectorPartMouseovered); Rect toolbarRect; Rect viewportRect; Rect previewAreaRect; GetDrawPositions(inspectorDimensions, out toolbarRect, out viewportRect, out previewAreaRect); // trying to fix a bug where the default inspector layout gets wacky if both it and this window are open // by making sure all values that could affect it are restored back to normal // var indentLevelWas = EditorGUI.indentLevel; var labelWidthWas = EditorGUIUtility.labelWidth; var matrixWas = GUI.matrix; var currentEvent = Event.current; switch (currentEvent.type) { case EventType.Layout: State.nextUpdateCachedValues--; if (State.nextUpdateCachedValues <= 0) { UpdateCachedValuesFromFields(); } OnCursorPositionOrLayoutChanged(); break; case EventType.MouseMove: case EventType.MouseDrag: case EventType.DragUpdated: if (IgnoreViewportMouseInputs()) { #if DEV_MODE //Debug.Log("ignoring "+ currentEvent.type+"..."); #endif break; } OnCursorPositionOrLayoutChanged(); InspectorDrawer.RefreshView(); break; } bool dirty; try { dirty = DrawViewport(viewportRect); } catch (Exception e) { if (ExitGUIUtility.ShouldRethrowException(e)) { NowDrawingPart = InspectorPart.None; DrawGUI.IndentLevel = 0; EditorGUIUtility.labelWidth = labelWidthWas; GUI.skin = null; GUI.matrix = matrixWas; throw; } #if DEV_MODE Debug.LogWarning(ToString() + " " + e); #endif // Always throw ExitGUI exception if exceptions were caught to avoid GUI Layout warnings. ExitGUIUtility.ExitGUI(); return; } #if !POWER_INSPECTOR_LITE NowDrawingPart = InspectorPart.Toolbar; { Toolbar.Draw(toolbarRect); #if UNITY_2019_3_OR_NEWER Color lineColor; if (DrawGUI.IsProSkin) { lineColor = Preferences.theme.ComponentSeparatorLine; } else { lineColor = new Color32(153, 153, 153, 255); } var lineRect = toolbarRect; lineRect.height = 1f; lineRect.y = toolbarRect.height; DrawGUI.DrawLine(lineRect, lineColor); #endif } #endif NowDrawingPart = InspectorPart.Other; try { if (DrawPreviewArea) { NowDrawingPart = InspectorPart.PreviewArea; { previewDrawer.Draw(previewAreaRect); } NowDrawingPart = InspectorPart.Other; } } #if DEV_MODE catch (ArgumentException e) // GUILayout: Mismatched LayoutGroup.repaint { Debug.LogError(StringUtils.ToString(Event.current) + " " + e + "\nEvent=" + StringUtils.ToString(Event.current)); #else catch (ArgumentException) { #endif // new test to avoid GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced. NowDrawingPart = InspectorPart.None; ExitGUIUtility.ExitGUI(); } //TO DO: Move to EndInspector if these are needed? //trying to fix a bug where the default inspector layout gets wacky if both it and this window are open //by making sure all values that could affect it are restored back to normal DrawGUI.IndentLevel = 0; EditorGUIUtility.labelWidth = labelWidthWas; GUI.skin = null; GUI.matrix = matrixWas; if (dirty) { InspectorDrawer.RefreshView(); } InspectorUtility.EndInspector(this); UnityEngine.Profiling.Profiler.EndSample(); }
/// <inheritdoc/> public override void Message(GUIContent message, Object context = null, MessageType messageType = MessageType.Info, bool alsoLogToConsole = true) { InspectorDrawer.Message(message, context, messageType, alsoLogToConsole); }
/// <summary> /// Draws the control bar. /// </summary> void DrawControlBar() { var componentColor = Color.HSVToRGB(0.5f, 0.7f, 1f); componentColor.a = 0.15f; var style = new GUIStyle(GUI.skin.label); style.normal.background = InspectorDrawer.createTexture(2, 2, componentColor); // EditorGUILayout.BeginHorizontal(style); //EditorGUILayout.LabelField (""); if (GUILayout.Button("Add Entity", GUILayout.MaxWidth(100))) { var node = curPoolConfig.PoolNodeRoot.FindNode(CurSelWndID); //curPoolConfig.CreateEntity (); curPoolConfig.CreateEntityAt(node); EntityPoolEditorBuildUtils.SaveEntity(curPoolConfig.CurEntity); EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot); Refresh(); } if (GUILayout.Button("Delete Entity", GUILayout.MaxWidth(100))) { ZEntity en = curPoolConfig.DeleteCurEntity(); EntityPoolEditorBuildUtils.DelEntityFile(en); EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot); Refresh(); } if (GUILayout.Button("Add System", GUILayout.MaxWidth(100))) { curPoolConfig.CreateSystem(); EntityPoolEditorBuildUtils.SaveEntity(curPoolConfig.CurEntity); EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot); Refresh(); } if (GUILayout.Button("Reset", GUILayout.MaxWidth(100))) { EntityPoolEditorBuildUtils.DelAllEntity(curPoolConfig.PoolNodeRoot); curPoolConfig.DeleteAllEntity(); EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot); Refresh(); } if (GUILayout.Button("Isolate", GUILayout.MaxWidth(100))) { if (curPoolConfig.CurEntity != null) { curPoolConfig.PoolNodeRoot.IsolateRelation(curPoolConfig.CurEntity.ID); EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot); Refresh(); } } strTempEditEntityName = GUILayout.TextArea(strTempEditEntityName, GUILayout.MaxWidth(200)); if (GUILayout.Button("Rename", GUILayout.MaxWidth(100))) { if (curPoolConfig.CurEntity != null && CurSelWndID >= 0) { //curPoolConfig.CurEntity.Name = strTempEditEntityName; curPoolConfig.PoolNodeRoot.Rename(curPoolConfig.CurEntity.ID, strTempEditEntityName); root.RenameTitle(curPoolConfig.CurEntity.ID, strTempEditEntityName); SaveLayout(); EntityPoolEditorBuildUtils.ChangeEntityName(curPoolConfig.CurEntity, strTempEditEntityName); EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot); Refresh(); } } //curEntity.Name = EditorGUILayout.TextField (curEntity.Name); EditorGUILayout.EndHorizontal(); }
/// <summary> /// Draws the entity. /// </summary> void DrawEntity() { EditorGUI.BeginChangeCheck(); var componentColor = Color.HSVToRGB(0.5f, 0.7f, 1f); componentColor.a = 0.15f; entityStyle = new GUIStyle(GUI.skin.box); entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor); List <IZComponent> coms = curEntity.GetComponents <IZComponent> (); //draw current selected entity EditorGUILayout.BeginVertical(entityStyle); //show the entity name EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Entity Name: " + curEntity.Name); //curEntity.Name = EditorGUILayout.TextField (curEntity.Name); EditorGUILayout.EndHorizontal(); //show component info EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Component x " + coms.Count, GUILayout.MaxWidth(100)); GUILayout.FlexibleSpace(); //show the component menu IZComponent c = curEntity.EType == EntityType.Entity ? ComponentsPool <IZComponent> .DrawAddComponentMenu() : ComponentsPool <IZComponent> .DrawAddSystemMenu(); if (c != null) { var com = ComponentsPool <IZComponent> .CreateComponent(c.GetType()); curEntity.AddComponent(com); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //Draw Component componentColor = Color.HSVToRGB(0.9f, 0.1f, 0.9f); componentColor.a = 0.15f; entityStyle = new GUIStyle(GUI.skin.box); entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor); ///EditorGUILayout.Space(); foreach (IZComponent com in coms) { DrawComponent(com); } if (EditorGUI.EndChangeCheck()) { // Code to execute if GUI.changed // was set to true inside the block of code above. if (poolConfig != null && poolConfig.CurPool != null) { //Debug.Log("EndChangeCheck"); EntityPoolEditorBuildUtils.SaveEntity(curEntity); serializedObject.SetIsDifferentCacheDirty(); EditorApplication.DirtyHierarchyWindowSorting(); EditorApplication.RepaintProjectWindow(); //AssetDatabase.Refresh (); //EditorApplication. } } }