예제 #1
0
    public static void generateBeatAnimation(TextAsset text, float zoom, float blur, Color beatcolor, Color betweencolor, AudioClip audio)
    {
        GameObject source = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/KorikasAvatarPlugin/Korikas Avatar Plugin/Examples/Prefabs/BeatFinderPrefab.prefab", typeof(GameObject));
        string     name   = source.name;

        source      = (GameObject)Instantiate(source, new Vector3(0, 0, 0), Quaternion.identity);
        source.name = name;

        float[]       fl = textToFloatArray(text);
        AnimationClip ac = new AnimationClip();

        ac.legacy = true;
        AddKeyFrames(typeof(MeshRenderer), fl, ac, "material._blurfactor", "zoom", 0f, blur, 0.5f);
        AddKeyFrames(typeof(MeshRenderer), fl, ac, "material._mag", "zoom", 1f, zoom, 0.5f);
        AddKeyFrames(typeof(GameObject), fl, ac, "m_IsActive", "trigger", 0f, 0.01f, 0.5f);
        AddKeyFrames(typeof(MeshRenderer), fl, ac, "material._greenvalue", "zoom", betweencolor.g, beatcolor.g, 0.5f);
        AddKeyFrames(typeof(MeshRenderer), fl, ac, "material._bluevalue", "zoom", betweencolor.b, beatcolor.b, 0.5f);
        AddKeyFrames(typeof(MeshRenderer), fl, ac, "material._redvalue", "zoom", betweencolor.r, beatcolor.r, 0.5f);
        AddKeyFrames(typeof(ParticleSystem), fl, ac, "simulationSpeed", "example", 0.5f, 1f, 0.5f);

        ac.legacy = false;
        AvatarStructureBuilder.createFolder("Assets", "KAPBeatFinderAnimations");
        AssetDatabase.CreateAsset(ac, "Assets/KAPBeatFinderAnimations/" + audio.name + ".anim");

        source.GetComponent <AudioSource>().clip = audio;
        Animator a = source.GetComponent <Animator>();

        UnityEditor.Animations.AnimatorController acnew = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/KAPBeatFinderAnimations/" + audio.name + ".controller");
        a.runtimeAnimatorController = acnew;
        AnimatorController anc = a.runtimeAnimatorController as AnimatorController;

        GestureDisplay.addMotionToControllerByPath("Assets/KAPBeatFinderAnimations/" + audio.name + ".anim", anc);
    }
예제 #2
0
        static AnimationClip GenerateTriggerableTransition(string name, UnityEditor.Animations.AnimatorController controller)
        {
            var clip = UnityEditor.Animations.AnimatorController.AllocateAnimatorClip(name);

            AssetDatabase.AddObjectToAsset(clip, controller);


            var state = controller.AddMotion(clip);

            controller.AddParameter(name, AnimatorControllerParameterType.Trigger);

            var stateMachine = controller.layers[0].stateMachine;
            var transition   = stateMachine.AddAnyStateTransition(state);

            transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, name);

            //         var state = UnityEditor.Animations.AnimatorController.AddAnimationClipToController(controller, clip);

            //controller.AddParameter(name, AnimatorControllerParameterType.Trigger);

            //var stateMachine = controller.GetLayer(0).stateMachine;
            //var transition = stateMachine.AddAnyStateTransition(state);
            //var condition = transition.GetCondition(0);
            //condition.mode = TransitionConditionMode.If;
            //condition.parameter = name;
//#endif

            return(clip);
        }
예제 #3
0
        public static bool AddClipToAnimatorComponent(Animator animator, AnimationClip newClip)
        {
            UnityEditor.Animations.AnimatorController animatorController = UnityEditor.Animations.AnimatorController.GetEffectiveAnimatorController(animator);
            if (animatorController == null)
            {
                animatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerForClip(newClip, animator.gameObject);
                UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, animatorController);
                return(animatorController != null);
            }
            ChildAnimatorState childAnimatorState = animatorController.layers[0].stateMachine.FindState(newClip.name);

            if (childAnimatorState.Equals(default(ChildAnimatorState)))
            {
                animatorController.AddMotion(newClip);
            }
            else if (childAnimatorState.state && childAnimatorState.state.motion == null)
            {
                childAnimatorState.state.motion = newClip;
            }
            else if (childAnimatorState.state && childAnimatorState.state.motion != newClip)
            {
                animatorController.AddMotion(newClip);
            }
            return(true);
        }
