Exemple #1
0
        public static AnimatorStateTransition AddExitTransitionDefaultParam(this AnimatorState sourceState)
        {
            var transition = sourceState.AddExitTransition();

            SetDefaultTransitionParam(transition);
            return(transition);
        }
Exemple #2
0
        public void Build()
        {
            var expName    = _expressionInfo.ExpressionName;
            var controller = _expressionInfo.Controller;

            AnimatorControllerLayer layer = AnimUtility.AddLayer(controller, expName, _dirtyAssets);

            controller.AddParameter(expName, AnimatorControllerParameterType.Bool);

            AnimatorStateMachine stateMachine = layer.stateMachine;
            var empty = AnimUtility.AddState(stateMachine, "Empty", true, _dirtyAssets);

            AnimatorState toggleState = AnimUtility.AddState(stateMachine, expName, false, _dirtyAssets);

            var animationClip = AnimUtility.CreateAnimation(_expressionInfo.AnimationsFolder.GetPath(), expName, _dirtyAssets);

            toggleState.motion = animationClip;

            foreach (var obj in GetObjects())
            {
                switch (obj.Type)
                {
                case AdvancedToggleObjectMode.GameObject:
                    AddToggleKeyframes(animationClip, obj.Target as Transform, obj.ToggleState, _dirtyAssets);
                    break;

                case AdvancedToggleObjectMode.Material:
                    AnimUtility.SetObjectReferenceKeyframe(animationClip, obj.Target, $"m_Materials.Array.data[{obj.MaterialSlot}]", obj.NewMaterial, _dirtyAssets);
                    break;
                }
            }

            AnimatorStateTransition anyStateTransition = stateMachine.AddAnyStateTransition(toggleState);

            anyStateTransition.AddCondition(AnimatorConditionMode.If, 1, expName);

            AnimatorStateTransition exitTransition = toggleState.AddExitTransition(false);

            exitTransition.AddCondition(AnimatorConditionMode.IfNot, 0, expName);

            AnimUtility.AddVRCExpressionsParameter(_expressionInfo.AvatarDescriptor, VRCExpressionParameters.ValueType.Bool, expName, _dirtyAssets);
            if (_expressionInfo.Menu != null)
            {
                AnimUtility.AddVRCExpressionsMenuControl(_expressionInfo.Menu, ControlType.Toggle, expName, _dirtyAssets);
            }

            _dirtyAssets.SetDirty();
            controller.AddObjectsToAsset(stateMachine, toggleState, anyStateTransition, exitTransition, empty);
            AssetDatabase.SaveAssets();

            _dirtyAssets.Clear();
            foreach (ObjectData obj in GetObjects().Where(o => o.Type == AdvancedToggleObjectMode.Parameter))
            {
                AnimUtility.AddVRCParameterDriver(toggleState, obj.ParameterName, obj.ParameterValue, _dirtyAssets);
            }
            _dirtyAssets.SetDirty();
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        static void AddTransition(AnimatorState start, AnimatorState end, string condition, float _duration = 0)
        {
            AnimatorStateTransition tempTransition = start.AddExitTransition();

            tempTransition.destinationState = end;
            tempTransition.hasExitTime      = false;
            tempTransition.AddCondition(AnimatorConditionMode.If, 0, condition);
            tempTransition.duration = _duration;
        }
        public void Build()
        {
            var expName    = _expressionInfo.ExpressionName;
            var controller = _expressionInfo.Controller;

            AnimatorControllerLayer layer = AnimUtility.AddLayer(controller, expName, _dirtyAssets);

            controller.AddParameter(expName, AnimatorControllerParameterType.Float);

            AnimatorStateMachine stateMachine = layer.stateMachine;
            var           empty = AnimUtility.AddState(stateMachine, "Empty", true, _dirtyAssets);
            AnimatorState state = AnimUtility.AddState(stateMachine, expName, false, _dirtyAssets);

            var blendTree = new BlendTree
            {
                name           = "BlendTree",
                blendParameter = expName,
            };

            state.motion = blendTree;
            _dirtyAssets.Add(blendTree);

            var materials = GetMaterials().ToList();

            var directory = $"{_expressionInfo.AnimationsFolder.GetPath()}/{expName}";
            var emptyClip = AnimUtility.CreateAnimation(directory, $"{expName}_{empty}", _dirtyAssets);

            blendTree.AddChild(emptyClip);

            for (var i = 0; i < materials.Count; i++)
            {
                Material material      = materials[i];
                var      animationClip = AnimUtility.CreateAnimation(directory, $"{expName} [{i}] {material.name}", _dirtyAssets);
                AnimUtility.SetObjectReferenceKeyframe(animationClip, _renderer, $"m_Materials.Array.data[{_materialSlot}]", material, _dirtyAssets);
                blendTree.AddChild(animationClip);
                _dirtyAssets.Add(animationClip);
            }

            AnimatorStateTransition anyStateTransition = stateMachine.AddAnyStateTransition(state);

            anyStateTransition.AddCondition(AnimatorConditionMode.Greater, 0.01f, expName);

            AnimatorStateTransition exitTransition = state.AddExitTransition(false);

            exitTransition.AddCondition(AnimatorConditionMode.Less, 0.01f, expName);

            AnimUtility.AddVRCExpressionsParameter(_expressionInfo.AvatarDescriptor, VRCExpressionParameters.ValueType.Float, expName, _dirtyAssets);
            if (_expressionInfo.Menu != null)
            {
                AnimUtility.AddVRCExpressionsMenuControl(_expressionInfo.Menu, ControlType.RadialPuppet, expName, _dirtyAssets);
            }

            _dirtyAssets.SetDirty();
            controller.AddObjectsToAsset(stateMachine, empty, state, anyStateTransition, exitTransition, blendTree);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        static void AddExit(AnimatorState start, AnimatorState end, float _exitTime = 1, float _duration = 0)
        {
            AnimatorStateTransition tempTransition = start.AddExitTransition();

            tempTransition.destinationState = end;
            tempTransition.hasExitTime      = true;
            tempTransition.exitTime         = _exitTime;
            tempTransition.duration         = _duration;
        }
Exemple #6
0
        private void CopyOrCreateExitTransition(AnimatorStateTransition refTransition, AnimatorState outState)
        {
            AnimatorStateTransition outTransition = FindExitTransition(outState);

            if (outTransition == null)
            {
                outTransition = outState.AddExitTransition();
            }
            CopyStateTransition(refTransition, outTransition);
        }
    /// <summary>
    /// Show how to relate exitState and anyState
    /// </summary>
    private void CreateDeath()
    {
        AnimationClip deathClip = AnimatorFactoryUtil.LoadAnimClip(AnimationPath + "WalkTurn.FBX");

        stateDeath = baseLayerMachine.AddState("Death", new Vector3(200f, 100f));
        productController.SetStateEffectiveMotion(stateDeath, deathClip);

        // death to exit
        var exitTransition = stateDeath.AddExitTransition();

        exitTransition.AddCondition(AnimatorConditionMode.If, 0, "TriggerA");
        exitTransition.duration = 0;

        // anyState to death
        var anyTransition = baseLayerMachine.AddAnyStateTransition(stateDeath);

        anyTransition.AddCondition(AnimatorConditionMode.If, 0, "TriggerB");
        anyTransition.duration = 0;
    }
        public void Build()
        {
            var expressionActiveState = _controller.ContentFrame.Q <Toggle>("expression-active-state");
            var expressionObject      = _controller.ContentFrame.Q <ObjectField>("expression-object");

            var expName    = _expressionInfo.ExpressionName;
            var controller = _expressionInfo.Controller;

            AnimatorControllerLayer layer = AnimUtility.AddLayer(controller, expName, _dirtyAssets);

            controller.AddParameter(expName, AnimatorControllerParameterType.Bool);

            AnimatorStateMachine stateMachine = layer.stateMachine;
            var empty = AnimUtility.AddState(stateMachine, "Empty", true, _dirtyAssets);

            AnimatorState toggleState = AnimUtility.AddState(stateMachine, expName, false, _dirtyAssets);

            var animationClip = AnimUtility.CreateAnimation(_expressionInfo.AnimationsFolder.GetPath(), expName, _dirtyAssets);

            AnimUtility.SetObjectReferenceKeyframe(animationClip, _renderer, $"m_Materials.Array.data[{_materialSlot}]", _material, _dirtyAssets);
            _dirtyAssets.Add(animationClip);
            toggleState.motion = animationClip;

            AnimatorStateTransition anyStateTransition = stateMachine.AddAnyStateTransition(toggleState);

            anyStateTransition.AddCondition(AnimatorConditionMode.If, 1, expName);

            AnimatorStateTransition exitTransition = toggleState.AddExitTransition(false);

            exitTransition.AddCondition(AnimatorConditionMode.IfNot, 0, expName);

            AnimUtility.AddVRCExpressionsParameter(_expressionInfo.AvatarDescriptor, VRCExpressionParameters.ValueType.Bool, expName, _dirtyAssets);
            if (_expressionInfo.Menu != null)
            {
                AnimUtility.AddVRCExpressionsMenuControl(_expressionInfo.Menu, ControlType.Toggle, expName, _dirtyAssets);
            }

            _dirtyAssets.SetDirty();
            controller.AddObjectsToAsset(stateMachine, toggleState, anyStateTransition, exitTransition, empty);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        public void Build()
        {
            var expName    = _expressionInfo.ExpressionName;
            var controller = _expressionInfo.Controller;

            AnimatorControllerLayer layer = AnimUtility.AddLayer(controller, expName, _dirtyAssets);

            controller.AddParameter(expName, AnimatorControllerParameterType.Bool);

            AnimatorStateMachine stateMachine = layer.stateMachine;
            var empty = AnimUtility.AddState(stateMachine, "Empty", true, _dirtyAssets);

            AnimatorState toggleState = AnimUtility.AddState(stateMachine, expName, false, _dirtyAssets);

            if (_createAnimation)
            {
                var animationClip = AnimUtility.CreateAnimation(_expressionInfo.AnimationsFolder.GetPath(), expName, _dirtyAssets);
                toggleState.motion = animationClip;
            }

            AnimatorStateTransition anyStateTransition = stateMachine.AddAnyStateTransition(toggleState);

            anyStateTransition.AddCondition(AnimatorConditionMode.If, 1, expName);

            AnimatorStateTransition exitTransition = toggleState.AddExitTransition(false);

            exitTransition.AddCondition(AnimatorConditionMode.IfNot, 0, expName);

            AnimUtility.AddVRCExpressionsParameter(_expressionInfo.AvatarDescriptor, ValueType.Bool, expName, _dirtyAssets);
            if (_expressionInfo.Menu != null)
            {
                AnimUtility.AddVRCExpressionsMenuControl(_expressionInfo.Menu, ControlType.Toggle, expName, _dirtyAssets);
            }

            _dirtyAssets.SetDirty();
            controller.AddObjectsToAsset(stateMachine, toggleState, anyStateTransition, exitTransition, empty);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Exemple #10
0
        // Set clip and states
        static int SetStates(AnimatorStateMachine stateMachine, AnimationClip clip)
        {
            // Empty entry state
            AnimatorState emptyState = stateMachine.AddState("EmptyState");

            emptyState.speed = 0;
            emptyState.writeDefaultValues = false;

            // Animation state
            AnimatorState recordState = stateMachine.AddState(clip.name);

            recordState.motion = clip;
            recordState.tag    = clip.name + "Tag";

            // Exit transition
            AnimatorStateTransition exitTransition = recordState.AddExitTransition();

            exitTransition.duration    = 0;
            exitTransition.hasExitTime = true;

            return(recordState.nameHash);
        }
Exemple #11
0
    /* Create AnimationController when imports */
    static void CreateController(string path, AnimationClip[] clips)
    {
        // Creates the controller
        AnimatorController controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(path);

        var           rootStateMachine = controller.layers[0].stateMachine;
        AnimatorState idleState        = rootStateMachine.AddState("Idle");

        idleState.motion = clips[0];         // Beta/test@walking

        idleState.AddExitTransition(idleState);

        // Add parameters
        controller.AddParameter("TransitionNow", AnimatorControllerParameterType.Trigger);
        controller.AddParameter("Reset", AnimatorControllerParameterType.Trigger);
        controller.AddParameter("GotoB1", AnimatorControllerParameterType.Trigger);
        controller.AddParameter("GotoC", AnimatorControllerParameterType.Trigger);

        // Add StateMachines
        var rootStateMachine = controller.layers[0].stateMachine;
        var stateMachineA    = rootStateMachine.AddStateMachine("smA");
        var stateMachineB    = rootStateMachine.AddStateMachine("smB");
        var stateMachineC    = stateMachineB.AddStateMachine("smC");

        // Add States
        var stateA1 = stateMachineA.AddState("stateA1");
        var stateB1 = stateMachineB.AddState("stateB1");
        var stateB2 = stateMachineB.AddState("stateB2");

        stateMachineC.AddState("stateC1");               // Blend Tree ?
        var stateC2 = stateMachineC.AddState("stateC2"); // don’t add an entry transition, should entry to state by default

        // Add Transitions
        var exitTransition = stateA1.AddExitTransition();

        exitTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "TransitionNow");
        exitTransition.duration = 0;

        var resetTransition = stateMachineA.AddAnyStateTransition(stateA1);

        resetTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "Reset");
        resetTransition.duration = 0;

        var transitionB1 = stateMachineB.AddEntryTransition(stateB1);

        transitionB1.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "GotoB1");

        stateMachineB.AddEntryTransition(stateB2);

        stateMachineC.defaultState = stateC2;

        var exitTransitionC2 = stateC2.AddExitTransition();

        exitTransitionC2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "TransitionNow");
        exitTransitionC2.duration = 0;

        var stateMachineTransition = rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineC);

        stateMachineTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "GotoC");
        rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineB);
    }
