Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Other playable layers than FX can accidentally be changed #7

Open
Ess-Ka opened this issue May 31, 2021 · 1 comment
Open

Other playable layers than FX can accidentally be changed #7

Ess-Ka opened this issue May 31, 2021 · 1 comment

Comments

@Ess-Ka
Copy link

Ess-Ka commented May 31, 2021

Ich suggest, to add an additinal validation for this:

        public bool ValidateAnimatorController()
        {
            AnimatorController controller = GetAnimatorController();

            if (controller == null)
                return false;

            _avaCryptController.ValidateAnimations(gameObject, controller);
            _avaCryptController.ValidateParameters(controller);
            _avaCryptController.ValidateLayers(controller);

            return true;
        }

        private AnimatorController GetAnimatorController()
        {
            if (transform.parent != null)
            {
                EditorUtility.DisplayDialog("AvaCryptRoot component not on a Root GameObject.",
                    "The GameObject which the AvaCryptRoot component is placed on must not be the child of any other GameObject.",
                    "Ok");
                return null;
            }

            Animator animator = GetComponent<Animator>();
            if (animator == null)
            {
                EditorUtility.DisplayDialog("No Animator.",
                    "Add an animator to the Avatar's root GameObject.",
                    "Ok");
                return null;
            }

            RuntimeAnimatorController runtimeController = animator.runtimeAnimatorController;
            if (runtimeController == null)
            {
                EditorUtility.DisplayDialog("Animator has no AnimatorController.",
                    "Add an AnimatorController to the Animator component.",
                    "Ok");
                return null;
            }

            AnimatorController controller = UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEditor.Animations.AnimatorController>(UnityEditor.AssetDatabase.GetAssetPath(runtimeController));
            if (controller == null)
            {
                EditorUtility.DisplayDialog("Could not get AnimatorController.",
                    "This shouldn't happen... don't know why this would happen.",
                    "Ok");
                return null;
            }

            VRCAvatarDescriptor descriptor = GetComponent<VRCAvatarDescriptor>();
            if (descriptor == null) 
            {
                EditorUtility.DisplayDialog("Could not get AvatarDescriptor.",
                    "Add an AvatarDescriptor to the Avatar's root GameObject.",
                    "Ok");
                return null;
            }
            else if (descriptor.baseAnimationLayers[4].animatorController == null) 
            {
                EditorUtility.DisplayDialog("Could not get AvatarDescriptor.",
                    "Add an custom FX layer to your AvatarDescriptor.",
                    "Ok");
                return null;
            }
            else if (descriptor.baseAnimationLayers[4].animatorController != runtimeController) {
                EditorUtility.DisplayDialog("Current AnimatorController doesn't match.",
                    "Set the AnimatorController of the FX layer in your Animator component.",
                    "Ok");
                return null;
            }

            return controller;
        }

        public void EncryptAvatar()
        {
            if (!ValidateAnimatorController())
                return;

            ...
@Ess-Ka Ess-Ka changed the title Other playable layers then FX can accidentally be changed Other playable layers than FX can accidentally be changed May 31, 2021
@swiveI
Copy link
Contributor

swiveI commented Jun 21, 2022

maybe get the controller directly from the fx layer in the avatar descriptor. something like:

VRCAvatarDescriptor Avatar;
Avatar = GetComponent<VRCAvatarDescriptor>();

RuntimeAnimatorController FXAnimator;
FXAnimator = (RuntimeAnimatorController)Avatar.baseAnimationLayers[4].animatorController;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants