Beispiel #1
0
        public static bool AddClipToAnimatorComponent(Animator animator, AnimationClip newClip)
        {
            AnimatorController effectiveAnimatorController = AnimatorController.GetEffectiveAnimatorController(animator);

            if (effectiveAnimatorController == null)
            {
                effectiveAnimatorController = AnimatorController.CreateAnimatorControllerForClip(newClip, animator.gameObject);
                AnimatorController.SetAnimatorController(animator, effectiveAnimatorController);
                return(effectiveAnimatorController != null);
            }
            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);
        }
        static AnimationClip GenerateTriggerableTransition(string name, AnimatorController controller)
        {
            var clip = AnimatorController.AllocateAnimatorClip(name);

            AssetDatabase.AddObjectToAsset(clip, controller);

#if UNITY_5 || UNITY_5_3_OR_NEWER
            var state = controller.AddMotion(clip);

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

            var stateMachine = controller.layers[0].stateMachine;
            var transition   = stateMachine.AddAnyStateTransition(state);
            transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, name);
#else
            var state = 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);
        }
Beispiel #3
0
    public void OnGUI()
    {
        EditorGUILayout.Space();

        if (_currentAnimator == null)
        {
            EditorGUILayout.HelpBox("Select Animation Controller", MessageType.Warning);
            return;
        }

        DrawAnimationClips();

        using (new EditorGUILayout.HorizontalScope())
        {
            _newClipName = EditorGUILayout.TextField("New Clip Name", _newClipName);
            if (!_newClipName.IsNullOrEmpty())
            {
                if (GUILayout.Button("+", MyGUI.ResizableToolbarButtonStyle, GUILayout.Width(20), GUILayout.Height(20)))
                {
                    AnimationClip newClip = new AnimationClip();
                    newClip.name = _newClipName;
                    _newClipName = string.Empty;

                    AssetDatabase.AddObjectToAsset(newClip, _currentAnimator);
                    // Reimport the asset after adding an object.
                    // Otherwise the change only shows up when saving the project

                    _currentAnimator.AddMotion(newClip);
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newClip));
                }
            }
        }
    }
        private static void AddClipToAnimatorController(Animator animator, AnimationClip clip)
        {
            RuntimeAnimatorController runtimeController = animator.runtimeAnimatorController;

            AnimatorController effectiveController = runtimeController as AnimatorController;

            if (effectiveController == null)
            {
                AnimatorOverrideController overrideController = runtimeController as AnimatorOverrideController;
                if (overrideController != null)
                {
                    effectiveController = overrideController.runtimeAnimatorController as AnimatorController;
                }
            }

            if (effectiveController != null)
            {
                string title   = "Add clip to controller";
                string message = String.Format("Do you want to add clip '{0}' to controller '{1}'?", clip.name, effectiveController.name);
                if (EditorUtility.DisplayDialog(title, message, "yes", "no", DialogOptOutDecisionType.ForThisSession, "com.unity.animation.rigging-add-clip-to-controller"))
                {
                    effectiveController.AddMotion(clip);
                    AnimationWindowUtils.activeAnimationClip = clip;
                    AnimationWindowUtils.StartPreview();
                }
            }
        }
Beispiel #5
0
 //设置状态
 public static bool SetupAnimationState(AnimatorController ctrl, AnimationClip clip, bool isDefault = false)
 {
     if (ctrl && clip)
     {
         //是否存在,没有就添加,有就覆盖
         var stateMachine = ctrl.layers[0].stateMachine;
         foreach (var stateInfo in stateMachine.states)
         {
             if (stateInfo.state.name == clip.name)
             {
                 stateInfo.state.motion = clip;
                 if (isDefault)                      //默认状态也改下
                 {
                     stateMachine.defaultState = stateInfo.state;
                 }
                 AssetDatabase.SaveAssets(); //保存变更
                 return(true);
             }
         }
         var state = ctrl.AddMotion(clip);
         if (isDefault)
         {
             stateMachine.defaultState = state;
         }
         AssetDatabase.SaveAssets(); //保存变更
         return(true);
     }
     return(false);
 }
Beispiel #6
0
 public void SetAnimators()
 {
     //animators = GetComponentInChildren<Animator>();
     foreach (Transform brique in transform)//buildingBase
     {
         ////Debug.Log(buildingBase.name);
         //foreach (Transform baseWall in buildingBase)
         //{
         //    //Debug.Log(baseWall.name);
         //    foreach (Transform brique in baseWall)
         //    {
         //Animator anim = brique.gameObject.GetComponent<Animator>();
         ////Debug.Log(brique.name);
         //string assetPath = "Assets/AnimationController_" + ID + "/" + "explosion_" + ID + "_" +
         //    buildingBase.name + baseWall.name + brique.name + ".controller";
         //AssetDatabase.FindAssets(assetPath);
         //anim.runtimeAnimatorController = AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(assetPath);
         Animator anim = brique.gameObject.GetComponent <Animator>();
         //Debug.Log(brique.name);
         Motion clipReverse = ReverseClip("Assets/Animation_" + ID + "/" + "explosion_" + ID + "_" +
                                          brique.name);
         string namePath = "Assets/AnimationController_" + ID + "/" + "explosion_" + ID + "_" +
                           brique.name;
         string assetPath = namePath + ".controller";
         AssetDatabase.FindAssets(assetPath);
         AnimatorController myController = AssetDatabase.LoadAssetAtPath <AnimatorController>(assetPath);
         myController.AddMotion(clipReverse);
         anim.runtimeAnimatorController = myController;
     }
     //    }
     //}
 }
    public void addAnimClip(string motionName)
    {
        Debug.Log(motionName);
        AnimationClip motion = (AnimationClip)AssetDatabase.LoadAssetAtPath("Assets/Recordings/" + motionName + ".anim", typeof(AnimationClip));

        modelAnimator.AddMotion(motion);
    }
        private static void AddMotion(AnimatorController controller, Motion motion, string name)
        {
            var originalName = motion.name;

            motion.name = name;
            controller.AddMotion(motion);
            motion.name = originalName;
        }
        private static AnimationClip GenerateInitialState(AnimatorController controller)
        {
            AnimationClip animationClip = AnimatorController.AllocateAnimatorClip("Initial");

            AssetDatabase.AddObjectToAsset(animationClip, controller);
            controller.AddMotion(animationClip);
            return(animationClip);
        }
