升级水插件
This commit is contained in:
@@ -7,9 +7,10 @@
|
||||
// Lovingly adapted from Cinemachine:
|
||||
// https://github.com/Unity-Technologies/com.unity.cinemachine/blob/593fa283bee378322337e5d9f5a7b91331a45799/Editor/Utility/EmbeddedAssetHelpers.cs
|
||||
|
||||
using UnityEngine;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.VersionControl;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
@@ -66,23 +67,24 @@ namespace WaveHarmonic.Crest.Editor
|
||||
System.Type _Type;
|
||||
|
||||
Object _DefaultTarget;
|
||||
FieldInfo _DefaultTargetField;
|
||||
|
||||
const int k_IndentOffset = 3;
|
||||
|
||||
public void DrawEditorCombo(GUIContent label, PropertyDrawer drawer, SerializedProperty property, string extension, int bottomMargin = 0)
|
||||
public void DrawEditorCombo(Embedded embedded, GUIContent label, PropertyDrawer drawer, SerializedProperty property, string extension)
|
||||
{
|
||||
_Type = drawer.fieldInfo.FieldType;
|
||||
|
||||
DrawEditorCombo
|
||||
(
|
||||
embedded,
|
||||
label,
|
||||
$"Create {property.displayName} Asset",
|
||||
$"{property.displayName.Replace(' ', '_')}",
|
||||
extension,
|
||||
string.Empty,
|
||||
false,
|
||||
property,
|
||||
bottomMargin
|
||||
property
|
||||
);
|
||||
}
|
||||
|
||||
@@ -92,17 +94,17 @@ namespace WaveHarmonic.Crest.Editor
|
||||
/// </summary>
|
||||
public void DrawEditorCombo
|
||||
(
|
||||
Embedded embedded,
|
||||
GUIContent label,
|
||||
string title,
|
||||
string defaultName,
|
||||
string extension,
|
||||
string message,
|
||||
bool indent,
|
||||
SerializedProperty property,
|
||||
int bottomMargin
|
||||
SerializedProperty property
|
||||
)
|
||||
{
|
||||
UpdateEditor(property);
|
||||
UpdateEditor(property, embedded);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var rect = AssetField(label, property, title, defaultName, extension, message);
|
||||
@@ -110,7 +112,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
UpdateEditor(property);
|
||||
UpdateEditor(property, embedded);
|
||||
}
|
||||
|
||||
// Display embedded editor.
|
||||
@@ -145,9 +147,9 @@ namespace WaveHarmonic.Crest.Editor
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if (bottomMargin > 0)
|
||||
if (embedded.BottomMargin > 0)
|
||||
{
|
||||
EditorGUILayout.Space(bottomMargin);
|
||||
EditorGUILayout.Space(embedded.BottomMargin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,14 +203,31 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateEditor(SerializedProperty property)
|
||||
public void UpdateEditor(SerializedProperty property, Embedded embedded)
|
||||
{
|
||||
var target = property.objectReferenceValue;
|
||||
var hasDefaultField = !string.IsNullOrEmpty(embedded.DefaultPropertyName);
|
||||
|
||||
if (target == null && _DefaultTarget == null)
|
||||
if (target == null)
|
||||
{
|
||||
_DefaultTarget = ScriptableObject.CreateInstance(_Type);
|
||||
_DefaultTarget.hideFlags = HideFlags.DontSave | HideFlags.NotEditable;
|
||||
if (!hasDefaultField)
|
||||
{
|
||||
if (_DefaultTarget == null)
|
||||
{
|
||||
_DefaultTarget = ScriptableObject.CreateInstance(_Type);
|
||||
_DefaultTarget.hideFlags = HideFlags.DontSave | HideFlags.NotEditable;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_DefaultTargetField == null)
|
||||
{
|
||||
_DefaultTargetField = property.serializedObject.targetObject.GetType().GetField(embedded.DefaultPropertyName, Helpers.s_AnyMethod);
|
||||
}
|
||||
|
||||
// Always call, as it is dynamic.
|
||||
_DefaultTarget = (Object)_DefaultTargetField.GetValue(property.serializedObject.targetObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (target == null)
|
||||
|
||||
Reference in New Issue
Block a user