mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-24 21:38:59 +08:00
parent
0e16721898
commit
f2856b2e09
@ -14,12 +14,12 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
var xButtonRect = new Rect(position.xMax - xButtonSize.x, position.y, xButtonSize.x, position.height);
|
var xButtonRect = new Rect(position.xMax - xButtonSize.x, position.y, xButtonSize.x, position.height);
|
||||||
position = new Rect(position.x, position.y, position.width - xButtonSize.x, position.height);
|
position = new Rect(position.x, position.y, position.width - xButtonSize.x, position.height);
|
||||||
|
|
||||||
var isNull = property.FindPropertyRelative(nameof(AvatarObjectReference.isNull));
|
|
||||||
property = property.FindPropertyRelative(nameof(AvatarObjectReference.referencePath));
|
property = property.FindPropertyRelative(nameof(AvatarObjectReference.referencePath));
|
||||||
|
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
position = EditorGUI.PrefixLabel(position, label);
|
||||||
|
|
||||||
EditorGUI.LabelField(position, isNull.boolValue ? "(null)" : property.stringValue);
|
EditorGUI.LabelField(position,
|
||||||
|
string.IsNullOrEmpty(property.stringValue) ? "(null)" : property.stringValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +28,6 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
var indentLevel = EditorGUI.indentLevel;
|
var indentLevel = EditorGUI.indentLevel;
|
||||||
var color = GUI.contentColor;
|
var color = GUI.contentColor;
|
||||||
|
|
||||||
var isNull = property.FindPropertyRelative(nameof(AvatarObjectReference.isNull));
|
|
||||||
property = property.FindPropertyRelative(nameof(AvatarObjectReference.referencePath));
|
property = property.FindPropertyRelative(nameof(AvatarObjectReference.referencePath));
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -44,7 +43,12 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
var avatar = RuntimeUtil.FindAvatarInParents(transform);
|
var avatar = RuntimeUtil.FindAvatarInParents(transform);
|
||||||
if (avatar == null) return false;
|
if (avatar == null) return false;
|
||||||
|
|
||||||
var target = isNull.boolValue ? null : avatar.transform.Find(property.stringValue);
|
bool isRoot = property.stringValue == AvatarObjectReference.AVATAR_ROOT;
|
||||||
|
bool isNull = string.IsNullOrEmpty(property.stringValue);
|
||||||
|
Transform target;
|
||||||
|
if (isNull) target = null;
|
||||||
|
else if (isRoot) target = avatar.transform;
|
||||||
|
else target = avatar.transform.Find(property.stringValue);
|
||||||
|
|
||||||
var labelRect = position;
|
var labelRect = position;
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
position = EditorGUI.PrefixLabel(position, label);
|
||||||
@ -52,7 +56,7 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
|
|
||||||
var nullContent = GUIContent.none;
|
var nullContent = GUIContent.none;
|
||||||
|
|
||||||
if (target != null || isNull.boolValue)
|
if (target != null || isNull)
|
||||||
{
|
{
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
var newTarget = EditorGUI.ObjectField(position, nullContent, target, typeof(Transform), true);
|
var newTarget = EditorGUI.ObjectField(position, nullContent, target, typeof(Transform), true);
|
||||||
@ -61,7 +65,10 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
if (newTarget == null)
|
if (newTarget == null)
|
||||||
{
|
{
|
||||||
property.stringValue = "";
|
property.stringValue = "";
|
||||||
isNull.boolValue = true;
|
}
|
||||||
|
else if (newTarget == avatar.transform)
|
||||||
|
{
|
||||||
|
property.stringValue = AvatarObjectReference.AVATAR_ROOT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -70,7 +77,6 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
if (relPath == null) return true;
|
if (relPath == null) return true;
|
||||||
|
|
||||||
property.stringValue = relPath;
|
property.stringValue = relPath;
|
||||||
isNull.boolValue = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +96,10 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
if (newTarget == null)
|
if (newTarget == null)
|
||||||
{
|
{
|
||||||
property.stringValue = "";
|
property.stringValue = "";
|
||||||
isNull.boolValue = true;
|
}
|
||||||
|
else if (newTarget == avatar.transform)
|
||||||
|
{
|
||||||
|
property.stringValue = AvatarObjectReference.AVATAR_ROOT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -99,7 +108,6 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
if (relPath == null) return true;
|
if (relPath == null) return true;
|
||||||
|
|
||||||
property.stringValue = relPath;
|
property.stringValue = relPath;
|
||||||
isNull.boolValue = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -6,7 +6,7 @@ namespace net.fushizen.modular_avatar.core
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public struct AvatarObjectReference
|
public struct AvatarObjectReference
|
||||||
{
|
{
|
||||||
public bool isNull;
|
public static string AVATAR_ROOT = "$$$AVATAR_ROOT$$$";
|
||||||
public string referencePath;
|
public string referencePath;
|
||||||
|
|
||||||
private bool _cacheValid;
|
private bool _cacheValid;
|
||||||
@ -15,12 +15,12 @@ namespace net.fushizen.modular_avatar.core
|
|||||||
|
|
||||||
public GameObject Get(Component container)
|
public GameObject Get(Component container)
|
||||||
{
|
{
|
||||||
if (_cacheValid && _cachedPath == referencePath && !isNull) return _cachedReference;
|
if (_cacheValid && _cachedPath == referencePath) return _cachedReference;
|
||||||
|
|
||||||
_cacheValid = true;
|
_cacheValid = true;
|
||||||
_cachedPath = referencePath;
|
_cachedPath = referencePath;
|
||||||
|
|
||||||
if (isNull)
|
if (referencePath == "")
|
||||||
{
|
{
|
||||||
_cachedReference = null;
|
_cachedReference = null;
|
||||||
return _cachedReference;
|
return _cachedReference;
|
||||||
@ -32,6 +32,12 @@ namespace net.fushizen.modular_avatar.core
|
|||||||
var avatar = RuntimeUtil.FindAvatarInParents(container.transform);
|
var avatar = RuntimeUtil.FindAvatarInParents(container.transform);
|
||||||
if (avatar == null) return (_cachedReference = null);
|
if (avatar == null) return (_cachedReference = null);
|
||||||
|
|
||||||
|
if (referencePath == AVATAR_ROOT)
|
||||||
|
{
|
||||||
|
_cachedReference = avatar.gameObject;
|
||||||
|
return _cachedReference;
|
||||||
|
}
|
||||||
|
|
||||||
return (_cachedReference = avatar.transform.Find(referencePath)?.gameObject);
|
return (_cachedReference = avatar.transform.Find(referencePath)?.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user