예제 #4
0
    static void BuildPrefab(DirectoryInfo dictorys, UnityEditor.Animations.AnimatorController animatorCountorller, bool isDirectory)
    {
        //生成Prefab 添加一张预览用的Sprite
        FileInfo images;

        if (isDirectory)
        {
            images = dictorys.GetDirectories()[0].GetFiles("*.png")[0];
        }
        else
        {
            images = dictorys.GetFiles("*.png")[0];
        }

        GameObject go = new GameObject();

        go.name = dictorys.Name;
        SpriteRenderer spriteRender = go.AddComponent <SpriteRenderer>();

        spriteRender.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(DataPathToAssetPath(images.FullName));
        Animator animator = go.AddComponent <Animator>();

        animator.runtimeAnimatorController = animatorCountorller;
        go.AddComponent <GameFish.GONet> ();


        PrefabUtility.CreatePrefab(PrefabPath + "/" + go.name + ".prefab", go);
        DestroyImmediate(go);
    }
예제 #5
0
        public void ValidateLayers(AnimatorController controller)
        {
            for (int i = 0; i < _avaCryptKeyNames.Length; ++i)
            {
                if (controller.layers.All(l => l.name != _avaCryptKeyNames[i]))
                {
                    CreateLayer(i, controller);
                }
                else
                {
                    Debug.Log($"Layer already existing: {_avaCryptKeyNames[i]}");
                    AnimatorControllerLayer layer = controller.layers.FirstOrDefault(l => l.name == _avaCryptKeyNames[i]);

                    if (layer == null || layer.stateMachine == null)
                    {
                        Debug.Log("Layer missing state machine.");

                        controller.RemoveLayer(controller.layers.ToList().IndexOf(layer));

                        CreateLayer(i, controller);
                    }
                    else
                    {
                        ValidateBitKeySwitch(i, layer, controller);
                    }
                }
            }
        }
        /// <summary>
        /// Generates an animator contoller.
        /// </summary>
        /// <returns>The animator contoller.</returns>
        /// <param name="animationTriggers">Animation triggers.</param>
        /// <param name="preferredName">The preferred animator name.</param>
        /// <param name="initialState">If animator should have initial state.</param>
        public static UnityEditor.Animations.AnimatorController GenerateAnimatorContoller(List <string> animationTriggers, string preferredName, bool initialState)
        {
            if (string.IsNullOrEmpty(preferredName))
            {
                preferredName = "New Animator Controller";
            }

            string saveControllerPath = UIAnimatorControllerGenerator.GetSaveControllerPath(preferredName);

            if (string.IsNullOrEmpty(saveControllerPath))
            {
                return(null);
            }

            UnityEditor.Animations.AnimatorController animatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(saveControllerPath);

            if (initialState)
            {
                UIAnimatorControllerGenerator.GenerateInitialState(animatorController);
            }

            foreach (string trigger in animationTriggers)
            {
                UIAnimatorControllerGenerator.GenerateTriggerableTransition(trigger, animatorController);
            }

            return(animatorController);
        }
 public virtual void OnEnable()
 {
     this.m_TransitionList = new ReorderableList(base.targets, typeof(AnimatorTransitionBase), false, true, false, true);
     this.m_TransitionList.onSelectCallback    = new ReorderableList.SelectCallbackDelegate(this.OnSelectTransition);
     this.m_TransitionList.onRemoveCallback    = new ReorderableList.RemoveCallbackDelegate(this.OnRemoveTransition);
     this.m_TransitionList.drawElementCallback = new ReorderableList.ElementCallbackDelegate(this.DrawTransitionElement);
     this.m_TransitionList.drawHeaderCallback  = new ReorderableList.HeaderCallbackDelegate(AnimatorTransitionInspectorBase.DrawTransitionHeaderCommon);
     this.m_TransitionList.index = 0;
     this.m_PreviewObject        = ((!AnimatorControllerTool.tool) ? null : AnimatorControllerTool.tool.previewAnimator);
     this.m_Controller           = ((!AnimatorControllerTool.tool) ? null : AnimatorControllerTool.tool.animatorController);
     if (this.m_Controller)
     {
         this.m_LayerIndex = AnimatorControllerTool.tool.selectedLayerIndex;
         UnityEditor.Animations.AnimatorController expr_F7 = this.m_Controller;
         expr_F7.OnAnimatorControllerDirty = (Action)Delegate.Combine(expr_F7.OnAnimatorControllerDirty, new Action(this.ControllerDirty));
     }
     if (AnimatorTransitionInspectorBase.m_intModes == null)
     {
         AnimatorTransitionInspectorBase.m_intModes = new List <AnimatorConditionMode>();
         AnimatorTransitionInspectorBase.m_intModes.Add(AnimatorConditionMode.Greater);
         AnimatorTransitionInspectorBase.m_intModes.Add(AnimatorConditionMode.Less);
         AnimatorTransitionInspectorBase.m_intModes.Add(AnimatorConditionMode.Equals);
         AnimatorTransitionInspectorBase.m_intModes.Add(AnimatorConditionMode.NotEqual);
     }
     if (AnimatorTransitionInspectorBase.m_floatModes == null)
     {
         AnimatorTransitionInspectorBase.m_floatModes = new List <AnimatorConditionMode>();
         AnimatorTransitionInspectorBase.m_floatModes.Add(AnimatorConditionMode.Greater);
         AnimatorTransitionInspectorBase.m_floatModes.Add(AnimatorConditionMode.Less);
     }
     this.m_SyncTransitionContexts = true;
 }
