internal static void BitrateField(string name, SerializedProperty prop) { GUILayout.BeginHorizontal(); { double factor = 1.0; switch (BitrateUnitsDisplay) { case BitrateUnits.BitsPerSecond: factor = 1.0; break; case BitrateUnits.KBitsPerSecond: factor = 1000; break; case BitrateUnits.MBitsPerSecond: factor = 1000000; break; } double bitrate = (uint)prop.intValue / factor; bitrate = EditorGUILayout.DelayedDoubleField(name, bitrate); prop.intValue = (int)(bitrate * factor); } BitrateUnitsDisplay = (BitrateUnits)EditorGUILayout.Popup((int)BitrateUnitsDisplay, new string[] { "bps", "Kbps", "Mbps" }, GUILayout.Width(64f), GUILayout.MaxWidth(64f), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); }
public static object DrawDouble(MemberInfoAndInspectAttr memberInfo, object value) { if (memberInfo.InspectAttribute is InspectAsFloatSliderAttribute) { var attr = (InspectAsFloatSliderAttribute)memberInfo.InspectAttribute; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(memberInfo.Info.Name); float narrowedDouble = Convert.ToSingle((double)value); float newValue = EditorGUILayout.Slider(narrowedDouble, attr.SliderMin, attr.SliderMax); EditorGUILayout.EndHorizontal(); return((double)newValue); } else { switch (memberInfo.InspectAttribute.InspectionType) { case InspectionType.DelayedDouble: return(EditorGUILayout.DelayedDoubleField(memberInfo.Info.Name, (double)value)); } return(EditorGUILayout.DoubleField(memberInfo.Info.Name, (double)value)); } }
public override double Draw(IMemberInspectionInfo attr, double value) { if (attr.InspectAttribute is InspectAsFloatSliderAttribute attr_) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(attr.Info.Name); float narrowedDouble = Convert.ToSingle(value); float newValue = EditorGUILayout.Slider(narrowedDouble, attr_.SliderMin, attr_.SliderMax); EditorGUILayout.EndHorizontal(); return(newValue); } else { switch (attr.InspectAttribute.InspectionKind) { case InspectionKind.Delayed: return(EditorGUILayout.DelayedDoubleField(attr.Info.Name, value)); default: return(EditorGUILayout.DoubleField(attr.Info.Name, value)); } } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.Space(); string _notes = "The purpose of this example is to demonstrate a slippy map built with the sdk \n" + " using satellite imagery draped over geometry generated from terrain data.\n" + "At runtime an area that corresponds the specified lat/lon Northeast and Southwest coordinates\n" + "and zoom level will be created. \n" + "The area displayed will be determined by the zoom and bounding box.\n" + " mouse click and drag to pan the map in play mode.\n"; EditorGUILayout.HelpBox(_notes, MessageType.Info); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Southwest coordinate"); south.doubleValue = EditorGUILayout.DelayedDoubleField(south.doubleValue); west.doubleValue = EditorGUILayout.DelayedDoubleField(west.doubleValue); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Northeast coordinate"); north.doubleValue = EditorGUILayout.DelayedDoubleField(north.doubleValue); east.doubleValue = EditorGUILayout.DelayedDoubleField(east.doubleValue); EditorGUILayout.EndHorizontal(); var bounds = new GeoCoordinateBounds( new GeoCoordinate(south.doubleValue, west.doubleValue), new GeoCoordinate(north.doubleValue, east.doubleValue)); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Center coordinate"); EditorGUILayout.LabelField(bounds.Center.ToString()); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.IntSlider(zoom, 0, 20, new GUIContent("Zoom")); var tileCount = TileCover.Get(bounds, zoom.intValue).Count; EditorGUILayout.Space(); EditorGUILayout.LabelField("Tile count", tileCount.ToString()); if (tileCount > Map <RasterTile> .TileMax) { EditorGUILayout.Space(); EditorGUILayout.HelpBox("Too many tiles!", MessageType.Error); } EditorGUILayout.Space(); edge.floatValue = EditorGUILayout.FloatField("Tile edge", edge.floatValue); serializedObject.ApplyModifiedProperties(); DrawDefaultInspector(); }
protected override void OnDraw() { double value = EditorGUILayout.DelayedDoubleField(Content, Value, Option.Values); if (value != Value) { Value = value; this.DipatchEvent(); } }
protected bool RenderDouble(IList <string> _, string name, object element, Type type, Action <object> setter) { var oldValue = (double)element; var newValue = EditorGUILayout.DelayedDoubleField(name, oldValue); var dirty = (oldValue != newValue); if (dirty) { setter(newValue); } return(dirty); }
/// <summary> /// DoubleField with optional toggle associated with a given SerializedProperty, to enable /// automatic GUI handlings like Prefab revert menu. /// /// Valid doubles values are any non-zero positive doubles. Any negative or zero value /// is considered invalid, and means that the value is considered as not set, which shows /// up as an unchecked left toggle widget. /// /// To enforce a valid value when the toggle control is checked by the user, a default valid /// value is provided <paramref name="lastValidValue"/>. For UI consistency, the last selected /// valid value is returned in <paramref name="lastValidValue"/>, to allow toggling the field /// ON and OFF without losing the valid value it previously had. /// </summary> /// <param name="doubleProperty">The double property associated with the control.</param> /// <param name="lastValidValue"> /// Default value if the property value is invalid (negative or zero). /// Assigned the new value on return if valid. /// </param> /// <param name="label">The label to display next to the toggle control.</param> /// <param name="unitLabel">The label indicating the unit of the value.</param> private void OptionalDoubleField(SerializedProperty doubleProperty, ref double lastValidValue, GUIContent label, GUIContent unitLabel) { if (lastValidValue <= 0.0) { throw new ArgumentOutOfRangeException("Default value cannot be invalid."); } using (new EditorGUILayout.HorizontalScope()) { var rect = EditorGUILayout.GetControlRect(); using (new EditorGUI.PropertyScope(rect, label, doubleProperty)) { bool hadValidValue = (doubleProperty.doubleValue > 0.0); bool needsValidValue = EditorGUI.ToggleLeft(rect, label, hadValidValue); double newValue = doubleProperty.doubleValue; if (needsValidValue) { // Force a valid value, otherwise the edit field won't show up if (newValue <= 0.0) { newValue = lastValidValue; } // Make updating the value of the serialized property delayed to allow overriding the // value the user will input before it's assigned to the property, for validation. newValue = EditorGUILayout.DelayedDoubleField(newValue); if (newValue < 0.0) { newValue = 0.0; } } else { // Force invalid value for consistency, otherwise this breaks Prefab revert newValue = 0.0; } doubleProperty.doubleValue = newValue; if (newValue > 0.0) { GUILayout.Label(unitLabel, GUILayout.Width(_unitWidth)); // Save valid value as new default. This allows toggling the toggle widget ON and OFF // without losing the value previously input. This works only while the inspector is // alive, that is while the object is select, but is better than nothing. lastValidValue = newValue; } else { GUILayout.Label(_anyContent, GUILayout.Width(_anyWidth)); } } } }
void DelayedValueField() { EditorGUILayout.BeginVertical(GUI.skin.box); m_bFoldOutDelayed = EditorGUILayout.Foldout(m_bFoldOutDelayed, "Foldout", true); if (m_bFoldOutDelayed) { m_fDelayedDouble = EditorGUILayout.DelayedDoubleField("DelayedDoubleField", m_fDelayedDouble); m_fDelayedFloat = EditorGUILayout.DelayedFloatField("DelayedFloatField", m_fDelayedFloat); m_iDelayedInt = EditorGUILayout.DelayedIntField("DelayedIntField", m_iDelayedInt); m_sDelayedString = EditorGUILayout.DelayedTextField("DelayedTextField", m_sDelayedString); } EditorGUILayout.EndVertical(); }
/// <summary> /// 延迟double字段,即输入之后要按下enter或移开输入焦点时才会返回结果值 /// </summary> public static void DelayedDoubleField(string head, string tip, ref double val, float headWidth = 0) { float preWidth = 0; if (headWidth > 0) { preWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = headWidth; val = EditorGUILayout.DelayedDoubleField(new GUIContent(head, tip), val); EditorGUIUtility.labelWidth = preWidth; } else { val = EditorGUILayout.DelayedDoubleField(new GUIContent(head, tip), val); } }
public object DrawAndGetNewValue(Type type, object value, DrawInfo draw, FieldInfo field) { EditorGUI.BeginDisabledGroup(!draw.Changeable); if (draw.ShowNameWidth < 0) { if (draw.NeedDelayed) { value = EditorGUILayout.DelayedDoubleField(draw.ShowName, (double)value); } else { value = EditorGUILayout.DoubleField(draw.ShowName, (double)value); } } else if (draw.ShowNameWidth == 0) { if (draw.NeedDelayed) { value = EditorGUILayout.DelayedDoubleField((double)value); } else { value = EditorGUILayout.DoubleField((double)value); } } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(draw.ShowName, GUILayout.Width(draw.ShowNameWidth)); if (draw.NeedDelayed) { value = EditorGUILayout.DelayedDoubleField((double)value); } else { value = EditorGUILayout.DoubleField((double)value); } EditorGUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); return(value); }
public static double DelayedDoubleField(string head, string tip, double val, float headWidth = 0) { float preWidth = 0; if (headWidth > 0) { preWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = headWidth; var ret = EditorGUILayout.DelayedDoubleField(new GUIContent(head, tip), val); EditorGUIUtility.labelWidth = preWidth; return(ret); } else { return(EditorGUILayout.DelayedDoubleField(new GUIContent(head, tip), val)); } }
/// 这些都是基本点击操作等处理方式 // public Transform[] bi = Selection.transforms ; void OnGUI() { // var d= new Bounds() ; // d.center = new Vector3(0,0,0) ; // // d.min = new Vector3(10,10,10 ) ; // // d.max = new Vector3(20,20,20); // // d.size = new Vector3(10,10,10 ) ; // d.extents = new Vector3(10,10,10 ); ling_d = EditorGUILayout.DelayedDoubleField(ling_d); /// dsf Debug.Log(ling_d); if (GUILayout.Button("")) { } }
private static void GetMajorAxis(OrbitUniversal orbitU, ref double p_inspector, ref bool sizeUpdate, GravityScaler.Units units) { float oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = oldLabelWidth + 50f; string prompt = string.Format("Semi-Major Axis (a) [{0}]", GravityScaler.LengthUnits(units)); double old_a = orbitU.GetMajorAxisInspector(); double a = EditorGUILayout.DelayedDoubleField(new GUIContent(prompt, aTip), old_a); if (!EditorApplication.isPlaying && (a != old_a)) { orbitU.SetMajorAxisInspector(a); sizeUpdate = true; // Need to update ecc and p with new values p_inspector = orbitU.p_inspector; } EditorGUILayout.LabelField(string.Format("Axis result in: p={0:0.00}", p_inspector)); EditorGUIUtility.labelWidth = oldLabelWidth; }
public static void Draw(this ICell self, CellType?FormulaResultType = null, GUILayoutOption[] guiOpts = null) { #if UNITY_EDITOR var cellType = FormulaResultType ?? self.CellType; switch (cellType) { case CellType.Unknown: self.SetCellValue(EditorGUILayout.DelayedTextField(self.SValueOneline(), guiOpts)); break; case CellType.Numeric: self.SetCellValue(EditorGUILayout.DelayedDoubleField(self.NumericCellValue, guiOpts)); break; case CellType.String: self.SetCellValue(EditorGUILayout.DelayedTextField(self.StringCellValue, guiOpts)); break; case CellType.Formula: EditorGUILayout.LabelField(self.SValue() + "=" + self.CellFormula, guiOpts); break; case CellType.Blank: self.SetCellValue(EditorGUILayout.DelayedTextField(self.StringCellValue, guiOpts)); break; case CellType.Boolean: self.SetCellValue(EditorGUILayout.Toggle(self.BooleanCellValue, guiOpts)); break; case CellType.Error: self.SetCellValue(EditorGUILayout.DelayedTextField(self.SValueOneline(), guiOpts)); break; default: break; } #endif }
public override void OnInspectorGUI() { // GUI style GUIStyle style = new GUIStyle(); style.fontSize = 30; style.normal.background = Texture2D.whiteTexture; style.normal.textColor = Color.red; style.margin = new RectOffset(0, 0, 3, 3); style.padding = new RectOffset(10, 10, 10, 10); style.alignment = TextAnchor.MiddleLeft; // double _target.DoubleValue = EditorGUILayout.DelayedDoubleField("Double Value", _target.DoubleValue, style, GUILayout.Height(50)); // float _target.FloatValue = EditorGUILayout.DelayedFloatField("Float Value", _target.FloatValue, style, GUILayout.Height(50)); // int _target.IntValue = EditorGUILayout.DelayedIntField("Int Value", _target.IntValue, style, GUILayout.Height(50)); // text _target.TextValue = EditorGUILayout.DelayedTextField("Text Value", _target.TextValue, style, GUILayout.Height(50)); // update the dispalying text _display = string.Join("\n", new string [] { "Delayed Double Value: " + _target.DoubleValue.ToString(), "Delayed Float Value: " + _target.FloatValue.ToString(), "Delayed Int Value: " + _target.IntValue.ToString(), "Delayed Text Value: " + _target.TextValue }); // force redraw every time when _target changes if (GUI.changed) { EditorUtility.SetDirty(_target); } }
public static object ValueTypeField(string title, ValueType value, List <PropertyAttribute> CustomAttributes = null) { if (value is Enum) { return(EditorGUILayout.EnumPopup(title, (Enum)value)); } else if (value is int) { if (CustomAttributes != null) { RangeAttribute range = CustomAttributes.Find(e => e is RangeAttribute) as RangeAttribute; if (range != null) { return(EditorGUILayout.IntSlider(title, (int)value, (int)range.min, (int)range.max)); } } return(EditorGUILayout.DelayedIntField(title, (int)value)); } else if (value is float) { return(EditorGUILayout.DelayedFloatField(title, (float)value)); } else if (value is double) { return(EditorGUILayout.DelayedDoubleField(title, (double)value)); } else if (value is bool) { return(EditorGUILayout.Toggle(title, (bool)value)); } else if (value is long) { return(EditorGUILayout.LongField(title, (long)value)); } else if (value is Color) { return(EditorGUILayout.ColorField(title, (Color)value)); } else if (value is Vector2) { return(EditorGUILayout.Vector2Field(title, (Vector2)value)); } else if (value is Vector3) { return(EditorGUILayout.Vector3Field(title, (Vector3)value)); } else if (value is Vector4) { return(EditorGUILayout.Vector4Field(title, (Vector4)value)); } else if (value is Rect) { return(EditorGUILayout.RectField(title, (Rect)value)); } else if (value is Quaternion) { Vector3 euler = ((Quaternion)value).eulerAngles; euler.x = (float)Math.Round(euler.x, 2); euler.y = (float)Math.Round(euler.y, 2); euler.z = (float)Math.Round(euler.z, 2); euler = EditorGUILayout.Vector3Field(title, euler); return(Quaternion.Euler(euler)); } else { EditorGUILayout.LabelField(title, "UnHandledType:" + value.GetType()); return(value); } }
public override void OnInspectorGUI() { this.serializedObject.Update(); // draw disabled MonoScript EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField("Script", this.monoScript, typeof(MonoScript), false); EditorGUI.EndDisabledGroup(); //---------------------------------------------------------------------------------------------------------------------- // draw intValue and boolValue, and boolValue has custom label display EditorGUILayout.PropertyField(this.serializedObject.FindProperty("intValue")); EditorGUILayout.PropertyField(this.serializedObject.FindProperty("boolValue"), this.boolValueContent); var v2Property = this.serializedObject.FindProperty("v2"); EditorGUILayout.PropertyField(v2Property); v2Property.FindPropertyRelative("x").floatValue = 999.0f; EditorGUILayout.Separator(); //---------------------------------------------------------------------------------------------------------------------- // draw array of elements var elements = this.serializedObject.FindProperty("floatArray"); if (EditorGUILayout.PropertyField(elements)) { EditorGUI.indentLevel++; elements.arraySize = EditorGUILayout.DelayedIntField("Size", elements.arraySize); for (int i = 0, size = elements.arraySize; i < size; i++) { var element = elements.GetArrayElementAtIndex(i); EditorGUILayout.PropertyField(element); } EditorGUI.indentLevel--; } EditorGUILayout.Space(); //---------------------------------------------------------------------------------------------------------------------- this.fadeGroup.target = EditorGUILayout.Foldout(this.fadeGroup.target, "BeginFadeGroup", true); if (EditorGUILayout.BeginFadeGroup(this.fadeGroup.faded)) { EditorGUILayout.BoundsField("BoundsField", new Bounds()); EditorGUILayout.BoundsIntField("BoundsIntField", new BoundsInt()); } EditorGUILayout.EndFadeGroup(); GUILayout.Space(10); //---------------------------------------------------------------------------------------------------------------------- EditorGUILayout.BeginHorizontal(GUI.skin.box); EditorGUILayout.LabelField("This is BeginHorizontal", GUILayout.MaxWidth(150.0f)); EditorGUILayout.DelayedDoubleField(11.1f); EditorGUILayout.DelayedTextField("DelayedTextField"); EditorGUILayout.DropdownButton(GUIContent.none, FocusType.Passive); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); //---------------------------------------------------------------------------------------------------------------------- EditorGUILayout.BeginVertical(GUI.skin.box); GUILayout.Box("This is BeginVertical"); EditorGUILayout.ColorField("ColorField", Color.yellow); EditorGUILayout.CurveField("CurveField", new AnimationCurve(), GUILayout.MaxWidth(400.0f)); EditorGUILayout.HelpBox("HelpBox", MessageType.Info); EditorGUILayout.EnumFlagsField("EnumFlagsField", this.types); EditorGUILayout.EnumPopup("EnumPopup", this.types); this.selectOption = EditorGUILayout.IntPopup("IntPopup", (int)this.selectOption, new[] { "0", "1", "2" }, new[] { 0, 1, 2 }); this.selectOption = EditorGUILayout.IntSlider("IntSlider", (int)this.selectOption, 0, 2); this.selectOption = EditorGUILayout.MaskField("MaskField", (int)this.selectOption, new[] { "mask1", "mask2", "mask3" }); this.selectOption = EditorGUILayout.Popup("Popup", (int)this.selectOption, new[] { "s1", "s2", "s3" }); EditorGUILayout.EndVertical(); EditorGUILayout.Separator(); //---------------------------------------------------------------------------------------------------------------------- this.scrollPos = EditorGUILayout.BeginScrollView(this.scrollPos, GUI.skin.box); GUILayout.Box("this is BeginScrollView"); EditorGUILayout.TextArea("this is TextArea"); EditorGUILayout.RectField("RectField", new Rect()); this.toggle = EditorGUILayout.Toggle("Toggle", this.toggle); this.toggleGroup = EditorGUILayout.BeginToggleGroup("BeginToggleGroup", this.toggleGroup); GUILayout.Button("Btn1"); GUILayout.Button("Btn2"); GUILayout.Button("Btn3"); EditorGUILayout.EndToggleGroup(); EditorGUILayout.EndScrollView(); this.serializedObject.ApplyModifiedProperties(); }
void OnPropertyGUI(SerializedProperty property, out bool modified) { modified = false; var name = property.FindPropertyRelative("name"); var type = property.FindPropertyRelative("type"); var value = property.FindPropertyRelative("value"); var values = property.FindPropertyRelative("values"); var description = property.FindPropertyRelative("description"); GUIContent content; if (string.IsNullOrEmpty(description.stringValue)) { content = new GUIContent(name.stringValue, type.stringValue); } else { content = new GUIContent(name.stringValue, description.stringValue); } switch (type.stringValue.ToLowerInvariant()) { default: //EditorGUILayout.LabelField(content, type.stringValue); //break; case "string": using (var scope = new EditorGUI.ChangeCheckScope()) { if (type.stringValue.ToLowerInvariant() != "string") { Debug.LogError(type.stringValue); } string f; f = EditorGUILayout.TextField(content, value.stringValue); if (scope.changed) { value.stringValue = f; modified = true; } } break; case "double": { var enumerable = Enumerable .Range(0, values.arraySize) .Select(values.GetArrayElementAtIndex) .DefaultIfEmpty(value); foreach (var v in enumerable) { using (var scope = new EditorGUI.ChangeCheckScope()) { double f; double.TryParse(v.stringValue, NumberStyles.Number, CultureInfo.InvariantCulture, out f); f = EditorGUILayout.DelayedDoubleField(content, f); if (scope.changed) { v.stringValue = f.ToString(); modified = true; } } } } break; case "float": switch (values.arraySize) { case 0: case 1: if (values.arraySize == 1) { value = values.GetArrayElementAtIndex(0); } using (var scope = new EditorGUI.ChangeCheckScope()) { float f; float.TryParse(value.stringValue, NumberStyles.Number, CultureInfo.InvariantCulture, out f); f = EditorGUILayout.FloatField(content, f); if (scope.changed) { value.stringValue = f.ToString(); modified = true; } } break; case 2: using (var scope = new EditorGUI.ChangeCheckScope()) { var v = new Vector2(); for (int i = 0; i < 2; ++i) { float f; float.TryParse(values.GetArrayElementAtIndex(i).stringValue, NumberStyles.Number, CultureInfo.InvariantCulture, out f); v[i] = f; } v = EditorGUILayout.Vector2Field(content, v); if (scope.changed) { for (int i = 0; i < 2; ++i) { values.GetArrayElementAtIndex(i).stringValue = v[i].ToString(); } modified = true; } } break; case 3: using (var scope = new EditorGUI.ChangeCheckScope()) { var v = new Vector3(); for (int i = 0; i < 3; ++i) { float f; float.TryParse(values.GetArrayElementAtIndex(i).stringValue, NumberStyles.Number, CultureInfo.InvariantCulture, out f); v[i] = f; } v = EditorGUILayout.Vector3Field(content, v); if (scope.changed) { for (int i = 0; i < 3; ++i) { values.GetArrayElementAtIndex(i).stringValue = v[i].ToString(); } modified = true; } } break; default: Debug.LogError(values.arraySize); var enumerable = Enumerable .Range(0, values.arraySize) .Select(values.GetArrayElementAtIndex) .DefaultIfEmpty(value); foreach (var v in enumerable) { using (var scope = new EditorGUI.ChangeCheckScope()) { float f; float.TryParse(v.stringValue, out f); f = EditorGUILayout.FloatField(content, f); if (scope.changed) { v.stringValue = f.ToString(); } modified = true; } } break; } break; case "integer": case "unsignedinteger": switch (values.arraySize) { case 0: case 1: if (values.arraySize == 1) { value = values.GetArrayElementAtIndex(0); } using (var scope = new EditorGUI.ChangeCheckScope()) { int f; int.TryParse(value.stringValue, NumberStyles.Number, CultureInfo.InvariantCulture, out f); f = EditorGUILayout.IntField(content, f); if (scope.changed) { value.stringValue = f.ToString(); modified = true; } } break; case 2: using (var scope = new EditorGUI.ChangeCheckScope()) { var v = new Vector2Int(); for (int i = 0; i < 2; ++i) { int f; int.TryParse(values.GetArrayElementAtIndex(i).stringValue, NumberStyles.Number, CultureInfo.InvariantCulture, out f); v[i] = f; } v = EditorGUILayout.Vector2IntField(content, v); if (scope.changed) { for (int i = 0; i < 2; ++i) { values.GetArrayElementAtIndex(i).stringValue = v[i].ToString(); } modified = true; } } break; case 3: using (var scope = new EditorGUI.ChangeCheckScope()) { var v = new Vector3Int(); for (int i = 0; i < 3; ++i) { int f; int.TryParse(values.GetArrayElementAtIndex(i).stringValue, NumberStyles.Number, CultureInfo.InvariantCulture, out f); v[i] = f; } if (content.text.ToLowerInvariant().Contains("color")) { var c = new Color32((byte)v.x, (byte)v.y, (byte)v.z, 0xFF); c = EditorGUILayout.ColorField(content, c); v = new Vector3Int(c.r, c.g, c.b); } else { v = EditorGUILayout.Vector3IntField(content, v); } if (scope.changed) { for (int i = 0; i < 3; ++i) { values.GetArrayElementAtIndex(i).stringValue = v[i].ToString(); } modified = true; } } break; default: Debug.LogError(values.arraySize); var enumerable = Enumerable .Range(0, values.arraySize) .Select(values.GetArrayElementAtIndex) .DefaultIfEmpty(value); foreach (var v in enumerable) { using (var scope = new EditorGUI.ChangeCheckScope()) { int f; int.TryParse(v.stringValue, out f); f = EditorGUILayout.IntField(content, f); if (scope.changed) { v.stringValue = f.ToString(); modified = true; } } } break; } break; } }
private void _drawValue(ValueS valueS) { //todo draw Value if (valueS.IsUnity) { Object obj; EditorGUI.BeginChangeCheck(); { obj = EditorGUILayout.ObjectField(valueS.UValue, valueS.ValueType, false); } if (EditorGUI.EndChangeCheck()) { valueS.SetValue(obj); _save(); } } else { //todo non Unity Type var value = valueS.GetValue(); if (value == null) { valueS.SetValue(Activator.CreateInstance(valueS.ValueType)); _save(); } _drawNonUnityValue <int>(valueS, x => EditorGUILayout.DelayedIntField((int)x.GetValue())); _drawNonUnityValue <float>(valueS, x => EditorGUILayout.DelayedFloatField((float)x.GetValue())); _drawNonUnityValue <double>(valueS, x => EditorGUILayout.DelayedDoubleField((double)x.GetValue())); _drawNonUnityValue <long>(valueS, x => EditorGUILayout.LongField((long)x.GetValue())); _drawNonUnityValue <string>(valueS, x => EditorGUILayout.DelayedTextField((string)x.GetValue())); _drawNonUnityValue <Vector2>(valueS, x => EditorGUILayout.Vector2Field("", (Vector2)x.GetValue())); _drawNonUnityValue <Vector2Int>(valueS, x => EditorGUILayout.Vector2IntField("", (Vector2Int)x.GetValue())); _drawNonUnityValue <Vector3>(valueS, x => EditorGUILayout.Vector3Field("", (Vector3)x.GetValue())); _drawNonUnityValue <Vector3Int>(valueS, x => EditorGUILayout.Vector3IntField("", (Vector3Int)x.GetValue())); _drawNonUnityValue <Vector4>(valueS, x => EditorGUILayout.Vector4Field("", (Vector4)x.GetValue())); _drawNonUnityValue <Color>(valueS, x => EditorGUILayout.ColorField((Color)x.GetValue())); _drawNonUnityValue <AnimationCurve>(valueS, x => EditorGUILayout.CurveField((AnimationCurve)x.GetValue())); _drawNonUnityValue <Bounds>(valueS, x => EditorGUILayout.BoundsField((Bounds)x.GetValue())); _drawNonUnityValue <BoundsInt>(valueS, x => EditorGUILayout.BoundsIntField((BoundsInt)x.GetValue())); _drawNonUnityValue <Rect>(valueS, x => EditorGUILayout.RectField((Rect)x.GetValue())); _drawNonUnityValue <RectInt>(valueS, x => EditorGUILayout.RectIntField((RectInt)x.GetValue())); _drawNonUnityValue <Enum>(valueS, x => EditorGUILayout.EnumFlagsField((Enum)x.GetValue())); _drawNonUnityValue <Gradient>(valueS, x => EditorGUILayout.GradientField((Gradient)x.GetValue())); if (GUILayout.Button("Edit Value")) { var size = 250; _ValueEditPopup.ValueS = valueS; PopupWindow.Show( new Rect(new Vector2(Event.current.mousePosition.x - size / 2, -(_rect.height - size - (Event.current.mousePosition.y + 60))) , new Vector2(size, size)), _ValueEditPopup); } } }
private void FieldInspector(string showName, Color color, FieldInfo fileInfo) { try { var oc = GUI.color; var hasColor = color != Color.clear; if (hasColor) { GUI.color = color; } var t = fileInfo.FieldType; var value = fileInfo.GetValue(target); if (t == typeof(float)) { var orignal = (float)value; var newValue = EditorGUILayout.DelayedFloatField(showName, orignal); if (!Mathf.Approximately(newValue, orignal)) { fileInfo.SetValue(target, newValue); } } else if (t == typeof(double)) { var orignal = (double)value; var newValue = EditorGUILayout.DelayedDoubleField(showName, orignal); if (!Mathf.Approximately((float)newValue, (float)orignal)) { fileInfo.SetValue(target, newValue); } } else if (t == typeof(int)) { var orignal = (int)value; var newValue = EditorGUILayout.DelayedIntField(showName, orignal); if (orignal != newValue) { fileInfo.SetValue(target, newValue); } } else if (t == typeof(string)) { var orignal = (string)value; var newValue = EditorGUILayout.DelayedTextField(showName, orignal); if (orignal != newValue) { fileInfo.SetValue(target, newValue); } } else if (t == typeof(bool)) { var orignal = (bool)value; var newValue = EditorGUILayout.Toggle(showName, orignal); if (orignal != newValue) { fileInfo.SetValue(target, newValue); } } else if (t == typeof(Color)) { var orignal = (Color)value; var newValue = EditorGUILayout.ColorField(showName, orignal); if (orignal != newValue) { fileInfo.SetValue(target, newValue); } } else if (t == typeof(Quaternion)) { var orignal = (Quaternion)value; var vect4 = EditorGUILayout.Vector4Field(showName, new Vector4(orignal.x, orignal.y, orignal.z, orignal.w)); var newValue = new Quaternion(vect4.x, vect4.y, vect4.z, vect4.w); if (orignal != newValue) { fileInfo.SetValue(target, newValue); } } else if (t == typeof(Vector3)) { var orignal = (Vector3)value; var newValue = EditorGUILayout.Vector3Field(showName, orignal); if (orignal != newValue) { fileInfo.SetValue(target, newValue); } } else if (t == typeof(Vector2)) { var orignal = (Vector2)value; var newValue = EditorGUILayout.Vector2Field(showName, orignal); if (orignal != newValue) { fileInfo.SetValue(target, newValue); } } else if (t == typeof(Vector4)) { var orignal = (Vector4)value; var newValue = EditorGUILayout.Vector4Field(showName, orignal); if (orignal != newValue) { fileInfo.SetValue(target, newValue); } } else if (t.IsEnum) { var orignal = (Enum)value; var newValue = t.IsDefined(typeof(FlagsAttribute), true) ? EditorGUILayout.EnumFlagsField(showName, orignal) : EditorGUILayout.EnumPopup(showName, orignal); if (!Equals(orignal, newValue)) { fileInfo.SetValue(target, newValue); } } else if (typeof(Object).IsAssignableFrom(t)) { var orignal = (Object)value; var newValue = EditorGUILayout.ObjectField(showName, orignal, t, true); if (newValue != orignal) { fileInfo.SetValue(target, newValue); } } if (hasColor) { GUI.color = oc; } } catch (Exception) { // ignored } }
void DrawValueNode(XmlNode node, Type valueType) { if (valueType == null) { valueType = typeof(string); } if (IsTextValue(node) || IsCombineValue(node)) { TextField(node); return; } string error = null; if (valueType.IsEnum) { try { Enum value = (Enum)Enum.Parse(valueType, node.InnerText, true); if (valueType.IsDefined(typeof(FlagsAttribute))) { node.InnerText = EditorGUILayout.EnumFlagsField(value).ToString(); } else { node.InnerText = EditorGUILayout.EnumPopup(value).ToString(); } return; } catch (Exception ex) { error = $"parse [enum] [{valueType.GetType().Name}] error"; } } if (valueType == typeof(bool)) { bool value; if (bool.TryParse(node.InnerText, out value)) { node.InnerText = EditorGUILayout.Toggle(value).ToString(); return; } else { error = "parse [bool] error"; } } else if (valueType == typeof(float)) { float value; if (float.TryParse(node.InnerText, out value)) { node.InnerText = EditorGUILayout.DelayedFloatField(value).ToString(); return; } else { error = "parse [float] error"; } } else if (valueType == typeof(double)) { double value; if (double.TryParse(node.InnerText, out value)) { node.InnerText = EditorGUILayout.DelayedDoubleField(value).ToString(); return; } else { error = "parse [double] error"; } } else if (valueType == typeof(int)) { int value; if (int.TryParse(node.InnerText, out value)) { node.InnerText = EditorGUILayout.DelayedFloatField(value).ToString(); return; } else { error = "parse [int32] error"; } } TextField(node); if (!string.IsNullOrEmpty(error)) { EditorGUILayout.HelpBox(error, MessageType.Error); } }
private static eDouble DelayedDoubleFieldMaster(GUICon guiCon, double value, GUIStyle style, params GUILayOpt[] options) { var val = EditorGUILayout.DelayedDoubleField(guiCon, value, style, options); return(GUIEvent.Create(GUILayoutUtility.GetLastRect(), val)); }
public void EditorGUILayoutExamples() { EditorGUILayout.LabelField("Hello World!"); Rect rect = EditorGUILayout.GetControlRect(false, 50); GUI.Button(rect, GUIContent.none); gradient = EditorGUILayout.GradientField("Gradient", gradient); //EditorGUILayout.HelpBox("Hello, World !", MessageType.Info); //EditorGUILayout.HelpBox("Hello, World !", MessageType.Error); EditorGUILayout.HelpBox("Hello, World !", MessageType.Warning); //EditorGUILayout.HelpBox("Hello, World !", MessageType.None); EditorGUILayout.SelectableLabel("This is a selectable label"); EditorGUILayout.DropdownButton(GUIContent.none, FocusType.Keyboard); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal("Toolbar", GUILayout.ExpandWidth(true)); { if (GUILayout.Button("Clear", "ToolbarButton", GUILayout.Width(45f))) { Debug.Log("You click Clear button"); } // Create space between Clear and Collapse button. GUILayout.Space(5f); // Create toggles button. collapsed = GUILayout.Toggle(collapsed, "Collapse", "ToolbarButton"); clearOnPlay = GUILayout.Toggle(clearOnPlay, "Clear on Play", "ToolbarButton"); // Push content to be what they should be. (ex. width) GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EditorToolbar(vertexTool); bounds = EditorGUILayout.BoundsField("Bounds", bounds); doubleValue = EditorGUILayout.DelayedDoubleField("Delayed Double", doubleValue); BuildTargetGroup buildTargetGroup = EditorGUILayout.BeginBuildTargetSelectionGrouping(); { EditorGUI.indentLevel++; EditorGUILayout.LabelField($"BuildTarget:{buildTargetGroup}"); EditorGUI.indentLevel--; } EditorGUILayout.EndBuildTargetSelectionGrouping(); using (var v = new EditorGUILayout.VerticalScope("button")) { Rect r = new Rect(v.rect); r.height = r.height / 2; if (GUI.Button(r, GUIContent.none)) { Debug.Log("Go here"); } GUILayout.Label("I'm inside the button"); GUILayout.Label("So am I"); GUILayout.Label($"{v.rect.width} x {v.rect.height}"); } // m_ShowExtraFields.target = EditorGUILayout.ToggleLeft("Show extra fields", m_ShowExtraFields.target); //Extra block that can be toggled on and off. using (var group = new EditorGUILayout.FadeGroupScope(m_ShowExtraFields.faded)) { if (group.visible) { EditorGUI.indentLevel++; EditorGUILayout.PrefixLabel("Color"); m_Color = EditorGUILayout.ColorField(m_Color); EditorGUILayout.PrefixLabel("Text"); m_String = EditorGUILayout.TextField(m_String); EditorGUILayout.PrefixLabel("Number"); m_Number = EditorGUILayout.IntSlider(m_Number, 0, 10); EditorGUI.indentLevel--; } } using (var h = new EditorGUILayout.HorizontalScope()) { using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPos, GUILayout.Width(100), GUILayout.Height(100))) { scrollPos = scrollView.scrollPosition; GUILayout.Label(t); } if (GUILayout.Button("Add More Text", GUILayout.Width(100), GUILayout.Height(100))) { t += " \nAnd this is more text!"; } } if (GUILayout.Button("Clear")) { t = ""; } using (var posGroup = new EditorGUILayout.ToggleGroupScope("Align position", posGroupEnabled)) { EditorGUI.indentLevel++; posGroupEnabled = posGroup.enabled; pos[0] = EditorGUILayout.Toggle("x", pos[0]); pos[1] = EditorGUILayout.Toggle("y", pos[1]); pos[2] = EditorGUILayout.Toggle("z", pos[2]); EditorGUI.indentLevel--; } }
private bool RenderJsonArray(string[] parentsKey, string arrayKey, List <object> array) { bool dirty = false; if (array.Count <= 0) { return(dirty); } for (int i = 0; i < array.Count; i++) { var key = new StringBuilder(arrayKey).Append("[").Append(i).Append("]").ToString(); var _value = array[i]; if (_value is string) { string value = _value as string; string newValue = EditorGUILayout.DelayedTextField(key, value); if (newValue != value) { array[i] = newValue; dirty = true; } } else if (_value is long) { // XXX: There are no DelayedLongField long __value = (long)_value; if (__value > int.MaxValue || __value < int.MinValue) { Debug.LogWarning("StateJsonEditor not handled long size value => " + __value); } int value = (int)__value; int newValue = EditorGUILayout.DelayedIntField(key, value); if (newValue != value) { array[i] = newValue; dirty = true; } } else if (_value is double) { double value = (double)_value; double newValue = EditorGUILayout.DelayedDoubleField(key, value); if (newValue != value) { array[i] = newValue; dirty = true; } } else if (_value is bool) { bool value = (bool)_value; bool newValue = EditorGUILayout.Toggle(key, value); if (newValue != value) { array[i] = newValue; dirty = true; } } else if (_value == null) { EditorGUILayout.LabelField(key, "null"); } else if (_value is List <object> ) { string[] newParentsKey = CreateParentsKey(parentsKey, key); string foldoutKey = CreateFoldoutKey(newParentsKey); string displayName = CreateDisplayKey(newParentsKey); if (ShouldFoldout(displayName, foldoutKey)) { dirty = RenderJsonArray(newParentsKey, key, _value as List <object>); } } else if (_value is Dictionary <string, object> ) { string[] newParentsKey = CreateParentsKey(parentsKey, key); string foldoutKey = CreateFoldoutKey(newParentsKey); string displayName = CreateDisplayKey(newParentsKey); if (ShouldFoldout(displayName, foldoutKey)) { dirty = RenderJsonDictionary(newParentsKey, _value as Dictionary <string, object>); } } else { Debug.LogWarning("Unknown type of json: key => " + key + ", value => " + _value); } } return(dirty); }
private bool RenderJsonDictionary(string[] parentsKey, Dictionary <string, object> dict) { bool dirty = false; if (dict == null || dict.Count <= 0) { return(dirty); } foreach (var key in dict.Keys.ToArray()) { object _value = dict[key]; if (_value is string) { // EditorGUILayout.LabelField(dict[key] as string); string value = _value as string; string newValue = EditorGUILayout.DelayedTextField(key, value); if (newValue != value) { dict[key] = newValue; dirty = true; } } else if (_value is long) { // XXX: There are no DelayedLongField long __value = (long)_value; if (__value > int.MaxValue || __value < int.MinValue) { Debug.LogWarning("StateJsonEditor not handled long size value => " + __value); } int value = (int)__value; int newValue = EditorGUILayout.DelayedIntField(key, value); if (newValue != value) { dict[key] = newValue; dirty = true; } } else if (_value is double) { double value = (double)_value; double newValue = EditorGUILayout.DelayedDoubleField(key, value); if (newValue != value) { dict[key] = newValue; dirty = true; } } else if (_value is bool) { bool value = (bool)_value; bool newValue = EditorGUILayout.Toggle(key, value); if (newValue != value) { dict[key] = newValue; dirty = true; } } else if (_value == null) { EditorGUILayout.LabelField(key, "null"); } else if (_value is List <object> ) { string[] newParentsKey = CreateParentsKey(parentsKey, key); string foldoutKey = CreateFoldoutKey(newParentsKey); string displayName = CreateDisplayKey(newParentsKey); if (ShouldFoldout(displayName, foldoutKey)) { dirty = RenderJsonArray(newParentsKey, key, (List <object>)_value); } } else if (_value is Dictionary <string, object> ) { string[] newParentsKey = CreateParentsKey(parentsKey, key); string foldoutKey = CreateFoldoutKey(newParentsKey); string displayName = CreateDisplayKey(newParentsKey); if (ShouldFoldout(displayName, foldoutKey)) { dirty = RenderJsonDictionary(newParentsKey, (Dictionary <string, object>)_value); } } else { Debug.LogWarning("Unknown type of json: key => " + key + ", value => " + _value); } } return(dirty); }
public static bool editDelayed(ref double val) { BeginCheckLine(); val = EditorGUILayout.DelayedDoubleField(val); return(EndCheckLine()); }
public void InspectorGUI_ViewModel() { EditorGUI.indentLevel++; EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Name & ID"); EditorGUILayout.TextField(string.Format("{0} ({1})", "SecondViewModel", VM.VMID.ToString().Substring(0, 8))); EditorGUILayout.EndHorizontal(); string vmk; vmk = "IntValue"; int tempIntValue = EditorGUILayout.DelayedIntField(vmk, VM.IntValue); if (tempIntValue != VM.IntValue) { VM.IntValue = tempIntValue; } vmk = "LongValue"; int tempLongValue = EditorGUILayout.DelayedIntField(vmk, (int)VM.LongValue); if ((long)tempLongValue != VM.LongValue) { VM.LongValue = (long)tempLongValue; } vmk = "FloatValue"; float tempFloatValue = EditorGUILayout.DelayedFloatField(vmk, VM.FloatValue); if (tempFloatValue != VM.FloatValue) { VM.FloatValue = tempFloatValue; } vmk = "DoubleValue"; double tempDoubleValue = EditorGUILayout.DelayedDoubleField(vmk, VM.DoubleValue); if (tempDoubleValue != VM.DoubleValue) { VM.DoubleValue = tempDoubleValue; } vmk = "IntList"; EditorGUILayout.BeginHorizontal(); string IntListJson = JsonConvert.SerializeObject(VM.IntList); string tempIntListJson = EditorGUILayout.DelayedTextField(vmk, IntListJson); if (tempIntListJson != IntListJson) { if (string.IsNullOrEmpty(tempIntListJson)) { VM.IntList = null; } else { VM.IntList = JsonConvert.DeserializeObject <ReactiveCollection <int> > (tempIntListJson); } } if (GUILayout.Button("...", GUILayout.MaxWidth(20))) { PopupWindow.Show( new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0f, 0f), new ReactiveCollectionEditorPopupWindow <int> (this, VM.IntList) ); } EditorGUILayout.EndHorizontal(); vmk = "LongList"; EditorGUILayout.BeginHorizontal(); string LongListJson = JsonConvert.SerializeObject(VM.LongList); string tempLongListJson = EditorGUILayout.DelayedTextField(vmk, LongListJson); if (tempLongListJson != LongListJson) { if (string.IsNullOrEmpty(tempLongListJson)) { VM.LongList = null; } else { VM.LongList = JsonConvert.DeserializeObject <ReactiveCollection <long> > (tempLongListJson); } } if (GUILayout.Button("...", GUILayout.MaxWidth(20))) { PopupWindow.Show( new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0f, 0f), new ReactiveCollectionEditorPopupWindow <long> (this, VM.LongList) ); } EditorGUILayout.EndHorizontal(); vmk = "FloatList"; EditorGUILayout.BeginHorizontal(); string FloatListJson = JsonConvert.SerializeObject(VM.FloatList); string tempFloatListJson = EditorGUILayout.DelayedTextField(vmk, FloatListJson); if (tempFloatListJson != FloatListJson) { if (string.IsNullOrEmpty(tempFloatListJson)) { VM.FloatList = null; } else { VM.FloatList = JsonConvert.DeserializeObject <ReactiveCollection <float> > (tempFloatListJson); } } if (GUILayout.Button("...", GUILayout.MaxWidth(20))) { PopupWindow.Show( new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0f, 0f), new ReactiveCollectionEditorPopupWindow <float> (this, VM.FloatList) ); } EditorGUILayout.EndHorizontal(); vmk = "DoubleList"; EditorGUILayout.BeginHorizontal(); string DoubleListJson = JsonConvert.SerializeObject(VM.DoubleList); string tempDoubleListJson = EditorGUILayout.DelayedTextField(vmk, DoubleListJson); if (tempDoubleListJson != DoubleListJson) { if (string.IsNullOrEmpty(tempDoubleListJson)) { VM.DoubleList = null; } else { VM.DoubleList = JsonConvert.DeserializeObject <ReactiveCollection <double> > (tempDoubleListJson); } } if (GUILayout.Button("...", GUILayout.MaxWidth(20))) { PopupWindow.Show( new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0f, 0f), new ReactiveCollectionEditorPopupWindow <double> (this, VM.DoubleList) ); } EditorGUILayout.EndHorizontal(); vmk = "StringList"; EditorGUILayout.BeginHorizontal(); string StringListJson = JsonConvert.SerializeObject(VM.StringList); string tempStringListJson = EditorGUILayout.DelayedTextField(vmk, StringListJson); if (tempStringListJson != StringListJson) { if (string.IsNullOrEmpty(tempStringListJson)) { VM.StringList = null; } else { VM.StringList = JsonConvert.DeserializeObject <ReactiveCollection <string> > (tempStringListJson); } } if (GUILayout.Button("...", GUILayout.MaxWidth(20))) { PopupWindow.Show( new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0f, 0f), new ReactiveCollectionEditorPopupWindow <string> (this, VM.StringList) ); } EditorGUILayout.EndHorizontal(); vmk = "IntDictionary"; EditorGUILayout.BeginHorizontal(); string IntDictionary = JsonConvert.SerializeObject(VM.IntDictionary); string tempIntDictionary = EditorGUILayout.DelayedTextField(vmk, IntDictionary); if (tempIntDictionary != IntDictionary) { if (string.IsNullOrEmpty(tempIntDictionary)) { VM.IntDictionary = null; } else { VM.IntDictionary = JsonConvert.DeserializeObject <ReactiveDictionary <string, int> > (tempIntDictionary); } } if (GUILayout.Button("...", GUILayout.MaxWidth(20))) { PopupWindow.Show( new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0f, 0f), new ReactiveDictionaryEditorPopupWindow <string, int> (this, VM.IntDictionary) ); } EditorGUILayout.EndHorizontal(); vmk = "StringDictionary"; EditorGUILayout.BeginHorizontal(); string StringDictionary = JsonConvert.SerializeObject(VM.StringDictionary); string tempStringDictionary = EditorGUILayout.DelayedTextField(vmk, StringDictionary); if (tempStringDictionary != StringDictionary) { if (string.IsNullOrEmpty(tempStringDictionary)) { VM.StringDictionary = null; } else { VM.StringDictionary = JsonConvert.DeserializeObject <ReactiveDictionary <int, string> > (tempStringDictionary); } } if (GUILayout.Button("...", GUILayout.MaxWidth(20))) { PopupWindow.Show( new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0f, 0f), new ReactiveDictionaryEditorPopupWindow <int, string> (this, VM.StringDictionary) ); } EditorGUILayout.EndHorizontal(); vmk = "StringCommand"; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(vmk); if (GUILayout.Button("Params")) { if (CommandParams.ContainsKey(vmk)) { CommandParams.Remove(vmk); } else { CommandParams [vmk] = JsonConvert.SerializeObject(new StringCommandCommand(), Formatting.Indented); } } if (GUILayout.Button("Invoke")) { if (CommandParams.ContainsKey(vmk) == false) { VM.RC_StringCommand.Execute(new StringCommandCommand() { Sender = VM }); } else { StringCommandCommand command = JsonConvert.DeserializeObject <StringCommandCommand> (CommandParams [vmk]); command.Sender = VM; VM.RC_StringCommand.Execute(command); } } EditorGUILayout.EndHorizontal(); if (CommandParams.ContainsKey(vmk)) { CommandParams [vmk] = EditorGUILayout.TextArea(CommandParams [vmk]); EditorGUILayout.Space(); } vmk = "IntCommand"; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(vmk); if (GUILayout.Button("Params")) { if (CommandParams.ContainsKey(vmk)) { CommandParams.Remove(vmk); } else { CommandParams [vmk] = JsonConvert.SerializeObject(new IntCommandCommand(), Formatting.Indented); } } if (GUILayout.Button("Invoke")) { if (CommandParams.ContainsKey(vmk) == false) { VM.RC_IntCommand.Execute(new IntCommandCommand() { Sender = VM }); } else { IntCommandCommand command = JsonConvert.DeserializeObject <IntCommandCommand> (CommandParams [vmk]); command.Sender = VM; VM.RC_IntCommand.Execute(command); } } EditorGUILayout.EndHorizontal(); if (CommandParams.ContainsKey(vmk)) { CommandParams [vmk] = EditorGUILayout.TextArea(CommandParams [vmk]); EditorGUILayout.Space(); } vmk = "SimpleCommand"; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(vmk); if (GUILayout.Button("Invoke")) { VM.RC_SimpleCommand.Execute(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUI.indentLevel--; if (EditorApplication.isPlaying == false) { if (GUI.changed) { VMCopyToJson(); } } }
public override void OnInspectorGUI() { GUI.changed = false; OrbitUniversal orbitU = (OrbitUniversal)target; bool displayAndExit = false; // check there is an NBody, if not likely a synthesized Orbit as part of a predictor if (orbitU.GetComponent <NBody>() == null) { EditorGUILayout.LabelField("Ellipse parameters determined from position/velocity."); EditorGUILayout.LabelField("(Orbit Predictor)."); displayAndExit = true; } // If there is a SolarBody, it is the one place data can be changed. The EB holds the // orbit scaled per SolarSystem scale. SolarBody sbody = orbitU.GetComponent <SolarBody>(); if (sbody != null) { EditorGUILayout.LabelField("Ellipse parameters controlled by SolarBody settings."); displayAndExit = true; } if (displayAndExit) { EditorGUILayout.LabelField(string.Format(" {0,-25} ({1,1})\t {2}", "Semi-Major Axis", "a", orbitU.GetMajorAxisInspector()), EditorStyles.wordWrappedLabel); EditorGUILayout.LabelField(string.Format(" {0,-25} ({1,1})\t {2}", "Eccentricity", "e", orbitU.eccentricity), EditorStyles.wordWrappedLabel); EditorGUILayout.LabelField(string.Format(" {0,-25} ({1,1})\t {2}", "Incliniation", "i", orbitU.inclination), EditorStyles.wordWrappedLabel); EditorGUILayout.LabelField(string.Format(" {0,-25} ({1,1})\t {2}", "Arg. of pericenter", "\u03c9", orbitU.omega_lc), EditorStyles.wordWrappedLabel); EditorGUILayout.LabelField(string.Format(" {0,-25} ({1,1})\t {2}", "Longitude of node", "\u03a9", orbitU.omega_uc), EditorStyles.wordWrappedLabel); EditorGUILayout.LabelField(string.Format(" {0,-25} ({1,1})\t {2}", "Phase", "M", orbitU.phase), EditorStyles.wordWrappedLabel); return; } // fields in class NBody centerNBody = null; OrbitUniversal.InputMode inputMode = orbitU.inputMode; double ecc = orbitU.eccentricity; double p_inspector = orbitU.p_inspector; double omega_uc = 0; double omega_lc = 0; double inclination = 0; double phase = 0; bool sizeUpdate = false; WarnAboutKeplerSeq(orbitU); centerNBody = (NBody)EditorGUILayout.ObjectField( new GUIContent("Center NBody", centerTip), orbitU.centerNbody, typeof(NBody), true); OrbitUniversal.EvolveMode evolveMode = orbitU.evolveMode; evolveMode = (OrbitUniversal.EvolveMode)EditorGUILayout.EnumPopup(new GUIContent("Evolve Mode", modeTip), evolveMode); EditorGUILayout.Space(); EditorGUILayout.LabelField("Shape Parameters", EditorStyles.boldLabel); inputMode = (OrbitUniversal.InputMode) EditorGUILayout.EnumPopup(new GUIContent("Parameter Choice", paramTip), orbitU.inputMode); sizeUpdate = false; GravityScaler.Units units = GravityEngine.Instance().units; string promptp = string.Format("Semi-parameter (p) [{0}]", GravityScaler.LengthUnits(units)); // The values for orbit size and shape can be entered in several ways. OrbitUniversal supports // these values as doubles (which is probably overkill in most case). Provide an explicit double mode // but also allow sliders (which reduce the value to a float). // The editor script changes p_inspector. (p in OU is scaled for GE internal units) switch (inputMode) { case OrbitUniversal.InputMode.ELLIPSE_MAJOR_AXIS_A: EditorGUILayout.LabelField("Ellipse with float/sliders using semi-major axis."); ecc = EditorGUILayout.Slider(new GUIContent("Eccentricity", eTip), (float)orbitU.eccentricity, 0f, 0.99f); GetMajorAxis(orbitU, ref p_inspector, ref sizeUpdate, units); break; case OrbitUniversal.InputMode.ELLIPSE_APOGEE_PERIGEE: EditorGUILayout.LabelField("Ellipse with float/sliders using agogee/perigee."); EditorGUILayout.LabelField("MUST use <Return> after updating values!"); double apogee_old = orbitU.GetApogeeInspector(); double apogee = EditorGUILayout.DelayedDoubleField(new GUIContent("Apogee", eTip), apogee_old); double perigee_old = orbitU.GetPerigeeInspector(); double perigee = EditorGUILayout.DelayedDoubleField(new GUIContent("Perigee", eTip), perigee_old); // enforce apogee > perigee if (apogee < perigee) { apogee = perigee; } if (!EditorApplication.isPlaying && (apogee != apogee_old) || (perigee != perigee_old)) { orbitU.SetSizeWithApogeePerigee(apogee, perigee); sizeUpdate = true; // Need to update ecc and p with new values p_inspector = orbitU.p_inspector; ecc = orbitU.eccentricity; } EditorGUILayout.LabelField(string.Format("Require Apogee > Perigee", ecc, p_inspector)); EditorGUILayout.LabelField(string.Format("Apogee/Perigee result in: eccentricty={0:0.00}, p={1:0.00}", ecc, p_inspector)); break; case OrbitUniversal.InputMode.ECC_PERIGEE: EditorGUILayout.LabelField("Orbit with double using eccentricity/perigee."); EditorGUILayout.LabelField("MUST use <Return> after updating values!"); double old_ecc = orbitU.eccentricity; ecc = EditorGUILayout.DelayedDoubleField(new GUIContent("Eccentricity", eTip), orbitU.eccentricity); double hperigee_old = orbitU.GetPerigeeInspector(); double hperigee = EditorGUILayout.DelayedDoubleField(new GUIContent("Perigee", eTip), hperigee_old); if (!EditorApplication.isPlaying && ((hperigee != hperigee_old) || (old_ecc != ecc))) { orbitU.SetSizeWithEccPerigee(ecc, hperigee); sizeUpdate = true; // Need to update ecc and p with new values p_inspector = orbitU.p_inspector; ecc = orbitU.eccentricity; } EditorGUILayout.LabelField(string.Format("Apogee/Perigee result in: eccentricty={0:0.00}, p={1:0.00}", ecc, p_inspector)); break; case OrbitUniversal.InputMode.DOUBLE: EditorGUILayout.LabelField("Specify values with double precision using semi-parameter"); EditorGUILayout.LabelField("MUST use <Return> after updating values!"); // no sliders (they do float) ecc = EditorGUILayout.DelayedDoubleField(new GUIContent("Eccentricity", eTip), orbitU.eccentricity); double old_p = orbitU.p_inspector; p_inspector = EditorGUILayout.DelayedDoubleField(new GUIContent(promptp, pTip), orbitU.p_inspector); if (old_p != p_inspector) { sizeUpdate = true; } break; case OrbitUniversal.InputMode.DOUBLE_ELLIPSE: EditorGUILayout.LabelField("Specify values with double precision using semi-parameter"); EditorGUILayout.LabelField("MUST use <Return> after updating values!"); // no sliders (they do float) ecc = EditorGUILayout.DelayedDoubleField(new GUIContent("Eccentricity", eTip), orbitU.eccentricity); GetMajorAxis(orbitU, ref p_inspector, ref sizeUpdate, units); break; default: Debug.LogWarning("Unknown input mode - internal error"); break; } if (!EditorApplication.isPlaying && (p_inspector != orbitU.p)) { sizeUpdate = true; } EditorGUILayout.LabelField("Scaled p (Unity units): " + orbitU.p); EditorGUILayout.Space(); EditorGUILayout.LabelField("Orientation Parameters", EditorStyles.boldLabel); if ((inputMode != OrbitUniversal.InputMode.DOUBLE) && (inputMode != OrbitUniversal.InputMode.DOUBLE_ELLIPSE)) { // implementation uses AngleAxis, so degrees are more natural omega_uc = EditorGUILayout.Slider(new GUIContent("\u03a9 (Longitude of AN)", omega_ucTip), (float)orbitU.omega_uc, 0, 360f); omega_lc = EditorGUILayout.Slider(new GUIContent("\u03c9 (AN to Pericenter)", omega_lcTip), (float)orbitU.omega_lc, 0, 360f); inclination = EditorGUILayout.Slider(new GUIContent("Inclination", inclinationTip), (float)orbitU.inclination, 0f, 180f); // physics uses radians - but ask user for degrees to be consistent phase = EditorGUILayout.Slider(new GUIContent("Starting Phase", phaseTip), (float)orbitU.phase, 0, 360f); } else { // DOUBLE, so no sliders omega_uc = EditorGUILayout.DoubleField(new GUIContent("\u03a9 (Longitude of AN)", omega_ucTip), orbitU.omega_uc); omega_lc = EditorGUILayout.DoubleField(new GUIContent("\u03c9 (AN to Pericenter)", omega_lcTip), orbitU.omega_lc); inclination = EditorGUILayout.DoubleField(new GUIContent("Inclination", inclinationTip), orbitU.inclination); phase = EditorGUILayout.DoubleField(new GUIContent("Starting Phase", phaseTip), orbitU.phase); } if (GUI.changed) { Undo.RecordObject(orbitU, "EllipseBase Change"); orbitU.p_inspector = p_inspector; orbitU.eccentricity = ecc; orbitU.centerNbody = centerNBody; orbitU.omega_lc = omega_lc; orbitU.omega_uc = omega_uc; orbitU.inclination = inclination; orbitU.phase = phase; orbitU.inputMode = inputMode; orbitU.evolveMode = evolveMode; EditorUtility.SetDirty(orbitU); } if (sizeUpdate) { orbitU.ApplyScale(GravityEngine.Instance().GetLengthScale()); } }
public static bool editDelayed(ref double val, int width) { BeginCheckLine(); val = EditorGUILayout.DelayedDoubleField(val, GUILayout.MaxWidth(width)); return(EndCheckLine()); }
protected override void OnGUI() { base.OnGUI(); pos = EditorGUILayout.BeginScrollView(pos); if (GUILayout.Button("这是一个按钮")) { Debug.Log("Click Button"); } EditorGUILayout.LabelField("空格"); EditorGUILayout.Separator(); EditorGUILayout.Space(); EditorGUILayout.LabelField("这是一个默认Lable"); EditorGUILayout.LabelField("这是高300,宽50的Label", GUILayout.Width(300), GUILayout.Height(50)); EditorGUILayout.LabelField("这是一个拾色器"); EditorGUILayout.ColorField(Color.white); EditorGUILayout.LabelField("Bounds"); bounds = EditorGUILayout.BoundsField(bounds); EditorGUILayout.LabelField("BoundsInt"); boundsInt = EditorGUILayout.BoundsIntField(boundsInt); EditorGUILayout.LabelField("AnimationCurve"); curve = EditorGUILayout.CurveField(curve); EditorGUILayout.LabelField("<color=#ff0000>注意比对延迟设置和直接设置的区别</color>", Style); EditorGUILayout.Space(); toggle = EditorGUILayout.Toggle("Toggle", toggle); toggleLeft = EditorGUILayout.ToggleLeft("ToggleLeft", toggleLeft); //double EditorGUILayout.LabelField("延迟设置" + delayedDou.ToString()); delayedDou = EditorGUILayout.DelayedDoubleField("DelayedDouble", delayedDou); EditorGUILayout.LabelField("直接设置" + dou.ToString()); dou = EditorGUILayout.DoubleField("Double", dou); delayedInt = EditorGUILayout.DelayedIntField("DelayedInt", delayedInt); //int i = EditorGUILayout.IntField("Int", i); sliderInt = EditorGUILayout.IntSlider(sliderInt, 0, 100); //text delayedText = EditorGUILayout.DelayedTextField("DelayedText", delayedText); text = EditorGUILayout.TextField("Text", text); password = EditorGUILayout.PasswordField("Password", password); EditorGUILayout.LabelField("TextArea"); textArea = EditorGUILayout.TextArea(textArea); //float delayedFloat = EditorGUILayout.DelayedFloatField("DelayedFloat", delayedFloat); f = EditorGUILayout.FloatField("Float", f); fSlider = EditorGUILayout.Slider("FloatSlider", fSlider, 0, 10); fKnob = EditorGUILayout.Knob(new Vector2(100, 100), fKnob, 0, 10, "Knob", Color.blue, Color.red, true); longvalue = EditorGUILayout.LongField("Long", longvalue); //vector v2 = EditorGUILayout.Vector2Field("Vector2", v2); v2Int = EditorGUILayout.Vector2IntField("Vector2Int", v2Int); v3 = EditorGUILayout.Vector3Field("Vector3", v3); v3Int = EditorGUILayout.Vector3IntField("Vector3Int", v3Int); v4 = EditorGUILayout.Vector4Field("Vector4", v4); EditorGUILayout.LabelField("枚举Field"); m_Flags = (ExampleFlagsEnum)EditorGUILayout.EnumFlagsField(m_Flags); EditorGUILayout.LabelField("注意两者的区别"); m_Flags = (ExampleFlagsEnum)EditorGUILayout.EnumPopup(m_Flags); gradient = EditorGUILayout.GradientField("Gradient", gradient); go = (GameObject)EditorGUILayout.ObjectField("GameObject", go, typeof(GameObject), true); clip = (AnimationClip)EditorGUILayout.ObjectField("Clip", clip, typeof(AnimationClip), true); EditorGUILayout.LabelField("Rect"); rect = EditorGUILayout.RectField(rect); EditorGUILayout.LabelField("RectInt"); rectInt = EditorGUILayout.RectIntField(rectInt); EditorGUILayout.HelpBox("这是一个信息Box", MessageType.Info); EditorGUILayout.HelpBox("这是一个警告Box", MessageType.Warning); EditorGUILayout.HelpBox("这是一个错误Box", MessageType.Error); EditorGUILayout.SelectableLabel("SelectableLabel"); EditorGUILayout.EndScrollView(); }