Beispiel #10
0
        public static void AddFolder(AnimatorController controller, string apath)
        {
            //Debug.Log( path );

            DefaultStatePosition(controller);


            var   st     = controller.layers[0].stateMachine.states;
            int   addcnt = 0;
            var   files  = Directory.GetFiles(apath, "*.fbx");
            float fval   = 0.00f;
            float fadd   = 1.00f / files.Length;

            foreach (string path in files)
            {
                fval += fadd;
                EditorUtility.DisplayProgressBar("クリップ複製中", path, fval);

                var fbxClipList = AssetDatabase.LoadAllAssetsAtPath(path.Replace("\\", "/")).
                                  Where(x => x.GetType() == typeof(AnimationClip)).
                                  Where(x => !x.name.Contains("__preview__")).ToArray();

                foreach (AnimationClip fbxClip in fbxClipList)
                {
                    int i = System.Array.FindIndex(st, c => c.state.motion == fbxClip);
                    if (0 <= i)
                    {
                        if (st[i].state.name != fbxClip.name)
                        {
                            st[i].state.name = fbxClip.name;
                        }
                        continue;
                    }

                    //if( 0 <= System.Array.FindIndex( self.animationClips, ( c ) => { return c.name == fbxClip.name; } ) ) {
                    //	int i = System.Array.FindIndex( st, c => c.state.motion == fbxClip );
                    //	if( 0 <= i ) {
                    //		if( st[ i ].state.name != fbxClip.name ) {
                    //			//console.log( st[ i ].state.name );
                    //			st[ i ].state.name = fbxClip.name;
                    //		}
                    //	}
                    //	continue;
                    //}

                    var lsls = AssetDatabase.GetLabels(fbxClip);
                    var lidx = System.Array.FindIndex(lsls, x => x == "Unused");
                    if (-1 == lidx)
                    {
                        addcnt++;
                        var state = controller.AddMotion(fbxClip);
                    }
                }
            }
            EditorUtility.ClearProgressBar();
        }
Beispiel #11
0
        /// <summary>
        /// 1個のAnitionClipを再生するだけの AnimatorController を作成する
        /// </summary>
        /// <param name="clip"></param>
        /// <returns></returns>
        public static RuntimeAnimatorController CreateAnimatorControllerWithClip(AnimationClip clip)
        {
            var animatorController = new AnimatorController();

            animatorController.AddLayer("main");
            animatorController.AddMotion(clip);
            EditorUtility.SetDirty(animatorController);

            return(animatorController);
        }
Beispiel #12
0
        static void AddMotionIfNotExist(AnimatorController preview, AnimationClip clip)
        {
            bool exist = preview.animationClips.Any(controllerClip => controllerClip == clip);

            if (!exist)
            {
                var motion = preview.AddMotion(clip, 1);
                motion.name = clip.name;
            }
        }
 private static AnimationClip GenerateTriggerableTransition(string name, AnimatorController controller)
 {
     AnimationClip animationClip = AnimatorController.AllocateAnimatorClip(name);
     AssetDatabase.AddObjectToAsset(animationClip, controller);
     AnimatorState animatorState = controller.AddMotion(animationClip);
     controller.AddParameter(name, AnimatorControllerParameterType.Trigger);
     AnimatorStateMachine stateMachine = controller.layers[0].stateMachine;
     AnimatorStateTransition animatorStateTransition = stateMachine.AddAnyStateTransition(animatorState);
     animatorStateTransition.AddCondition(AnimatorConditionMode.If, 0f, name);
     return animationClip;
 }
        private static AnimationClip GenerateTriggerableTransition(string name, AnimatorController controller)
        {
            AnimationClip animationClip = AnimatorController.AllocateAnimatorClip(name);

            AssetDatabase.AddObjectToAsset((UnityEngine.Object)animationClip, (UnityEngine.Object)controller);
            AnimatorState destinationState = controller.AddMotion((Motion)animationClip);

            controller.AddParameter(name, AnimatorControllerParameterType.Trigger);
            controller.layers[0].stateMachine.AddAnyStateTransition(destinationState).AddCondition(AnimatorConditionMode.If, 0.0f, name);
            return(animationClip);
        }
        private void ReplaceLayer(AnimatorController controller, AnimationClip[] clipList = null)
        {
            controller.RemoveLayer(0);
            controller.AddLayer("Base Layer");

            if (clipList != null)
            {
                for (int i = 0; i < clipList.Length; i++)
                {
                    controller.AddMotion(clipList[i]);
                }
            }
        }
    /// <summary>
    /// 添加或替换状态机状态的动画片段
    /// </summary>
    /// <param name="name">使用状态机角色名</param>
    /// <param name="stateName">状态名</param>
    /// <param name="m_animator">Animator组件</param>
    /// <param name="isFBX">是否FBX文件</param>
    public void AddAnimMoion(string name, string stateName, bool isFBX)
    {
        animatorController = m_animator.runtimeAnimatorController as AnimatorController;
        animStM            = animatorController.layers[0].stateMachine;
        AnimationClip newClip;
        AnimatorState animState;

        foreach (ChildAnimatorState chidstate in animStM.states)
        {
            if (chidstate.state.name == stateName)
            {
                if (isFBX)
                {
                    newClip          = AssetDatabase.LoadAssetAtPath(string.Format(@"Assets/{0}/Animations/{0}@{1}.FBX", name, stateName), typeof(AnimationClip)) as AnimationClip;
                    animState        = GetState(stateName);
                    animState.motion = newClip;
                    return;
                }
                else
                {
                    newClip          = AssetDatabase.LoadAssetAtPath(string.Format(@"Assets/{0}/Animations/{1}.anim", name, stateName), typeof(AnimationClip)) as AnimationClip;
                    animState        = GetState(stateName);
                    animState.motion = newClip;
                    return;
                }
            }
        }
        if (isFBX)
        {
            newClip = AssetDatabase.LoadAssetAtPath(string.Format(@"Assets/{0}/Animations/{0}@{1}.FBX", name, stateName), typeof(AnimationClip)) as AnimationClip;
            animatorController.AddMotion(newClip);
        }
        else
        {
            newClip = AssetDatabase.LoadAssetAtPath(string.Format(@"Assets/{0}/Animations/{1}.anim", name, stateName), typeof(AnimationClip)) as AnimationClip;
            animatorController.AddMotion(newClip);
        }
    }
        private void InsertNewClip()
        {
            AnimationClip newClip = new AnimationClip();

            newClip.name = _newClipName;
            _newClipName = string.Empty;

            AssetDatabase.AddObjectToAsset(newClip, _currentAnimator);
            _currentAnimator.AddMotion(newClip);

            // Reimport the asset after adding an object.
            // Otherwise the change only shows up when saving the project
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newClip));
        }
        private static AnimationClip GenerateTriggerableTransition(string name, AnimatorController controller)
        {
            AnimationClip animationClip = AnimatorController.AllocateAnimatorClip(name);

            AssetDatabase.AddObjectToAsset(animationClip, controller);
            AnimatorState animatorState = controller.AddMotion(animationClip);

            controller.AddParameter(name, AnimatorControllerParameterType.Trigger);
            AnimatorStateMachine    stateMachine            = controller.layers[0].stateMachine;
            AnimatorStateTransition animatorStateTransition = stateMachine.AddAnyStateTransition(animatorState);

            animatorStateTransition.AddCondition(AnimatorConditionMode.If, 0f, name);
            return(animationClip);
        }
        public static RuntimeAnimatorController CreateControllerWith(IEnumerable <AnimationClip> clips)
        {
            var controller = new AnimatorController {
                layers = new[] { new AnimatorControllerLayer {
                                     stateMachine = new AnimatorStateMachine()
                                 } }
            };

            controller.AddMotion(new AnimationClip {
                name = "Idle"
            });
            foreach (var clip in clips)
            {
                AddMotion(controller, clip);
            }
            return(controller);
        }
