void Draw( IEnumerable <Trait> children, Trait[] all, List <Problem> problems ) { foreach (var trait in children) { trait.TryClaim(entity, all, out var dependencies, false); if (dependencies == null) { continue; } using (new EditorGUILayout.HorizontalScope(Styles.box)) { var content = new GUIContent(trait.GetType().Name); if (!dependencies.Problems.IsEmpty()) { TsukiGUILayout.Icon(Icons.console_erroricon, 16); } EditorGUILayout.PrefixLabel(content); EditorGUILayout.Space(0, true); var obj = Selection.activeObject; var editable = true; if (obj == trait) { editable = false; } else if (obj is GameObject go && go == trait.gameObject) { editable = false; } using (new GUIEnabledScope(editable)) { if (GUILayout.Button("Select", GUILayout.Height(22), GUILayout.Width(32F * 4))) { Selection.activeObject = trait; } } if (GUILayout.Button(Icons.treeeditor_trash, GUILayout.Height(22), GUILayout.Width(22))) { Delete(trait); } } problems.AddRange(dependencies.Problems); } }
public override void OnInspectorGUI() { var found = entity.GetComponentsInChildren <Trait>(); var problems = new List <Problem>(); using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.LabelField($"Traits ({found.Length})", EditorStyles.boldLabel); button.OnInspectorGUI(); } EditorGUILayout.Space(); if (EditorApplication.isPlaying) { GUILayout.Label( new GUIContent { image = Icons.console_infoicon, text = "Please exit play mode to inspect entity" }, Styles.CenteredLabel ); return; } foreach (var trait in found) { trait.TryClaim(entity, found, out var dependencies, false); if (dependencies == null) { continue; } using (new EditorGUILayout.HorizontalScope(Styles.box)) { var content = new GUIContent(trait.GetType().Name); if (!dependencies.Problems.IsEmpty()) { TsukiGUILayout.Icon(Icons.console_erroricon, 16); } EditorGUILayout.PrefixLabel(content); EditorGUILayout.Space(0, true); var obj = Selection.activeObject; var editable = true; if (obj == trait) { editable = false; } else if (obj is GameObject go && go == trait.gameObject) { editable = false; } using (new GUIEnabledScope(editable)) { if (GUILayout.Button("Select", GUILayout.Height(22), GUILayout.Width(32F * 4))) { Selection.activeObject = trait; } } if (GUILayout.Button(Icons.treeeditor_trash, GUILayout.Height(22), GUILayout.Width(22))) { Delete(trait); } } problems.AddRange(dependencies.Problems); } } if (problems.IsEmpty()) { return; } using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { EditorGUILayout.LabelField("Problems: ", EditorStyles.boldLabel); foreach (var problem in problems) { using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) { GUILayout.Label(new GUIContent(problem.Description, Icons.console_erroricon), ProblemStyle.Value); var solution = problem.Solution; if (solution == null) { continue; } if (GUILayout.Button( solution.Description, GUILayout.ExpandHeight(true) )) { solution.Action(); } } } } }