升级6.4.升级水,升级天气

This commit is contained in:
2026-04-05 00:26:54 +08:00
parent 63bc9b5536
commit 5f7cbfb713
635 changed files with 34718 additions and 22567 deletions

View File

@@ -18,13 +18,19 @@ namespace WaveHarmonic.Crest.Editor
[CustomEditor(typeof(EditorBehaviour), editorForChildClasses: true)]
partial class Inspector : UnityEditor.Editor
{
public const int k_FieldGroupOrder = 1000;
public const int k_FieldGroupOrder = k_FieldHeadingOrder * 100;
public const int k_FieldHeadingOrder = k_FieldOrder * 100;
public const int k_FieldOrder = 1000;
const string k_NoPrefabModeSupportWarning = "Prefab mode is not supported. Changes made in prefab mode will not be reflected in the scene view. Save this prefab to see changes.";
internal static Inspector Current { get; private set; }
readonly Dictionary<FieldInfo, object> _MaterialOwners = new();
readonly Dictionary<Material, MaterialEditor> _MaterialEditors = new();
readonly Dictionary<string, DecoratedDrawer> _Lists = new();
internal readonly List<EmbeddedAssetEditor> _EmbeddedEditors = new();
internal static readonly List<EmbeddedAssetEditor> s_EmbeddedEditors = new();
public override bool RequiresConstantRepaint() => TexturePreview.s_ActiveInstance?.Open == true;
@@ -32,12 +38,16 @@ namespace WaveHarmonic.Crest.Editor
.GetFieldsWithAttribute<AttachMaterialEditor>()
.OrderBy(x => x.GetCustomAttribute<AttachMaterialEditor>().Order);
readonly List<string> _Headings = new();
readonly Utility.SortedList<int, SerializedProperty> _Properties = new(Helpers.DuplicateComparison);
protected virtual void OnEnable()
{
_MaterialOwners.Clear();
Undo.undoRedoPerformed -= OnUndoRedo;
Undo.undoRedoPerformed += OnUndoRedo;
foreach (var field in s_AttachMaterialEditors)
{
var target = (object)this.target;
@@ -60,7 +70,20 @@ namespace WaveHarmonic.Crest.Editor
GUI.enabled = (target.hideFlags & HideFlags.NotEditable) == 0;
RenderBeforeInspectorGUI();
RenderInspectorGUI();
try
{
RenderInspectorGUI();
}
catch (InvalidOperationException exception)
{
// Happens when using New with embedded editor and not change the filename.
if (exception.Message != "Stack empty.")
{
throw exception;
}
}
RenderValidationMessages();
EditorGUI.BeginDisabledGroup(target is Behaviour component && !component.isActiveAndEnabled);
@@ -74,10 +97,23 @@ namespace WaveHarmonic.Crest.Editor
protected virtual void OnDisable()
{
Undo.undoRedoPerformed -= OnUndoRedo;
foreach (var (_, editor) in _MaterialEditors)
{
Helpers.Destroy(editor);
}
foreach (var embedded in _EmbeddedEditors)
{
embedded?.OnDisable();
s_EmbeddedEditors.Remove(embedded);
}
}
protected virtual void OnChange()
{
}
protected virtual void RenderBeforeInspectorGUI()
@@ -95,10 +131,13 @@ namespace WaveHarmonic.Crest.Editor
var previous = Current;
Current = this;
_Headings.Clear();
_Properties.Clear();
serializedObject.Update();
EditorGUI.BeginChangeCheck();
using var iterator = serializedObject.GetIterator();
if (iterator.NextVisible(true))
{
@@ -112,7 +151,7 @@ namespace WaveHarmonic.Crest.Editor
if (iterator.name == "m_Script")
{
#if CREST_DEBUG
_Properties.Add(index++, property);
_Properties.Add(index++ * k_FieldOrder, property);
#endif
continue;
}
@@ -129,7 +168,44 @@ namespace WaveHarmonic.Crest.Editor
// Null checking but there should always be one DecoratedProperty.
var order = field.GetCustomAttribute<Attributes.DecoratedProperty>()?.order ?? 0;
group = field.GetCustomAttribute<Group>()?.order * k_FieldGroupOrder ?? group;
_Properties.Add(order + group + index++, property);
var headingAttribute = field.GetCustomAttribute<Heading>();
if (headingAttribute != null)
{
_Headings.Add(headingAttribute._Text.text);
}
var heading = Mathf.Max(0, _Headings.Count - 1);
var orderAttribute = field.GetCustomAttribute<Order>();
if (orderAttribute != null)
{
var target = orderAttribute._Target;
if (orderAttribute._Placement == Order.Placement.Heading)
{
heading = _Headings.FindIndex(x => x == target);
}
}
var key = order + group + heading * k_FieldHeadingOrder + index * k_FieldOrder;
// Override.
if (orderAttribute != null)
{
var target = orderAttribute._Target;
switch (orderAttribute._Placement)
{
case Order.Placement.Below: key = _Properties.First(x => x.Value.name == target).Key + index; break;
case Order.Placement.Above: key = _Properties.First(x => x.Value.name == target).Key - index; break;
}
}
_Properties.Add(key, property);
index += 1;
}
while (iterator.NextVisible(false));
}
@@ -140,6 +216,33 @@ namespace WaveHarmonic.Crest.Editor
using (new EditorGUI.DisabledGroupScope(property.name == "m_Script"))
#endif
{
// Handle lists as PropertyDrawer is not called on the list itself.
if (property.isArray)
{
var field = property.GetFieldInfo(out var _);
var attribute = field?.GetCustomAttribute<Attributes.DecoratedProperty>();
if (field != null && attribute != null)
{
var id = GetPropertyIdentifier(property);
if (!_Lists.ContainsKey(id))
{
_Lists[id] = new DecoratedDrawer()
{
_Attribute = attribute,
_Field = field,
};
}
DecoratedDrawer.s_IsList = true;
var label = new GUIContent(property.displayName);
_Lists[id].OnGUI(Rect.zero, property, label);
DecoratedDrawer.s_IsList = false;
continue;
}
}
// Only support top level ordering for now.
EditorGUILayout.PropertyField(property, includeChildren: true);
}
@@ -148,11 +251,18 @@ namespace WaveHarmonic.Crest.Editor
// Need to call just in case there is no decorated property.
serializedObject.ApplyModifiedProperties();
if (EditorGUI.EndChangeCheck())
{
OnChange();
}
// Restore previous in case this is a nested editor.
Current = previous;
// Fixes indented validation etc.
EditorGUI.indentLevel = 0;
_UndoRedo = false;
}
protected virtual void RenderBottomButtons()
@@ -212,6 +322,55 @@ namespace WaveHarmonic.Crest.Editor
}
}
}
internal virtual void OnCustomField(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
{
}
internal virtual GUIContent OnCustomLabel(SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
{
return label;
}
}
// Reflection
partial class Inspector
{
static readonly PropertyInfo s_GUIViewCurrent = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GUIView").GetProperty("current", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
static readonly PropertyInfo s_GUIViewNativeHandle = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GUIView").GetProperty("nativeHandle", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
// Adapted from:
// https://github.com/Unity-Technologies/UnityCsReference/blob/59b03b8a0f179c0b7e038178c90b6c80b340aa9f/Editor/Mono/Inspector/ReorderableListWrapper.cs#L77-L88
static string GetPropertyIdentifier(SerializedProperty serializedProperty)
{
// Property may be disposed.
try
{
var handle = -1;
var current = s_GUIViewCurrent.GetValue(null);
if (current != null)
{
handle = ((IntPtr)s_GUIViewNativeHandle.GetValue(current)).ToInt32();
}
return serializedProperty?.propertyPath + serializedProperty.serializedObject.targetObject.GetEntityId() + handle;
}
catch (NullReferenceException)
{
return string.Empty;
}
}
}
partial class Inspector
{
internal bool _UndoRedo;
void OnUndoRedo()
{
_UndoRedo = true;
}
}
// Adapted from: