Esempio n. 1
0
        public PointInfo FindSameYPointOnWholePath(float y, List <int> excludesIndex = null)
        {
            //			Log.Debug ("movinf points {0}",LogUtils.logList(movePoints));
            PointInfo info = null;
            Vector3   vx   = new Vector3(0, y);
            Vector3   vx1  = new Vector3(1, y);
            Vector3   vx2  = new Vector3(-1, y);

            return(FindCrossPointOnWholePath(vx, vx1, vx2, excludesIndex));
        }
        protected override void PostUpdate(int reachedPoint)
        {
            base.PostUpdate(reachedPoint);

            if (null == target)
            {
                return;
            }

            PointInfo pi = FindClosestPointOnWholePath(target.position);

            Debug.DrawLine(pi.position, target.position);
        }
        bool CheckReached(PointInfo pi)
        {
            float dis = 0f;

            if (xAxis)
            {
                dis = Mathf.Abs(transform.position.x - pi.position.x);
            }
            else
            {
                dis = Mathf.Abs(transform.position.y - pi.position.y);
            }

            return(error > dis);
        }
        bool IsSameDirection(Vector3 lastPoint, PointInfo pi)
        {
            Vector3 movingPoint = movePoints[movingIndex];
            float   dir         = 0f;

            if (xAxis)
            {
                dir = (movingPoint.x - lastPoint.x) * (pi.position.x - transform.position.x);
            }
            else
            {
                dir = (movingPoint.y - lastPoint.y) * (pi.position.y - transform.position.y);
            }
            return(dir >= 0);
        }
        public PointInfo FindSamePointOnWholePath()
        {
            PointInfo pi = null;

            if (xAxis)
            {
                pi = FindSameXPointOnWholePath(target.position.x, excludesIndex);
            }
            else
            {
                pi = FindSameYPointOnWholePath(target.position.y, excludesIndex);
            }

            return(pi);
        }
        protected override void PostUpdate(int reachedPoint)
        {
            base.PostUpdate(reachedPoint);

            if (null == target)
            {
                return;
            }

            if (_reached)
            {
                _traceIntervalPast += Time.deltaTime;
                if (_traceIntervalPast < traceInterval)
                {
                    return;
                }
                else
                {
                    _traceIntervalPast = 0f;
                    _reached           = false;
                }
            }
            PointInfo pi = FindSamePointOnWholePath();

            if (null == pi)
            {
//								Log.Debug ("FindSameXPointOnWholePath is null");
                return;
            }
            //			Log.Debug ("FindSameXPointOnWholePath is {0}",pi);
            Debug.DrawLine(pi.position, target.position, Color.magenta);
            //			Log.Debug ("x dis {0}",transform.position.x - pi.position.x);
            if (CheckReached(pi))
            {
                _reached = true;
                ReachTargetEvent(this);
//				Log.Debug ("reached target .... ");
                return;
            }
            int lastIndex = fliping ? movingIndex + 1 : movingIndex - 1;

            if (!(onlyFlipWhenReachPoint && -1 == reachedPoint))
            {
                if (lastIndex >= 0 && lastIndex <= movePoints.Length - 1)
                {
                    Vector3 lastPoint = movePoints [lastIndex];
                    if (!IsSameDirection(lastPoint, pi))
                    {
                        //different direction, need flip
//						Log.Debug ("Flip.... {0},{1}",lastIndex, pi);
                        Flip();
                    }
                    else
                    {
//						Log.Debug ("2 ----- {0},{1}",lastIndex, pi);
                    }
                }
                else
                {
//					Log.Debug("1---- {0},{1}",onlyFlipWhenReachPoint,reachedPoint);
                }
            }
            else
            {
//				Log.Debug("not flip {0},{1}",onlyFlipWhenReachPoint,reachedPoint);
            }
        }