Exemple #12
0
        public static AnimatorState CloneDeep(this AnimatorState source)
        {
            var dest = new AnimatorState
            {
                cycleOffset                = source.cycleOffset,
                cycleOffsetParameter       = source.cycleOffsetParameter,
                cycleOffsetParameterActive = source.cycleOffsetParameterActive,
                iKOnFeet              = source.iKOnFeet,
                mirror                = source.mirror,
                mirrorParameter       = source.mirrorParameter,
                mirrorParameterActive = source.mirrorParameterActive,
                motion                = source.motion,
                speed                = source.speed,
                speedParameter       = source.speedParameter,
                speedParameterActive = source.speedParameterActive,
                tag                 = source.tag,
                timeParameter       = source.timeParameter,
                timeParameterActive = source.timeParameterActive,
                writeDefaultValues  = source.writeDefaultValues,
                name                = source.name,
                hideFlags           = source.hideFlags
            };

            foreach (var sourceTransition in source.transitions.Where(w => w.isExit))
            {
                var transition = dest.AddExitTransition(false);
                sourceTransition.ApplyTo(transition);

                InstanceCache <AnimatorStateTransition> .SafeRegister(sourceTransition.GetInstanceID(), transition);
            }

            foreach (var sourceTransition in source.transitions.Where(w => !w.isExit))
            {
                AnimatorStateTransition transition = null;
                if (sourceTransition.destinationStateMachine != null)
                {
                    transition = dest.AddTransition(InstanceCache <AnimatorStateMachine> .FindOrCreate(sourceTransition.destinationStateMachine, w => w.CloneDeep()));
                }

                if (sourceTransition.destinationState != null)
                {
                    transition = dest.AddTransition(InstanceCache <AnimatorState> .FindOrCreate(sourceTransition.destinationState, w => w.CloneDeep()));
                }

                if (transition == null)
                {
                    throw new ArgumentNullException(nameof(transition));
                }

                sourceTransition.ApplyTo(transition);

                InstanceCache <AnimatorStateTransition> .SafeRegister(sourceTransition.GetInstanceID(), transition);
            }

            foreach (var sourceBehaviour in source.behaviours)
            {
                var behaviour = dest.AddStateMachineBehaviour(sourceBehaviour.GetType());
                sourceBehaviour.ApplyTo(behaviour);

                InstanceCache <StateMachineBehaviour> .SafeRegister(behaviour.GetInstanceID(), behaviour);
            }

            return(dest);
        }