Beispiel #20
0
	private static AnimationClip GenerateTriggerableTransition(string name, AnimatorController controller)
	{
		// Create the clip
		var clip = AnimatorController.AllocateAnimatorClip(name);
		AssetDatabase.AddObjectToAsset(clip, controller);

		// Create a state in the animatior controller for this clip
		var state = controller.AddMotion(clip);

		// Add a transition property
		controller.AddParameter(name, AnimatorControllerParameterType.Trigger);

		// Add an any state transition
		var stateMachine = controller.layers[0].stateMachine;

		var transition = stateMachine.AddAnyStateTransition(state);
		transition.AddCondition(AnimatorConditionMode.If, 0, name);
		return clip;
	}
    public static void CreateAnimatorcontroller(string modelName)
    {
        string path = animControllerFolder + modelName + ".controller";

        if (File.Exists(path))
        {
            File.Delete(path);
        }
        AnimatorController.CreateAnimatorControllerAtPath(path);
        AnimatorController   ac      = AssetDatabase.LoadAssetAtPath <AnimatorController>(path);
        AnimatorStateMachine machine = ac.layers[0].stateMachine;

        string     modelPath = modelFolder + modelName + ".FBX";
        GameObject model     = AssetDatabase.LoadAssetAtPath <GameObject>(modelPath);

        if (model.GetComponent <Animator>() == null)
        {
            ConfigModel(modelName);
        }

        Object[] clips   = AssetDatabase.LoadAllAssetsAtPath(modelPath);
        int      clipNum = 0;

        foreach (var v in clips)
        {
            if (v.GetType() == typeof(AnimationClip) && v.name != "__preview__Take 001")
            {
                AnimatorState state = ac.AddMotion(v as Motion, 0);
                clipNum++;
                if (v.name == "swim")
                {
                    machine.defaultState = state;
                }
            }
        }
        if (clipNum == 0)
        {
            Debug.LogError(modelName + "没有动画clip!!");
        }

        Debug.Log("create animatorController:" + path);
    }
Beispiel #22
0
        public override void Sync(Component c)
        {
            this.name = "cc.SkeletalAnimation";

            var motionsComp = c as Motions;
            var animator    = c.GetComponent <Animator>();

            if (!animator)
            {
                animator = c.gameObject.AddComponent <Animator>();
            }

            var animatorCtrl = new AnimatorController();

            animator.runtimeAnimatorController = animatorCtrl;

            animatorCtrl.AddLayer("Temp");

            int stateIndex = 0;

            foreach (var motion in motionsComp.motions)
            {
                if (!motion)
                {
                    continue;
                }

                var state = animatorCtrl.AddMotion(motion, 0);
                var clips = animatorCtrl.animationClips;

                var param = new AnimationClipParam();
                param.animator   = animator;
                param.stateName  = "state:" + stateIndex + "(" + state.name + ")";
                param.folderName = motionsComp.folderName;

                state.name = param.stateName;
                stateIndex++;

                var clipData = SyncAssetData.GetAssetData <SyncAnimationClipData>(clips[clips.Length - 1], param);
                this.clips.Add(clipData.uuid);
            }
        }
    private static AnimationClip GenerateTriggerableTransition(string name, AnimatorController controller)
    {
        // Create the clip
        var clip = AnimatorController.AllocateAnimatorClip(name);

        AssetDatabase.AddObjectToAsset(clip, controller);

        // Create a state in the animatior controller for this clip
        var state = controller.AddMotion(clip);

        // Add a transition property
        controller.AddParameter(name, AnimatorControllerParameterType.Trigger);

        // Add an any state transition
        var stateMachine = controller.layers[0].stateMachine;
        var transition   = stateMachine.AddAnyStateTransition(state);

        transition.AddCondition(AnimatorConditionMode.If, 0, name);
        return(clip);
    }
