コード例 #1
0
    /// <summary>
    /// 开始去建造
    /// </summary>
    /// <param name="targeter"></param>
    public void BuildStart(TileEntity targeter)
    {
        Assert.Should(_state == WorkerState.Free || _state == WorkerState.FinishWork);
        Assert.Should(targeter != null);

        this.enabled = true;

        _buildTargeter       = targeter;
        _buildindLastTilePos = new TilePoint(9999, 9999);
        if (_buildArea == null)
        {
            _buildArea = new List <TilePoint>();
        }

        //  当前休息中则从工人小屋出来 回家中则停止移动
        if (_state == WorkerState.Free)
        {
            Entity.tileOffset = new Vector2(0.0f, 0.0f);
            Entity.SetTilePosition(GetDoorOfTheWorkerHouse());
            Entity.ShowEntity();
        }
        else
        {
            ActorMoveComponent move = Entity.GetComponent <ActorMoveComponent>();
            Assert.Should(move != null);
            move.OnMoveCompleteEvent -= OnMoveCompleteEvent;
            move.CancelMove();
        }
        //  设置上班状态 && 开始移动(3倍速移动)
        RefreshBuildGridArea();
        _state = WorkerState.Working;
        DoActionMove(RandomMoveGrid(IsInBuildArea()), 3.0f);
    }
コード例 #2
0
    /// <summary>
    /// 停止移动重新行动
    /// </summary>
    protected virtual void StopMoveAndTryAction()
    {
        ActorMoveComponent move = Entity.GetComponent <ActorMoveComponent>();

        Assert.Should(move != null);
        move.OnMoveCompleteEvent -= OnMoveCompleteEvent;
        move.CancelMove();

        TryAction();
    }