升级水插件
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Adapted from:
|
||||
@@ -619,6 +619,44 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
}
|
||||
|
||||
sealed class InlineToggle : DecoratedProperty
|
||||
{
|
||||
// Add extra y offset. Needed for foldouts in foldouts so far.
|
||||
readonly bool _Fix;
|
||||
|
||||
public InlineToggle(bool fix = false)
|
||||
{
|
||||
_Fix = fix;
|
||||
}
|
||||
|
||||
internal override bool NeedsControlRectangle(SerializedProperty property)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
internal override void OnGUI(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
var r = position;
|
||||
r.x -= 16f;
|
||||
// Align with Space offset.
|
||||
if (drawer.Space > 0) r.y += drawer.Space + 2f;
|
||||
if (_Fix) r.y += EditorGUIUtility.singleLineHeight + 2f;
|
||||
// Seems to be needed.
|
||||
r.width = 16f * (1f + EditorGUI.indentLevel);
|
||||
r.height = EditorGUIUtility.singleLineHeight;
|
||||
label.text = "";
|
||||
|
||||
using (new EditorGUI.PropertyScope(r, label, property))
|
||||
{
|
||||
EditorGUI.BeginProperty(r, label, property);
|
||||
// Passing a tooltip to Toggle does nothing.
|
||||
GUI.Label(r, label);
|
||||
property.boolValue = EditorGUI.Toggle(r, property.boolValue);
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows an enum to render only a subset of options in subclasses.
|
||||
/// </summary>
|
||||
@@ -793,6 +831,9 @@ namespace WaveHarmonic.Crest
|
||||
case SerializedPropertyType.Float:
|
||||
EditorGUILayout.FloatField(label, (float)_PropertyInfo.GetValue(_Target));
|
||||
break;
|
||||
case SerializedPropertyType.Integer:
|
||||
EditorGUILayout.IntField(label, (int)_PropertyInfo.GetValue(_Target));
|
||||
break;
|
||||
case SerializedPropertyType.Enum:
|
||||
_EnumValues ??= Enum.GetValues(_PropertyInfo.PropertyType);
|
||||
EditorGUILayout.Popup(label, Array.IndexOf(_EnumValues, _PropertyInfo.GetValue(_Target)), property.enumDisplayNames);
|
||||
@@ -886,7 +927,7 @@ namespace WaveHarmonic.Crest
|
||||
/// </summary>
|
||||
sealed class Space : Decorator
|
||||
{
|
||||
readonly float _Height;
|
||||
public readonly float _Height;
|
||||
readonly bool _AlwaysVisible;
|
||||
|
||||
public Space(float height, bool isAlwaysVisible = false)
|
||||
@@ -978,13 +1019,13 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
}
|
||||
|
||||
sealed class AttachMaterialEditor : Decorator
|
||||
sealed class AttachMaterialEditor : Attribute
|
||||
{
|
||||
public override bool AlwaysVisible => true;
|
||||
public int Order { get; private set; }
|
||||
|
||||
internal override void Decorate(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
public AttachMaterialEditor(int order = 0)
|
||||
{
|
||||
Inspector.Current._Materials.Add((Material)property.objectReferenceValue);
|
||||
Order = order;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEditor;
|
||||
@@ -11,17 +11,19 @@ namespace WaveHarmonic.Crest
|
||||
sealed class Embedded : DecoratedProperty
|
||||
{
|
||||
internal EmbeddedAssetEditor _Editor;
|
||||
readonly int _BottomMargin;
|
||||
public int BottomMargin { get; private set; }
|
||||
public string DefaultPropertyName { get; private set; }
|
||||
|
||||
public Embedded(int margin = 0)
|
||||
public Embedded(int margin = 0, string defaultPropertyName = null)
|
||||
{
|
||||
_Editor = new();
|
||||
_BottomMargin = margin;
|
||||
BottomMargin = margin;
|
||||
DefaultPropertyName = defaultPropertyName;
|
||||
}
|
||||
|
||||
internal override void OnGUI(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
_Editor.DrawEditorCombo(label, drawer, property, "asset", _BottomMargin);
|
||||
_Editor.DrawEditorCombo(this, label, drawer, property, "asset");
|
||||
}
|
||||
|
||||
internal override bool NeedsControlRectangle(SerializedProperty property) => false;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using System;
|
||||
@@ -51,6 +51,12 @@ namespace WaveHarmonic.Crest
|
||||
_Member = _Type.GetMember(member, Helpers.s_AnyMethod)[0];
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Predicated(Type, string, object, bool, bool)"/>
|
||||
public Predicated(Type type, string member, bool inverted = false, bool hide = false) : this(type, member, true, inverted, hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable/Disable field depending on the current type of the component.
|
||||
/// </summary>
|
||||
@@ -165,11 +171,11 @@ namespace WaveHarmonic.Crest
|
||||
if (_Member is PropertyInfo autoProperty)
|
||||
{
|
||||
// == operator does not work.
|
||||
enabled = autoProperty.GetValue(@object).Equals(_DisableValue);
|
||||
enabled = !autoProperty.GetValue(@object).Equals(_DisableValue);
|
||||
}
|
||||
else if (_Member is MethodInfo method)
|
||||
{
|
||||
enabled = method.Invoke(@object, new object[] { }).Equals(_DisableValue);
|
||||
enabled = !method.Invoke(@object, new object[] { }).Equals(_DisableValue);
|
||||
}
|
||||
|
||||
if (_Inverted) enabled = !enabled;
|
||||
|
||||
Reference in New Issue
Block a user