Exemplo n.º 1
0
        public NavLinePosCurveDir(NavPathData pathData, Vector3 offset, bool pathFlipOn, IPathTrigger triggerHandler) : base(pathData, offset, pathFlipOn, triggerHandler)
        {
#if UNITY_EDITOR
            mMovedTime   = 0;
            mMovedLength = 0;
#endif
        }
Exemplo n.º 2
0
        public static AbstractNavPath Create(NavPathType pathType, NavPathData pathData, Vector3 offset, bool pathFlipOn, IPathTrigger triggerHandler)
        {
            AbstractNavPath navPath = null;

            if (pathData.WayPoints.Count == 2 && pathType != NavPathType.LinePosLineDir)
            {
                pathType = NavPathType.LinePosLineDir;
                DebugUtils.Warning("AbstractNavPath", "Create LineType, Not ", EnumUtils.EnumToString(pathType));
            }
            switch (pathType)
            {
            case NavPathType.CurvePosCurveDir:
                navPath = new NavCurvePosCurveDir(pathData, offset, pathFlipOn, triggerHandler);
                break;

            case NavPathType.LinePosLineDir:
                navPath = new NavCurvePosCurveDir(pathData, offset, pathFlipOn, triggerHandler);
                break;

            case NavPathType.LinePosLineAngle:
                navPath = new NavCurvePosCurveDir(pathData, offset, pathFlipOn, triggerHandler);
                break;

            case NavPathType.LinePosCurveDir:
                navPath = new NavCurvePosCurveDir(pathData, offset, pathFlipOn, triggerHandler);
                break;

            default:
                DebugUtils.Error("AbstractNavPath", "Create Not Supported ", EnumUtils.EnumToString(pathType));
                break;
            }
            return(navPath);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据路点生成 NavPath
        /// </summary>
        /// <param name="waypoints">路点</param>
        /// <param name="subdivisions">两个路点之间的分段数量</param>
        /// <returns></returns>
        public static NavPathData CreatePathData(List <Vector3> waypoints, int subdivisions = 5)
        {
            int cnt = waypoints.Count;

            Debug.Assert(cnt >= 2, "路点数据量不够 < 2");

            NavPathData    pathData  = new NavPathData();
            List <Vector3> wayPoints = new List <Vector3>();

            // 拷贝一份 waypoints
            wayPoints.AddRange(waypoints);
            pathData.OriginWayPoints = new List <Vector3>();
            pathData.OriginWayPoints.AddRange(wayPoints);
            if (cnt == 2)
            {
                // 直接用直线, 直接加
                // 后面可通过 判断多点共线,直接使用支线
                pathData.WayPoints.AddRange(wayPoints);
            }
            else
            {
                float          div  = 1.0f / subdivisions;
                float          half = 0.5f * div;
                List <Vector3> temp = new List <Vector3>();
                Vector3        diff = (2.0f * wayPoints[1] - wayPoints[0] - wayPoints[2]) * 0.5f;
                temp.Add(wayPoints[0] + diff);
                temp.AddRange(wayPoints);
                diff = (2.0f * wayPoints[wayPoints.Count - 2] - wayPoints[wayPoints.Count - 3] - wayPoints[wayPoints.Count - 1]) * 0.5f;
                temp.Add(wayPoints[wayPoints.Count - 1] + diff);
                cnt = temp.Count - 2;
                // path.KeyPoints 的第0号,现在是第1号;最后一个,现在是倒数第2个
                for (int i = 1; i < cnt; ++i)
                {
                    for (float u = 0; u < 1 - div * half; u += div)
                    {
                        Vector3 inter = .5f * (
                            (-temp[i - 1] + 3f * temp[i] - 3f * temp[i + 1] + temp[i + 2]) * (u * u * u)
                            + (2f * temp[i - 1] - 5f * temp[i] + 4f * temp[i + 1] - temp[i + 2]) * (u * u)
                            + (-temp[i - 1] + temp[i + 1]) * u
                            + 2f * temp[i]);
                        pathData.WayPoints.Add(inter);
                    }
                }
                pathData.WayPoints.Add(wayPoints[wayPoints.Count - 1]);
            }
            cnt = pathData.WayPoints.Count;
            pathData.PathLength = 0.0f;
            pathData.RangeLengths.Add(0.0f);
            for (int i = 1; i < cnt; ++i)
            {
                Vector3 diff   = pathData.WayPoints[i] - pathData.WayPoints[i - 1];
                float   length = diff.magnitude;
                pathData.PathLength += length;
                pathData.RangeLengths.Add(pathData.PathLength);
            }
            return(pathData);
        }
Exemplo n.º 4
0
        private Vector3 mNext;          // 插值的结束方向

        public NavLinePosLineAngle(NavPathData pathData, Vector3 offset, NavPathFlipType flipType, IPathTrigger triggerHandler, float frameCount) : base(pathData, offset, flipType, triggerHandler)
        {
            // 会先执行 Initialize()
            mFrameCountInv       = 1.0f / frameCount;
            mCurFrame            = 0;
            CurInfo.isDirChanged = true;
            UpdatePosAndTangent();
            CurInfo.curveDir = mNext;
            mLast            = mNext;
        }
Exemplo n.º 5
0
        private Vector3 mNext;          // 插值的结束方向

        public NavLinePosLineAngle(NavPathData pathData, Vector3 offset, bool pathFlipOn, IPathTrigger triggerHandler, float frameCount) : base(pathData, offset, pathFlipOn, triggerHandler)
        {
            // 会先执行 Initialize()
            mFrameCountInv       = 1.0f / frameCount;
            mCurFrame            = 0;
            CurInfo.isDirChanged = true;
            UpdatePosAndTangent();
            CurInfo.curveDir = mNext;
            mLast            = mNext;
#if UNITY_EDITOR
            mMovedTime   = 0;
            mMovedLength = 0;
#endif
        }
Exemplo n.º 6
0
        public static AbstractNavPath Create(NavPathMoveType pathType, NavPathData pathData, Vector3 offset, NavPathFlipType flipType, IPathTrigger triggerHandler)
        {
            AbstractNavPath navPath = null;

            if (pathData.WayPoints.Count == 1)
            {
                pathType = NavPathMoveType.Fixed;
            }
            else if (pathData.WayPoints.Count == 2)
            {
                pathType = NavPathMoveType.LinePosLineDir;
                // DebugUtils.Log(InfoType.Warning, "AbstractNavPath Create LineType, Not " + EnumUtils.EnumToString(pathType));
            }
            switch (pathType)
            {
            case NavPathMoveType.Fixed:
                navPath = new NavPointFixed(pathData, offset, flipType, triggerHandler);
                break;

            case NavPathMoveType.CurvePosCurveDir:
                navPath = new NavCurvePosCurveDir(pathData, offset, flipType, triggerHandler);
                break;

            case NavPathMoveType.LinePosLineDir:
                navPath = new NavLinePosLineDir(pathData, offset, flipType, triggerHandler);
                break;

            case NavPathMoveType.LinePosLineAngle:
                navPath = new NavLinePosLineAngle(pathData, offset, flipType, triggerHandler, 10);
                break;

            case NavPathMoveType.LinePosCurveDir:
                navPath = new NavLinePosCurveDir(pathData, offset, flipType, triggerHandler);
                break;

            default:
                DebugUtils.Log(InfoType.Error, "AbstractNavPath Create Not Supported " + EnumUtils.EnumToString(pathType));
                break;
            }
            return(navPath);
        }
Exemplo n.º 7
0
        public static AbstractNavPath Create(NavPathType pathType, Vector3 offset, bool pathFlipOn, IPathTrigger triggerHandler, List <Vector3> waypoints, int subdivisions = 5)
        {
            NavPathData pathData = CreatePathData(waypoints, subdivisions);

            return(Create(pathType, pathData, offset, pathFlipOn, triggerHandler));
        }
Exemplo n.º 8
0
 public NavPointFixed(NavPathData pathData, Vector3 offset, NavPathFlipType flipType, IPathTrigger triggerHandler) : base(pathData, offset, flipType, triggerHandler)
 {
 }
Exemplo n.º 9
0
        public static AbstractNavPath Create(NavPathMoveType pathType, Vector3 offset, NavPathFlipType flipType, IPathTrigger triggerHandler, List <Vector3> waypoints, int subdivisions = 5, float pathLength = 0.0f)
        {
            NavPathData pathData = CreatePathData(waypoints, subdivisions, pathLength);

            return(Create(pathType, pathData, offset, flipType, triggerHandler));
        }
Exemplo n.º 10
0
 public NavCurvePosCurveDir(NavPathData pathData, Vector3 offset, NavPathFlipType flipType, IPathTrigger triggerHandler) : base(pathData, offset, flipType, triggerHandler)
 {
 }
Exemplo n.º 11
0
 public NavCurvePosCurveDir(NavPathData pathData, Vector3 offset, bool pathFlipOn, IPathTrigger triggerHandler) : base(pathData, offset, pathFlipOn, triggerHandler)
 {
 }