예제 #8
0
        public static void addMotionToControllerByPath(string path, UnityEditor.Animations.AnimatorController ac)
        {
            AnimationClip fist       = (AnimationClip)AssetDatabase.LoadAssetAtPath(path, typeof(AnimationClip));
            Motion        fistmotion = (Motion)fist as Motion;

            ac.AddMotion(fistmotion);
        }
예제 #9
0
 public void Release()
 {
     if (tmpAnimatorController != null)
     {
         if (animator != null)
         {
             animator.runtimeAnimatorController = null;
         }
         {
             var layerCount = tmpAnimatorController.layers.Length;
             for (int i = 0; i < layerCount; i++)
             {
                 tmpAnimatorController.RemoveLayer(0);
             }
         }
         UnityEditor.Animations.AnimatorController.DestroyImmediate(tmpAnimatorController);
         tmpAnimatorController = null;
     }
     animator  = null;
     animation = null;
     if (vaEdit != null)
     {
         Component.DestroyImmediate(vaEdit);
         vaEdit = null;
     }
     if (gameObject != null)
     {
         GameObject.DestroyImmediate(gameObject);
         gameObject = null;
     }
     sourceObject = null;
 }
        public static bool AddClipToAnimatorComponent(Animator animator, AnimationClip newClip)
        {
            UnityEditor.Animations.AnimatorController animatorController = UnityEditor.Animations.AnimatorController.GetEffectiveAnimatorController(animator);
            if ((UnityEngine.Object)animatorController == (UnityEngine.Object)null)
            {
                UnityEditor.Animations.AnimatorController controllerForClip = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerForClip(newClip, animator.gameObject);
                UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, controllerForClip);
                return((UnityEngine.Object)controllerForClip != (UnityEngine.Object)null);
            }
            ChildAnimatorState state = animatorController.layers[0].stateMachine.FindState(newClip.name);

            if (state.Equals((object)new ChildAnimatorState()))
            {
                animatorController.AddMotion((Motion)newClip);
            }
            else if ((bool)((UnityEngine.Object)state.state) && (UnityEngine.Object)state.state.motion == (UnityEngine.Object)null)
            {
                state.state.motion = (Motion)newClip;
            }
            else if ((bool)((UnityEngine.Object)state.state) && (UnityEngine.Object)state.state.motion != (UnityEngine.Object)newClip)
            {
                animatorController.AddMotion((Motion)newClip);
            }
            return(true);
        }
