mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 08:18:49 -05:00
Add OnValueChanged attribute
This commit is contained in:
parent
fb8041857a
commit
de2582134f
@ -277,6 +277,17 @@ namespace TriInspector
|
||||
|
||||
void ITriPropertyParent.NotifyValueChanged(TriProperty property)
|
||||
{
|
||||
if (_definition.OnValueChanged != null)
|
||||
{
|
||||
_serializedProperty?.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
for (var targetIndex = 0; targetIndex < PropertyTree.TargetObjects.Length; targetIndex++)
|
||||
{
|
||||
_definition.OnValueChanged.InvokeForTarget(this, targetIndex);
|
||||
EditorUtility.SetDirty(PropertyTree.TargetObjects[targetIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
_parent.NotifyValueChanged(property);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using JetBrains.Annotations;
|
||||
using TriInspector.Resolvers;
|
||||
using TriInspector.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
@ -62,6 +63,11 @@ namespace TriInspector
|
||||
IsArray = true;
|
||||
ArrayElementType = elementType;
|
||||
}
|
||||
|
||||
if (Attributes.TryGet(out OnValueChangedAttribute onValueChangedAttribute))
|
||||
{
|
||||
OnValueChanged = ActionResolver.Resolve(this, onValueChangedAttribute.Method);
|
||||
}
|
||||
}
|
||||
|
||||
public MemberInfo MemberInfo { get; }
|
||||
@ -81,6 +87,8 @@ namespace TriInspector
|
||||
|
||||
public bool IsArray { get; }
|
||||
|
||||
[CanBeNull] public ActionResolver OnValueChanged { get; }
|
||||
|
||||
public IReadOnlyList<TriPropertyHideProcessor> HideProcessors
|
||||
{
|
||||
get
|
||||
|
@ -19,6 +19,7 @@ public class BasicSample : MonoBehaviour
|
||||
public float unityField;
|
||||
|
||||
[Required]
|
||||
[OnValueChanged(nameof(OnMaterialChanged))]
|
||||
public Material mat;
|
||||
|
||||
[ValidateInput(nameof(ValidateTexture))]
|
||||
@ -61,6 +62,11 @@ public class BasicSample : MonoBehaviour
|
||||
public float rotation;
|
||||
}
|
||||
|
||||
private void OnMaterialChanged()
|
||||
{
|
||||
Debug.Log("Material changed!");
|
||||
}
|
||||
|
||||
private TriValidationResult ValidateTexture()
|
||||
{
|
||||
if (tex == null) return TriValidationResult.Error("Tex is null");
|
||||
|
17
Runtime/Attributes/OnValueChangedAttribute.cs
Normal file
17
Runtime/Attributes/OnValueChangedAttribute.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public sealed class OnValueChangedAttribute : Attribute
|
||||
{
|
||||
public OnValueChangedAttribute(string method)
|
||||
{
|
||||
Method = method;
|
||||
}
|
||||
|
||||
public string Method { get; }
|
||||
}
|
||||
}
|
3
Runtime/Attributes/OnValueChangedAttribute.cs.meta
Normal file
3
Runtime/Attributes/OnValueChangedAttribute.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae1fa081898a4d13b8612da57bc9a349
|
||||
timeCreated: 1652265504
|
Loading…
Reference in New Issue
Block a user