public void Clear_ResetsCount() { _layerCollection.Add(new OutlineLayer()); _layerCollection.Clear(); Assert.Zero(_layerCollection.Count); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUI.BeginChangeCheck(); var removeLayer = -1; // 1) Layers list. if (_layers.Count > 0) { for (var i = 0; i < _layers.Count; i++) { EditorGUILayout.Space(); var rect = EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Layer #" + i.ToString()); GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove", _layerButtonStyle)) { removeLayer = i; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); rect.xMin -= 2; rect.xMax += 2; rect.yMin -= 2; rect.yMax += 2; GUI.Box(rect, GUIContent.none); OutlineEditorUtility.Render(_layers[i], _layers); } } else { EditorGUILayout.HelpBox("The layer collection is empty.", MessageType.Info, true); } // Add/remove processing. OutlineEditorUtility.RenderDivider(Color.gray); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add New", _layerButtonStyle)) { Undo.RecordObject(_layers, "Add Layer"); _layers.Add(new OutlineLayer()); } if (GUILayout.Button("Remove All", _layerButtonStyle)) { Undo.RecordObject(_layers, "Remove All Layers"); _layers.Clear(); } if (removeLayer >= 0) { Undo.RecordObject(_layers, "Remove Layer"); _layers.RemoveAt(removeLayer); } EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(_layers); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUI.BeginChangeCheck(); var removeLayer = -1; // 1) Layers list. if (_layers.Count > 0) { for (var i = 0; i < _layers.Count; i++) { EditorGUILayout.Space(); var rect = EditorGUILayout.BeginHorizontal(); var enabled = EditorGUILayout.ToggleLeft("Layer #" + i.ToString(), _layers[i].Enabled); if (enabled != _layers[i].Enabled) { if (enabled) { Undo.RecordObject(_layers, "Enable Layer"); } else { Undo.RecordObject(_layers, "Disable Layer"); } _layers[i].Enabled = enabled; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove", _layerButtonStyle)) { removeLayer = i; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); rect.xMin -= 2; rect.xMax += 2; rect.yMin -= 2; rect.yMax += 2; GUI.Box(rect, GUIContent.none); var name = EditorGUILayout.TextField("Layer Name", _layers[i].NameTag); if (name != _layers[i].NameTag) { Undo.RecordObject(_layers, "Set Layer Name"); _layers[i].NameTag = name; } var priority = EditorGUILayout.IntField("Layer Priority", _layers[i].Priority); if (priority != _layers[i].Priority) { Undo.RecordObject(_layers, "Set Layer Priority"); _layers[i].Priority = priority; } OutlineEditorUtility.Render(_layers[i], _layers); } } else { EditorGUILayout.HelpBox("The layer collection is empty.", MessageType.Info, true); } // Add/remove processing. OutlineEditorUtility.RenderDivider(Color.gray); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add New", _layerButtonStyle)) { Undo.RecordObject(_layers, "Add Layer"); _layers.Add(new OutlineLayer()); } if (GUILayout.Button("Remove All", _layerButtonStyle)) { Undo.RecordObject(_layers, "Remove All Layers"); _layers.Clear(); } if (removeLayer >= 0) { Undo.RecordObject(_layers, "Remove Layer"); _layers.RemoveAt(removeLayer); } EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(_layers); } }