예제 #11
0
        private void ValidateBitKeySwitch(int index, AnimatorControllerLayer layer, AnimatorController controller)
        {
            string trueSwitchName  = string.Format(BitKeySwitchName, "True", index);
            string falseSwitchName = string.Format(BitKeySwitchName, "False", index);

            if (layer.stateMachine.states.All(s => s.state.name != trueSwitchName))
            {
                Debug.Log($"Layer missing BitKeySwtich. {trueSwitchName}");
                AddBitKeySwitch(index, layer, controller);
            }
            else
            {
                Debug.Log($"Layer BitKey Switch Validated {trueSwitchName}.");
                AssetDatabase.SaveAssets();;
            }

            if (layer.stateMachine.states.All(s => s.state.name != falseSwitchName))
            {
                Debug.Log($"Layer missing BitKeySwtich. {falseSwitchName}");
                AddBitKeySwitch(index, layer, controller);
            }
            else
            {
                Debug.Log($"Layer BitKey Switch Validated {falseSwitchName}.");
                AssetDatabase.SaveAssets();;
            }
        }
예제 #12
0
        void ShowAnimatorController()
        {
            _controller = (RuntimeAnimatorController)CreateObjectField("animator", _controller, typeof(RuntimeAnimatorController));

            if (null != _controller)
            {
                EditorGUILayout.BeginHorizontal();
                CreateLabel("clip");
                CreateLabel("duration");
                CreateLabel("isloop");
                EditorGUILayout.EndHorizontal();

                if (_controller is UnityEditor.Animations.AnimatorController)
                {
                    UnityEditor.Animations.AnimatorController controller = _controller as UnityEditor.Animations.AnimatorController;
#if UNITY_4_6
                    ShowAnimatorControllerLayer(controller.GetLayer(0));
#endif

                    for (int i = 0; i < controller.layers.Length; i++)
                    {
                        ShowAnimatorControllerLayer(controller.layers[i]);
                    }
                }
                else if (_controller is AnimatorOverrideController)
                {
                    AnimatorOverrideController overrideController = _controller as AnimatorOverrideController;
                    //				AnimationClipPair[] clips = (AnimationClipPair[])_controller.GetType().BaseType.GetProperty("clips").GetValue(_controller, null);
                    //ShowAnimatorOverrideControllerClips(overrideController.clips);
                }
            }
        }
예제 #13
0
        public void ValidateAnimations(GameObject gameObject, AnimatorController controller)
        {
            for (int i = 0; i < AvaCryptKeyNames.Length; ++i)
            {
                ValidateClip(gameObject, controller, i);
            }

            MeshRenderer[] meshRenderers = gameObject.GetComponentsInChildren <MeshRenderer>(true);
            foreach (MeshRenderer meshRenderer in meshRenderers)
            {
                for (int i = 0; i < _clips0.Length; ++i)
                {
                    string transformPath = AnimationUtility.CalculateTransformPath(meshRenderer.transform, gameObject.transform);
                    _clips0[i].SetCurve(transformPath, typeof(MeshRenderer), $"material._Key{i}", new AnimationCurve(new Keyframe(0, 0)));
                    _clips100[i].SetCurve(transformPath, typeof(MeshRenderer), $"material._Key{i}", new AnimationCurve(new Keyframe(0, 100)));
                }
            }

            SkinnedMeshRenderer[] skinnedMeshRenderers = gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(true);
            foreach (SkinnedMeshRenderer skinnedMeshRenderer in skinnedMeshRenderers)
            {
                for (int i = 0; i < _clips0.Length; ++i)
                {
                    string transformPath = AnimationUtility.CalculateTransformPath(skinnedMeshRenderer.transform, gameObject.transform);
                    _clips0[i].SetCurve(transformPath, typeof(SkinnedMeshRenderer), $"material._Key{i}", new AnimationCurve(new Keyframe(0, 0)));
                    _clips100[i].SetCurve(transformPath, typeof(SkinnedMeshRenderer), $"material._Key{i}", new AnimationCurve(new Keyframe(0, 100)));
                }
            }

            AssetDatabase.SaveAssets();
        }