Beispiel #24
0
    private void CreateAnimation()
    {
        errorString = "";
        if (CheckObjs())
        {
            clip           = new AnimationClip();
            clip.frameRate = 24;

            //AnimationClipSettings clipSettings = new AnimationClipSettings();
            //clipSettings.loopTime = true;
            //AnimationUtility.SetAnimationClipSettings(clip, clipSettings);

            keys = new Keyframe[3][];
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = new Keyframe[2];
            }
            binding = new EditorCurveBinding();
            curve   = new AnimationCurve();

            DFS_Anim(obj1, obj2);

            //生成AnimatorController
            AnimatorController controller = new AnimatorController();
            controller.AddLayer("Base Layer");
            controller.AddMotion(clip, 0).name = "change";
            //注册Animator组件
            Animator animator = obj1.GetComponent <Animator>();
            if (animator == null)
            {
                animator = obj1.gameObject.AddComponent <Animator>();
            }
            animator.runtimeAnimatorController = controller;

            //生成Assets
            AssetDatabase.CreateAsset(clip, Path.Combine(AnimationPath, obj1.name + ".anim"));
            AssetDatabase.CreateAsset(controller, Path.Combine(AnimationPath, obj1.name + ".controller"));
            AssetDatabase.SaveAssets();
        }
    }
        public static AnimationClip AddClipToAnimatorComponent(GameObject animatedObject, AnimationClip newClip)
        {
            Animator animator = animatedObject.GetComponent <Animator>();

            if (animator == null)
            {
                animator = animatedObject.AddComponent <Animator>();
            }
            AnimatorController animatorController = AnimatorController.GetEffectiveAnimatorController(animator);

            if (!(animatorController == null))
            {
                animatorController.AddMotion(newClip);
                return(newClip);
            }
            animatorController = AnimatorController.CreateAnimatorControllerForClip(newClip, animatedObject);
            AnimatorController.SetAnimatorController(animator, animatorController);
            if (animatorController != null)
            {
                return(newClip);
            }
            return(null);
        }
        void GenerateSimpleAnim(string animName, int spritesheetSize, Func <int, int> spriteChooser,
                                Func <AnimatorCondition[]> conditionFactory, AnimatorController animatorController,
                                ReferencedSpritesheet spritesheet, GameObject targetGameObject, bool silent)
        {
            if (!spritesheet.IsValid)
            {
                if (!silent)
                {
                    Debug.LogErrorFormat("Spritesheet for anim '{0}' is invalid", animName);
                }
                return;
            }
            var sprites = spritesheet.Sprites;

            if (sprites.Count != spritesheetSize)
            {
                Debug.LogErrorFormat("Invalid spritesheet size for anim '{0}': '{1}'", animName, spritesheetSize);
                return;
            }

            var referenceClip = spritesheet.ReferenceClip;

            var stateMachine = animatorController.layers[0].stateMachine;

            var clip = new AnimationClip {
                name     = animName,
                wrapMode = WrapMode.Loop
            };

            var bindings = AnimationUtility.GetObjectReferenceCurveBindings(referenceClip);

            Debug.Assert(bindings.Length == 1);
            foreach (var referenceBinding in bindings)
            {
                var referenceCurve = AnimationUtility.GetObjectReferenceCurve(referenceClip, referenceBinding);

                var mod = new PropertyModification {
                    propertyPath = referenceBinding.path,
                };
                AnimationUtility.PropertyModificationToEditorCurveBinding(mod, targetGameObject, out var binding);
                binding.propertyName = referenceBinding.propertyName;
                binding.path         = referenceBinding.path;
                binding.type         = referenceBinding.type;

                var curve = new ObjectReferenceKeyframe[referenceCurve.Length];
                for (var i = 0; i < referenceCurve.Length; ++i)
                {
                    curve[i] = new ObjectReferenceKeyframe {
                        time  = referenceCurve[i].time,
                        value = sprites[spriteChooser(i)]
                    };
                }
                AnimationUtility.SetObjectReferenceCurve(clip, binding, curve);
            }

            foreach (var referenceBinding in AnimationUtility.GetCurveBindings(referenceClip))
            {
                var referenceCurve = AnimationUtility.GetEditorCurve(referenceClip, referenceBinding);
                var mod            = new PropertyModification {
                    propertyPath = referenceBinding.path,
                };
                AnimationUtility.PropertyModificationToEditorCurveBinding(mod, targetGameObject, out var binding);
                var curve = new AnimationCurve();
                for (var j = 0; j < referenceCurve.length; ++j)
                {
                    var referenceKey = referenceCurve.keys[j];
                    curve.AddKey(new Keyframe(referenceKey.time, referenceKey.value));
                }
                AnimationUtility.SetEditorCurve(clip, binding, curve);
            }

            if (AddEvents)
            {
                var clipEvents = new List <AnimationEvent>();
                foreach (var referenceEvent in AnimationUtility.GetAnimationEvents(referenceClip))
                {
                    var ev = new AnimationEvent {
                        time                     = referenceEvent.time,
                        functionName             = referenceEvent.functionName,
                        floatParameter           = referenceEvent.floatParameter,
                        intParameter             = referenceEvent.intParameter,
                        messageOptions           = referenceEvent.messageOptions,
                        stringParameter          = referenceEvent.stringParameter,
                        objectReferenceParameter = referenceEvent.objectReferenceParameter
                    };
                    clipEvents.Add(ev);
                }
                if (clipEvents.Count > 0)
                {
                    AnimationUtility.SetAnimationEvents(clip, clipEvents.ToArray());
                }
            }

            AssetDatabase.CreateAsset(clip, AssetDatabase.GetAssetPath(animatorController).Replace("Controller.asset", animName + ".anim"));
            var animatorState = animatorController.AddMotion(clip);

            animatorState.name = $"{animName}";

            var transition = stateMachine.AddAnyStateTransition(animatorState);

            transition.duration    = 0f;
            transition.hasExitTime = false;
            transition.conditions  = conditionFactory();
        }