Exemple #13
0
        public bool BurnTracks(List <AudioClip> libAssets)
        {
            if (null == fxAnimator)
            {
                throw new System.Exception("We need your FX Animator Controller");
            }
            if (null == AudioClip)
            {
                throw new System.Exception("We need an AudioClip from your Song Library");
            }
            if (null == _8TrackObject)
            {
                throw new System.Exception("8Track object was not set");
            }
            _8TrackObject.SetActive(false);

            int childIndex = 0;

            while (true)
            {
                if (0 == _8TrackObject.transform.childCount || childIndex >= _8TrackObject.transform.childCount)
                {
                    break;
                }
                else if (_8TrackObject.transform.GetChild(childIndex).gameObject.name.StartsWith("Track"))
                {
                    Debug.Log("deleting child " + _8TrackObject.transform.GetChild(childIndex).gameObject.name);
                    DestroyImmediate(_8TrackObject.transform.GetChild(childIndex).gameObject);
                }
                else
                {
                    childIndex++;
                }
            }

            RemoveExistingAnimatorLayer(fxAnimator, _8TrackObject.name);
            HandleAnimatorParameters(fxAnimator, _8TrackObject.name);

            //--- --- Volume Animation Controller --- ---
            AnimationClip volumeSet = new AnimationClip {
                name = VolumeEPName
            };

            //--- --- Track Animation Controller --- ---
            AnimatorControllerLayer trackLayer = new AnimatorControllerLayer {
                name          = _8TrackObject.name,
                defaultWeight = 1,
                stateMachine  = new AnimatorStateMachine()
                {
                    name = _8TrackObject.name
                }
            };

            fxAnimator.AddLayer(trackLayer);
            AnimatorStateMachine stateMachine = trackLayer.stateMachine;

            //--- --- No Track --- ---
            int           trackCount   = 0;
            AnimatorState defaultState = stateMachine.AddState("Stop");

            defaultState.speed = 100;
            AnimatorStateTransition anyToWait = stateMachine.AddAnyStateTransition(defaultState);

            anyToWait.AddCondition(AnimatorConditionMode.Equals, trackCount, TrackEPName);
            anyToWait.hasExitTime = true;
            anyToWait.exitTime    = 0;
            anyToWait.duration    = 0;

            AnimatorState loopState = stateMachine.AddState("LoopOff");

            loopState.speed = 100;
            if (!PlayerLoops)
            {
                PersistAnimator(fxAnimator);
                VRCAvatarParameterDriver driver = loopState.AddStateMachineBehaviour <VRCAvatarParameterDriver>();
                driver.parameters.Add(new VRC.SDKBase.VRC_AvatarParameterDriver.Parameter()
                {
                    name  = TrackEPName,
                    value = 0,
                    type  = VRC.SDKBase.VRC_AvatarParameterDriver.ChangeType.Set
                });
            }
            AnimatorStateTransition loopExit = loopState.AddExitTransition();

            loopExit.hasExitTime = true;
            loopExit.exitTime    = 0;
            loopExit.duration    = 0;

            //--- --- All Tracks --- ---
            foreach (Object asset in libAssets)
            {
                if (asset is AudioClip)
                {
                    //Animation setup
                    string trackName = "Track " + ++trackCount;

                    AnimationClip tracktoggle = new AnimationClip {
                        name = trackName
                    };

                    AudioClip clip = asset as AudioClip;

                    tracktoggle.SetCurve(_8TrackObject.name, typeof(GameObject), "m_IsActive", AnimationCurve.Linear(0.0f, 1f, clip.length, 1f));
                    tracktoggle.SetCurve(_8TrackObject.name + "/" + trackName, typeof(GameObject), "m_IsActive", AnimationCurve.Linear(0.0f, 1f, clip.length, 1f));
                    AnimatorState state = stateMachine.AddState(trackName);
                    state.motion = tracktoggle;
                    AnimatorStateTransition toTrack = defaultState.AddTransition(state);
                    toTrack.AddCondition(AnimatorConditionMode.Equals, trackCount, TrackEPName);
                    toTrack.hasExitTime = true;
                    toTrack.exitTime    = 0;
                    toTrack.duration    = 0;
                    AnimatorStateTransition trackOut = state.AddTransition(loopState);
                    trackOut.hasExitTime = true;
                    trackOut.exitTime    = 1;
                    trackOut.duration    = 0;
                    AnimatorStateTransition trackSwitch = state.AddTransition(defaultState);
                    trackSwitch.AddCondition(AnimatorConditionMode.NotEqual, trackCount, TrackEPName);
                    trackSwitch.duration = 0;
                    Avatar8Track.CreateAsset(AudioClip, tracktoggle, trackName + ".anim");

                    //volume
                    volumeSet.SetCurve(_8TrackObject.name + "/" + trackName, typeof(AudioSource), "m_Volume", AnimationCurve.Linear(0.0f, 0f, 0.033333335f, 1f));

                    //Object setup
                    GameObject trackObject = new GameObject(trackName, new System.Type[] { typeof(AudioSource) });
                    trackObject.transform.SetParent(_8TrackObject.transform);
                    trackObject.SetActive(false);
                    //trackObject.AddComponent<AudioSource>();
                    Avatar8Track.CopyComponent(_8TrackObject.GetComponent <AudioSource>(), trackObject.GetComponent <AudioSource>());
                    AudioSource source = trackObject.GetComponent <AudioSource>();
                    source.enabled   = true;
                    source.clip      = clip;
                    trackObject.name = trackName;
                }
            }

            fxAnimator.AddLayer(CreateVolumeLayer(_8TrackObject.name, VolumeEPName, volumeSet));
            PersistAnimator(fxAnimator);

            return(true);
        }
