public IEnumerator Walk()
    {
        FarmRoot      farmRoot  = FarmRoot.Instance;
        FarmField     farmField = farmRoot.Field;
        FarmDigimonAI ai        = base.GetComponent <FarmDigimonAI>();

        FarmDigimonAI.ActionParam param = ai.GetActionParam();
        float speed = 1.6f;

        if (param.pathGridIndexs != null && 0 < param.pathGridIndexs.Length)
        {
            int nowIndex   = param.pathGridIndexs.Length;
            int checkIndex = 0;
            while (checkIndex < nowIndex)
            {
                Vector3 digimonPos3D = base.transform.localPosition;
                digimonPos3D.y = 0f;
                int     gridIndex = param.pathGridIndexs[checkIndex];
                Vector3 gridPos3D = farmField.Grid.GetPositionGridCenter(gridIndex, false);
                gridPos3D.y = 0f;
                Vector3 rayDirection = gridPos3D - digimonPos3D;
                digimonPos3D.y = farmRoot.transform.localPosition.y + 0.1f;
                gridPos3D.y    = farmRoot.transform.localPosition.y + 0.1f;
                if (!Physics.Raycast(digimonPos3D, rayDirection, rayDirection.magnitude, this.MASK_LAYER))
                {
                    digimonPos3D.y = 0f;
                    gridPos3D.y    = 0f;
                    Vector3 digimonDirection      = Quaternion.AngleAxis(base.transform.localEulerAngles.y, Vector3.up) * Vector3.forward;
                    float   angle                 = Vector3.Angle(digimonDirection, rayDirection);
                    Vector3 digimonRightDirection = Quaternion.AngleAxis(90f, Vector3.up) * digimonDirection;
                    if (0f > Vector3.Dot(digimonRightDirection, rayDirection))
                    {
                        angle *= -1f;
                    }
                    this.enumerator = this.Turn(angle, speed);
                    Coroutine coroutine = base.StartCoroutine(this.enumerator);
                    if (40f <= Mathf.Abs(angle))
                    {
                        yield return(coroutine);
                    }
                    this.enumerator = this.Movement(digimonPos3D, gridPos3D, speed);
                    yield return(base.StartCoroutine(this.enumerator));

                    this.enumerator = null;
                    nowIndex        = checkIndex;
                    checkIndex      = 0;
                }
                else
                {
                    checkIndex += Mathf.Max(1, (nowIndex - checkIndex) / 2);
                }
            }
        }
        yield break;
    }
Exemple #2
0
 private void Awake()
 {
     this.stateRoutines = new Func <IEnumerator>[]
     {
         null,
         new Func <IEnumerator>(this.WaitAppearance),
         new Func <IEnumerator>(this.Thinking),
         new Func <IEnumerator>(this.Act),
         new Func <IEnumerator>(this.WaitEndAction)
     };
     this.cancelRoutines = new Action[]
     {
         null,
         new Action(this.CancelAppearance),
         new Action(this.CancelThinking),
         new Action(this.CancelAct),
         new Action(this.CancelWait)
     };
     this.manager           = base.GetComponentInParent <FarmDigimonManager>();
     this.farmDigimonAI     = base.GetComponent <FarmDigimonAI>();
     this.farmDigimonAction = base.GetComponent <FarmDigimonAction>();
 }