Пример #1
0
    // Start is called before the first frame update
    void Start()
    {
        if (patrol == null || patrol.Count == 0)
        {
            Debug.LogError("Not valid patrol path");
        }

        controler = GetComponent <CharacterController>();
        agent     = GetComponent <K_PathFinder.PathFinderAgent>();
        _animator = GetComponent <Animator>();

        //find nearest point
        float   sqrDist = float.MaxValue;
        Vector3 pos     = transform.position;

        for (int i = 0; i < patrol.Count; i++)
        {
            float curSqrDist = (patrol[i] - pos).sqrMagnitude;
            if (curSqrDist < sqrDist)
            {
                sqrDist      = curSqrDist;
                currentPoint = i;
            }
        }

        agent.SetRecievePathDelegate((K_PathFinder.Path path) => { Debug.Log(path.pathType); });

        //queue navmesh
        K_PathFinder.PathFinder.QueueGraph(new Bounds(transform.position, Vector3.one * 20), agent.properties);
    }
Пример #2
0
 public void Clear()
 {
     pathType = PathResultType.InvalidInternalIssue;
     pathNodes.Clear();
     pathContent.Clear();
     owner         = null;
     _currentIndex = 0;
 }
        public static void GetBattleGrid(PathFinderAgent agent, int depth, Action callBack, params Vector3[] vectors)
        {
            Init();

            if (_acceptingWork == false || ContainsKey(InfoTaskType.battleGrid, agent))
            {
                return;
            }

            QueueItem(InfoTaskType.battleGrid, agent, callBack, new InfoTemplateBattleGrid(agent, depth, vectors));
        }
        public static void GetCover(PathFinderAgent agent, int minChunkDepth, float maxMoveCost, Action callBack, bool ignoreCrouchCost = false)
        {
            Init();

            if (_acceptingWork == false || ContainsKey(InfoTaskType.cover, agent))
            {
                return;
            }

            QueueItem(InfoTaskType.cover, agent, callBack, new InfoTemplateCover(agent, minChunkDepth, maxMoveCost, ignoreCrouchCost));
        }
        public static void GetPath(PathFinderAgent agent, Vector3 target, Vector3 start, bool snapToNavMesh, Action callBack, bool applyRaycastBeforeFunnel = false, int maxRaycastIterations = 100, bool ignoreCrouchCost = false)
        {
            Init();

            if (_acceptingWork == false || ContainsKey(InfoTaskType.move, agent))
            {
                return;
            }

            QueueItem(InfoTaskType.move, agent, callBack, new PathTemplateMove(agent, target, start, snapToNavMesh, applyRaycastBeforeFunnel, maxRaycastIterations, ignoreCrouchCost));
        }
        private static void QueueItem(InfoTaskType t, PathFinderAgent agent, Action callBackDelegate, InfoTemplateAbstract template)
        {
            template.AddCallBack(callBackDelegate);
            template.AddCallBack(() => {
                lock (_infoExtraction[(int)t])
                    _infoExtraction[(int)t].Remove(agent);
            });

            WaitCallback templateCallBack = new WaitCallback(InfoExtractionThreadWorker);
            DataPair     pair             = new DataPair(template, templateCallBack);

            lock (_infoExtraction[(int)t])
                _infoExtraction[(int)t].Add(agent, pair);

            ThreadPool.QueueUserWorkItem(templateCallBack, template);
        }
Пример #7
0
        public override void OnInspectorGUI()
        {
            Event e = Event.current;

            serializedObject.Update();
            EditorGUI.showMixedValue = true;

            Color guiColor = GUI.color;

            if (properties.hasMultipleDifferentValues)
            {
                GUI.color = niceYellow;
            }
            else if (properties.objectReferenceValue != null)
            {
                GUI.color = niceGreen;
            }
            else
            {
                GUI.color = niceRed;
            }

            GUI.Box(lastPropertiesRect, string.Empty);
            GUI.color = guiColor;

            if (properties.hasMultipleDifferentValues)
            {
                EditorGUILayout.PropertyField(properties, agentPropertiesWarningYellow);
            }
            else if (properties.objectReferenceValue != null)
            {
                EditorGUILayout.PropertyField(properties, agentPropertiesDescription);
            }
            else
            {
                EditorGUILayout.PropertyField(properties, agentPropertiesWarningRed);
            }

            if (e.type == EventType.Repaint)
            {
                lastPropertiesRect = GUILayoutUtility.GetLastRect();
            }

            if (properties.objectReferenceValue != null)
            {
                EditorGUILayout.PropertyField(updateNavmeshPosition, updateNavmeshPositionContent);

                //updateNeighbourAgents
                if (updateNeighbourAgents.boolValue)
                {
                    GUILayout.Box(string.Empty, guiLayoutForNiceLine);
                }
                EditorGUILayout.PropertyField(updateNeighbourAgents, updateNeighbourAgentsContent);
                if (updateNeighbourAgents.boolValue)
                {
                    EditorGUILayout.PropertyField(maxNeighbors, maxNeighboursContent);
                    EditorGUILayout.PropertyField(maxNeighbourDistance, maxNeighbourDistanceContent);
                }
                if (updateNeighbourAgents.boolValue)
                {
                    GUILayout.Box(string.Empty, guiLayoutForNiceLine);
                }

                EditorGUILayout.PropertyField(velocityObstacle, velocityObstacleContent);
                if (velocityObstacle.boolValue)
                {
                    updateNavmeshPosition.boolValue = true;
                    updateNeighbourAgents.boolValue = true;

                    EditorGUILayout.PropertyField(maxAgentVelocity, maxAgentVelocityContent);
                    EditorGUILayout.PropertyField(avoidanceResponsibility, avoidanceResponsibilityContent);
                    EditorGUILayout.PropertyField(careDistance, careDistanceContent);

                    EditorGUILayout.PropertyField(useDeadLockFailsafe, useDeadLockFailsafeContent);
                    if (useDeadLockFailsafe.boolValue)
                    {
                        EditorGUILayout.PropertyField(deadLockVelocityThreshold, deadLockVelocityThresholdContent);
                        EditorGUILayout.PropertyField(deadLockFailsafeVelocity, deadLockFailsafeVelocityContent);
                        EditorGUILayout.PropertyField(deadLockFailsafeTime, deadLockFailsafeTimeContent);
                    }

                    EditorGUILayout.PropertyField(preferOneSideEvasion, preferOneSideEvasionContent);
                    if (preferOneSideEvasion.boolValue)
                    {
                        EditorGUILayout.PropertyField(preferOneSideEvasionOffset, preferOneSideEvasionOffsetContent);
                        if (preferOneSideEvasionOffset.floatValue < 0)
                        {
                            preferOneSideEvasionOffset.floatValue = 0f;
                        }
                    }
                }
            }


            UITools.Line();

            debugPath = EditorGUILayout.Toggle("Debug Path", debugPath);
            if (debugPath)
            {
                PathFinderAgent agent = (PathFinderAgent)target;
                if (agent != null && agent.path != null)
                {
                    lock (agent.path) {
                        for (int i = 0; i < agent.path.pathNodes.Count - 1; i++)
                        {
                            Debug.DrawLine(agent.path.pathNodes[i], agent.path.pathNodes[i + 1], Color.red);
                        }
                    }
                }
            }


            EditorGUI.showMixedValue = false;
            serializedObject.ApplyModifiedProperties();
        }
 private static bool ContainsKey(InfoTaskType t, PathFinderAgent agent)
 {
     return(_infoExtraction[(int)t].ContainsKey(agent));
 }