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();
    }
Ejemplo n.º 2
0
    void Awake()
    {
        controller = GetComponent <Controller2D>();

        movementMachine = new MovementStateMachine();
        movementMachine.ChangeState(new LiquidState(), this);
    }
Ejemplo n.º 3
0
    void Awake()
    {
        instance = this;

        movementScript = GetComponentInChildren <PlayerMovement>();

        movementSM = GetComponentInChildren <MovementStateMachine>();
    }
Ejemplo n.º 4
0
    public PlayerJump(Character character, MovementStateMachine stateMachine)
    {
        this.character    = character;
        this.stateMachine = stateMachine;

        fishRB    = character.MyRigidbody;
        jumpForce = character.JumpForce;
    }
Ejemplo n.º 5
0
    public PlayerMoving(Character character, MovementStateMachine stateMachine)
    {
        this.character    = character;
        this.stateMachine = stateMachine;

        fishRB      = this.character.MyRigidbody;
        maxVelocity = this.character.MaxVelocity;
        speedChange = this.character.SpeedChange;
    }
Ejemplo n.º 6
0
            /// <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);
            }
Ejemplo n.º 7
0
    private IEnumerator KillEnemy()
    {
        _movementStateMachine = null;
        _gameController.enemiesAlive--;
        collider.isTrigger = false;
        yield return(new WaitForSeconds(0.3f));

        gameObject.SetActive(false);
        _isAlive = false;
    }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
    public static MovementStateMachineData CreateAssetAndSave(MovementStateMachine machine, string assetStoragePath)
    {
        MovementStateMachineData data = CreateInstance <MovementStateMachineData>();

        machine.FillDataObject(data);

        AssetDatabase.CreateAsset(data, assetStoragePath);

        AssetDatabase.Refresh();

        return(data);
    }
Ejemplo n.º 10
0
    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);
    }
Ejemplo n.º 11
0
    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);
    }
Ejemplo n.º 12
0
        /// <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);
        }
Ejemplo n.º 13
0
 /// <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);
 }
Ejemplo n.º 14
0
    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);
    }
Ejemplo n.º 15
0
 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);
 }
Ejemplo n.º 16
0
    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;
    }
Ejemplo n.º 17
0
    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();
            }
        }
    }
Ejemplo n.º 18
0
    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);
        }
    }
Ejemplo n.º 19
0
 public WaitAttack(MovementStateMachine movementStateMachine, MoveToFinalPoint previousMoveToFinalPointState)
     : base(movementStateMachine)
 {
     _previousMoveToFinalPointState = previousMoveToFinalPointState;
 }
Ejemplo n.º 20
0
 void Start()
 {
     player = GetComponent <Player>();
     playerMovementMachine = player.movementMachine;
 }//Start
Ejemplo n.º 21
0
 public AirMovement(MovementStateMachine MSM)
 {
     movementStateMachine = MSM;
 }
Ejemplo n.º 22
0
 public GroundMovement(MovementStateMachine MSM)
 {
     movementStateMachine = MSM;
 }
Ejemplo n.º 23
0
 public MoveToSecondStop(MovementStateMachine movementStateMachine) :
     base(movementStateMachine, movementStateMachine.SecondStop)
 {
 }
Ejemplo n.º 24
0
 public MoveToFinalPoint(MovementStateMachine movementStateMachine) :
     base(movementStateMachine, movementStateMachine.FinalPoint)
 {
     _waitAttack = new WaitAttack(MovementStateMachine, this);
 }
Ejemplo n.º 25
0
 /// <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);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// unity editor on validate, calls virtual function validate
 /// ensures StateMachine member is set
 /// </summary>
 public void OnValidate()
 {
     EntiyMovementStateMachine = GetComponent <MovementStateMachine>();
     Validate();
 }
Ejemplo n.º 27
0
 /// <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);
 }
Ejemplo n.º 29
0
 public ClimbingMovement(MovementStateMachine MSM)
 {
     movementStateMachine = MSM;
 }
Ejemplo n.º 30
0
 public AttackPlayer(MovementStateMachine movementStateMachine,
                     MoveToFinalPoint previousMoveToFinalPointState) :
     base(movementStateMachine, movementStateMachine.PlayerTransform.position)
 {
     _previousMoveToFinalPointState = previousMoveToFinalPointState;
 }
Ejemplo n.º 31
0
 public MovementState InitializeStateMachine(MovementStateMachine machine)
 {
     HandleGeneralMovementOptrions(machine);
     return(HandleMovementStates(machine));
 }