예제 #14
0
        public void ValidateLayers(AnimatorController controller)
        {
            for (int i = 0; i < AvaCryptKeyNames.Length; ++i)
            {
                if (controller.layers.All(l => l.name != AvaCryptKeyNames[i]))
                {
                    CreateLayer(i, controller);
                }
                else
                {
                    Debug.Log($"Layer already existing: {AvaCryptKeyNames[i]}");
                    AnimatorControllerLayer layer = controller.layers.FirstOrDefault(l => l.name == AvaCryptKeyNames[i]);

                    if (layer.stateMachine == null)
                    {
                        Debug.Log("Layer missing state machine.");

                        // Try to delete blend tree and layers if by chance they still exist for some reason.
                        DeleteObjectFromController(controller, string.Format(StateMachineName, i));
                        DeleteObjectFromController(controller, string.Format(BlendTreeName, i));

                        controller.RemoveLayer(controller.layers.ToList().IndexOf(layer));

                        CreateLayer(i, controller);
                    }
                    else
                    {
                        ValidateLayerBlendTree(i, layer, controller);
                    }
                }
            }
        }
예제 #15
0
    public static List <string> GetStatesNames(Animator animator, int layer = -1)
    {
        UnityEditor.Animations.AnimatorController animatorInternal = (UnityEditor.Animations.AnimatorController)animator.runtimeAnimatorController;

        List <string> AnimStatesName = new List <string>();

        if (animatorInternal != null)
        {
            AnimatorControllerLayer[] layers = animatorInternal.layers;
            if (layer == -1)
            {
                for (int i = 0; i < layers.Length; i++)
                {
                    AnimatorStateMachine _stateMachine = layers[i].stateMachine;

                    ChildAnimatorState[] sates = _stateMachine.states;
                    for (int ib = 0; ib < sates.Length; ib++)
                    {
                        AnimStatesName.Add(sates[ib].state.name);
                    }
                }
            }
            else
            {
                AnimatorStateMachine _stateMachine = layers[layer].stateMachine;
                ChildAnimatorState[] sates         = _stateMachine.states;
                for (int ib = 0; ib < sates.Length; ib++)
                {
                    AnimStatesName.Add(sates[ib].state.name);
                }
            }
            return(AnimStatesName);
        }
        return(null);
    }
        private static Dictionary <int, AnimClipData> GetStates(Animator animator, List <AnimClipData> clips)
        {
            UnityEditor.Animations.AnimatorController controller = animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
            Dictionary <int, int> states = GetStatesFromStatemachine(controller.layers[0].stateMachine);

            Dictionary <int, AnimClipData> stateClip = new Dictionary <int, AnimClipData>();

            foreach (var state in states)
            {
                AnimClipData data = clips.Find(delegate(AnimClipData clip)
                {
                    if (Animator.StringToHash(clip.clip.name) == state.Value)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
                stateClip.Add(state.Key, data);
            }

            return(stateClip);
        }
예제 #17
0
    public static void MergeAnimClips()
    {
        UnityEditor.Animations.AnimatorController animatorController = null;
        AnimationClip[] clips = null;

        if (Selection.activeObject.GetType() == typeof(UnityEditor.Animations.AnimatorController))
        {
            animatorController = (UnityEditor.Animations.AnimatorController)Selection.activeObject;
            clips = animatorController.animationClips;

            if (animatorController != null && clips.Length > 0)
            {
                foreach (AnimationClip clip in clips)
                {
                    var acAssetPath = AssetDatabase.GetAssetPath(clip);
                    if (acAssetPath.EndsWith(".anim"))
                    {
                        var newClip = UnityEngine.Object.Instantiate(clip) as AnimationClip;
                        newClip.name = clip.name;

                        AssetDatabase.AddObjectToAsset(newClip, animatorController);
                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newClip));
                        AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(clip));
                    }
                }
                Debuger.Log("<color=orange>Added " + clips.Length.ToString() + " clips to controller: </color><color=yellow>" + animatorController.name + "</color>");
            }
            else
            {
                Debuger.Log("<color=red>Nothing done. Select a controller that has anim clips to nest.</color>");
            }
        }
    }
 public static bool AddClipToAnimatorComponent(Animator animator, AnimationClip newClip)
 {
     UnityEditor.Animations.AnimatorController effectiveAnimatorController = UnityEditor.Animations.AnimatorController.GetEffectiveAnimatorController(animator);
     if (effectiveAnimatorController == null)
     {
         effectiveAnimatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerForClip(newClip, animator.gameObject);
         UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, effectiveAnimatorController);
         if (effectiveAnimatorController != null)
         {
             return(true);
         }
     }
     else
     {
         ChildAnimatorState state = effectiveAnimatorController.layers[0].stateMachine.FindState(newClip.name);
         if (state.Equals(new ChildAnimatorState()))
         {
             effectiveAnimatorController.AddMotion(newClip);
         }
         else if ((state.state != null) && (state.state.motion == null))
         {
             state.state.motion = newClip;
         }
         else if ((state.state != null) && (state.state.motion != newClip))
         {
             effectiveAnimatorController.AddMotion(newClip);
         }
         return(true);
     }
     return(false);
 }
