Ejemplo n.º 1
0
        public void Update()
        {
            if (mPolyRefs.HandleResize())
            {
                mStraightPath  = new Vector3[mPolyRefs.MaxElementCount];
                mVisitedCount  = 0;
                mStraightCount = 0;
            }

            if (Input.GetKeyDown(StdButtons.SelectA) ||
                Input.GetKey(StdButtons.SelectB))
            {
                Vector3      trasha;
                string       trashb;
                NavmeshPoint point;

                QEUtil.SearchResult searchResult =
                    QEUtil.HandleStandardPolySearch(mHelper, out trasha, out point, out trashb);

                if ((searchResult & QEUtil.SearchResult.HitNavmesh) == 0)
                {
                    return;
                }

                if (mPosition.polyRef == 0 || Input.GetKey(StdButtons.SelectB))
                {
                    mPosition     = point;
                    mGoal.polyRef = 0;
                }
                else
                {
                    mGoal = point;
                }

                mVisitedCount  = 0;
                mStraightCount = 0;
            }

            if (mVisitedCount == 0 &&
                mPosition.polyRef != 0 &&
                mGoal.polyRef != 0)
            {
                NavStatus status = mHelper.query.MoveAlongSurface(mPosition, mGoal.point
                                                                  , mHelper.filter
                                                                  , out mTarget.point, mPolyRefs.buffer, out mVisitedCount);

                mMessages = "MoveAlongSurface: " + status.ToString();

                if (mVisitedCount > 0)
                {
                    mHelper.query.GetStraightPath(mPosition.point, mTarget.point
                                                  , mPolyRefs.buffer, 0, mVisitedCount
                                                  , mStraightPath
                                                  , null, null, out mStraightCount);
                }
            }
        }
Ejemplo n.º 2
0
        public void Update()
        {
            // Must set message before returning.

            mHasPosition = false;
            mResultCount = 0;

            mYOffset += QEUtil.GetYFactor();

            Vector3 trash;

            QEUtil.SearchResult result =
                QEUtil.HandleStandardPolySearch(mHelper, out trash, out mPosition, out mMessage);

            mHasPosition = (result & QEUtil.SearchResult.HitNavmesh) != 0;

            if (!mHasPosition)
            {
                return;
            }

            Vector3 pos = mPosition.point;

            for (int i = 0; i < mSearchPoly.Length; i++)
            {
                mSearchPoly[i]    = pos + mBasePoly[i];
                mSearchPoly[i].y += mYOffset;
            }

            if (mPolyRefs.HandleResize())
            {
                int size = mPolyRefs.MaxElementCount;
                mParentRefs = new uint[size];
                mCosts      = new float[size];
                mCentroids  = new Vector3[size];
            }

            NavStatus status = mHelper.query.FindPolys(mPosition.polyRef, mSearchPoly
                                                       , mHelper.filter
                                                       , mPolyRefs.buffer, mParentRefs, mCosts, out mResultCount);

            mMessage = "FindPolys: " + status.ToString() + ".";

            if (mResultCount > 0)
            {
                NavDebug.GetCentroids(mHelper.mesh, mPolyRefs.buffer, mResultCount, mCentroids);
            }
        }
Ejemplo n.º 3
0
        public void Update()
        {
            mHasPosition = false;
            mResultCount = 0;

            Vector3 trash;

            QEUtil.SearchResult result =
                QEUtil.HandleStandardPolySearch(mHelper, out trash, out mPosition, out mMessage);

            mHasPosition = (result & QEUtil.SearchResult.HitNavmesh) != 0;

            if (!mHasPosition)
            {
                return;
            }

            mYOffset          += QEUtil.GetYFactor();
            mPosition.point.y += mYOffset;

            mSearchRadius += QEUtil.GetXZFactor();

            if (mPolyRefs.HandleResize())
            {
                int size = mPolyRefs.MaxElementCount;
                mParentRefs = new uint[size];
                mCentroids  = new Vector3[size];
            }

            NavStatus status = mHelper.query.GetPolysLocal(mPosition, mSearchRadius
                                                           , mHelper.filter
                                                           , mPolyRefs.buffer, mParentRefs, out mResultCount);

            mMessage = "GetPolysLocal: " + status.ToString() + ".";

            if (mResultCount > 0)
            {
                NavDebug.GetCentroids(mHelper.mesh
                                      , mPolyRefs.buffer
                                      , mResultCount
                                      , mCentroids);
            }
        }
Ejemplo n.º 4
0
        public void Update()
        {
            if (mPolyRefs.HandleResize())
            {
                mResultCount = 0;
                mHitNorm     = Vector3.zero;
                mHitParam    = 0;
            }

            if (Input.GetKeyDown(StdButtons.SelectA) || Input.GetKeyDown(StdButtons.SelectB))
            {
                Vector3      trasha;
                string       trashb;
                NavmeshPoint point;

                QEUtil.SearchResult searchResult =
                    QEUtil.HandleStandardPolySearch(mHelper, out trasha, out point, out trashb);

                if ((searchResult & QEUtil.SearchResult.HitNavmesh) == 0)
                {
                    return;
                }

                if (mPosition.polyRef == 0 || Input.GetKeyDown(StdButtons.SelectB))
                {
                    mPosition = point;
                }
                else
                {
                    mGoal = point;
                }

                mResultCount = 0;
                mHitNorm     = Vector3.zero;
                mHitParam    = 0;
            }

            if (mResultCount == 0 && mPosition.polyRef != 0 && mGoal.polyRef != 0)
            {
                CastRay();
            }
        }
