Exemple #1
0
    //https://gist.github.com/jbroadway/b94b971d224332f9158988a66f35f22d
    //https://answers.unity.com/questions/546668/how-to-create-coroutine-delegates.html
    void Start()
    {
        if (PRINT_METHOD_CALL)
        {
            Debug.Log("Start");
        }

        CachePlatforms();

        StateMachine = new StateMachine(this);
        Logger       = new Logger();

        LineRender         = GetComponent <LineRenderer>();
        LineRender.enabled = false;

        // Since our update methods are all of type void, pass them as delegates
        // Pass coroutines as illustrated in the second link

        UDelegateFn dNormalUpdate = NormalUpdate, dNormalBegin = NormalBegin, dNormalEnd = NormalEnd;

        System.Action l_normalCoroutine = () => StartCoroutine(NormalCoroutine());
        StateMachine.SetCallbacks(StNormal, dNormalUpdate, l_normalCoroutine, dNormalBegin, dNormalEnd);

        UDelegateFn dClimbUpdate = ClimbUpdate, dClimbBegin = ClimbBegin, dClimbEnd = ClimbEnd;

        System.Action l_climbCoroutine = () => StartCoroutine(ClimbCoroutine());
        StateMachine.SetCallbacks(StClimb, dClimbUpdate, l_climbCoroutine, dClimbBegin, dClimbEnd);

        UDelegateFn dDashUpdate = DashUpdate, dDashBegin = DashBegin, dDashEnd = DashEnd;

        System.Action l_dashCoroutine = () => StartCoroutine(DashCoroutine());
        StateMachine.SetCallbacks(StDash, DashUpdate, l_dashCoroutine, DashBegin, DashEnd);

        UDelegateFn dSwingUpdate = SwingUpdate, dSwingBegin = SwingBegin, dSwingEnd = SwingEnd;

        System.Action l_swingCoroutine = () => StartCoroutine(SwingCoroutine());
        StateMachine.SetCallbacks(StSwing, SwingUpdate, l_swingCoroutine, SwingBegin, SwingEnd);

        UDelegateFn dSlideUpdate = SlideUpdate, dSlideBegin = SlideBegin, dSlideEnd = SlideEnd;

        System.Action l_slideCoroutine = () => StartCoroutine(SlideCoroutine());
        StateMachine.SetCallbacks(StSlide, dSlideUpdate, l_slideCoroutine, dSlideBegin, dSlideEnd);

        // Set up our input class instance
        Input_ = new Input_();

        // Freeze rotation on the player
        rb.freezeRotation = true;

        StateMachine.State = StNormal;

        Animator = GetComponent <Animator>();
    }
Exemple #2
0
 public void LogStep(Input_ Input_)
 {
     recording.Add(Input_.RecordInputState());
 }