升级水插件
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.Editor.Internal;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
@@ -21,15 +23,32 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
internal static Inspector Current { get; private set; }
|
||||
|
||||
readonly Dictionary<FieldInfo, object> _MaterialOwners = new();
|
||||
readonly Dictionary<Material, MaterialEditor> _MaterialEditors = new();
|
||||
|
||||
public override bool RequiresConstantRepaint() => TexturePreview.AnyActivePreviews;
|
||||
public override bool RequiresConstantRepaint() => TexturePreview.s_ActiveInstance?.Open == true;
|
||||
|
||||
// Set this from a decorator to enable the material editor.
|
||||
internal List<Material> _Materials = new();
|
||||
static readonly IOrderedEnumerable<FieldInfo> s_AttachMaterialEditors = TypeCache
|
||||
.GetFieldsWithAttribute<AttachMaterialEditor>()
|
||||
.OrderBy(x => x.GetCustomAttribute<AttachMaterialEditor>().Order);
|
||||
|
||||
readonly Utility.SortedList<int, SerializedProperty> _Properties = new(Helpers.DuplicateComparison);
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
_MaterialOwners.Clear();
|
||||
|
||||
foreach (var field in s_AttachMaterialEditors)
|
||||
{
|
||||
var target = (object)this.target;
|
||||
|
||||
if (field.FindOwner(ref target))
|
||||
{
|
||||
_MaterialOwners.Add(field, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
// Reset foldout values.
|
||||
@@ -61,7 +80,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
}
|
||||
|
||||
protected void RenderBeforeInspectorGUI()
|
||||
protected virtual void RenderBeforeInspectorGUI()
|
||||
{
|
||||
if (this.target is EditorBehaviour target && target._IsPrefabStageInstance)
|
||||
{
|
||||
@@ -143,13 +162,14 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
protected virtual void RenderAfterInspectorGUI()
|
||||
{
|
||||
foreach (var material in _Materials)
|
||||
foreach (var mapping in _MaterialOwners)
|
||||
{
|
||||
if (material == null) continue;
|
||||
DrawMaterialEditor(material);
|
||||
var material = (Material)mapping.Key.GetValue(mapping.Value);
|
||||
if (material != null)
|
||||
{
|
||||
DrawMaterialEditor(material);
|
||||
}
|
||||
}
|
||||
|
||||
_Materials.Clear();
|
||||
}
|
||||
|
||||
// Adapted from: http://answers.unity.com/answers/975894/view.html
|
||||
|
||||
Reference in New Issue
Block a user