예제 #19
0
        public static void FuncCreateShowHideAnim()
        {
            var type = typeof(Animator);

            string path             = GetActiveFolderPath();// AssetDatabase.GetAssetPath(Selection.activeObject);
            string assetPath        = path + $"/NewShowHide.controller";
            var    duplicated_index = 1;

            while (System.IO.File.Exists(assetPath))
            {
                assetPath = path + $"/NewShowHide {duplicated_index}.controller";
                duplicated_index++;
            }

            var controller = new UnityEditor.Animations.AnimatorController();

            AssetDatabase.CreateAsset(controller, assetPath);
            Undo.RegisterCreatedObjectUndo(controller, "Generate new controller");

            controller.AddLayer("default");

            var clip1 = CreateAnimatorClip("Show", controller);
            var clip2 = CreateAnimatorClip("Hide", controller);

            AssetDatabase.AddObjectToAsset(clip1, controller);
            AssetDatabase.AddObjectToAsset(clip2, controller);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            Selection.activeObject = controller;
        }
 private void ResetAnimationData()
 {
     animator           = null;
     animatorController = null;
     animationClips     = null;
     animationClipNames = null;
 }
예제 #21
0
    // Use this for initialization
    void Start()
    {
        AnimatorController controller =
            AnimatorController.CreateAnimatorControllerAtPath("Assets/resources/animation/controller/Enemy01.controller");
        Animator ownAnimator = gameObject.AddComponent <Animator>();

        ownAnimator.runtimeAnimatorController = controller;
    }
 public virtual void OnDisable()
 {
     if (this.m_Controller)
     {
         UnityEditor.Animations.AnimatorController expr_16 = this.m_Controller;
         expr_16.OnAnimatorControllerDirty = (Action)Delegate.Remove(expr_16.OnAnimatorControllerDirty, new Action(this.ControllerDirty));
     }
 }
예제 #23
0
 public void AcquireController()
 {
     this.m_Controller = AnimatorControllerTool.tool?.animatorController;
     if (this.m_Controller != null)
     {
         this.m_Controller.OnAnimatorControllerDirty = (System.Action)Delegate.Combine(this.m_Controller.OnAnimatorControllerDirty, new System.Action(this.ResetTransitionList));
     }
 }
예제 #24
0
 public void OnDisable()
 {
     AnimatorControllerTool.graphDirtyCallback = (Action)Delegate.Remove(AnimatorControllerTool.graphDirtyCallback, new Action(this.OnGraphDirty));
     if (this.m_Controller)
     {
         UnityEditor.Animations.AnimatorController expr_36 = this.m_Controller;
         expr_36.OnAnimatorControllerDirty = (Action)Delegate.Remove(expr_36.OnAnimatorControllerDirty, new Action(this.ResetTransitionList));
     }
 }
예제 #25
0
        public static void addMotionToController(string name, UnityEditor.Animations.AnimatorController ac)
        {
            GameObject av = getVRCSceneAvatar();
            AnimatorOverrideController controller = av.GetComponent <VRC_AvatarDescriptor>().CustomStandingAnims;
            AnimationClip anclip     = controller[name];
            Motion        fistmotion = (Motion)anclip as Motion;

            ac.AddMotion(fistmotion);
        }
예제 #26
0
 public void AcquireController()
 {
     this.m_Controller = ((!AnimatorControllerTool.tool) ? null : AnimatorControllerTool.tool.animatorController);
     if (this.m_Controller)
     {
         UnityEditor.Animations.AnimatorController expr_3B = this.m_Controller;
         expr_3B.OnAnimatorControllerDirty = (Action)Delegate.Combine(expr_3B.OnAnimatorControllerDirty, new Action(this.ResetTransitionList));
     }
 }
