public override void OnInspectorGUI() { GUILayout.Space(20); GUILayout.BeginVertical(NanoEditorHelper.backStyle()); GUILayout.Space(5); GUILayout.Label(handler.ContextName + " Context", new GUIStyle() { fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter }); GUILayout.Space(20); if (GUILayout.Button("Create Entity")) { handler.CreateEntity(); } GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.Space(20); }
public override void OnInspectorGUI() { serializedObject.Update(); DrawLogo(); GUILayout.BeginVertical(NanoEditorHelper.backStyle()); GUILayout.Space(5); GUILayout.Label("(triggers recompilation)", NanoEditorHelper.SettingsTitleStyle); GUILayout.Space(5); settings.VisualDebugEnabled = GUILayout.Toggle(settings.VisualDebugEnabled, "Visual Debug Enabled"); settings.ReactivityEnabled = GUILayout.Toggle(settings.ReactivityEnabled, "Reactivity Enabled"); GUILayout.EndVertical(); GUILayout.Space(25); EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratedFolderPath")); EditorGUILayout.PropertyField(serializedObject.FindProperty("SourceFolderPath")); EditorGUILayout.PropertyField(serializedObject.FindProperty("TriggerGenerationOnSourceChange")); GUILayout.Space(25); list.DoLayoutList(); serializedObject.ApplyModifiedProperties(); if (target != null) { EditorUtility.SetDirty(target); } }
void UpdateEditor() { EditorGUILayout.Space(); if (GUILayout.Button(new GUIContent("Destroy"), GUILayout.Height(20))) { observer.OnEntityDestroy(entity); } EditorGUILayout.Space(); #if UNITY_EDITOR && NANOECS_DEBUG var componentObservers = new List <ComponentObserver>(entity.ComponentObservers); foreach (var componentObserver in componentObservers) { var component = componentObserver.Component; //DrawUILine(backColor, 4); GUILayout.Space(5); var type = component.GetType(); GUILayout.BeginHorizontal(NanoEditorHelper.backStyle(component.GetHashCode())); var name = type.Name.Replace("Component", ""); var fields = type.GetFields( BindingFlags.NonPublic | BindingFlags.Instance).ToList(); if (fields.Count > 0) { GUILayout.Space(15); componentObserver.IsFoldout = EditorGUILayout.Foldout(componentObserver.IsFoldout, name, true); } else { EditorGUILayout.LabelField(name); } if (GUILayout.Button("✕", GUILayout.Width(19), GUILayout.Height(19))) { entity.RemoveComponentOfIndex(observer.ComponentsLookup[component.GetType().ToString()]); } GUILayout.EndHorizontal(); if (!componentObserver.IsFoldout) { continue; } foreach (var field in fields) { var fieldValue = field.GetValue(component); var fieldType = field.FieldType; var strVal = fieldValue != null?string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", fieldValue) : "null"; if (strVal.Length > MaxFieldToStringLength) { strVal = strVal.Substring(0, MaxFieldToStringLength); } GUILayout.BeginHorizontal(NanoEditorHelper.backStyle(component.GetHashCode())); //EditorGUILayout.LabelField(field.Name, GUILayout.MaxWidth(EditorGUIUtility.labelWidth - 16)); if (fieldType == typeof(bool)) { var newValue = EditorGUILayout.Toggle(field.Name, (bool)fieldValue); SetValue(component, fields, field, newValue); } else if (fieldType == typeof(int)) { var newValue = EditorGUILayout.IntField(field.Name, (int)fieldValue); SetValue(component, fields, field, newValue); } else if (fieldType == typeof(float)) { var newValue = EditorGUILayout.FloatField(field.Name, (float)fieldValue); SetValue(component, fields, field, newValue); } else if (fieldType == typeof(string)) { var newValue = EditorGUILayout.DelayedTextField(field.Name, (string)fieldValue); SetValue(component, fields, field, newValue); } else if (fieldType == typeof(Vector3)) { var newValue = EditorGUILayout.Vector3Field(field.Name, (Vector3)fieldValue); SetValue(component, fields, field, newValue); } else if (fieldType == typeof(Vector2)) { var newValue = EditorGUILayout.Vector2Field(field.Name, (Vector2)fieldValue); SetValue(component, fields, field, newValue); } else if (fieldType == typeof(Vector2Int)) { var newValue = EditorGUILayout.Vector2IntField(field.Name, (Vector2Int)fieldValue); SetValue(component, fields, field, newValue); } else if (fieldType.IsEnum) { var newValue = (Enum)EditorGUILayout.EnumPopup(field.Name, (Enum)fieldValue); SetValue(component, fields, field, newValue); } else if (fieldType == typeof(UnityEngine.Object) || fieldType.IsSubclassOf(typeof(UnityEngine.Object)) || (fieldType.IsInterface && fieldValue is MonoBehaviour)) { var newValue = EditorGUILayout.ObjectField(field.Name, (UnityEngine.Object)fieldValue, fieldType, true); SetValue(component, fields, field, newValue); } else if (fieldType.IsSubclassOf(typeof(Entity)) && fieldValue != null) { var p = observer.transform.parent; var go = p.Find("Entity_" + (fieldValue as Entity).ID); var newValue = EditorGUILayout.ObjectField(field.Name, go, fieldType, true); //SetValue(component, fields, field, newValue); } else if (fieldType.GetInterfaces().Contains(typeof(IEnumerable))) { int itemsCount = 0; float minHeight = EditorGUIUtility.singleLineHeight; foreach (var item in (IEnumerable)fieldValue) { itemsCount++; } GUILayout.BeginScrollView(EditorGUILayout.GetControlRect().position, GUILayout.Height(itemsCount * minHeight + minHeight)); GUILayout.BeginVertical(); foreach (var item in (IEnumerable)fieldValue) { EditorGUILayout.SelectableLabel(item.ToString(), (GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight))); } GUILayout.EndVertical(); GUILayout.EndScrollView(); } else { EditorGUILayout.SelectableLabel(strVal, GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight)); } GUILayout.EndHorizontal(); } } GUILayout.Space(25); if (!observer.DisplayDropDown) { if (GUILayout.Button(new GUIContent("Add Component"), GUILayout.Height(20))) { observer.DisplayDropDown = true; } } if (observer.DisplayDropDown) { var types = observer.ComponentsLookup.Keys .Where(type => !componentObservers.Select(o => o.Component.GetType().ToString()).ToList().Contains(type)) .ToArray(); var r = EditorGUILayout.GetControlRect(); r.height = 20; observer.CurrentComponentName = EditorExtend.TextFieldAutoComplete(r, observer.CurrentComponentName, types, maxShownCount: 10, levenshteinDistance: 0.5f); } if (observer.ComponentsLookup.ContainsKey(observer.CurrentComponentName)) { entity.Add <ComponentEcs>(observer.ComponentsLookup[observer.CurrentComponentName]); observer.CurrentComponentName = string.Empty; } Event e = Event.current; if (e.type == EventType.Ignore || (e.type == EventType.MouseDown)) { observer.DisplayDropDown = false; } GUILayout.Space(50); if (target != null) { EditorUtility.SetDirty(target); } #endif }