public static object DrawAndGetNewValue(Type type, string fieldName, object value, Entity entity, int index, IComponent component) { if (value == null) { var isUnityObject = type == typeof(UnityEngine.Object) || type.IsSubclassOf(typeof(UnityEngine.Object)); EntitasEditorLayout.BeginHorizontal(); { if (isUnityObject) { value = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)value, type, true); } else { EditorGUILayout.LabelField(fieldName, "null"); } if (GUILayout.Button("Create", GUILayout.Height(14))) { object defaultValue; if (CreateDefault(type, out defaultValue)) { value = defaultValue; } } } EntitasEditorLayout.EndHorizontal(); return(value); } if (!type.IsValueType) { EntitasEditorLayout.BeginHorizontal(); EntitasEditorLayout.BeginVertical(); } var typeDrawer = getTypeDrawer(type); if (typeDrawer != null) { value = typeDrawer.DrawAndGetNewValue(type, fieldName, value, entity, index, component); } else { drawUnsupportedType(type, fieldName, value); } if (!type.IsValueType) { EntitasEditorLayout.EndVertical(); if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) { value = null; } EntitasEditorLayout.EndHorizontal(); } return(value); }
void drawCodeGenerators() { EditorGUILayout.Space(); EditorGUILayout.LabelField("Code Generators", EditorStyles.boldLabel); var enabledCodeGenerators = new HashSet <string>(_codeGeneratorConfig.enabledCodeGenerators); var availableGeneratorNames = new HashSet <string>(); EntitasEditorLayout.BeginHorizontal(); { var rect = EntitasEditorLayout.BeginVertical(); if (rect.height > 0) { _generatorsRectHeight = rect.height - 2; } { foreach (var codeGenerator in _codeGenerators) { availableGeneratorNames.Add(codeGenerator.Name); var isEnabled = enabledCodeGenerators.Contains(codeGenerator.Name); isEnabled = EditorGUILayout.Toggle(codeGenerator.Name.Replace("Generator", string.Empty), isEnabled); if (isEnabled) { enabledCodeGenerators.Add(codeGenerator.Name); } else { enabledCodeGenerators.Remove(codeGenerator.Name); } } } EntitasEditorLayout.EndVertical(); var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.green; if (GUILayout.Button("Generate", GUILayout.Width(200), GUILayout.Height(_generatorsRectHeight))) { UnityCodeGenerator.Generate(); } GUI.backgroundColor = bgColor; } EntitasEditorLayout.EndHorizontal(); foreach (var generatorName in _codeGeneratorConfig.enabledCodeGenerators.ToArray()) { if (!availableGeneratorNames.Contains(generatorName)) { enabledCodeGenerators.Remove(generatorName); } } var sortedCodeGenerators = enabledCodeGenerators.ToArray(); Array.Sort(sortedCodeGenerators); _codeGeneratorConfig.enabledCodeGenerators = sortedCodeGenerators; }
void drawCodeGenerators() { EditorGUILayout.Space(); EditorGUILayout.LabelField("Code Generators", EditorStyles.boldLabel); var enabledCodeGenerators = new HashSet <string>(_codeGeneratorConfig.enabledCodeGenerators); var availableGeneratorNames = new HashSet <string>(); EntitasEditorLayout.BeginHorizontal(); { EntitasEditorLayout.BeginVertical(); { foreach (var codeGenerator in _codeGenerators) { availableGeneratorNames.Add(codeGenerator.Name); var isEnabled = enabledCodeGenerators.Contains(codeGenerator.Name); isEnabled = EditorGUILayout.Toggle(codeGenerator.Name, isEnabled); if (isEnabled) { enabledCodeGenerators.Add(codeGenerator.Name); } else { enabledCodeGenerators.Remove(codeGenerator.Name); } } } EntitasEditorLayout.EndVertical(); if (GUILayout.Button("Generate", GUILayout.Width(200), GUILayout.Height(68))) { UnityCodeGenerator.Generate(); } } EntitasEditorLayout.EndHorizontal(); foreach (var generatorName in _codeGeneratorConfig.enabledCodeGenerators.ToArray()) { if (!availableGeneratorNames.Contains(generatorName)) { enabledCodeGenerators.Remove(generatorName); } } var sortedCodeGenerators = enabledCodeGenerators.ToArray(); Array.Sort(sortedCodeGenerators); _codeGeneratorConfig.enabledCodeGenerators = sortedCodeGenerators; }
static bool draw(string propertyName, object value, bool drawLuaTable, out object nvalue) { bool ret = false; if (value == null) { nvalue = null; EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField(propertyName, "null"); if (GUILayout.Button("CreateString", GUILayout.Height(14))) { nvalue = string.Empty; ret = true; } if (GUILayout.Button("CreateNumber", GUILayout.Height(14))) { nvalue = 0d; ret = true; } } EntitasEditorLayout.EndHorizontal(); return(ret); } EntitasEditorLayout.BeginVertical(); { PropertyDrawer drawer; if ((!drawLuaTable && value is LuaTable) || !propertyTypeDrawer.TryGetValue(value.GetType(), out drawer)) { drawer = defaultDrawer; } ret = drawer(propertyName, value, out nvalue); } EntitasEditorLayout.EndVertical(); return(ret); }
void drawSystemList(string systemsName) { EntitasEditorLayout.BeginVertical(); { EntitasEditorLayout.BeginHorizontal(); { LuaSystems ls = target as LuaSystems; ls.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", ls.avgResetInterval); if (GUILayout.Button("Reset Ø now", GUILayout.Width(88), GUILayout.Height(14))) { LuaSystems.Reset(systemsName); } } EntitasEditorLayout.EndHorizontal(); _threshold = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f); _sortSystemInfos = EditorGUILayout.Toggle("Sort by execution duration", _sortSystemInfos); EditorGUILayout.Space(); EntitasEditorLayout.BeginHorizontal(); { _systemNameSearchTerm = EditorGUILayout.TextField("Search", _systemNameSearchTerm); const string clearButtonControlName = "Clear Button"; GUI.SetNextControlName(clearButtonControlName); if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) { _systemNameSearchTerm = string.Empty; GUI.FocusControl(clearButtonControlName); } } EntitasEditorLayout.EndHorizontal(); _showInitializeSystems = EditorGUILayout.Foldout(_showInitializeSystems, "Initialize Systems"); if (_showInitializeSystems) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systemsName, true, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } _showExecuteSystems = EditorGUILayout.Foldout(_showExecuteSystems, "Execute Systems"); if (_showExecuteSystems) { EntitasEditorLayout.BeginVerticalBox(); { var systemsDrawn = drawSystemInfos(systemsName, false, false); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } EntitasEditorLayout.EndVertical(); } } EntitasEditorLayout.EndVertical(); }