protected static void DrawRangedFloatVariable(SerializedProperty property, Rect area) { var minArea = area.VerticalSlice(0, 10, 3); var maxArea = area.VerticalSlice(7, 10, 3); var minProp = property.FindPropertyRelative("_min"); var maxProp = property.FindPropertyRelative("_max"); var valueProp = property.FindPropertyRelative("_value"); var valueFloatProp = valueProp.FindPropertyRelative("_value"); var val = valueFloatProp.floatValue; var changed = false; changed |= minProp.ValueStateField <float>(minArea, GUIContent.none); changed |= maxProp.ValueStateField <float>(maxArea, GUIContent.none); var minVal = minProp.FindPropertyRelative("_value").floatValue; var maxVal = maxProp.FindPropertyRelative("_value").floatValue; bool invalid = (val < minVal && !Mathf.Approximately(val, minVal)) || (val > maxVal && !Mathf.Approximately(val, maxVal)); if (invalid) { GuiColorManager.New(K10GuiStyles.RED_TINT_COLOR); } changed |= valueProp.ValueStateField <float>(area.VerticalSlice(3, 10, 4), GUIContent.none); if (invalid) { GuiColorManager.Revert(); } EditorGUI.LabelField(minArea.Shrink(2), "min", K10GuiStyles.unitStyle); EditorGUI.LabelField(maxArea.Shrink(2), "max", K10GuiStyles.unitStyle); #if UNITY_EDITOR if (changed || invalid) { valueFloatProp.floatValue = Mathf.Clamp(valueFloatProp.floatValue, minVal, maxVal); } #endif }
void EditEffect(SerializedProperty fxOrderProp, int id) { var canUp = id > 0; var canDown = id < fxOrderProp.arraySize - 1; EditorGUILayout.BeginVertical(GUILayout.MaxWidth(20)); //GUILayout.Space( 5); GuiColorManager.New((canUp) ? Color.white : Color.gray); if (GUILayout.Button("↑", GUILayout.MaxWidth(15)) && canUp) { var val = fxOrderProp.GetArrayElementAtIndex(id).intValue; fxOrderProp.GetArrayElementAtIndex(id).intValue = fxOrderProp.GetArrayElementAtIndex(id - 1).intValue; fxOrderProp.GetArrayElementAtIndex(id - 1).intValue = val; } GuiColorManager.Revert(); //SeparationLine.Horizontal(); GuiColorManager.New((canDown) ? Color.white : Color.gray); if (GUILayout.Button("↓", GUILayout.MaxWidth(15)) && canDown) { var val = fxOrderProp.GetArrayElementAtIndex(id).intValue; fxOrderProp.GetArrayElementAtIndex(id).intValue = fxOrderProp.GetArrayElementAtIndex(id + 1).intValue; fxOrderProp.GetArrayElementAtIndex(id + 1).intValue = val; } GuiColorManager.Revert(); EditorGUILayout.EndVertical(); }
public static void Layout(string msg) { EditorGUILayout.BeginHorizontal(); GuiColorManager.New(Color.white); GUILayout.Label(IconCache.Get("warning").Texture, GUILayout.Width(64), GUILayout.Height(64)); GuiColorManager.Revert(); GuiColorManager.New(K10GuiStyles.RED_TINT_COLOR); GUILayout.Box(msg, GUILayout.ExpandWidth(true), GUILayout.MinHeight(59)); GuiColorManager.Revert(); EditorGUILayout.EndHorizontal(); }
public static bool Layout(Texture2D texture, float iconSize, Color failColor, char failLetter = ' ', string tooltip = "") { var ret = false; if (texture != null) { ret = GUILayout.Button(new GUIContent(texture, tooltip), K10GuiStyles.basicStyle, GUILayout.MaxWidth(iconSize), GUILayout.MaxHeight(iconSize)); } else { GuiColorManager.New(failColor); ret = GUILayout.Button(new GUIContent(failLetter.ToString(), tooltip), GUILayout.MaxWidth(20)); GuiColorManager.Revert(); } return(ret); }
public static bool Draw(Rect r, Texture2D texture, char failLetter, string tooltip, Color failColor) { var ret = false; if (texture != null) { ret = GUI.Button(r, new GUIContent(texture, tooltip), K10GuiStyles.basicStyle); } else { GuiColorManager.New(failColor); ret = GUI.Button(r, new GUIContent(failLetter.ToString(), tooltip)); GuiColorManager.Revert(); } return(ret); }
public void OnGUI() { var percentage = 0; if (_objectCount > 0) { percentage = (100 * _actives) / _objectCount; } var realyRercentage = 0; if (_objectCount > 0) { realyRercentage = (100 * _realyActives) / _objectCount; } GUILayout.Label($"{percentage}%({_actives}/{_objectCount}) realy:{realyRercentage}%({_realyActives}/{_objectCount})", K10GuiStyles.bigBoldCenterStyle); K10.EditorGUIExtention.SeparationLine.Horizontal(); _actives = 0; _realyActives = 0; _scroll = GUILayout.BeginScrollView(_scroll); for (int i = 0; i < _branches.Count; i++) { var branch = _branches[i]; var greyout = branch.ActivesCount == 0; if (greyout) { GuiColorManager.New(Color.grey); } branch.OnGUI(true); if (greyout) { GuiColorManager.Revert(); } branch.CalculateActives(); _actives += branch.ActivesCount; _realyActives += branch.RealyActivesCount; } GUILayout.EndScrollView(); }
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() { serializedObject.Update(); exporting = false; for (int i = 0; i < _exportation.Count && !exporting; i++) { var ex = _exportation[i]; exporting |= ex.Exporting; } GUILayout.BeginVertical(GUI.skin.box); bool allSelected = true; // bool allSelectedAreOpen = true; // bool allUnselectedAreClosed = true; for (int i = 0; i < _exportFields.arraySize; i++) { var element = _exportFields.GetArrayElementAtIndex(i); var selected = element.isExpanded; allSelected &= selected; // var editMode = element.isExpanded; // if( selected ) allSelectedAreOpen &= editMode; // else allUnselectedAreClosed &= !editMode; } GUILayout.BeginHorizontal(GUI.skin.box); EditorGUI.BeginDisabledGroup(exporting); if (GUILayout.Button($"{( allSelected ? "Unselect" : "Select" )} All")) { for (int i = 0; i < _exportFields.arraySize; i++) { var element = _exportFields.GetArrayElementAtIndex(i); element.isExpanded = !allSelected; } } if (GUILayout.Button($"Invert Selection")) { for (int i = 0; i < _exportFields.arraySize; i++) { var element = _exportFields.GetArrayElementAtIndex(i); var selected = element.FindPropertyRelative("_selected"); selected.boolValue = !selected.boolValue; } } EditorGUI.EndDisabledGroup(); // if( GUILayout.Button( $"{( allSelectedAreOpen ? "Close" : "Open" )} all selected(s)" ) ) ToggleElements( _exportFields, !allSelectedAreOpen, true ); // if( GUILayout.Button( $"{( allUnselectedAreClosed ? "Open" : "Close" )} all unselected(s)" ) ) ToggleElements( _exportFields, allUnselectedAreClosed, false ); GUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(exporting); _exportList.DoLayoutList(); EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); GUILayout.BeginVertical(GUI.skin.box); GUILayout.BeginVertical(GUI.skin.box); GuiLabelWidthManager.New(25); EditorGUI.BeginDisabledGroup(exporting); var authorName = _author.Get; bool authorIsValid = IsValidAuthorName(authorName); if (!authorIsValid) { GuiColorManager.New(K10GuiStyles.RED_TINT_COLOR); } GUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Author", GUILayout.MaxWidth(40)); authorName = EditorGUILayout.TextArea(authorName); EditorGUILayout.EndHorizontal(); _author.Set = authorName; bool canSend = !exporting && IsValidAuthorName(authorName); EditorGUILayout.PropertyField(_urlField); EditorGUI.BeginDisabledGroup(!canSend); var send = GUILayout.Button("Export", K10GuiStyles.bigbuttonStyle) && canSend; EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); if (!authorIsValid) { GuiColorManager.Revert(); } EditorGUI.EndDisabledGroup(); GuiLabelWidthManager.Revert(); GUILayout.BeginVertical(GUI.skin.box); if (_exportation.Count > 0) { for (int i = 0; i < _exportation.Count; i++) { var color = _exportation[i].GetColor(); if (color.HasValue) { GuiColorManager.New(color.Value); } GUILayout.BeginHorizontal(GUI.skin.box); if (color.HasValue) { GuiColorManager.Revert(); } GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label("\"" + _exportation[i].Name + "\""); GUILayout.EndHorizontal(); if (color.HasValue) { GuiColorManager.New(color.Value); } GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label(_exportation[i].Message); GUILayout.EndHorizontal(); if (color.HasValue) { GuiColorManager.Revert(); } GUILayout.EndHorizontal(); } } else { GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label("No export data"); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); if (!exporting) { var exporter = target as JsonExporterData; int count = exporter.FieldsCount; while (_exportation.Count < count) { _exportation.Add(new ExportationElement()); } while (_exportation.Count > count) { _exportation.RemoveAt(_exportation.Count - 1); } for (int i = 0; i < count; i++) { var field = exporter.GetField(i); _exportation[i].Set(field); } if (send) { if (_exportation.Count > 0) { JsonExporterData.OnPreExport?.Invoke(); var url = _urlField.stringValue; IEventTrigger sendNext = new CallOnce(SetDataDirty); for (int i = _exportation.Count - 1; i >= 0; i--) { var exp = _exportation[i]; if (exp.Ignored) { continue; } var f = exporter.GetField(i); var field = f.Reference.Definition; var batchSize = f.BatchSize; var nextTrigger = sendNext; var datas = new List <string>(); if (batchSize == 0) { datas.Add($"{{ \"tableName\": \"{field.FieldName}\", \"data\": {field.GetMemberValueSerialized()} }}"); } else { var elementsCount = field.GetCount(); for (int e = 0; e < elementsCount; e += batchSize) { datas.Add($"{{ \"tableName\": \"{field.FieldName}\"," + $" \"ignoreClear\": {( ( e != 0 ) ? "true" : "false" )}," + $"\"data\": {field.GetMemberValueSerialized( e, batchSize )} }}"); } } exp.SetState(EExportStep.Queue); sendNext = new CallOnce(() => { exp.Trigger(url, datas, nextTrigger, authorName); SetDataDirty(); }); } sendNext.Trigger(); } } } }
public override void OnInspectorGUI() { var collection = (BaseHashedSOCollection)target; int size = collection.Count; var count = 0; for (int i = 0; i < size; i++) { var entry = collection.GetElementBase(i); if (entry == null) { continue; } count++; } SeparationLine.Horizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField($"{_title} ({count})", K10GuiStyles.bigBoldCenterStyle, GUILayout.Height(28)); if (IconButton.Layout("log", 32, 'L', "Show modification log", K10GuiStyles.CYAN_TINT_COLOR)) { var asset = collection.Editor_Log; // if( asset != null ) // { // EditorUtility.FocusProjectWindow(); // Selection.activeObject = asset; // } } EditorGUILayout.EndHorizontal(); SeparationLine.Horizontal(); var edit = (IHashedSOCollectionEditor)collection; EditorGUILayout.BeginVertical(); var lastValid = -1; for (int i = 0; i < size; i++) { var entry = collection.GetElementBase(i) as IHashedSO; if (entry == null) { if (lastValid + 1 == i) { GUILayout.Space(5); } continue; } lastValid = i; EditorGUILayout.BeginHorizontal(); var hasConflict = (entry.HashID < 0 || entry.HashID != i); if (hasConflict) { GuiColorManager.New(Color.red); } if (IconButton.Layout("objective", 's')) { Selection.SetActiveObjectWithContext(entry as Object, entry as Object); } EditorGUILayout.LabelField("[" + i.ToString() + "]", GUILayout.Width(30f)); var tryResolve = hasConflict && GUILayout.Button("!!CONFLICT!!"); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField(entry as Object, collection.GetElementType(), false); EditorGUI.EndDisabledGroup(); if (hasConflict) { GuiColorManager.Revert(); } EditorGUILayout.EndHorizontal(); if (tryResolve) { edit.TryResolveConflict(i); } } EditorGUILayout.EndVertical(); if (GUILayout.Button("Check Consistency")) { edit.EditorCheckConsistency(); } if (edit.EditorCanChangeIDsToOptimizeSpace && GUILayout.Button("Optimize")) { edit.EditorTryOptimize(); } GuiColorManager.New(Color.red); if (GUILayout.Button("!DANGER! Enforce HashIDs")) { edit.Editor_HACK_EnforceHashIDs(); } GuiColorManager.Revert(); }
public static void EnumInt <T>(Rect rect, Prop prop, Color guiColor, string tag = null, bool breakUnderline = true) where T : struct, System.IConvertible { GuiColorManager.New(guiColor); EnumInt <T>(rect, prop, tag, breakUnderline); GuiColorManager.Revert(); }
public static void PropertyField(Rect rect, Prop prop, string tag, Color guiColor) { GuiColorManager.New(guiColor); PropertyField(rect, prop, tag); GuiColorManager.Revert(); }
public static void EnumIntMask <T>(Rect rect, Prop prop, Color guiColor, string tag = null) where T : struct, System.IConvertible { GuiColorManager.New(guiColor); EnumIntMask <T>(rect, prop, tag); GuiColorManager.Revert(); }