From 207ffffb65ad5c7e9ca5ee951ef71a45ba3cf1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AF=7E?= Date: Thu, 15 Aug 2024 10:47:48 +0200 Subject: [PATCH] Code cleanup, no functional changes. --- .../V1/Editor/AacInternals.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacInternals.cs b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacInternals.cs index 6a898ac..45b7b12 100644 --- a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacInternals.cs +++ b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacInternals.cs @@ -19,7 +19,7 @@ namespace AnimatorAsCode.V1 internal static AnimatorController NewAnimatorController(AacConfiguration component, string suffix) { var animatorController = new AnimatorController(); - animatorController.name = AutoGeneratedPrefix + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict + animatorController.name = Internal_GenerateAnimationName(component, suffix); // FIXME animation name conflict animatorController.hideFlags = HideFlags.None; if (component.AsPersistentContainerRequired() != null) AssetDatabase.AddObjectToAsset(animatorController, component.AsPersistentContainerRequired()); return animatorController; @@ -32,7 +32,7 @@ namespace AnimatorAsCode.V1 internal static AnimationClip RegisterClip(AacConfiguration component, string suffix, AnimationClip clip) { - clip.name = AutoGeneratedPrefix + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict + clip.name = Internal_GenerateAnimationName(component, suffix); clip.hideFlags = HideFlags.None; if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.AsRegularContainer()); return clip; @@ -41,7 +41,7 @@ namespace AnimatorAsCode.V1 internal static BlendTree NewBlendTreeAsRaw(AacConfiguration component, string suffix) { var clip = new BlendTree(); - clip.name = AutoGeneratedPrefix + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict + clip.name = Internal_GenerateAnimationName(component, suffix); clip.hideFlags = HideFlags.None; if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.AsRegularContainer()); return clip; @@ -50,12 +50,17 @@ namespace AnimatorAsCode.V1 internal static T DuplicateAssetIntoContainer(AacConfiguration component, T assetToDuplicate) where T : Object { var duplicated = (T)Object.Instantiate(assetToDuplicate); - duplicated.name = AutoGeneratedPrefix + component.AssetKey + "__" + assetToDuplicate.name + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict + duplicated.name = Internal_GenerateAnimationName(component, assetToDuplicate.name); duplicated.hideFlags = HideFlags.None; if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(duplicated, component.AsRegularContainer()); return duplicated; } - + + private static string Internal_GenerateAnimationName(AacConfiguration component, string middle) + { + return AutoGeneratedPrefix + component.AssetKey + "__" + middle + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict + } + internal static AvatarMask NewAvatarMask(AacConfiguration component, string fullLayerName) { var avatarMask = new AvatarMask(); @@ -140,16 +145,18 @@ namespace AnimatorAsCode.V1 private static void UndoDisable(T state) { - typeof(T) - .GetProperty("pushUndo", BindingFlags.Instance | BindingFlags.NonPublic) - .SetValue(state, false); + GetPushUndoProperty().SetValue(state, false); } private static void UndoEnable(T state) { - typeof(T) - .GetProperty("pushUndo", BindingFlags.Instance | BindingFlags.NonPublic) - .SetValue(state, true); + GetPushUndoProperty().SetValue(state, true); + } + + private static PropertyInfo GetPushUndoProperty() + { + return typeof(T) + .GetProperty("pushUndo", BindingFlags.Instance | BindingFlags.NonPublic); } } } \ No newline at end of file