Draw Script property by default and add HideMonoScriptAttribute attribute

This commit is contained in:
VladV 2023-01-14 20:42:21 +04:00
parent f5f09ed76e
commit c368664252
4 changed files with 39 additions and 2 deletions

View File

@ -48,7 +48,7 @@ namespace TriInspector
RequestRepaint();
}
public void Draw(float? viewWidth = null)
public virtual void Draw(float? viewWidth = null)
{
RepaintRequired = false;

View File

@ -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();
}
}
}

View 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
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 306721f92da846b5aac744073764a4e2
timeCreated: 1673714382