Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using Vexe.Runtime.Types;
- using System.Collections.Generic;
- public partial class ExplodingGrubController : PossessableUnit
- {
- [DontSerialize][Show]
- public StanceManager StanceMgr;
- void LoadStanceManager()
- {
- StanceMgr = gameObject.AddComponent<StanceManager>();
- StanceMgr.Unit = this;
- StanceMgr.skeleton = GetComponentInChildren<SkeletonAnimation>();
- List<Stance> StanceList = new List<Stance>()
- {
- // Movement
- new Stance { Name = "Idle", Animation = "Idle", Looping = true, BundleNames = {"Common", "Ground"}, },
- new Stance { Name = "Move Forward", Animation = "Walk", Looping = true, BundleNames = {"Common", "Ground"}, },
- new Stance { Name = "Move Backward", Animation = "Walk", Looping = true, BundleNames = {"Common", "Ground"}, },
- // Burrow
- new Stance { Name = "Burrow Start", Animation = "Burrow Start", Looping = false, BundleNames = {"Burrow"}, },
- new Stance { Name = "Burrow Loop", Animation = "Burrow Loop", Looping = true, BundleNames = {"Burrow"}, },
- new Stance { Name = "Burrow End", Animation = "Burrow End", Looping = false, BundleNames = {}, },
- new Stance { Name = "Burrow Leap Start", Animation = "Burrow Leap Start", Looping = false, BundleNames = {}, },
- new Stance { Name = "Burrow Leap Start Delayed", Animation = "Burrow Leap Start Delayed", Looping = false, BundleNames = {}, },
- new Stance { Name = "Burrow Leap Start Reaction", Animation = "Burrow Leap Start Reaction", Looping = false, BundleNames = {}, },
- new Stance { Name = "Burrow Leap Arc", Animation = "Burrow Leap Arc", Looping = false, BundleNames = {"Common"}, },
- new Stance { Name = "Burrow Leap Down", Animation = "Burrow Leap Straight Down", Looping = true, BundleNames = {"Common"}, },
- new Stance { Name = "Burrow Leap Up", Animation = "Burrow Leap Straight Up", Looping = true, BundleNames = {"Common"}, },
- new Stance { Name = "Burrow Leap End", Animation = "Burrow Leap End", Looping = false, BundleNames = {}, },
- // Air
- new Stance { Name = "Jump Start", Animation = "Jump Start", Looping = false, BundleNames = {}, },
- new Stance { Name = "Jump Upward", Animation = "Jump Loop", Looping = true, BundleNames = {"Air Common"}, },
- new Stance { Name = "Jump Falling", Animation = "Jump Loop", Looping = true, BundleNames = {"Air Common"}, },
- new Stance { Name = "Jump Landing", Animation = "Jump Landing", Looping = false, BundleNames = {}, },
- new Stance { Name = "Spin Start", Animation = "Spin Start", Looping = false, BundleNames = {"Spin"}, },
- new Stance { Name = "Spin Loop", Animation = "Spin Loop", Looping = true, BundleNames = {"Spin", "Common"}, },
- new Stance { Name = "Spin Explode", Animation = "Spin Explode", Looping = false, BundleNames = {}, },
- new Stance { Name = "Spin End", Animation = "Spin End", Looping = false, BundleNames = {}, },
- // One-Offs
- new Stance { Name = "Hit Reaction", Animation = "Hit Reaction", Looping = false, CanResume = false, StandardReactionRules = true },
- new Stance { Name = "Death", Animation = "Death", Looping = false, CanResume = false },
- new Stance { Name = "Dead", Animation = "Dead", Looping = true, },
- new Stance { Name = "Revive", Animation = "Revive", Looping = false, CanResume = false },
- // Attacks
- new Stance { Name = "Attack", Animation = "Attack", Looping = false, CanResume = false },
- new Stance { Name = "Explode", Animation = "Explode", Looping = false, CanResume = false },
- new Stance { Name = "Explode Death", Animation = "Explode Death", Looping = false, CanResume = false },
- new Stance { Name = "Explode Dead", Animation = "Explode Dead", Looping = true, CanResume = false },
- };
- Dictionary< string, BranchBundle > BranchBundles = new Dictionary< string, BranchBundle > ()
- {
- {
- "Common",
- new BranchBundle()
- {
- Name = "Common",
- Branches = new List<Branch>()
- {
- new Branch {
- Condition = context => { return this[PS.Health] <= 0; },
- NextStance = "Death",
- },
- new Branch {
- Signal = Signal.DoReaction,
- Action = DoReaction,
- NextStance = "Hit Reaction",
- },
- }
- }
- },
- {
- "Spin",
- new BranchBundle()
- {
- Name = "Spin",
- Branches = new List<Branch>()
- {
- new Branch {
- Condition = context => { return this[PS.HeldSpecial] && !this[PS.Grounded]; },
- NextStance = "Spin Explode",
- },
- new Branch {
- Condition = context => { return this[PS.Health] <= 0; },
- NextStance = "Death",
- },
- new Branch {
- Signal = Signal.DoReaction,
- Action = DoReaction,
- NextStance = "Hit Reaction",
- },
- new Branch
- {
- Label = "Cling to Ceiling",
- Condition = context => { return this["SpinWallDetection_N"] > -1f && this["SpinWallDetection_N"] < this["SpinSensorDistance"]; },
- Action = StickNorth,
- NextStance = "Spin End",
- NextStanceBlendTime = 0f,
- },
- new Branch
- {
- Label = "Cling to Floor",
- Condition = context => { return this["SpinWallDetection_S"] > -1f && this["SpinWallDetection_S"] < this["SpinSensorDistance"] && !ShouldFall(context); },
- Action = StickSouth,
- NextStance = "Spin End",
- NextStanceBlendTime = 0f,
- },
- new Branch
- {
- Label = "Cling to Front",
- Condition = context => { return this["SpinWallDetection_E"] > -1f && this["SpinWallDetection_E"] < this["SpinSensorDistance"]; },
- Action = StickEast,
- NextStance = "Spin End",
- NextStanceBlendTime = 0f,
- },
- new Branch
- {
- Label = "Cling to West",
- Condition = context => { return this["SpinWallDetection_W"] > -1f && this["SpinWallDetection_W"] < this["SpinSensorDistance"]; },
- Action = StickWest,
- NextStance = "Spin End",
- NextStanceBlendTime = 0f,
- },
- }
- }
- },
- {
- "Ground",
- new BranchBundle()
- {
- Name = "Ground",
- Branches = new List<Branch>()
- {
- new Branch {
- Condition = context => { return this[PS.HeldAttack]; },
- NextStance = "Attack",
- },
- new Branch {
- Condition = context => { return this[PS.HeldSpecial] && this[PS.Grounded]; },
- NextStance = "Explode",
- },
- new Branch {
- Condition = context => { return this[PS.InputForward] > 0.1f && this[PS.WallInFront] == false; },
- ResetBones = true,
- NextStance = "Move Forward",
- },
- new Branch {
- Condition = context => { return this[PS.InputForward] <-0.1f && this[PS.BackToTheWall] == false; },
- ResetBones = true,
- NextStance = "Move Forward",
- Action = FlipDirection,
- },
- new Branch {
- Label = "Wall In Front",
- Priority = 0,
- Condition = context => { return this[PS.WallInFront] && this[PS.InputForward] > 0.1f; },
- NextStance = "Idle",
- },
- new Branch {
- Label = "Wall Behind",
- Priority = 0,
- Condition = context => { return (this[PS.BackToTheWall] && this[PS.InputForward] < -0.1f); },
- NextStance = "Idle",
- },
- new Branch {
- Signal = Signal.DoJump,
- Condition = context => { return this[PS.Grounded]; },
- NextStance = "Jump Start",
- },
- new Branch {
- Condition = ShouldFall,
- NextStance = "Jump Falling",
- },
- new Branch {
- Condition = context => { return this[PS.Grounded] && this[PS.InputUpward] < -0.1f; },
- NextStance = "Burrow Start",
- },
- }
- }
- },
- {
- "Air Common",
- new BranchBundle()
- {
- Name = "Air Common",
- Branches = new List<Branch>()
- {
- new Branch {
- Condition = context => { return !ShouldFall(context); },
- NextStance = "Jump Landing",
- },
- new Branch {
- Priority = 2,
- Condition = context => { return this[PS.HeldSwitch] && this[PS.Grounded] == false; },
- NextStance = "Spin Start",
- },
- },
- }
- },
- };
- // Stance:Branch Map
- Dictionary<string, List<Branch> > StanceBranches = new Dictionary<string, List<Branch> > ()
- {
- {
- "Attack",
- new List<Branch>()
- {
- new Branch
- {
- Signal = Signal.StanceEnter,
- Action = Attack,
- },
- new Branch
- {
- On = 1.0f,
- NextStance = StanceManager.PreviousStance,
- },
- new Branch
- {
- On = 0.8f,
- Condition = context => { return this[PS.HeldAttack]; },
- NextStance = StanceManager.ResetStance,
- },
- }
- },
- {
- "Hit Reaction",
- new List<Branch>()
- {
- new Branch
- {
- On = 1.0f,
- NextStance = StanceManager.PreviousStance,
- },
- }
- },
- {
- "Move Forward",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceEnter,
- Action = MoveForward,
- },
- new Branch {
- Condition = context => { return this[PS.InputForward] < 0.1f; },
- NextStance = "Idle",
- },
- }
- },
- {
- "Move Backward",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceEnter,
- Action = MoveBackward,
- },
- new Branch {
- Condition = context => { return this[PS.InputForward] > -0.1f; },
- NextStance = "Idle",
- },
- }
- },
- {
- "Idle",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceEnter,
- Action = Idle,
- }
- }
- },
- // Spin
- {
- "Spin Start",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceEnter,
- Action = context => { Properties["Spin"] = true; return SignalDispatcher.BlockParent; },
- },
- new Branch {
- On = 1.0f,
- NextStance = "Spin Loop",
- },
- }
- },
- {
- "Spin Loop",
- new List<Branch>()
- {
- new Branch {
- Condition = context => { return this[PS.HeldSwitch] == false; },
- NextStance = "Spin End",
- },
- }
- },
- {
- "Spin Explode",
- new List<Branch>()
- {
- new Branch
- {
- On = 0.9f,
- Action = context =>
- {
- var t = StaticVisualHelpers.CreateUnitVFX ( this, Explosion, Vector3.zero );
- // 5.0 seconds is arbitrary to ensure cleanup
- Object.Destroy ( t, 1.0f );
- return SignalDispatcher.BlockParent;
- },
- },
- new Branch
- {
- On = 1.0f,
- NextStance = "Explode Death",
- },
- }
- },
- {
- "Spin End",
- new List<Branch>()
- {
- new Branch {
- On = 1.0f,
- NextStance = "Idle",
- Action = context => {
- StaticMovementHelper.ResetVelocity(this);
- StaticMovementHelper.RemoveAllMoversExceptGravity(this);
- Properties["Spin"] = false;
- return SignalDispatcher.BlockParent;
- },
- },
- }
- },
- // Burrower
- {
- "Burrow Start",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceEnter,
- Action = BurrowStart,
- },
- new Branch {
- On = 1.0f,
- NextStance = "Burrow Loop",
- },
- }
- },
- {
- "Burrow Loop",
- new List<Branch>()
- {
- new Branch {
- Condition = context => { return this[PS.InputUpward] > 0.1f; },
- NextStance = "Burrow End",
- },
- new Branch {
- ActionRunsPerStance = 3,
- Signal = Signal.DoDash,
- Action = context => { this.transform.position = this.transform.position + GetForwardVector() * BurrowTeleportDistance * context["AxisValue"]*GetForwardDirection(); return SignalDispatcher.BlockParent;}
- },
- new Branch {
- Signal = Signal.DoJump,
- Condition = context => { return this[PS.PlayerControlled];},
- CooldownAmount = 1.5f,
- NextStance = "Burrow Leap Start",
- },
- new Branch {
- Signal = Signal.DoJump,
- Condition = context => { return !this[PS.PlayerControlled];},
- CooldownAmount = 1.5f,
- NextStance = "Burrow Leap Start Delayed",
- },
- }
- },
- {
- "Burrow End",
- new List<Branch>()
- {
- new Branch {
- On = 1.0f,
- NextStance = "Idle",
- Action = BurrowEnd,
- },
- }
- },
- {
- "Burrow Leap Start",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceEnter,
- Action = LeapStart,
- },
- new Branch {
- On = 1.0f,
- Condition = context => { return this[PS.InputUpward] < 0.5f; },
- NextStance = "Burrow Leap Arc",
- },
- new Branch {
- On = 1.0f,
- Condition = context => { return this[PS.InputUpward] >= 0.5f; },
- NextStance = "Burrow Leap Up",
- },
- }
- },
- {
- "Burrow Leap Start Delayed",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceEnter,
- Action = LeapStart,
- },
- new Branch {
- Signal = Signal.TakeHit,
- NextStance = "Burrow Leap Start Reaction",
- },
- new Branch {
- On = 1.0f,
- Condition = context => { return this[PS.InputUpward] < 0.5f; },
- NextStance = "Burrow Leap Arc",
- },
- new Branch {
- On = 1.0f,
- Condition = context => { return this[PS.InputUpward] >= 0.5f; },
- NextStance = "Burrow Leap Up",
- },
- }
- },
- {
- "Burrow Leap Start Reaction",
- new List<Branch>()
- {
- new Branch {
- On = 1.0f,
- Actions = {
- BurrowEnd,
- KnockLoose,
- context =>
- {
- Properties[PS.AIState] = (Properties[PS.AIState] == ExplodingGrubBehaviours.BurrowAndArc) ? (int) ExplodingGrubBehaviours.ApproachAndExplode : (int) Properties[PS.AIState];
- return true;
- },
- },
- NextStance = "Spin Loop",
- }
- }
- },
- {
- "Burrow Leap Arc",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceEnter,
- Actions = {BurrowEnd, DoArcJump},
- },
- new Branch {
- On = 1.0f,
- NextStance = "Burrow Leap End",
- },
- new Branch {
- Signal = Signal.TakeHit,
- Actions =
- {
- KnockLoose,
- context =>
- {
- Properties[PS.AIState] = (Properties[PS.AIState] == ExplodingGrubBehaviours.BurrowAndArc) ? (int) ExplodingGrubBehaviours.ApproachAndExplode : (int) Properties[PS.AIState];
- return true;
- },
- },
- ResetBones = true,
- ApplyPose = "Idle",
- NextStance = "Spin Loop",
- },
- new Branch {
- Signal = Signal.DealBlock,
- Actions = { KnockLoose, context =>
- {
- Properties[PS.AIState] = (Properties[PS.AIState] == ExplodingGrubBehaviours.BurrowAndArc) ? (int) ExplodingGrubBehaviours.ApproachAndExplode : (int) Properties[PS.AIState];
- return true;
- },
- },
- ResetBones = true,
- ApplyPose = "Idle",
- NextStance = "Spin Loop",
- },
- new Branch
- {
- On = 0.25f,
- Label = "Cling to Ceiling",
- Condition = context => { return this["SpinWallDetection_N"] > -1f && this["SpinWallDetection_N"] < this["SpinSensorDistance"]; },
- Action = StickNorth,
- NextStance = "Burrow Leap End",
- NextStanceBlendTime = 0f,
- },
- new Branch
- {
- On = 0.25f,
- Label = "Cling to Floor",
- Condition = context => { return this["SpinWallDetection_S"] > -1f && this["SpinWallDetection_S"] < this["SpinSensorDistance"]; },
- Action = StickSouth,
- NextStance = "Burrow Leap End",
- NextStanceBlendTime = 0f,
- },
- new Branch
- {
- On = 0.25f,
- Label = "Cling to Front",
- Condition = context => { return this["SpinWallDetection_E"] > -1f && this["SpinWallDetection_E"] < this["SpinSensorDistance"]; },
- Action = StickEast,
- NextStance = "Burrow Leap End",
- NextStanceBlendTime = 0f,
- },
- new Branch
- {
- On = 0.25f,
- Label = "Cling to West",
- Condition = context => { return this["SpinWallDetection_W"] > -1f && this["SpinWallDetection_W"] < this["SpinSensorDistance"]; },
- Action = StickWest,
- NextStance = "Burrow Leap End",
- NextStanceBlendTime = 0f,
- },
- }
- },
- {
- "Burrow Leap End",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceExit,
- Action = LeapEnd,
- },
- new Branch {
- On = 1.0f,
- NextStance = "Burrow Loop",
- Action = BurrowStart,
- },
- }
- },
- // Air Stuff
- {
- "Jump Start",
- new List<Branch>()
- {
- new Branch {
- Signal = Signal.StanceEnter,
- Action = JumpPause,
- },
- new Branch {
- On = 3f / 7f, // 10 of 20 frames
- Action = DoStandardJump,
- },
- new Branch {
- On = 1.0f,
- NextStance = "Jump Upward",
- },
- }
- },
- {
- "Jump Upward",
- new List<Branch>()
- {
- new Branch {
- Condition = context => { return IsFalling(); },
- NextStance = "Jump Falling",
- KeepProgress = true,
- },
- }
- },
- {
- "Jump Falling",
- new List<Branch>()
- {
- new Branch {
- Condition = context => { return !IsFalling() && !this[PS.Stopped] && this["GroundDistance_C"] > 0.25f; },
- NextStance = "Jump Upward",
- KeepProgress = true,
- },
- }
- },
- {
- "Jump Landing",
- new List<Branch>()
- {
- new Branch {
- On = 0.4f,
- Action = JumpPause,
- },
- new Branch {
- On = 1.0f,
- NextStance = "Idle",
- },
- new Branch {
- On = 0.5f,
- Condition = context => { return this[PS.InputForward] > 0.1f; },
- NextStance = "Move Forward",
- },
- new Branch {
- On = 0.5f,
- Condition = context => { return this[PS.InputForward] < -0.1f; },
- NextStance = "Move Backward",
- },
- new Branch {
- Signal = Signal.DoJump,
- // TODO : Re-evaluate
- Condition = context => { return this[PS.Grounded]; },
- NextStance = "Jump Start",
- },
- }
- },
- // Death Standard
- {
- "Death",
- new List<Branch>()
- {
- // Return to the previous stance after this animation completes
- new Branch
- {
- On = 1f, // Frames
- Action = MakeDead,
- NextStance = "Dead",
- },
- }
- },
- {
- "Dead",
- new List<Branch>()
- {
- // Return to the previous stance after this animation completes
- new Branch
- {
- Condition = context => { return this[PS.Possessed]; },
- On = 0f, // Frames
- NextStance = "Revive",
- },
- }
- },
- {
- "Revive",
- new List<Branch>()
- {
- // Return to the previous stance after this animation completes
- new Branch
- {
- On = 1.0f,
- Action = Revive,
- NextStance = "Idle",
- },
- }
- },
- {
- "Explode",
- new List<Branch>()
- {
- new Branch
- {
- Signal = Signal.StanceEnter,
- Action = ExplodeStart,
- },
- new Branch {
- Condition = context => { return this[PS.Health] <= 0; },
- NextStance = "Death",
- },
- new Branch
- {
- On = 0.9f,
- Action = context =>
- {
- var t = StaticVisualHelpers.CreateUnitVFX ( this, Explosion, Vector3.zero );
- // 5.0 seconds is arbitrary to ensure cleanup
- Object.Destroy ( t, 1.0f );
- return SignalDispatcher.BlockParent;
- },
- },
- new Branch
- {
- On = 1.0f,
- NextStance = "Explode Death",
- },
- }
- },
- {
- "Explode Death",
- new List<Branch>()
- {
- new Branch
- {
- Signal = Signal.StanceEnter,
- Action = MakeDead,
- },
- new Branch
- {
- On = 1.0f,
- NextStance = "Explode Dead",
- },
- }
- },
- };
- // Now load the data into the stances
- StanceManager.BuildStances(StanceMgr, StanceList, BranchBundles, StanceBranches);
- // Validate Data
- StanceMgr.CurrentStance = "Spin Loop";
- StanceMgr.ValidateStances();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment