public override void OnInspectorGUI() { MovementStateMachine tar = target as MovementStateMachine; var playerProp = serializedObject.FindProperty(tar.PlayerPropertyName); EditorGUILayout.ObjectField(playerProp, new GUIContent("Player: ")); MovementStateMachineData data = tar.Data; data = EditorGUILayout.ObjectField("Data:", data, typeof(MovementStateMachineData), false) as MovementStateMachineData; if (data != null) { tar.MovementStateMachineDataAssetPath = AssetDatabase.GetAssetPath(data); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save")) { MovementStateMachineData.Save(tar); } if (GUILayout.Button("Reload")) { tar.ReloadFromData(); } EditorGUILayout.EndHorizontal(); }
void Awake() { controller = GetComponent <Controller2D>(); movementMachine = new MovementStateMachine(); movementMachine.ChangeState(new LiquidState(), this); }
void Awake() { instance = this; movementScript = GetComponentInChildren <PlayerMovement>(); movementSM = GetComponentInChildren <MovementStateMachine>(); }
public PlayerJump(Character character, MovementStateMachine stateMachine) { this.character = character; this.stateMachine = stateMachine; fishRB = character.MyRigidbody; jumpForce = character.JumpForce; }
public PlayerMoving(Character character, MovementStateMachine stateMachine) { this.character = character; this.stateMachine = stateMachine; fishRB = this.character.MyRigidbody; maxVelocity = this.character.MaxVelocity; speedChange = this.character.SpeedChange; }
/// <summary> /// Constructor. /// </summary> /// <param name="movementStateMachine">A reference to the state machine owning this state.</param> /// <param name="target">The target towards which the enemy will move to.</param> protected LinealMovement(MovementStateMachine movementStateMachine, Vector3 target) : base(movementStateMachine) { _target = target; var difference = _target - MovementStateMachine.EnemyTransform.position; var degrees = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; MovementStateMachine.EnemyTransform.rotation = Quaternion.Euler(0f, 0f, degrees + 90.0f); }
private IEnumerator KillEnemy() { _movementStateMachine = null; _gameController.enemiesAlive--; collider.isTrigger = false; yield return(new WaitForSeconds(0.3f)); gameObject.SetActive(false); _isAlive = false; }
public MovementState(uint id, string name, MovementStateMachine stateMachine) : base(id, name) { this.StateMachine = stateMachine; movementOptions = new List <EntityMovementOption>(); transitions = new List <Transition>(); requestPriorityMapping = new Dictionary <TransitionRequest, int>(); minPriorityValue = 0; MovementHandler = new StateMovementHandler(this, stateMachine.Player); isInitialized = false; }
public static MovementStateMachineData CreateAssetAndSave(MovementStateMachine machine, string assetStoragePath) { MovementStateMachineData data = CreateInstance <MovementStateMachineData>(); machine.FillDataObject(data); AssetDatabase.CreateAsset(data, assetStoragePath); AssetDatabase.Refresh(); return(data); }
public static bool Save(MovementStateMachine machine) { string path = EditorUtility.SaveFilePanelInProject("Save Data", $"StateMachine{machine.StateCount}", "asset", "Create Data Object"); if (path.Length != 0) { //Success machine.Save(path); return(true); } return(false); }
private void Awake() { //initialize this first before assigned to object MaxVelocity = 1f; SpeedChange = 8f; JumpForce = 5f; MyRigidbody = GetComponent <Rigidbody>(); movementSM = new MovementStateMachine(); MovingState = new PlayerMoving(this, movementSM); JumpingState = new PlayerJump(this, movementSM); }
/// <summary> /// creates a movement state based on this data, for the state machine /// </summary> /// <param name="machineFor">the machine that is gonna contain this state</param> /// <returns>the created state</returns> public MovementState Create(MovementStateMachine machineFor) { MovementState state = new MovementState(id, name, machineFor); state.IsInitialState = isInitial; state.Initialize(allowedMovements, requestPriorities); for (int i = 0; i < dataTransitions.Count; i++) { state.AddTransition(dataTransitions[i].Create(machineFor)); } return(state); }
/// <summary> /// Spawns this enemy. /// </summary> /// <param name="startingPoint">The starting point for this enemy.</param> /// <param name="firstStop">The point in which this enemy will start performing the circular movement.</param> /// <param name="secondStop">The center of the circle.</param> /// <param name="finalPoint">The final point for the enemy (i.e place in the enemy grid).</param> public void Spawn(Vector3 startingPoint, Vector3 firstStop, Vector3 secondStop, Vector3 finalPoint) { if (_movementStateMachine != null) { return; } animatorCtrl.ResetTrigger("Death"); collider.isTrigger = true; transform.position = startingPoint; gameObject.SetActive(true); _isAlive = true; _movementStateMachine = new MovementStateMachine(speed, firstStop, secondStop, finalPoint, _player.transform, transform); }
private MovementState HandleMovementStates(MovementStateMachine machine) { MovementState initial = null; for (int i = 0; i < states.Count; i++) { var st = states[i].Create(machine); machine.AddNewState(st); if (st.IsInitialState) { initial = st; } } return(initial); }
public override void Bind() { base.Bind(); _IsMovingProperty = new P <Boolean>(this, "IsMoving"); _MovementStateMachineProperty = new MovementStateMachine(this, "MovementStateMachine"); _FiringCommandProperty = new P <Boolean>(this, "FiringCommand"); _FireStateMachineProperty = new FireStateMachine(this, "FireStateMachine"); _FireTimeOutElapsedProperty = new P <Boolean>(this, "FireTimeOutElapsed"); _ShouldFireProperty = new P <Boolean>(this, "ShouldFire"); _AsteroidsDestroyedProperty = new P <Int32>(this, "AsteroidsDestroyed"); _WeaponProperty = new P <BaseWeaponViewModel>(this, "Weapon"); _IsAliveProperty = new P <Boolean>(this, "IsAlive"); _MovementSpeedProperty = new P <Single>(this, "MovementSpeed"); this._IsMovingProperty.Subscribe(_MovementStateMachineProperty.MoveTransition); this._IsMovingProperty.Subscribe(_MovementStateMachineProperty.StopTransition); this._ShouldFireProperty.Subscribe(_FireStateMachineProperty.FireTransition); this._ShouldFireProperty.Subscribe(_FireStateMachineProperty.StopTransition); }
void Start() { position = transform.position; MoveState moveState = new MoveState(); JumpState jumpState = new JumpState(); FallState fallState = new FallState(); movementStateMachine = new MovementStateMachine(); movementStateMachine.inputActionMap = actionMap; movementStateMachine.transform = transform; movementStateMachine.motor = motor; movementStateMachine.animator = animator; movementStateMachine.AddState("move", moveState); movementStateMachine.AddState("jump", jumpState); movementStateMachine.AddState("fall", fallState); movementStateMachine.Init(moveState); moveDir = Vector3.forward; }
private void Draw() { EntityEdited = EditorGUILayout.ObjectField("Editing", EntityEdited, typeof(MovementStateMachine), true) as MovementStateMachine; if (EntityEdited != null) { prefabAssetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(EntityEdited); EditorGUILayout.Space(); EditorGUILayout.LabelField("Movement Options For Entity:"); EditorGUI.indentLevel += 1; for (int i = EntityEdited.GeneralMovementOptions.Count - 1; i >= 0; i--) { var opt = EntityEdited.GeneralMovementOptions[i]; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(opt.Name); if (GUILayout.Button("X")) { EntityEdited.RemoveGeneralMovementOption(opt); Save(); } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel -= 1; if (GUILayout.Button("Add General Movement Option")) { AddGeneralMovementOption(); } string buttonText = EntityEdited.IsLoaded ? "Reload" : "Load"; if (GUILayout.Button(buttonText)) { EntityEdited.ReloadFromData(); OnEntityReloaded?.Invoke(); } } }
private void HandleGeneralMovementOptrions(MovementStateMachine machine) { for (int i = 0; i < generalOptionsData.Count; i++) { Type optionType = Type.GetType(generalOptionsData[i]); if (optionType == null) { throw new Exception($"Type does not exist {generalOptionsData[i]}"); } EntityMovementOption movementOption; if (!GameObjectHasOptionComponent(machine.gameObject, optionType)) { movementOption = machine.gameObject.AddComponent(optionType) as EntityMovementOption; } else { movementOption = machine.GetComponent(optionType) as EntityMovementOption; } machine.AddGeneralMovementOption(movementOption); } }
public WaitAttack(MovementStateMachine movementStateMachine, MoveToFinalPoint previousMoveToFinalPointState) : base(movementStateMachine) { _previousMoveToFinalPointState = previousMoveToFinalPointState; }
void Start() { player = GetComponent <Player>(); playerMovementMachine = player.movementMachine; }//Start
public AirMovement(MovementStateMachine MSM) { movementStateMachine = MSM; }
public GroundMovement(MovementStateMachine MSM) { movementStateMachine = MSM; }
public MoveToSecondStop(MovementStateMachine movementStateMachine) : base(movementStateMachine, movementStateMachine.SecondStop) { }
public MoveToFinalPoint(MovementStateMachine movementStateMachine) : base(movementStateMachine, movementStateMachine.FinalPoint) { _waitAttack = new WaitAttack(MovementStateMachine, this); }
/// <summary> /// Initializes movemnet optio for a states movement handler /// calls Initialize implemented by classes inheriting from base /// </summary> /// <param name="handler">a states movement handler</param> public void Init(StateMovementHandler handler) { EntiyMovementStateMachine = GetComponent <MovementStateMachine>(); Initialize(handler); }
/// <summary> /// unity editor on validate, calls virtual function validate /// ensures StateMachine member is set /// </summary> public void OnValidate() { EntiyMovementStateMachine = GetComponent <MovementStateMachine>(); Validate(); }
/// <summary> /// Constructor. This sets the state machine to null. /// </summary> public Enemy() { _movementStateMachine = null; _isAlive = false; }
public override void Bind() { base.Bind(); _IsMovingProperty = new P<Boolean>(this, "IsMoving"); _MovementStateMachineProperty = new MovementStateMachine(this, "MovementStateMachine"); _FiringCommandProperty = new P<Boolean>(this, "FiringCommand"); _FireStateMachineProperty = new FireStateMachine(this, "FireStateMachine"); _FireTimeOutElapsedProperty = new P<Boolean>(this, "FireTimeOutElapsed"); _ShouldFireProperty = new P<Boolean>(this, "ShouldFire"); _AsteroidsDestroyedProperty = new P<Int32>(this, "AsteroidsDestroyed"); _WeaponProperty = new P<BaseWeaponViewModel>(this, "Weapon"); _IsAliveProperty = new P<Boolean>(this, "IsAlive"); _MovementSpeedProperty = new P<Single>(this, "MovementSpeed"); this._IsMovingProperty.Subscribe(_MovementStateMachineProperty.MoveTransition); this._IsMovingProperty.Subscribe(_MovementStateMachineProperty.StopTransition); this._ShouldFireProperty.Subscribe(_FireStateMachineProperty.FireTransition); this._ShouldFireProperty.Subscribe(_FireStateMachineProperty.StopTransition); }
public ClimbingMovement(MovementStateMachine MSM) { movementStateMachine = MSM; }
public AttackPlayer(MovementStateMachine movementStateMachine, MoveToFinalPoint previousMoveToFinalPointState) : base(movementStateMachine, movementStateMachine.PlayerTransform.position) { _previousMoveToFinalPointState = previousMoveToFinalPointState; }
public MovementState InitializeStateMachine(MovementStateMachine machine) { HandleGeneralMovementOptrions(machine); return(HandleMovementStates(machine)); }