From f049177e20a276049c61edbad631c1b2bbdd5706 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 15 Oct 2020 19:05:22 +0800 Subject: -advanced inspector +odin --- .../Editor/Vector2IntMinMaxAttributeDrawer.cs | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/Vector2IntMinMaxAttributeDrawer.cs (limited to 'Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/Vector2IntMinMaxAttributeDrawer.cs') diff --git a/Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/Vector2IntMinMaxAttributeDrawer.cs b/Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/Vector2IntMinMaxAttributeDrawer.cs new file mode 100644 index 00000000..f70613f9 --- /dev/null +++ b/Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/Vector2IntMinMaxAttributeDrawer.cs @@ -0,0 +1,73 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) Sirenix IVS. All rights reserved. +// +//----------------------------------------------------------------------- + +#if UNITY_EDITOR && UNITY_2017_2_OR_NEWER + +namespace Sirenix.OdinInspector.Editor.Drawers +{ + using Sirenix.OdinInspector; + using Sirenix.OdinInspector.Editor; + using Sirenix.OdinInspector.Editor.ValueResolvers; + using Sirenix.Utilities; + using Sirenix.Utilities.Editor; + using System.Reflection; + using UnityEditor; + using UnityEngine; + + /// + /// Draws Vector2Int properties marked with . + /// + public class Vector2IntMinMaxAttributeDrawer : OdinAttributeDrawer + { + private ValueResolver minGetter; + private ValueResolver maxGetter; + private ValueResolver vector2IntMinMaxGetter; + + /// + /// Initializes the drawer by resolving any optional references to members for min/max value. + /// + protected override void Initialize() + { + // Min member reference. + this.minGetter = ValueResolver.Get(this.Property, this.Attribute.MinValueGetter, this.Attribute.MinValue); + this.maxGetter = ValueResolver.Get(this.Property, this.Attribute.MaxValueGetter, this.Attribute.MaxValue); + + // Min max member reference. + if (this.Attribute.MinMaxValueGetter != null) + { + this.vector2IntMinMaxGetter = ValueResolver.Get(this.Property, this.Attribute.MinMaxValueGetter); + } + } + + /// + /// Draws the property. + /// + protected override void DrawPropertyLayout(GUIContent label) + { + ValueResolver.DrawErrors(this.minGetter, this.maxGetter, this.vector2IntMinMaxGetter); + + // Get the range of the slider from the attribute or from member references. + Vector2 range; + if (this.vector2IntMinMaxGetter != null && !this.vector2IntMinMaxGetter.HasError) + { + range = (Vector2)this.vector2IntMinMaxGetter.GetValue(); + } + else + { + range.x = this.minGetter.GetValue(); + range.y = this.maxGetter.GetValue(); + } + + EditorGUI.BeginChangeCheck(); + Vector2 value = SirenixEditorFields.MinMaxSlider(label, (Vector2)this.ValueEntry.SmartValue, range, this.Attribute.ShowFields); + if (EditorGUI.EndChangeCheck()) + { + this.ValueEntry.SmartValue = new Vector2Int((int)value.x, (int)value.y); + } + } + } +} +#endif // UNITY_EDITOR && UNITY_2017_2_OR_NEWER \ No newline at end of file -- cgit v1.1-26-g67d0