当前位置: 首页>>代码示例>>C#>>正文


C# IState.ChangeState方法代码示例

本文整理汇总了C#中IState.ChangeState方法的典型用法代码示例。如果您正苦于以下问题:C# IState.ChangeState方法的具体用法?C# IState.ChangeState怎么用?C# IState.ChangeState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IState的用法示例。


在下文中一共展示了IState.ChangeState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    // Use this for initialization
    void Start()
    {
        rootState = new StateMachineBuilder()
            // First, approach the goal
            .State<MovingState>("Approach")
                .Enter(state =>
                {
                    Debug.Log("Entering Approach state");
                })
                // Move towards the goal
                .Update((state, deltaTime) =>
                {
                    var directionToTarget = transform.position - goal.position;
                    directionToTarget.y = 0; // Only calculate movement on a 2d plane
                    directionToTarget.Normalize();

                    transform.position -= directionToTarget * deltaTime * state.movementSpeed;
                })
                // Once the TargetReached event is triggered, retreat away again
                .Event("TargetReached", state =>
                {
                    state.PushState("Retreat");
                })
                .Exit(state =>
                {
                    Debug.Log("Exiting Approach state");
                })
                // Retreating state
                .State<RetreatingState>("Retreat")
                    // Set a new destination
                    .Enter(state =>
                    {
                        Debug.Log("Entering Retreat state");

                        // Work out a new target, away from the goal
                        var direction = new Vector3(Random.value, 0f, Random.value);
                        direction.Normalize();

                        state.direction = direction;
                    })
                    // Move towards the new destination
                    .Update((state, deltaTime) =>
                    {
                        transform.position -= state.direction * deltaTime * state.movementSpeed;
                    })
                    // If we go further away from the original target than the reset distance, exit and
                    // go back to the previous state
                    .Condition(() =>
                    {
                        return Vector3.Distance(transform.position, goal.position) >= resetDistance;
                    },
                    state =>
                    {
                        state.Parent.PopState();
                    })
                    .Exit(state =>
                    {
                        Debug.Log("Exiting Retreat state");
                    })
                    .End()
                .End()
            .Build();

        rootState.ChangeState("Approach");
    }
开发者ID:Real-Serious-Games,项目名称:Fluent-State-Machine,代码行数:66,代码来源:Example2Actor.cs


注:本文中的IState.ChangeState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。