mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Draw Script property by default and add HideMonoScriptAttribute attribute
This commit is contained in:
parent
f5f09ed76e
commit
c368664252
@ -48,7 +48,7 @@ namespace TriInspector
|
||||
RequestRepaint();
|
||||
}
|
||||
|
||||
public void Draw(float? viewWidth = null)
|
||||
public virtual void Draw(float? viewWidth = null)
|
||||
{
|
||||
RepaintRequired = false;
|
||||
|
||||
|
@ -8,15 +8,17 @@ namespace TriInspector
|
||||
public sealed class TriPropertyTreeForSerializedObject : TriPropertyTree
|
||||
{
|
||||
private readonly SerializedObject _serializedObject;
|
||||
private readonly SerializedProperty _scriptProperty;
|
||||
|
||||
public TriPropertyTreeForSerializedObject([NotNull] SerializedObject serializedObject)
|
||||
{
|
||||
_serializedObject = serializedObject ?? throw new ArgumentNullException(nameof(serializedObject));
|
||||
_scriptProperty = serializedObject.FindProperty("m_Script");
|
||||
|
||||
TargetObjectType = _serializedObject.targetObject.GetType();
|
||||
TargetsCount = _serializedObject.targetObjects.Length;
|
||||
TargetIsPersistent = _serializedObject.targetObject is var targetObject &&
|
||||
targetObject != null && EditorUtility.IsPersistent(targetObject);
|
||||
targetObject != null && EditorUtility.IsPersistent(targetObject);
|
||||
|
||||
RootPropertyDefinition = new TriPropertyDefinition(
|
||||
memberInfo: null,
|
||||
@ -54,6 +56,13 @@ namespace TriInspector
|
||||
base.Update(forceUpdate);
|
||||
}
|
||||
|
||||
public override void Draw(float? viewWidth = null)
|
||||
{
|
||||
DrawMonoScriptProperty();
|
||||
|
||||
base.Draw(viewWidth);
|
||||
}
|
||||
|
||||
public override bool ApplyChanges()
|
||||
{
|
||||
var changed = base.ApplyChanges();
|
||||
@ -77,5 +86,19 @@ namespace TriInspector
|
||||
RequestValidation();
|
||||
RequestRepaint();
|
||||
}
|
||||
|
||||
private void DrawMonoScriptProperty()
|
||||
{
|
||||
if (RootProperty.TryGetAttribute(out HideMonoScriptAttribute _))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
var scriptRect = EditorGUILayout.GetControlRect(true);
|
||||
scriptRect.xMin += 3;
|
||||
EditorGUI.PropertyField(scriptRect, _scriptProperty);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
}
|
||||
}
|
11
Runtime/Attributes/HideMonoScriptAttribute.cs
Normal file
11
Runtime/Attributes/HideMonoScriptAttribute.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
[AttributeUsage((AttributeTargets.Class | AttributeTargets.Struct))]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public sealed class HideMonoScriptAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
3
Runtime/Attributes/HideMonoScriptAttribute.cs.meta
Normal file
3
Runtime/Attributes/HideMonoScriptAttribute.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 306721f92da846b5aac744073764a4e2
|
||||
timeCreated: 1673714382
|
Loading…
Reference in New Issue
Block a user