2022-10-03 09:04:27 +08:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
2022-10-17 05:05:26 +08:00
|
|
|
|
using static net.fushizen.modular_avatar.core.editor.Localization;
|
2022-10-03 09:04:27 +08:00
|
|
|
|
|
|
|
|
|
namespace net.fushizen.modular_avatar.core.editor
|
|
|
|
|
{
|
|
|
|
|
internal class TempObjRef : ScriptableObject
|
|
|
|
|
{
|
|
|
|
|
public Transform target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[CustomEditor(typeof(ModularAvatarBoneProxy))]
|
|
|
|
|
[CanEditMultipleObjects]
|
2022-11-11 12:30:10 +08:00
|
|
|
|
internal class BoneProxyEditor : MAEditorBase
|
2022-10-03 09:04:27 +08:00
|
|
|
|
{
|
|
|
|
|
private bool foldout = false;
|
|
|
|
|
|
|
|
|
|
private Object[] objRefs;
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
objRefs = new Object[targets.Length];
|
|
|
|
|
for (int i = 0; i < targets.Length; i++)
|
|
|
|
|
{
|
2022-10-21 11:53:46 +08:00
|
|
|
|
objRefs[i] = CreateInstance<TempObjRef>();
|
2022-10-03 09:04:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-11 12:30:10 +08:00
|
|
|
|
protected override void OnInnerInspectorGUI()
|
2022-10-03 09:04:27 +08:00
|
|
|
|
{
|
|
|
|
|
GameObject parentAvatar = null;
|
|
|
|
|
|
2022-10-21 11:53:46 +08:00
|
|
|
|
bool suppressTarget = false;
|
2022-10-03 09:04:27 +08:00
|
|
|
|
for (int i = 0; i < targets.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var t = (ModularAvatarBoneProxy) targets[i];
|
|
|
|
|
var av = RuntimeUtil.FindAvatarInParents(t.transform);
|
|
|
|
|
|
2022-10-16 05:36:54 +08:00
|
|
|
|
if (av != null && parentAvatar == null) parentAvatar = av.gameObject;
|
2022-10-03 09:04:27 +08:00
|
|
|
|
if (av == null || parentAvatar != av.gameObject)
|
|
|
|
|
{
|
2022-10-21 11:53:46 +08:00
|
|
|
|
suppressTarget = true;
|
|
|
|
|
break;
|
2022-10-03 09:04:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
((TempObjRef) objRefs[i]).target = t.target;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-21 11:53:46 +08:00
|
|
|
|
if (suppressTarget)
|
|
|
|
|
{
|
|
|
|
|
foldout = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var virtObj = new SerializedObject(objRefs);
|
|
|
|
|
var virtProp = virtObj.FindProperty(nameof(TempObjRef.target));
|
2022-10-03 09:04:27 +08:00
|
|
|
|
|
2022-10-23 04:04:25 +08:00
|
|
|
|
EditorGUI.BeginChangeCheck();
|
2022-10-03 09:04:27 +08:00
|
|
|
|
|
2022-10-23 04:04:25 +08:00
|
|
|
|
EditorGUILayout.PropertyField(virtProp, G("boneproxy.target"));
|
|
|
|
|
if (EditorGUI.EndChangeCheck())
|
2022-10-03 09:04:27 +08:00
|
|
|
|
{
|
2022-10-23 04:04:25 +08:00
|
|
|
|
virtObj.ApplyModifiedPropertiesWithoutUndo();
|
|
|
|
|
for (int i = 0; i < targets.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var t = (ModularAvatarBoneProxy) targets[i];
|
|
|
|
|
Undo.RecordObjects(targets, "Set targets");
|
|
|
|
|
t.target = ((TempObjRef) objRefs[i]).target;
|
|
|
|
|
}
|
2022-10-03 09:04:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 05:05:26 +08:00
|
|
|
|
foldout = EditorGUILayout.Foldout(foldout, G("boneproxy.foldout.advanced"));
|
2022-10-03 09:04:27 +08:00
|
|
|
|
if (foldout)
|
|
|
|
|
{
|
|
|
|
|
EditorGUI.indentLevel++;
|
|
|
|
|
base.OnInspectorGUI();
|
|
|
|
|
EditorGUI.indentLevel--;
|
|
|
|
|
}
|
2022-10-17 05:05:26 +08:00
|
|
|
|
|
|
|
|
|
Localization.ShowLanguageUI();
|
2022-10-03 09:04:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|