Exemple #14
0
	private static AnimatorController GenerateTEA_Animator(TEA_Manager manager) {
	 // --- TEA  ---
	 AnimatorController teaAnimContr = AssetDatabase.LoadAssetAtPath<AnimatorController>(AssetDatabase.GetAssetPath(manager.TEA_Animations));
	 while(teaAnimContr.layers.Length > 0) {
		teaAnimContr.RemoveLayer(0);
	 }
	 AnimatorStateMachine stateD = new AnimatorStateMachine();
	 teaAnimContr.AddLayer(new AnimatorControllerLayer() {
		name = AvatarController.TEA_HAND_LAYER,
		defaultWeight = 1,
		avatarMask = manager.AvatarMaskArms,
		stateMachine = stateD
	 });

	 //default
	 stateD.defaultState = stateD.AddState("Default");

	 manager.TEA_AnimationClips.ClearOptions();
	 List<Dropdown.OptionData> options = new List<Dropdown.OptionData>();

	 int count = 0;
	 List<AnimationClip> armClips = GetAnimationClips("Assets/TEA Manager/Resources/Animation/TEA Animations/TEA Hand Animations");
	 foreach(AnimationClip clip in armClips) {
		AnimatorState state = stateD.AddState(clip.name);
		state.motion = clip;
		stateD.defaultState.AddTransition(state).AddCondition(AnimatorConditionMode.Equals, count, AvatarController.TEA_ANIM_PARAM);
		state.AddExitTransition().AddCondition(AnimatorConditionMode.NotEqual, count, AvatarController.TEA_ANIM_PARAM);

		Dropdown.OptionData option = new Dropdown.OptionData(clip.name);
		options.Add(option);
		count++;
	 }//for

	 manager.GetComponent<AvatarController>().TEA_HAND_LAYER_COUNT = count;

	 // --- Full Body Animations
	 AnimatorStateMachine stateM = new AnimatorStateMachine();
	 teaAnimContr.AddLayer(new AnimatorControllerLayer() {
		name = AvatarController.TEA_LAYER,
		defaultWeight = 0,
		avatarMask = manager.AvatarMaskAll,
		stateMachine = stateM
	 });

	 stateM.defaultState = stateM.AddState("Default");

	 // dynamic
	 foreach(string folder in AssetDatabase.GetSubFolders("Assets/TEA Manager/Resources/Animation/TEA Animations")) {
		string name = folder.Substring(folder.LastIndexOf('/') + 1);
		if("TEA Hand Animations" == name)
		 continue;
		Dropdown.OptionData option = new Dropdown.OptionData(name);
		options.Add(option);
		AnimationClip start = null;
		AnimationClip loop = null;
		foreach(AnimationClip clip in GetAnimationClips(folder)) {
		 if(clip.name.Contains("intro") || clip.name.Contains("Intro")) {
			start = clip;
		 } else
			loop = clip;
		}//for
		AnimatorState state = stateM.AddState(name);
		state.motion = loop;
		if(null != start) {
		 AnimatorState startState = stateM.AddState(name + "-intro");
		 startState.motion = start;
		 stateM.defaultState.AddTransition(startState).AddCondition(AnimatorConditionMode.Equals, count, AvatarController.TEA_ANIM_PARAM);
		 startState.AddTransition(state).hasExitTime = true;
		} else {
		 stateM.defaultState.AddTransition(state).AddCondition(AnimatorConditionMode.Equals, count, AvatarController.TEA_ANIM_PARAM);
		}
		state.AddExitTransition().AddCondition(AnimatorConditionMode.NotEqual, count, AvatarController.TEA_ANIM_PARAM);
		count++;
	 }//for
	 manager.TEA_AnimationClips.AddOptions(options);
	 AssetDatabase.SaveAssets();
	 return teaAnimContr;
	}
        public static void Apply(this AnimatorState dest, AnimatorState source)
        {
            dest.cycleOffsetParameter       = source.cycleOffsetParameter;
            dest.cycleOffset                = source.cycleOffset;
            dest.cycleOffsetParameterActive = source.cycleOffsetParameterActive;
            dest.iKOnFeet              = source.iKOnFeet;
            dest.mirror                = source.mirror;
            dest.mirrorParameter       = source.mirrorParameter;
            dest.mirrorParameterActive = source.mirrorParameterActive;
            dest.motion                = source.motion; // keep reference
            dest.speed                = source.speed;
            dest.speedParameter       = source.speedParameter;
            dest.speedParameterActive = source.speedParameterActive;
            dest.tag                 = source.tag;
            dest.timeParameter       = source.timeParameter;
            dest.timeParameterActive = source.timeParameterActive;
            dest.writeDefaultValues  = source.writeDefaultValues;
            dest.name                = source.name;
            dest.hideFlags           = source.hideFlags;

            foreach (var sourceTransition in source.transitions.Where(w => w.isExit))
            {
                var transition = dest.AddExitTransition(false);
                sourceTransition.CloneTo(transition);

                // should always false
                if (InstanceCaches <AnimatorStateTransition> .Find(sourceTransition.GetInstanceID()) == null)
                {
                    InstanceCaches <AnimatorStateTransition> .Register(sourceTransition.GetInstanceID(), transition);
                }
            }

            foreach (var sourceTransition in source.transitions.Where(w => !w.isExit))
            {
                AnimatorStateTransition transition = null;
                if (sourceTransition.destinationStateMachine != null)
                {
                    transition = dest.AddTransition(InstanceCaches <AnimatorStateMachine> .FindOrCreate(sourceTransition.destinationStateMachine, w => w.CloneDeep()));
                }

                if (sourceTransition.destinationState != null)
                {
                    transition = dest.AddTransition(InstanceCaches <AnimatorState> .FindOrCreate(sourceTransition.destinationState, CloneDeep));
                }

                if (transition == null)
                {
                    throw new ArgumentNullException(nameof(transition));
                }

                sourceTransition.CloneTo(transition);

                // should always false
                if (InstanceCaches <AnimatorStateTransition> .Find(sourceTransition.GetInstanceID()) == null)
                {
                    InstanceCaches <AnimatorStateTransition> .Register(sourceTransition.GetInstanceID(), transition);
                }
            }

            foreach (var sourceBehaviour in source.behaviours)
            {
                var behaviour = dest.AddStateMachineBehaviour(sourceBehaviour.GetType());
                sourceBehaviour.CloneDeepTo(behaviour);

                // store
                InstanceCaches <StateMachineBehaviour> .Register(behaviour.GetInstanceID(), behaviour);
            }
        }
 internal Transitionist Exits()
 {
     return(new Transitionist(NewDefaultTransition(State.AddExitTransition())));
 }
        static void CreateController()
        {
            // Creates the controller
            AnimatorController controller = AnimatorController.CreateAnimatorControllerAtPath("Assets/Animations/Motion.controller");

            // Add Animation Clips
            AnimationClip clip = new AnimationClip();

            clip.frameRate = 24;
            AssetDatabase.CreateAsset(clip, "Assets/Animations/Motion.anim");
            AssetDatabase.SaveAssets();

            // Add parameters
            controller.AddParameter("TransitionNow", AnimatorControllerParameterType.Trigger);
            controller.AddParameter("Reset", AnimatorControllerParameterType.Trigger);
            controller.AddParameter("GotoB1", AnimatorControllerParameterType.Trigger);
            controller.AddParameter("GotoC", AnimatorControllerParameterType.Trigger);

            // Add StateMachines
            AnimatorStateMachine rootStateMachine = controller.layers[0].stateMachine;
            AnimatorStateMachine stateMachineA    = rootStateMachine.AddStateMachine("smA");
            AnimatorStateMachine stateMachineB    = rootStateMachine.AddStateMachine("smB");
            AnimatorStateMachine stateMachineC    = stateMachineB.AddStateMachine("smC");

            // Add Clip


            // Add States
            AnimatorState stateA1 = stateMachineA.AddState("stateA1");
            AnimatorState stateB1 = stateMachineB.AddState("stateB1");
            AnimatorState stateB2 = stateMachineB.AddState("stateB2");

            stateMachineC.AddState("stateC1");
            AnimatorState stateC2 = stateMachineC.AddState("stateC2"); // don’t add an entry transition, should entry to state by default

            // Add clip
            stateA1.motion = clip;

            // Add Transitions
            AnimatorStateTransition exitTransition = stateA1.AddExitTransition();

            exitTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "TransitionNow");
            exitTransition.duration = 0;

            AnimatorStateTransition resetTransition = rootStateMachine.AddAnyStateTransition(stateA1);

            resetTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "Reset");
            resetTransition.duration = 0;

            AnimatorTransition transitionB1 = stateMachineB.AddEntryTransition(stateB1);

            transitionB1.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "GotoB1");
            stateMachineB.AddEntryTransition(stateB2);
            stateMachineC.defaultState = stateC2;
            AnimatorStateTransition exitTransitionC2 = stateC2.AddExitTransition();

            exitTransitionC2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "TransitionNow");
            exitTransitionC2.duration = 0;

            AnimatorTransition stateMachineTransition = rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineC);

            stateMachineTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "GotoC");
            rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineB);
        }