Beispiel #27
0
        public void Build(Animation animation, IDictionary <int, TimeLine> timeLines)
        {
            var clip = new AnimationClip();

            clip.name = animation.name;
            var pendingTransforms = new Dictionary <string, Transform> (Transforms);            //This Dictionary will shrink in size for every transform

            foreach (var key in animation.mainlineKeys)                                         //that is considered "used"
            {
                var parentTimelines = new Dictionary <int, List <TimeLineKey> > ();
                var brefs           = new Queue <Ref> (key.boneRefs ?? new Ref [0]);
                while (brefs.Count > 0)
                {
                    var bref = brefs.Dequeue();
                    if (bref.parent < 0 || parentTimelines.ContainsKey(bref.parent))
                    {
                        var timeLine = timeLines [bref.timeline];
                        parentTimelines [bref.id] = new List <TimeLineKey> (timeLine.keys);
                        Transform bone;
                        if (pendingTransforms.TryGetValue(timeLine.name, out bone))                            //Skip it if it's already "used"
                        {
                            List <TimeLineKey> parentTimeline;
                            parentTimelines.TryGetValue(bref.parent, out parentTimeline);
                            SetCurves(bone, DefaultBones [timeLine.name], parentTimeline, timeLine, clip, animation);
                            pendingTransforms.Remove(timeLine.name);
                        }
                    }
                    else
                    {
                        brefs.Enqueue(bref);
                    }
                }
                foreach (var sref in key.objectRefs)
                {
                    var       timeLine = timeLines [sref.timeline];
                    Transform sprite;
                    if (pendingTransforms.TryGetValue(timeLine.name, out sprite))
                    {
                        var defaultZ = sref.z_index;
                        List <TimeLineKey> parentTimeline;
                        parentTimelines.TryGetValue(sref.parent, out parentTimeline);
                        SetCurves(sprite, DefaultSprites [timeLine.name], parentTimeline, timeLine, clip, animation, ref defaultZ);
                        SetAdditionalCurves(sprite, animation.mainlineKeys, timeLine, clip, defaultZ);
                        pendingTransforms.Remove(timeLine.name);
                    }
                }
                foreach (var kvPair in pendingTransforms)                   //Disable the remaining tansforms if they are sprites and not already disabled
                {
                    if (DefaultSprites.ContainsKey(kvPair.Key) && kvPair.Value.gameObject.activeSelf)
                    {
                        var curve = new AnimationCurve(new Keyframe(0f, 0f, inf, inf));
                        clip.SetCurve(GetPathToChild(kvPair.Value), typeof(GameObject), "m_IsActive", curve);
                    }
                }
            }
            var settings = AnimationUtility.GetAnimationClipSettings(clip);

            settings.stopTime = animation.length;             //Set the animation's length and other settings
            if (animation.looping)
            {
                clip.wrapMode     = WrapMode.Loop;
                settings.loopTime = true;
            }
            else
            {
                clip.wrapMode = WrapMode.ClampForever;
            }
            AnimationUtility.SetAnimationClipSettings(clip, settings);
            if (OriginalClips.ContainsKey(animation.name))                //If the clip already exists, copy this clip into the old one
            {
                var oldClip      = OriginalClips [animation.name];
                var cachedEvents = oldClip.events;
                EditorUtility.CopySerialized(clip, oldClip);
                clip = oldClip;
                AnimationUtility.SetAnimationEvents(clip, cachedEvents);
                ProcessingInfo.ModifiedAnims.Add(clip);
            }
            else
            {
                switch (S2USettings.ImportStyle)
                {
                case AnimationImportOption.NestedInPrefab:
                    AssetDatabase.AddObjectToAsset(clip, PrefabPath);                      //Otherwise create a new one
                    break;

                case AnimationImportOption.SeparateFolder:
                    if (!AssetDatabase.IsValidFolder(AnimationsPath))
                    {
                        var splitIndex = AnimationsPath.LastIndexOf('/');
                        var path       = AnimationsPath.Substring(0, splitIndex);
                        var newFolder  = AnimationsPath.Substring(splitIndex + 1);
                        AssetDatabase.CreateFolder(path, newFolder);
                    }
                    AssetDatabase.CreateAsset(clip, string.Format("{0}/{1}.anim", AnimationsPath, clip.name));
                    break;
                }
                ProcessingInfo.NewAnims.Add(clip);
            }
            if (!ArrayUtility.Contains(Controller.animationClips, clip))        //Don't add the clip if it's already there
            {
                var state = GetStateFromController(clip.name);                  //Find a state of the same name
                if (state != null)
                {
                    state.motion = clip;                                //If it exists, replace it
                }
                else
                {
                    Controller.AddMotion(clip);                   //Otherwise add it as a new state
                }
                if (!ModdedController)
                {
                    if (!ProcessingInfo.NewControllers.Contains(Controller) && !ProcessingInfo.ModifiedControllers.Contains(Controller))
                    {
                        ProcessingInfo.ModifiedControllers.Add(Controller);
                    }
                    ModdedController = true;
                }
            }
        }
Beispiel #28
0
    void CreateController()
    {
        // Creates the controller


        // Add parameters
        controller.AddParameter("Letter", AnimatorControllerParameterType.Int);
        //add first layer
        int layer_start = -1;

        foreach (var x in controller.layers)
        {
            layer_start += 1;
        }
        for (int j = 1; j < 13; j++)
        {
            var layer = new UnityEditor.Animations.AnimatorControllerLayer
            {
                name          = "Letter" + j,
                defaultWeight = 1f,
                stateMachine  = new UnityEditor.Animations.AnimatorStateMachine()
            };
            var working_layer = j + layer_start;
            controller.AddLayer(layer);
            // Add StateMachines
            var    rootStateMachine = controller.layers[working_layer].stateMachine;
            Motion reset            = Resources.Load <Motion>("tentenVRCkeyboard/reset");

            var           entry = controller.AddMotion(reset, working_layer);
            AnimatorState idle  = entry;
            AnimatorState input = entry;
            for (int k = 1; k < j; k++)
            {
                var old_idle = idle;
                input = rootStateMachine.AddState(k.ToString() + "input");
                var trans = idle.AddTransition(input);
                trans.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Greater, 0, "Letter");
                trans.AddCondition(UnityEditor.Animations.AnimatorConditionMode.NotEqual, 255, "Letter");
                idle = rootStateMachine.AddState(k.ToString() + "idle");
                var trans2 = input.AddTransition(idle);
                trans2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 0, "Letter");
                var reset_transition = idle.AddTransition(entry);
                reset_transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 255, "Letter");


                var back_space = rootStateMachine.AddState(k.ToString() + "back space buffer");

                var trans3 = idle.AddTransition(back_space);
                trans3.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 254, "Letter");

                var trans4 = back_space.AddTransition(old_idle);
                trans4.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 0, "Letter");
            }

            for (int i = 1; i < 28; i++)
            {
                var    file   = "tentenVRCkeyboard/" + j + "/" + j + " " + i;
                Motion motion = Resources.Load <Motion>(file);

                var state            = controller.AddMotion(motion, working_layer);
                var reset_transition = state.AddTransition(entry);
                reset_transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 255, "Letter");
                var transition = idle.AddTransition(state);
                transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, i, "Letter");

                /*
                 * for (int x = 1; x < 13; x++)
                 * {
                 *  var newstate = controller.AddMotion(motion, working_layer);
                 *  var newstateAdvance = rootStateMachine.AddState(i + x + "back space Advance");
                 *  var backspaceBuffer = rootStateMachine.AddState(i + x + "back space Backward");
                 *
                 *  var newtransition = state.AddTransition(newstateAdvance);
                 *  newtransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Greater, 0, "Letter");
                 *  newtransition = newstateAdvance.AddTransition(newstate);
                 *  newtransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 0, "Letter");
                 *  var newtransition2 = newstate.AddTransition(backspaceBuffer);
                 *
                 *  newtransition2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 0, "Letter");
                 *  newtransition2 = backspaceBuffer.AddTransition(state);
                 *  newtransition2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 254, "Letter");
                 * }
                 */
            }
        }
        var resetLayer = new UnityEditor.Animations.AnimatorControllerLayer
        {
            name          = "Toggle",
            defaultWeight = 1f,
            stateMachine  = new UnityEditor.Animations.AnimatorStateMachine()
        };

        controller.AddLayer(resetLayer);
        controller.AddParameter("ToggleKeyboard", AnimatorControllerParameterType.Int);
        Motion enable       = Resources.Load <Motion>("tentenVRCkeyboard/enableKeyboard");
        Motion disable      = Resources.Load <Motion>("tentenVRCkeyboard/disableKeyboard");
        var    disableState = controller.AddMotion(disable, 13 + layer_start);
        var    enableState  = controller.AddMotion(enable, 13 + layer_start);
        var    toEnable     = disableState.AddTransition(enableState);
        var    toDisable    = enableState.AddTransition(disableState);

        toEnable.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 1, "ToggleKeyboard");
        toDisable.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals, 0, "ToggleKeyboard");
    }
 private static AnimationClip GenerateTriggerableTransition(string name, AnimatorController controller)
 {
   AnimationClip animationClip = AnimatorController.AllocateAnimatorClip(name);
   AssetDatabase.AddObjectToAsset((UnityEngine.Object) animationClip, (UnityEngine.Object) controller);
   AnimatorState destinationState = controller.AddMotion((Motion) animationClip);
   controller.AddParameter(name, AnimatorControllerParameterType.Trigger);
   controller.layers[0].stateMachine.AddAnyStateTransition(destinationState).AddCondition(AnimatorConditionMode.If, 0.0f, name);
   return animationClip;
 }
