/// <summary> /// Show how to add a 1D tree /// </summary> private void CreateMove() { // Load Animation AnimationClip walkClip = AnimatorFactoryUtil.LoadAnimClip(AnimationPath + "Walk.FBX"); AnimationClip runClip = AnimatorFactoryUtil.LoadAnimClip(AnimationPath + "Run.FBX"); // new a tree BlendTree tree = new BlendTree(); // Set blendtree parameters tree.name = "Move"; tree.blendType = BlendTreeType.Simple1D; tree.useAutomaticThresholds = true; tree.minThreshold = 0f; tree.maxThreshold = 1f; tree.blendParameter = "FloatA"; // Add clip to BlendTree tree.AddChild(walkClip, 0f); tree.AddChild(runClip, 1f); // Add tree to controller asset if (AssetDatabase.GetAssetPath(productController) != string.Empty) { AssetDatabase.AddObjectToAsset(tree, AssetDatabase.GetAssetPath(productController)); } // add tree state & set state motion stateMove = baseLayerMachine.AddState(tree.name, new Vector3(600f, 0f)); stateMove.motion = tree; }
/// <summary> /// Show how to set speed parameter, And set state motion in other way /// </summary> /// <param name="fbxPath"></param> private void CreateCrouchIdle(string fbxPath) { // Load Animation AnimationClip idleClip = AnimatorFactoryUtil.LoadAnimClip(fbxPath, "HumanoidCrouchIdle"); stateIdle = crouchLayerMachine.AddState("Idle", new Vector3(300f, 0f)); stateIdle.speedParameterActive = true; stateIdle.speedParameter = "FloatA"; // Set state motion,the other way productController.SetStateEffectiveMotion(stateIdle, idleClip); // set to default state crouchLayerMachine.defaultState = stateIdle; }
/// <summary> /// Show how to add a basic state, And add a behaviour /// </summary> private void CreateIdle() { // Load Animation AnimationClip idleClip = AnimatorFactoryUtil.LoadAnimClip(AnimationPath + "Idle.FBX"); // add tree state & set state motion stateIdle = baseLayerMachine.AddState("Idle", new Vector3(300f, 0f)); stateIdle.motion = idleClip; // Add behaviour to state stateIdle.AddStateMachineBehaviour <CharacterIdleState>(); // set to default state baseLayerMachine.defaultState = stateIdle; }
/// <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; }
/// <summary> /// Show how to add a child machine /// </summary> /// <param name="fbxPath"></param> private void CreateCrouchWalk(string fbxPath) { AnimatorStateMachine walkMachine = crouchLayerMachine.AddStateMachine("Walk", new Vector3(0f, 100f)); walkMachine.entryPosition = Vector3.zero; walkMachine.anyStatePosition = new Vector3(0f, -200f); walkMachine.exitPosition = new Vector3(0f, -400f); AnimationClip walkClip = AnimatorFactoryUtil.LoadAnimClip(fbxPath, "HumanoidCrouchWalk"); AnimationClip walkLeftClip = AnimatorFactoryUtil.LoadAnimClip(fbxPath, "HumanoidCrouchWalkLeft"); AnimationClip walkRightClip = AnimatorFactoryUtil.LoadAnimClip(fbxPath, "HumanoidCrouchWalkRight"); stateWalk = walkMachine.AddState("Walk", new Vector3(200f, 0f)); stateWalk.motion = walkClip; stateWalkLeft = walkMachine.AddState("WalkLeft", new Vector3(200f, -200f)); stateWalkLeft.motion = walkLeftClip; stateWalkRight = walkMachine.AddState("WalkRight", new Vector3(200f, -400f)); stateWalkRight.motion = walkRightClip; }
/// <summary> /// Show how to add 2D tree /// </summary> private void CreateJump() { // Load Animation string fbxPath = AnimationPath + "IdleJumpUp.FBX"; AnimationClip fallClip = AnimatorFactoryUtil.LoadAnimClip(fbxPath, "HumanoidFall"); AnimationClip idleJumpUpClip = AnimatorFactoryUtil.LoadAnimClip(fbxPath, "HumanoidIdleJumpUp"); AnimationClip jumpUpClip = AnimatorFactoryUtil.LoadAnimClip(fbxPath, "HumanoidJumpUp"); AnimationClip midAirClip = AnimatorFactoryUtil.LoadAnimClip(fbxPath, "HumanoidMidAir"); // create a tree BlendTree tree = new BlendTree(); // Set blendtree parameters tree.name = "Jump"; tree.blendType = BlendTreeType.FreeformDirectional2D; tree.useAutomaticThresholds = true; tree.minThreshold = 0f; tree.maxThreshold = 1f; tree.blendParameter = "FloatA"; tree.blendParameterY = "FloatB"; // Add clip to BlendTree tree.AddChild(fallClip, new Vector2(0f, 0f)); tree.AddChild(idleJumpUpClip, new Vector2(0f, 1f)); tree.AddChild(jumpUpClip, new Vector2(1f, 0f)); tree.AddChild(midAirClip, new Vector2(-1f, 0f)); // Add tree to controller asset if (AssetDatabase.GetAssetPath(productController) != string.Empty) { AssetDatabase.AddObjectToAsset(tree, AssetDatabase.GetAssetPath(productController)); } // add tree state & set state motion stateJump = baseLayerMachine.AddState(tree.name, new Vector3(300f, -100f)); stateJump.motion = tree; }