public override void OnInspectorGUI() { var state = target as MonoBehaviourState; K10EditorGUIUtils.Semaphore(state.IsAlive, "IsAlive"); K10EditorGUIUtils.Semaphore(state.IsActive, "IsActive"); }
public static bool DrawSemaphoresOnGUI <T, K>(object obj, float sizePerElements = 100) where T : class where K : IValueStateObserver <bool> { var t = obj as T; var props = typeof(T).GetProperties(); bool initialLabel = false; int items = 1; int itemsPerRow = (int)(EditorGUIUtility.currentViewWidth / sizePerElements); GUILayout.BeginHorizontal(); for (int i = 0; i < props.Length; i++) { var prop = props[i]; if (prop.PropertyType == typeof(K)) { if (!initialLabel) { initialLabel = true; GUILayout.Label(typeof(K).Name + "(s)", K10GuiStyles.boldStyle); } var name = prop.Name; try { var semaphore = (K)prop.GetValue(t, null); K10EditorGUIUtils.Semaphore(semaphore, name); } catch (System.Exception ex) { GUILayout.BeginHorizontal(); K10.EditorGUIExtention.IconButton.Layout("error", 18, 'X', "", Color.red); GUILayout.Label($"{name}({ex.Message})", K10GuiStyles.smallStyle); GUILayout.EndHorizontal(); } items++; if (items >= itemsPerRow) { items = 0; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); return(initialLabel); }
public static void Layout(SerializedProperty property, string newFilePreffix) { EditorGUILayout.BeginHorizontal(); bool valid = (property.objectReferenceValue != null) && (property.objectReferenceValue is T); var id = -1; if (valid) { id = PrefabCache <T> .Cache.IndexOf(property.objectReferenceValue as T); } id++; var iconSize = 20; if (id == 0 && newFilePreffix != null) { if (IconButton.Layout("add", iconSize, '+', "Create new " + typeof(T).ToString() + " prefab", Color.green)) { property.objectReferenceValue = K10EditorGUIUtils.CreateSequentialGO <T>(newFilePreffix + typeof(T)); PrefabCache <T> .Refresh(); } } else { PreviewButton.Layout(iconSize, property.objectReferenceValue as T); } var nid = EditorGUILayout.Popup(id, PrefabCache <T> .NamesWithNone); if (nid != id) { nid--; if (nid < 0) { property.objectReferenceValue = null; } else { property.objectReferenceValue = PrefabCache <T> .Cache[nid]; } } if (IconButton.Layout("refreshButton", iconSize, 'R', "Refresh prefabs loaded", Color.blue)) { PrefabCache <T> .Refresh(); } EditorGUILayout.EndHorizontal(); }
public static void Draw(Rect area, SerializedProperty property, string addFolder) { bool valid = (property.objectReferenceValue != null) && (property.objectReferenceValue is T); var id = -1; if (valid) { id = PrefabCache <T> .Cache.IndexOf(property.objectReferenceValue as T); } id++; var iconSize = Mathf.Min(area.height, area.width / 4); var iconArea = area.CutRight(area.width - iconSize).RequestHeight(iconSize); if (id == 0 && addFolder != null) { if (IconButton.Draw(iconArea, "add", '+', "Create new " + typeof(T).ToString() + " prefab", Color.green)) { property.objectReferenceValue = K10EditorGUIUtils.CreateSequentialGO <T>(addFolder + "/New" + typeof(T).ToString()); PrefabCache <T> .Refresh(); } } else { PreviewButton.Draw(iconArea, property.objectReferenceValue as T); } area = area.CutLeft(iconSize).RequestHeight(EditorGUIUtility.singleLineHeight); var nid = EditorGUI.Popup(area.CutRight(iconSize), id, PrefabCache <T> .NamesWithNone); if (nid != id) { nid--; if (nid < 0) { property.objectReferenceValue = null; } else { property.objectReferenceValue = PrefabCache <T> .Cache[nid]; } } if (IconButton.Draw(area.CutLeft(area.width - iconSize).RequestHeight(iconSize), "refreshButton", 'R', "Refresh prefabs loaded", Color.blue)) { PrefabCache <T> .Refresh(); } }
public static bool DrawReactiveProperties <T>(object target) where T : class { var drawSomething = false; drawSomething |= K10EditorGUIUtils.DrawSemaphoresOnGUI <T, ISemaphore>(target); drawSomething |= K10EditorGUIUtils.DrawSemaphoresOnGUI <T, IBoolStateObserver>(target, 120); drawSomething |= K10EditorGUIUtils.DrawSemaphoresOnGUI <T, IStateRequester>(target, 120); drawSomething |= K10EditorGUIUtils.DrawValueObserverOnGUI <T, int>(target); drawSomething |= K10EditorGUIUtils.DrawValueObserverOnGUI <T, uint>(target); drawSomething |= K10EditorGUIUtils.DrawValueObserverOnGUI <T, float>(target); drawSomething |= K10EditorGUIUtils.DrawValueObserverOnGUI <T, Vector2>(target); drawSomething |= K10EditorGUIUtils.DrawValueObserverOnGUI <T, Rect>(target, 300); drawSomething |= K10EditorGUIUtils.DrawValueObserverOnGUI <T, Ray>(target, 300); return(drawSomething); }
public static void Layout <T>(SerializedProperty prop, string newFolderPath) where T : Behaviour { var obj = prop.objectReferenceValue; if (obj == null) { var create = GUILayout.Button(IconCache.Get("match").Texture, new GUIStyle(), GUILayout.Width(16)); if (create) { var go = K10EditorGUIUtils.CreateSequentialGO <T>(newFolderPath + prop.ToFileName()); prop.objectReferenceValue = go; prop.serializedObject.ApplyModifiedProperties(); } } Layout <T>(prop, false); }
public static void Draw <T>(Rect r, SerializedProperty prop, string newFolderPath) where T : MonoBehaviour { var obj = prop.objectReferenceValue; if (obj == null) { var iconSize = 16; var create = GUI.Button(new Rect(r.x, r.y + (r.height - iconSize) / 2, iconSize, iconSize), IconCache.Get("match").Texture, new GUIStyle()); if (create) { var go = K10EditorGUIUtils.CreateSequentialGO <T>(newFolderPath + prop.ToFileName()); prop.objectReferenceValue = go; prop.serializedObject.ApplyModifiedProperties(); } r.x += iconSize + 2; r.width -= iconSize + 2; } Draw <T>(r, prop, false); }
public static bool DrawValueObserverOnGUI <T, K>(object obj, float sizePerElements = 100) where T : class where K : struct { var t = obj as T; var props = typeof(T).GetProperties(); bool initialLabel = false; int items = 1; int itemsPerRow = (int)(EditorGUIUtility.currentViewWidth / sizePerElements); GUILayout.BeginHorizontal(); for (int i = 0; i < props.Length; i++) { var prop = props[i]; if (prop.PropertyType == typeof(IValueStateObserver <K>)) { if (!initialLabel) { initialLabel = true; GUILayout.Label(typeof(K).Name + "(s)", K10GuiStyles.boldStyle); } var name = prop.Name; var data = (IValueStateObserver <K>)prop.GetValue(t, null); K10EditorGUIUtils.Data(data.Value.ToStringOrNull(), name); items++; if (items >= itemsPerRow) { items = 0; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); return(initialLabel); }
void ButtonAddEffect(SerializedProperty list, int id, string name) { var listId = -1; for (int i = 0; i < list.arraySize && listId == -1; i++) { if (list.GetArrayElementAtIndex(i).intValue == id) { listId = i; } } EditorGUILayout.BeginHorizontal(); var has = (listId != -1); if (EditorGUILayout.Toggle(has, GUILayout.MaxWidth(15)) != has) { if (!has) { listId = list.arraySize; list.arraySize++; list.GetArrayElementAtIndex(listId).intValue = id; } else { K10EditorGUIUtils.RemoveItemFromArray(list, listId); } } var icon = IconCache.Get(name.ToLower()).Texture; if (icon != null) { GUILayout.Label(icon, K10GuiStyles.basicCenterStyle, GUILayout.Width(ICON_SIZE)); } GUILayout.Label(name, K10GuiStyles.smallboldStyle); EditorGUILayout.EndHorizontal(); }
public override void OnInspectorGUI() { bool changed = false; serializedObject.Update(); _target = (UiSkinManager)target; Event ev = Event.current; HashSet <string> _codes = new HashSet <string>(); var defsProp = serializedObject.FindProperty("_colorDefinitions"); //var defs = _target.SkinDefinitions; //if( defsProp.arraySize == 0 ) // return; if (_folds == null) { _folds = new List <bool>(); } while (_folds.Count > defsProp.arraySize) { _folds.RemoveAt(_folds.Count - 1); } while (_folds.Count < defsProp.arraySize) { _folds.Add(false); } for (int i = 0; i < defsProp.arraySize; i++) { SeparationLine.Horizontal(); var def = defsProp.GetArrayElementAtIndex(i); var codeName = def.FindPropertyRelative("_code"); var valid = !_codes.Contains(codeName.stringValue); var color = valid ? Color.white : Color.red; GuiColorManager.New(color); EditorGUILayout.BeginHorizontal(); _folds[i] = EditorGUILayout.Foldout(_folds[i], (valid ? "" : "!UNUSED! ") + codeName.stringValue, K10GuiStyles.bigFoldStyle); var fxOrderProp = def.FindPropertyRelative("_effectOrder"); var instance = _target.SkinDefinitions[i]; for (int e = 0; e < instance.FxCount; e++) { var fx = instance.GetFxAt(e); DrawFxIcon(fx); } bool canUp = i > 0; GuiColorManager.New((canUp) ? color : Color.gray); if (GUILayout.Button("↑", GUILayout.MaxWidth(15)) && canUp) { SwapSkins(i, i - 1); } GuiColorManager.Revert(); bool canDown = i < defsProp.arraySize - 1; GuiColorManager.New((canDown) ? color : Color.gray); if (GUILayout.Button("↓", GUILayout.MaxWidth(15)) && canDown) { SwapSkins(i, i + 1); } GuiColorManager.Revert(); GuiColorManager.New(new Color(.6f, .1f, .1f, 1)); if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { K10EditorGUIUtils.RemoveItemFromArray(defsProp, i); i--; GuiColorManager.Revert(); GuiColorManager.Revert(); EditorGUILayout.EndHorizontal(); continue; } GuiColorManager.Revert(); EditorGUILayout.EndHorizontal(); if (_folds[i]) { SeparationLine.Horizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Codename", K10GuiStyles.smallboldStyle, GUILayout.Width(75)); codeName.stringValue = EditorGUILayout.TextField(codeName.stringValue, K10GuiStyles.smalltextFieldStyle, GUILayout.Height(18)); _codes.Add(codeName.stringValue); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); //GUILayout.Label( "Color", K10EditorGUIUtils._smallboldStyle, GUILayout.Width( 40 ) ); ColorPicker.Layout(def.FindPropertyRelative("_color")); //def.Color = EditorGUILayout.ColorField( def.Color ); //GUILayout.Label( "Font", K10EditorGUIUtils._smallboldStyle, GUILayout.Width( 35 ) ); var fontProp = def.FindPropertyRelative("_font"); fontProp.objectReferenceValue = (Font)EditorGUILayout.ObjectField(fontProp.objectReferenceValue, typeof(Font), false); EditorGUILayout.EndHorizontal(); SeparationLine.Horizontal(); GUILayout.Label("Effects", K10GuiStyles.titleStyle); SeparationLine.Horizontal(); var shadowProp = def.FindPropertyRelative("_shadow"); var outlineProp = def.FindPropertyRelative("_outline"); var gradientProp = def.FindPropertyRelative("_gradient"); var sid = UiSkinDefinition.GetID <UiShadowEffect>(); var oid = UiSkinDefinition.GetID <UiOutlineEffect>(); var gid = UiSkinDefinition.GetID <UiGradientEffect>(); EditorGUILayout.BeginHorizontal(); //GUILayout.FlexibleSpace(); //EditorGUILayout.BeginVertical(); ButtonAddEffect(fxOrderProp, sid, "Shadow"); ButtonAddEffect(fxOrderProp, oid, "Outline"); ButtonAddEffect(fxOrderProp, gid, "Gradient"); //EditorGUILayout.EndVertical(); //GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (fxOrderProp.arraySize > 0) { SeparationLine.Horizontal(); GUILayout.Label("Edit Effects", K10GuiStyles.titleStyle); for (int e = 0; e < fxOrderProp.arraySize; e++) { SeparationLine.Horizontal(); if (sid == fxOrderProp.GetArrayElementAtIndex(e).intValue) { EditShadow(shadowProp, fxOrderProp, e); } else if (oid == fxOrderProp.GetArrayElementAtIndex(e).intValue) { EditOutline(outlineProp, fxOrderProp, e); } else if (gid == fxOrderProp.GetArrayElementAtIndex(e).intValue) { EditGradient(gradientProp, fxOrderProp, e); } } } } SeparationLine.Horizontal(); EditorGUILayout.Space(); GuiColorManager.Revert(); } if (GUILayout.Button("Add New Skin Definition", K10GuiStyles.buttonStyle, GUILayout.Height(30))) { defsProp.arraySize++; } serializedObject.ApplyModifiedProperties(); changed = true; if (changed) { UpdateInstances(); } }
public override void OnInspectorGUI() { K10EditorGUIUtils.DrawReactiveProperties <T>(target); DrawDefaultInspector(); // EditorUtility.SetDirty( target ); }