Beispiel #30
0
        private void CreateAnimatorStates(AnimatorController controller, bool mirrored = false)
        {
            AnimationClip PanelOpenedClip = new AnimationClip();

            PanelOpenedClip.name = PANEL_OPENED_STATE;

            AnimationClip PanelClosedClip = new AnimationClip();

            PanelClosedClip.name = PANEL_CLOSED_STATE;

            AnimationCurve curve = AnimationCurve.EaseInOut(0.0f, 0.0f, 0.4f, 1.0f);

            PanelOpenedClip.SetCurve("", typeof(CanvasGroup), "m_Alpha", curve);
            curve = AnimationCurve.EaseInOut(0.0f, 0.0f, 0.01f, 1.0f);
            PanelOpenedClip.SetCurve("", typeof(CanvasGroup), "m_Interactable", curve);
            PanelOpenedClip.SetCurve("", typeof(CanvasGroup), "m_BlocksRaycasts", curve);

            curve = AnimationCurve.EaseInOut(0.0f, 1.0f, 0.4f, 0.0f);
            PanelClosedClip.SetCurve("", typeof(CanvasGroup), "m_Alpha", curve);

            curve = AnimationCurve.EaseInOut(0.0f, 1.0f, 0.0f, 0.0f);
            PanelClosedClip.SetCurve("", typeof(CanvasGroup), "m_Interactable", curve);
            PanelClosedClip.SetCurve("", typeof(CanvasGroup), "m_BlocksRaycasts", curve);

            curve = AnimationCurve.EaseInOut(0.0f, 0.0f, 0.0f, 0.0f);

            //		controller.AddParameter(IS_OPENED, AnimatorControllerParameterType.Bool);
            //		controller.AddParameter(IS_DEFINED, AnimatorControllerParameterType.Bool);
            controller.AddParameter(OPENING_SPEED, AnimatorControllerParameterType.Float);
            controller.AddParameter(CLOSING_SPEED, AnimatorControllerParameterType.Float);

            AnimatorState statePanelClosed;

            AnimatorControllerLayer layer = new AnimatorControllerLayer();

            layer.name          = LAYER_NAME;
            layer.defaultWeight = 1.0f;
            layer.stateMachine  = new AnimatorStateMachine();

            if (mirrored)
            {
                statePanelClosed = layer.stateMachine.AddState(PANEL_CLOSED_STATE);

                statePanelClosed.motion = PanelOpenedClip;
                statePanelClosed.speed  = -1.0f;
                statePanelClosed.speedParameterActive = true;
                statePanelClosed.speedParameter       = CLOSING_SPEED;
            }
            else
            {
                statePanelClosed = layer.stateMachine.AddState(PANEL_CLOSED_STATE);

                statePanelClosed.motion = PanelClosedClip;
                statePanelClosed.speed  = 1.0f;
                statePanelClosed.speedParameterActive = true;
                statePanelClosed.speedParameter       = CLOSING_SPEED;
            }

            AnimatorState statePanelNotDefined = layer.stateMachine.AddState(PANEL_NOT_DEFINED_STATE);


            controller.AddLayer(layer);
            var layerIndex = GetLayerIndex(layer, controller);

            var statePanelOpened = controller.AddMotion(PanelOpenedClip, layerIndex);

            statePanelOpened.speed = 1.0f;
            statePanelOpened.speedParameterActive = true;
            statePanelOpened.speedParameter       = OPENING_SPEED;
            layer.stateMachine.defaultState       = statePanelNotDefined;

            layer.stateMachine.hideFlags = HideFlags.HideInInspector;
            AssetDatabase.AddObjectToAsset(layer.stateMachine, controller);

            AssetDatabase.AddObjectToAsset(statePanelOpened, controller);
            AssetDatabase.AddObjectToAsset(statePanelClosed, controller);
            AssetDatabase.AddObjectToAsset(statePanelNotDefined, controller);

            AssetDatabase.AddObjectToAsset(PanelOpenedClip, controller);
            AssetDatabase.AddObjectToAsset(PanelClosedClip, controller);

            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(controller));
        }
