mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2024-12-29 02:35:06 +08:00
fix: non-backwards-compatible changes to component initial values (#1114)
* fix: init menu item settings only when added manually from inspector * fix: init menu item settings when added from some shortcuts * fix: init menu item settings when reset from context menu * fix: init merge animator settings only when added manually from inspector
This commit is contained in:
parent
3eaf8bee6d
commit
c0582a9961
@ -212,7 +212,10 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
var newChild = new GameObject();
|
var newChild = new GameObject();
|
||||||
newChild.name = "New item";
|
newChild.name = "New item";
|
||||||
newChild.transform.SetParent(nodesUnder.root.transform, false);
|
newChild.transform.SetParent(nodesUnder.root.transform, false);
|
||||||
newChild.AddComponent<ModularAvatarMenuItem>();
|
|
||||||
|
var mami = newChild.AddComponent<ModularAvatarMenuItem>();
|
||||||
|
mami.InitSettings();
|
||||||
|
|
||||||
Undo.RegisterCreatedObjectUndo(newChild, "Added menu item");
|
Undo.RegisterCreatedObjectUndo(newChild, "Added menu item");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,13 +226,12 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
newChild.transform.SetParent(nodesUnder.root.transform, false);
|
newChild.transform.SetParent(nodesUnder.root.transform, false);
|
||||||
|
|
||||||
var mami = newChild.AddComponent<ModularAvatarMenuItem>();
|
var mami = newChild.AddComponent<ModularAvatarMenuItem>();
|
||||||
|
mami.InitSettings();
|
||||||
mami.Control = new VRCExpressionsMenu.Control()
|
mami.Control = new VRCExpressionsMenu.Control()
|
||||||
{
|
{
|
||||||
type = VRCExpressionsMenu.Control.ControlType.Toggle,
|
type = VRCExpressionsMenu.Control.ControlType.Toggle,
|
||||||
value = 1,
|
value = 1,
|
||||||
};
|
};
|
||||||
mami.isSaved = true;
|
|
||||||
mami.isSynced = true;
|
|
||||||
|
|
||||||
newChild.AddComponent<ModularAvatarObjectToggle>();
|
newChild.AddComponent<ModularAvatarObjectToggle>();
|
||||||
|
|
||||||
|
@ -40,7 +40,10 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
var objToggle = toggle.AddComponent<ModularAvatarObjectToggle>();
|
var objToggle = toggle.AddComponent<ModularAvatarObjectToggle>();
|
||||||
|
|
||||||
toggle.transform.SetParent(parent, false);
|
toggle.transform.SetParent(parent, false);
|
||||||
toggle.AddComponent<ModularAvatarMenuItem>().Control = new VRCExpressionsMenu.Control
|
|
||||||
|
var mami = toggle.AddComponent<ModularAvatarMenuItem>();
|
||||||
|
mami.InitSettings();
|
||||||
|
mami.Control = new VRCExpressionsMenu.Control
|
||||||
{
|
{
|
||||||
type = VRCExpressionsMenu.Control.ControlType.Toggle,
|
type = VRCExpressionsMenu.Control.ControlType.Toggle,
|
||||||
name = "New Toggle",
|
name = "New Toggle",
|
||||||
|
@ -50,6 +50,16 @@ namespace nadena.dev.modular_avatar.core
|
|||||||
public bool automaticValue;
|
public bool automaticValue;
|
||||||
|
|
||||||
private void Reset()
|
private void Reset()
|
||||||
|
{
|
||||||
|
// Init settings only when added or reset manually from the Inspector.
|
||||||
|
// Otherwise, some plugins that add this component may break in non-playmode builds.
|
||||||
|
if (RuntimeUtil.IsResetFromInspector())
|
||||||
|
{
|
||||||
|
InitSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InitSettings()
|
||||||
{
|
{
|
||||||
Control = new VRCExpressionsMenu.Control();
|
Control = new VRCExpressionsMenu.Control();
|
||||||
Control.type = VRCExpressionsMenu.Control.ControlType.Toggle;
|
Control.type = VRCExpressionsMenu.Control.ControlType.Toggle;
|
||||||
|
@ -54,6 +54,16 @@ namespace nadena.dev.modular_avatar.core
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Reset()
|
private void Reset()
|
||||||
|
{
|
||||||
|
// Init settings only when added or reset manually from the Inspector.
|
||||||
|
// Otherwise, some plugins that add this component may break in non-playmode builds.
|
||||||
|
if (RuntimeUtil.IsResetFromInspector())
|
||||||
|
{
|
||||||
|
InitSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InitSettings()
|
||||||
{
|
{
|
||||||
deleteAttachedAnimator = true;
|
deleteAttachedAnimator = true;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -161,5 +161,32 @@ namespace nadena.dev.modular_avatar.core
|
|||||||
{
|
{
|
||||||
OnHierarchyChanged?.Invoke();
|
OnHierarchyChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
private static readonly Type addComponentWindowType = Type.GetType("UnityEditor.AddComponent.AddComponentWindow, UnityEditor");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public static bool IsResetFromInspector(int skipStackFrames = 1)
|
||||||
|
{
|
||||||
|
#if !UNITY_EDITOR
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
var frames = new System.Diagnostics.StackTrace(skipStackFrames).GetFrames();
|
||||||
|
|
||||||
|
// Reset from component context menu
|
||||||
|
if (frames.Length == 1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Added from Add Component button
|
||||||
|
if (frames.Any(x => x.GetMethod().DeclaringType == addComponentWindowType))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user