mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Prepare for Odin integration
This commit is contained in:
parent
36a78379c4
commit
7d48204c2d
@ -65,8 +65,7 @@ namespace TriInspector.Drawers
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var allowSceneObjects = _property.PropertyTree.TargetObjects[0] is var targetObject &&
|
||||
targetObject != null && !EditorUtility.IsPersistent(targetObject);
|
||||
var allowSceneObjects = _property.PropertyTree.TargetIsPersistent;
|
||||
|
||||
var value = (Object) _property.Value;
|
||||
value = EditorGUI.ObjectField(pickerRect, GUIContent.none, value,
|
||||
|
@ -40,8 +40,7 @@ namespace TriInspector.Drawers
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var allowSceneObjects = _propertyValue.Property.PropertyTree.TargetObjects[0] is var targetObject &&
|
||||
targetObject != null && !EditorUtility.IsPersistent(targetObject);
|
||||
var allowSceneObjects = _propertyValue.Property.PropertyTree.TargetIsPersistent;
|
||||
|
||||
value = (T) EditorGUI.ObjectField(position, _propertyValue.Property.DisplayNameContent, value,
|
||||
_propertyValue.Property.FieldType, allowSceneObjects);
|
||||
|
@ -1,12 +1,15 @@
|
||||
namespace TriInspector.Elements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TriInspector.Elements
|
||||
{
|
||||
internal class TriInspectorElement : TriPropertyCollectionBaseElement
|
||||
{
|
||||
public TriInspectorElement(TriPropertyTree propertyTree)
|
||||
public TriInspectorElement(Type targetObjectType, IReadOnlyList<TriProperty> properties)
|
||||
{
|
||||
DeclareGroups(propertyTree.TargetObjectType);
|
||||
DeclareGroups(targetObjectType);
|
||||
|
||||
foreach (var childProperty in propertyTree.Properties)
|
||||
foreach (var childProperty in properties)
|
||||
{
|
||||
AddProperty(childProperty);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace TriInspector.Resolvers
|
||||
[PublicAPI]
|
||||
public void InvokeForAllTargets(TriProperty property)
|
||||
{
|
||||
for (var targetIndex = 0; targetIndex < property.PropertyTree.TargetObjects.Length; targetIndex++)
|
||||
for (var targetIndex = 0; targetIndex < property.PropertyTree.TargetsCount; targetIndex++)
|
||||
{
|
||||
InvokeForTarget(property, targetIndex);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace TriInspector
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_inspector?.Destroy();
|
||||
_inspector?.Dispose();
|
||||
_inspector = null;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ namespace TriInspector
|
||||
private string _isExpandedPrefsKey;
|
||||
|
||||
internal TriProperty(
|
||||
TriPropertyTree propertyTree,
|
||||
ITriPropertyTree propertyTree,
|
||||
ITriPropertyParent parent,
|
||||
TriPropertyDefinition definition,
|
||||
int propertyIndex,
|
||||
@ -219,7 +219,7 @@ namespace TriInspector
|
||||
: throw new InvalidOperationException("Cannot read ArrayElementProperties for " + PropertyType);
|
||||
|
||||
[PublicAPI]
|
||||
public TriPropertyTree PropertyTree { get; }
|
||||
public ITriPropertyTree PropertyTree { get; }
|
||||
|
||||
[PublicAPI]
|
||||
[CanBeNull]
|
||||
@ -249,22 +249,19 @@ namespace TriInspector
|
||||
public void ModifyAndRecordForUndo(Action<int> call)
|
||||
{
|
||||
// save any pending changes
|
||||
PropertyTree.ApplySerializedObjectModifiedProperties();
|
||||
PropertyTree.PrepareForValueModification();
|
||||
|
||||
// record object state for undp
|
||||
Undo.RegisterCompleteObjectUndo(PropertyTree.TargetObjects, "Inspector");
|
||||
Undo.FlushUndoRecordObjects();
|
||||
|
||||
// set value for all targets
|
||||
for (var targetIndex = 0; targetIndex < PropertyTree.TargetObjects.Length; targetIndex++)
|
||||
for (var targetIndex = 0; targetIndex < PropertyTree.TargetsCount; targetIndex++)
|
||||
{
|
||||
call.Invoke(targetIndex);
|
||||
|
||||
EditorUtility.SetDirty(PropertyTree.TargetObjects[targetIndex]);
|
||||
}
|
||||
|
||||
// actualize
|
||||
PropertyTree.ForceUpdateSerializedObject();
|
||||
PropertyTree.UpdateAfterValueModification();
|
||||
Update();
|
||||
|
||||
NotifyValueChanged();
|
||||
@ -281,10 +278,9 @@ namespace TriInspector
|
||||
{
|
||||
_serializedProperty?.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
for (var targetIndex = 0; targetIndex < PropertyTree.TargetObjects.Length; targetIndex++)
|
||||
for (var targetIndex = 0; targetIndex < PropertyTree.TargetsCount; targetIndex++)
|
||||
{
|
||||
_definition.OnValueChanged.InvokeForTarget(this, targetIndex);
|
||||
EditorUtility.SetDirty(PropertyTree.TargetObjects[targetIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -461,7 +457,7 @@ namespace TriInspector
|
||||
{
|
||||
newValue = property.GetValue(0);
|
||||
|
||||
if (property.PropertyTree.TargetObjects.Length == 1)
|
||||
if (property.PropertyTree.TargetsCount == 1)
|
||||
{
|
||||
isMixed = false;
|
||||
return;
|
||||
@ -472,7 +468,7 @@ namespace TriInspector
|
||||
case TriPropertyType.Array:
|
||||
{
|
||||
var list = (IList) newValue;
|
||||
for (var i = 1; i < property.PropertyTree.TargetObjects.Length; i++)
|
||||
for (var i = 1; i < property.PropertyTree.TargetsCount; i++)
|
||||
{
|
||||
if (list == null)
|
||||
{
|
||||
@ -491,7 +487,7 @@ namespace TriInspector
|
||||
}
|
||||
case TriPropertyType.Reference:
|
||||
{
|
||||
for (var i = 1; i < property.PropertyTree.TargetObjects.Length; i++)
|
||||
for (var i = 1; i < property.PropertyTree.TargetsCount; i++)
|
||||
{
|
||||
var otherValue = property.GetValue(i);
|
||||
|
||||
@ -513,7 +509,7 @@ namespace TriInspector
|
||||
}
|
||||
case TriPropertyType.Primitive:
|
||||
{
|
||||
for (var i = 1; i < property.PropertyTree.TargetObjects.Length; i++)
|
||||
for (var i = 1; i < property.PropertyTree.TargetsCount; i++)
|
||||
{
|
||||
var otherValue = property.GetValue(i);
|
||||
if (!AreValuesEqual(property.FieldType, otherValue, newValue))
|
||||
|
@ -9,7 +9,7 @@ using Object = UnityEngine.Object;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
public sealed class TriPropertyTree : ITriPropertyParent
|
||||
public sealed class TriPropertyTree : ITriPropertyParent, ITriPropertyTree
|
||||
{
|
||||
private readonly TriEditorMode _mode;
|
||||
private readonly TriInspectorElement _inspectorElement;
|
||||
@ -19,7 +19,6 @@ namespace TriInspector
|
||||
SerializedObject = serializedObject ?? throw new ArgumentNullException(nameof(serializedObject));
|
||||
TargetObjects = serializedObject.targetObjects;
|
||||
TargetObjectType = TargetObjects[0].GetType();
|
||||
Root = this;
|
||||
|
||||
Properties = TriTypeDefinition.GetCached(TargetObjectType)
|
||||
.Properties
|
||||
@ -31,7 +30,7 @@ namespace TriInspector
|
||||
.ToList();
|
||||
|
||||
_mode = mode;
|
||||
_inspectorElement = new TriInspectorElement(this);
|
||||
_inspectorElement = new TriInspectorElement(TargetObjectType, Properties);
|
||||
_inspectorElement.AttachInternal();
|
||||
|
||||
Update();
|
||||
@ -47,12 +46,16 @@ namespace TriInspector
|
||||
[PublicAPI]
|
||||
public Type TargetObjectType { get; }
|
||||
|
||||
[PublicAPI]
|
||||
public int TargetsCount => TargetObjects.Length;
|
||||
|
||||
private SerializedObject SerializedObject { get; }
|
||||
|
||||
public TriPropertyTree Root { get; }
|
||||
|
||||
public bool IsInlineEditor => (_mode & TriEditorMode.InlineEditor) != 0;
|
||||
|
||||
public bool TargetIsPersistent => TargetObjects[0] is var targetObject &&
|
||||
targetObject != null && !EditorUtility.IsPersistent(targetObject);
|
||||
|
||||
internal bool RepaintRequired { get; set; }
|
||||
internal bool ValidationRequired { get; set; }
|
||||
|
||||
@ -64,7 +67,7 @@ namespace TriInspector
|
||||
return new TriPropertyTree(scriptableObject, mode);
|
||||
}
|
||||
|
||||
internal void Destroy()
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_inspectorElement.IsAttached)
|
||||
{
|
||||
@ -101,23 +104,31 @@ namespace TriInspector
|
||||
_inspectorElement.OnGUI(rect);
|
||||
}
|
||||
|
||||
public void ForceUpdateSerializedObject()
|
||||
public void UpdateAfterValueModification()
|
||||
{
|
||||
SerializedObject.SetIsDifferentCacheDirty();
|
||||
SerializedObject.Update();
|
||||
}
|
||||
|
||||
public void ApplySerializedObjectModifiedProperties()
|
||||
public void PrepareForValueModification()
|
||||
{
|
||||
if (SerializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
RequestValidation();
|
||||
RequestRepaint();
|
||||
}
|
||||
|
||||
Undo.RegisterCompleteObjectUndo(TargetObjects, "Inspector");
|
||||
Undo.FlushUndoRecordObjects();
|
||||
}
|
||||
|
||||
public void NotifyValueChanged(TriProperty property)
|
||||
{
|
||||
foreach (var targetObject in TargetObjects)
|
||||
{
|
||||
EditorUtility.SetDirty(targetObject);
|
||||
}
|
||||
|
||||
RequestValidation();
|
||||
}
|
||||
|
||||
@ -132,6 +143,17 @@ namespace TriInspector
|
||||
}
|
||||
}
|
||||
|
||||
public interface ITriPropertyTree : IDisposable
|
||||
{
|
||||
Type TargetObjectType { get; }
|
||||
int TargetsCount { get; }
|
||||
bool TargetIsPersistent { get; }
|
||||
|
||||
void PrepareForValueModification();
|
||||
void UpdateAfterValueModification();
|
||||
void RequestRepaint();
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum TriEditorMode
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user