Beispiel #31
0
    private void BakeAnimation()
    {
        // 노드들이 텐터클의 자식인지 검사.
        if (!CheckNodesInTentacle())
        {
            EditorUtility.DisplayDialog("Bake Animation Error", "Bake Animation does not work because there is a Node that is not a child of Tentacle.", "OK");
            return;
        }

        // Get Path
        string pathAbs = EditorUtility.SaveFilePanel("Bake Animation", "", tentacle.gameObject.name, "anim");

        if (pathAbs == "")
        {
            return;
        }
        string path = pathAbs;

        if (pathAbs.StartsWith(Application.dataPath))
        {
            path = "Assets" + pathAbs.Substring(Application.dataPath.Length);
        }
        else
        {
            EditorUtility.DisplayDialog("Bake Animation Error", "You can not create an asset outside the project.", "OK");
            return;
        }

        if (AnimationMode.InAnimationMode())
        {
            AnimationWindowTurnOffPreview();
        }

        // Create Animator
        Animator animator = tentacle.GetComponent <Animator>();

        if (animator == null)
        {
            animator = tentacle.gameObject.AddComponent <Animator>();
        }

        // if Get Path Canceled
        if (path == "")
        {
            return;
        }

        // Create Assets
        AnimationClip animClip = new AnimationClip();

        // (Sample Rate)
        animClip.frameRate = tentacle.m_bakeSamples;
        // (Loop Time)
        AnimationClipSettings tSettings = AnimationUtility.GetAnimationClipSettings(animClip);

        tSettings.loopTime = tentacle.m_bakeLoopTime;
        AnimationUtility.SetAnimationClipSettings(animClip, tSettings);
        AssetDatabase.CreateAsset(animClip, path);
        path = System.IO.Path.GetDirectoryName(path) + "/" + System.IO.Path.GetFileNameWithoutExtension(pathAbs) + ".controller";
        // AssetDatabase.CreateAsset(animController, path); <-- 이 방식으로 animController 를 생성하면 문제가 많다. (디폴트 세팅이 거의 안되어 생성되기때문으로 짐작). 다음 방식으로 생성하면 문제 없음.
        AnimatorController animController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(path);

        // Assign Clip
        animController.AddMotion(animClip, 0);
        animator.runtimeAnimatorController = animController;

        // Save local rotation of nodes
        Quaternion[] rotBakNodes = new Quaternion[tentacle.m_nodes.Length];
        for (int i = 0; i < tentacle.m_nodes.Length; i++)
        {
            if (tentacle.m_nodes[i] != null)
            {
                rotBakNodes[i] = tentacle.m_nodes[i].localRotation;
            }
        }

        float frameLength = 1f / (float)tentacle.m_bakeSamples;
        int   frameCount  = (int)(tentacle.m_bakeTime / frameLength) + 1;

        // Initialize Keyframes
        EulerXYZKeys[] eulerXYZKeys = new EulerXYZKeys[tentacle.m_nodes.Length];
        for (int i = 0; i < tentacle.m_nodes.Length; i++)
        {
            if (tentacle.m_nodes[i] != null)
            {
                eulerXYZKeys[i].keysX = new Keyframe[frameCount];
                eulerXYZKeys[i].keysY = new Keyframe[frameCount];
                eulerXYZKeys[i].keysZ = new Keyframe[frameCount];
            }
        }

        // Update Tentacle
        // i = node index, o = frame
        tentacle.Initialize();
        int totalFrame = frameCount * tentacle.m_nodes.Length;

        for (int o = 0; o < frameCount; o++)
        {
            float     time             = o * frameLength;
            Vector3[] localEulerAlgles = tentacle.UpdateTentalces(time, true); // Update

            for (int i = 0; i < tentacle.m_nodes.Length; i++)
            {
                if (tentacle.m_nodes[i] != null)
                {
                    eulerXYZKeys[i].keysX[o] = new Keyframe(time, localEulerAlgles[i].x);
                    eulerXYZKeys[i].keysY[o] = new Keyframe(time, localEulerAlgles[i].y);
                    eulerXYZKeys[i].keysZ[o] = new Keyframe(time, localEulerAlgles[i].z);
                }
                float progress = (float)((i + 1) * (o + 1)) / (float)totalFrame;
                EditorUtility.DisplayProgressBar("Bake Animation", ("Node " + i.ToString() + "," + " Frame " + o.ToString()), progress);
            }
        }
        EditorUtility.ClearProgressBar();

        for (int i = 0; i < tentacle.m_nodes.Length; i++)
        {
            AnimationCurve curve = new AnimationCurve(eulerXYZKeys[i].keysX);
            animClip.SetCurve(GetRelativePath(tentacle.m_nodes[i]), typeof(Transform), "localEulerAngles.x", curve);
            curve = new AnimationCurve(eulerXYZKeys[i].keysY);
            animClip.SetCurve(GetRelativePath(tentacle.m_nodes[i]), typeof(Transform), "localEulerAngles.y", curve);
            curve = new AnimationCurve(eulerXYZKeys[i].keysZ);
            animClip.SetCurve(GetRelativePath(tentacle.m_nodes[i]), typeof(Transform), "localEulerAngles.z", curve);
        }

        // Restore local rotation of nodes
        for (int i = 0; i < tentacle.m_nodes.Length; i++)
        {
            if (tentacle.m_nodes[i] != null)
            {
                tentacle.m_nodes[i].localRotation = rotBakNodes[i];
            }
        }

        // Disable Tentacle
        if (tentacle.m_bakeDisableTentacle)
        {
            tentacle.enabled = false;
        }

        AutoTangent();
    }
    public void ToAnimation(UnityEngine.Object obj)
    {
        string prefabName        = "";
        string animationClipName = "";

        if (linkToPrefab)
        {
            string[] split = obj.name.Split(new char[] { '_' });
            if (split.Length > 1)
            {
                prefabName        = split[0];
                animationClipName = split[split.Length - 1];
            }
        }
        //Debug.Log(prefabName);

        Image gifImage = Image.FromFile(AssetDatabase.GetAssetPath(obj));

        if (gifImage == null)
        {
            //Debug.Log("Invalid Path: " + AssetDatabase.GetAssetPath(obj));
            return;
        }

        FrameDimension dimension  = new FrameDimension(gifImage.FrameDimensionsList[0]);
        int            frameCount = gifImage.GetFrameCount(dimension);

        //Debug.Log("frameCount: " + frameCount);

        EditorUtility.DisplayProgressBar(progress + "/" + maxProgress + " Converting GIF To Frames", "This Step is fast!", .25f);
        Texture2D[] frames = GetGIFFrames(gifImage, dimension, frameCount, padding);
        //Debug.Log("Writing out frames: " + frames.Length);

        byte[] pngBytes = null;

        //EXPORTING OUT EACH FRAME individually
        //for (int i = 0; i < frames.Length; i++)
        //{
        //    pngBytes = frames[i].EncodeToPNG();
        //    string framePath = Application.dataPath + AssetDatabase.GetAssetPath(obj).Inset(6, 4 + obj.name.Length) + "/" + obj.name +"_"+ i + ".png";
        //    Debug.Log(framePath);
        //    File.WriteAllBytes(framePath, pngBytes);
        //}

        EditorUtility.DisplayProgressBar(progress + "/" + maxProgress + " Combining Frames", "Please Wait", .5f);
        Texture2D combinedTexture = CombineTextures(frames, padding);
        int       frameLength     = frames.Length;
        int       width           = frames[0].width;
        int       height          = frames[0].height;

        pngBytes = combinedTexture.EncodeToPNG();
        string assetPath = AssetDatabase.GetAssetPath(obj);

        assetPath = assetPath.Substring(0, assetPath.Length - 4);

        string path = Application.dataPath + assetPath.Substring(6, assetPath.Length - 6) + ".png";

        //Debug.Log(path);
        File.WriteAllBytes(path, pngBytes);

        AssetDatabase.ImportAsset(assetPath.Substring(0, assetPath.Length) + ".png", ImportAssetOptions.Default);
        if (combinedTexture == null)
        {
            combinedTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath + ".png", typeof(Texture2D));
        }
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        EditorUtility.DisplayProgressBar(progress + "/" + maxProgress + " Slicing Up Sprites", "Like Pie", .75f);
        float time = 0;

        while (combinedTexture == null && time < 10000)
        {
            time += Time.deltaTime + .001f;
        }

        Sprite[] sprites = SliceUKpSprite(combinedTexture,
                                          frameLength,
                                          assetPath + ".png",
                                          width,
                                          height,
                                          padding);

        EditorUtility.DisplayProgressBar(progress + "/" + maxProgress + " Making AnimationClip", "Every Single Byte", .9f);
        AnimationClip animationClip = new AnimationClip();

        animationClip.name = animationClipName;


        EditorCurveBinding binding = new EditorCurveBinding()
        {
            propertyName = "m_Sprite", path = "", type = typeof(SpriteRenderer)
        };


        List <ObjectReferenceKeyframe> objectReferenceKeyframe = new List <ObjectReferenceKeyframe>();

        for (int i = 0; i < sprites.Length; i++)
        {
            ObjectReferenceKeyframe orkf = new ObjectReferenceKeyframe()
            {
                value = sprites[i], time = (float)(i) * .1f
            };
            objectReferenceKeyframe.Add(orkf);
        }


        if (animationClip == null)
        {
            Debug.Log("NO Aniamtion Clip");
        }

        //AnimationClip loadedClip = AssetDatabase.LoadAssetAtPath<AnimationClip>("Assets/" + animationClip.name + ".anim");
        EditorCurveBinding[] bindings = AnimationUtility.GetObjectReferenceCurveBindings(animationClip);
        for (int i = 0; i < bindings.Length; i++)
        {
            Debug.Log(bindings[i].path + "_AND_" + bindings[i].propertyName);
        }
        //AnimationUtility.GetObjectReferenceCurve(loadedClip)//

        if (animationClip == null)
        {
            //Debug.Log("No Such Clip Exists");
        }

        string savePath = assetPath + ".anim";

        //Debug.Log(obj.name);
        if (!string.IsNullOrEmpty(prefabName))
        {
            //Debug.Log("Searching For Prefab..." + prefabName);
            GameObject prefab = FindPrefabInProject(prefabName);
            if (prefab)
            {
                //Debug.Log("prefab found");
                Animator animator = prefab.GetComponent <Animator>();
                if (animator == null)
                {
                    animator = prefab.AddComponent <Animator>();
                }
                AnimatorController animatorController = (AnimatorController)animator.runtimeAnimatorController;
                if (animatorController == null)
                {
                    animatorController = (AnimatorController) new AnimatorController();
                    string animatorSavePath = InsetFromEnd(AssetDatabase.GetAssetPath(prefab), prefab.name.Length + 7) + prefabName + ".controller";
                    //Debug.Log(animatorSavePath.RTBlue());
                    AssetDatabase.CreateAsset(animatorController, animatorSavePath);
                    animator.runtimeAnimatorController = (RuntimeAnimatorController)animatorController;
                }
                Motion motion = (Motion)animationClip as Motion;
                animatorController.AddLayer("Base Layer");
                animatorController.AddMotion(motion, 0);
                savePath = InsetFromEnd(AssetDatabase.GetAssetPath(prefab), prefab.name.Length + 7) + animationClipName + ".anim";

                AssetDatabase.MoveAsset(Inset(AssetDatabase.GetAssetPath(obj), 0, 4) + ".png", InsetFromEnd(AssetDatabase.GetAssetPath(prefab), prefab.name.Length + 7) + prefabName + ".png");
            }
        }

        AnimationUtility.SetObjectReferenceCurve(animationClip, binding, objectReferenceKeyframe.ToArray()); //objectReferenceKeyframe.ToArray()
                                                                                                             //Debug.Log(savePath);
        AssetDatabase.CreateAsset(animationClip, savePath);
        EditorUtility.DisplayProgressBar(progress + "/" + maxProgress + " Saving...", "In Computer time 1 min Left (In Real Life 1 hr...)", .95f);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.ClearProgressBar();
    }
        private void CreateThumbUpStates(AnimatorController animator, int layerIndex, HandClips clips)
        {
            AnimatorState thumbupState = animator.AddMotion(clips.thumbUp, layerIndex);

            animator.layers[layerIndex].stateMachine.defaultState = thumbupState;
        }