Ejemplo n.º 5
0
        public void Update()
        {
            float offset = QEUtil.GetXZFactor();

            mHelper.extents[0] += offset;
            mHelper.extents[1] += QEUtil.GetYFactor();
            mHelper.extents[2] += offset;

            mPolyRefs.HandleResize();

            mResultCount = 0;

            mHasPosition = QEUtil.hasHit;
            if (!mHasPosition)
            {
                mMessage = "Outside source geometry.";
                return;
            }

            mHasPosition = true;
            mPosition    = QEUtil.hitPosition;

            for (int i = 0; i < mPolyRefs.buffer.Length; i++)
            {
                mPolyRefs.buffer[i] = 0;
            }

            NavStatus status = mHelper.query.GetPolys(mPosition
                                                      , mHelper.extents, mHelper.filter
                                                      , mPolyRefs.buffer, out mResultCount);

            for (int i = 0; i < mResultCount; i++)
            {
                if (mPolyRefs.buffer[i] == 0)
                {
                    Debug.Log("Invalid poly");
                }
            }

            mMessage = "GetPolys: " + status.ToString();
        }
Ejemplo n.º 6
0
        public override void Update()
        {
            base.Update();

            if (pathCount == 0 || pathID != mPathId)
            {
                mStraightCount  = 0;
                mTarget.polyRef = 0;
            }

            if (mStraightPath.HandleResize())
            {
                mStraightCount = 0;
            }

            mPathId = pathID;

            if (pathCount == 0)
            {
                return;
            }

            if (Input.GetKeyDown(StdButtons.SelectB))
            {
                QEUtil.SearchResult searchResult;
                Vector3             trasha;
                string       trashb;
                NavmeshPoint point;

                // Path start.
                searchResult =
                    QEUtil.HandleStandardPolySearch(helper, out trasha, out point, out trashb);

                if ((searchResult & QEUtil.SearchResult.HitNavmesh) == 0)
                {
                    return;
                }

                bool found      = false;
                int  iStartPoly = 0;
                for (; iStartPoly < pathCount; iStartPoly++)
                {
                    if (point.polyRef == path.buffer[iStartPoly])
                    {
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    mTargetPathIndex = iStartPoly;
                }
                else
                {
                    mTargetPathIndex = -1;
                    mLocalMessage    = "Target outside path.";
                }


                mTarget = point;

                mStraightCount = 0;
            }

            if (mTarget.polyRef == 0)
            {
                mLocalMessage = "No target";
            }
            else if (mStraightCount == 0)
            {
                GenerateStraightPath();
            }
        }
Ejemplo n.º 7
0
    void OnGUI()
    {
        if (SimGUIUtil.hideGUI || mGroup.mesh == null)
        {
            return;
        }

        LabelRegion labels = SimGUIUtil.labels;

        labels.Clear();

        if (mPathCount == 0)
        {
            labels.Last = "No path.";
            SimGUIUtil.OnGUI();
            return;
        }

        GUILayout.BeginArea(SimGUIUtil.contextControlZone, GUI.skin.box);

        if (GUILayout.Button("Optimize Topology"))
        {
            mCorridor.OptimizePathTopology(true);
        }

        GUI.enabled = (mPathEnd.polyRef != 0);
        if (GUILayout.Button("Replan Path"))
        {
            FindPath();
        }

        GUI.enabled = true;

        mPath.OnGUI();
        if (mPath.HandleResize())
        {
            HandlePathBufferResize();
        }

        mCornerPolys.OnGUI();
        if (mCornerPolys.HandleResize())
        {
            mCorridor.ResizeCornerBuffer(mCornerPolys.MaxElementCount);
        }

        GUILayout.Label("Optimiation Range");

        GUILayout.BeginHorizontal();

        optimizationRange = (int)GUILayout.HorizontalSlider(optimizationRange, 1, 30);

        GUILayout.Label(optimizationRange.ToString());

        GUILayout.EndHorizontal();

        GUILayout.EndArea();

        const int LabelCount = 2;
        int       slotIndex  = labels.SlotCount - LabelCount;

        string msg = mCorridor.Corners.cornerCount + " of " + (mCorridor.Corners.MaxCorners - 1);

        labels.Set(slotIndex++, "Detected Corners", msg);

        msg = mPathCount + " of " + mCorridor.MaxPathSize;
        labels.Set(slotIndex++, "Corridor Polygons", msg);

        SimGUIUtil.OnGUI();
    }
Ejemplo n.º 8
0
        public virtual void Update()
        {
            if (path.HandleResize())
            {
                if (pathCount != 0)
                {
                    pathID++;
                }

                pathCount     = 0;
                mLocalMessage = "No path";
            }

            if (Input.GetKeyDown(StdButtons.SelectA) || Input.GetKeyDown(StdButtons.SetB))
            {
                Vector3      trasha;
                string       trashb;
                NavmeshPoint point;

                QEUtil.SearchResult searchResult =
                    QEUtil.HandleStandardPolySearch(helper, out trasha, out point, out trashb);

                if ((searchResult & QEUtil.SearchResult.HitNavmesh) == 0)
                {
                    return;
                }

                // Switching to pure readability style.
                if (mUseAutoAdvance)
                {
                    if (!Input.GetKeyDown(StdButtons.SetB))
                    {
                        if (position.polyRef == 0)
                        {
                            position = point;
                        }
                        else if (goal.polyRef == 0)
                        {
                            goal = point;
                        }
                        else
                        {
                            position = goal;
                            goal     = point;
                        }
                    }
                }
                else
                {
                    if (position.polyRef == 0 || Input.GetKeyDown(StdButtons.SetB))
                    {
                        position = point;
                    }
                    else
                    {
                        goal = point;
                    }
                }
                pathCount = 0;
            }

            if (pathCount == 0 && position.polyRef != 0 && goal.polyRef != 0)
            {
                GeneratePath();
                pathID++;
            }
        }