예제 #27
0
        public void Initialize(GameObject sourceObject)
        {
            Release();

            this.sourceObject = sourceObject;
            gameObject        = sourceObject != null?GameObject.Instantiate <GameObject>(sourceObject) : new GameObject();

            gameObject.hideFlags |= HideFlags.HideAndDontSave | HideFlags.HideInInspector;
            gameObject.name       = sourceObject.name;
            EditorCommon.DisableOtherBehaviors(gameObject);
            gameObjectTransform = gameObject.transform;

            animator = gameObject.GetComponent <Animator>();
            if (animator != null)
            {
                animator.fireEvents      = false;
                animator.applyRootMotion = false;
                animator.updateMode      = AnimatorUpdateMode.Normal;
                animator.cullingMode     = AnimatorCullingMode.AlwaysAnimate;
                if (animator.runtimeAnimatorController == null) //In case of Null, AnimationClip.SampleAnimation does not work, so create it.
                {
                    tmpAnimatorController            = new UnityEditor.Animations.AnimatorController();
                    tmpAnimatorController.name       = "Very Animation Temporary Controller";
                    tmpAnimatorController.hideFlags |= HideFlags.HideAndDontSave;
                    tmpAnimatorController.AddLayer("Very Animation Layer");
                    UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, tmpAnimatorController);
                }
            }
            animation = gameObject.GetComponent <Animation>();

            UpdateBones();

            #region rendererDictionary
            {
                rendererDictionary = new Dictionary <Renderer, Renderer>();
                var sourceRenderers = sourceObject.GetComponentsInChildren <Renderer>(true);
                var objectRenderers = gameObject.GetComponentsInChildren <Renderer>(true);
                foreach (var sr in sourceRenderers)
                {
                    if (sr == null)
                    {
                        continue;
                    }
                    var spath = AnimationUtility.CalculateTransformPath(sr.transform, sourceObject.transform);
                    var index = ArrayUtility.FindIndex(objectRenderers, (x) => AnimationUtility.CalculateTransformPath(x.transform, gameObject.transform) == spath);
                    Assert.IsTrue(index >= 0);
                    if (index >= 0 && !rendererDictionary.ContainsKey(objectRenderers[index]))
                    {
                        rendererDictionary.Add(objectRenderers[index], sr);
                    }
                }
            }
            #endregion

            UpdateState();
        }
예제 #28
0
        public static void PlayMotion(string path, string name, UnityEditor.Animations.AnimatorController ac)
        {
            UnityEditor.Animations.AnimatorStateMachine sm = ac.layers[0].stateMachine;

            for (int i = 0; i < sm.states.Length; i++)
            {
                sm.RemoveState(sm.states[i].state);
            }
            addMotionToController(name, ac);
        }
예제 #29
0
 void OnEnable()
 {
     animatorController = (UnityEditor.Animations.AnimatorController)target;
     listParameter      = new List <AnimatorControllerParameter>(animatorController.parameters);
     listStrParameter   = new List <string>();
     for (int i = 0; i < listParameter.Count; i++)
     {
         listStrParameter.Add(listParameter[i].name);
     }
 }
예제 #30
0
    public static AnimatorStateMachine GetStateMachine(Animator animator, int layerId = 0)
    {
        UnityEditor.Animations.AnimatorController animatorInternal = (UnityEditor.Animations.AnimatorController)animator.runtimeAnimatorController;

        if (animatorInternal != null)
        {
            AnimatorControllerLayer[] layers = animatorInternal.layers;
            return(layers[layerId].stateMachine);
        }
        return(null);
    }
 private void InitController()
 {
   if (this.m_AvatarPreview == null || !((UnityEngine.Object) this.m_AvatarPreview.Animator != (UnityEngine.Object) null))
     return;
   if ((UnityEngine.Object) this.m_Controller == (UnityEngine.Object) null)
   {
     this.m_Controller = new UnityEditor.Animations.AnimatorController();
     this.m_Controller.pushUndo = false;
     this.m_Controller.hideFlags = HideFlags.HideAndDontSave;
     this.m_Controller.AddLayer("preview");
     this.m_StateMachine = this.m_Controller.layers[0].stateMachine;
     this.m_StateMachine.pushUndo = false;
     this.m_StateMachine.hideFlags = HideFlags.HideAndDontSave;
     if ((UnityEngine.Object) this.mask != (UnityEngine.Object) null)
     {
       UnityEditor.Animations.AnimatorControllerLayer[] layers = this.m_Controller.layers;
       layers[0].avatarMask = this.mask;
       this.m_Controller.layers = layers;
     }
   }
   if ((UnityEngine.Object) this.m_State == (UnityEngine.Object) null)
   {
     this.m_State = this.m_StateMachine.AddState("preview");
     this.m_State.pushUndo = false;
     UnityEditor.Animations.AnimatorControllerLayer[] layers = this.m_Controller.layers;
     this.m_State.motion = (Motion) this.m_Clip;
     this.m_Controller.layers = layers;
     this.m_State.iKOnFeet = this.m_AvatarPreview.IKOnFeet;
     this.m_State.hideFlags = HideFlags.HideAndDontSave;
   }
   UnityEditor.Animations.AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
   if (!((UnityEngine.Object) UnityEditor.Animations.AnimatorController.GetEffectiveAnimatorController(this.m_AvatarPreview.Animator) != (UnityEngine.Object) this.m_Controller))
     return;
   UnityEditor.Animations.AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
 }
 public void OnEnable()
 {
     this.m_ControllerContext = (AnimatorControllerTool.tool == null) ? null : AnimatorControllerTool.tool.animatorController;
     this.m_LayerIndexContext = (AnimatorControllerTool.tool == null) ? -1 : AnimatorControllerTool.tool.selectedLayerIndex;
 }
 private void DestroyController()
 {
   if (this.m_AvatarPreview != null && (UnityEngine.Object) this.m_AvatarPreview.Animator != (UnityEngine.Object) null)
     UnityEditor.Animations.AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, (UnityEditor.Animations.AnimatorController) null);
   UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_Controller);
   UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_State);
   this.m_Controller = (UnityEditor.Animations.AnimatorController) null;
   this.m_StateMachine = (AnimatorStateMachine) null;
   this.m_State = (AnimatorState) null;
 }
		private void InitController()
		{
			if (this.m_AvatarPreview != null && this.m_AvatarPreview.Animator != null)
			{
				if (this.m_Controller == null)
				{
					this.m_Controller = new UnityEditor.Animations.AnimatorController();
					this.m_Controller.pushUndo = false;
					this.m_Controller.hideFlags = HideFlags.HideAndDontSave;
					this.m_Controller.AddLayer("preview");
					this.m_StateMachine = this.m_Controller.layers[0].stateMachine;
					this.m_StateMachine.pushUndo = false;
					this.m_StateMachine.hideFlags = HideFlags.HideAndDontSave;
					if (this.m_ClipInfo != null)
					{
						this.InitMask();
						UnityEditor.Animations.AnimatorControllerLayer[] layers = this.m_Controller.layers;
						layers[0].avatarMask = this.m_Mask;
						this.m_Controller.layers = layers;
					}
				}
				if (this.m_State == null)
				{
					this.m_State = this.m_StateMachine.AddState("preview");
					this.m_State.pushUndo = false;
					UnityEditor.Animations.AnimatorControllerLayer[] layers2 = this.m_Controller.layers;
					this.m_State.motion = this.m_Clip;
					this.m_Controller.layers = layers2;
					this.m_State.iKOnFeet = this.m_AvatarPreview.IKOnFeet;
					this.m_State.hideFlags = HideFlags.HideAndDontSave;
				}
				UnityEditor.Animations.AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
				if (UnityEditor.Animations.AnimatorController.GetEffectiveAnimatorController(this.m_AvatarPreview.Animator) != this.m_Controller)
				{
					UnityEditor.Animations.AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
				}
			}
		}
		private void DestroyController()
		{
			if (this.m_AvatarPreview != null && this.m_AvatarPreview.Animator != null)
			{
				UnityEditor.Animations.AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, null);
			}
			UnityEngine.Object.DestroyImmediate(this.m_Controller);
			UnityEngine.Object.DestroyImmediate(this.m_State);
			this.m_Controller = null;
			this.m_StateMachine = null;
			this.m_State = null;
		}