Exemplo n.º 1
0
        private void DrawBlackboardKeyAndValues(string label, Blackboard blackboard)
        {
            EditorGUILayout.BeginVertical();
            {
                GUILayout.Label(label, EditorStyles.boldLabel);

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                {
                    List <string> keys = blackboard.Keys;
                    foreach (string key in keys)
                    {
                        DrawKeyValue(key, blackboard.Get(key).ToString());
                    }
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            if (!target)
            {
                return;
            }

            Debugger debugger = (Debugger)target;

            if (!target || debugger.BehaviorTree == null)
            {
                return;
            }

            if (debugger.BehaviorTree == null)
            {
                GUILayout.Label("NPBehave Debugger: No Behavor Tree Set");
            }
            else
            {
                EditorGUILayout.LabelField("Blackboard: ", EditorStyles.boldLabel);
                Blackboard    blackboard = debugger.BehaviorTree.Blackboard;
                List <string> keys       = blackboard.Keys;
                foreach (string key in keys)
                {
                    GUILayout.Label(" -  " + key + " : " + blackboard.Get(key));
                }

                EditorGUILayout.LabelField("Behaviour Tree: ", EditorStyles.boldLabel);
                Traverse(" ", debugger.BehaviorTree);

                EditorUtility.SetDirty(debugger); // ensure we are redrawn every frame

                EditorGUILayout.LabelField("Statistics:", EditorStyles.boldLabel);
                GUILayout.Label(" - Totals (Start|Stop|Stopped):  " + debugger.BehaviorTree.TotalNumStartCalls + "|" + debugger.BehaviorTree.TotalNumStopCalls + "|" + debugger.BehaviorTree.TotalNumStoppedCalls);
                GUILayout.Label(" - Active Timers:  " + debugger.BehaviorTree.Clock.NumTimers);
                GUILayout.Label(" - Timer Pool Size:  " + debugger.BehaviorTree.Clock.DebugPoolSize);
                GUILayout.Label(" - Active Update Observers:  " + debugger.BehaviorTree.Clock.NumUpdateObservers);
                GUILayout.Label(" - Active Blackboard Observers:  " + debugger.BehaviorTree.Blackboard.NumObservers);
            }
        }
        private void moveToBlackboardKey()
        {
            object target = Blackboard.Get(blackboardKey);

            if (target == null || !agent.MovementController._navMeshAgent.enabled)
            {
                stopAndCleanUp(false);
                return;
            }

            // get target location
            Vector3 destination = Vector3.zero;

            if (target is Transform)
            {
                if (updateFrequency >= 0.0f)
                {
                    destination = ((Transform)target).position;
                }
            }
            else if (target is Vector3)
            {
                destination = (Vector3)target;
            }
            else
            {
                Debug.LogWarning("NavMoveTo: Blackboard Key '" + this.blackboardKey + "' contained unsupported type '" + target.GetType());
                stopAndCleanUp(false);
                return;
            }

            // set new destination
            //agent.destination = destination;
            agent.MovementController.SetDestination(destination);

            bool destinationChanged = (agent.MovementController._navMeshAgent.destination - lastDestination).sqrMagnitude > (DESTINATION_CHANGE_THRESHOLD * DESTINATION_CHANGE_THRESHOLD); //(destination - agent.destination).sqrMagnitude > (DESTINATION_CHANGE_THRESHOLD * DESTINATION_CHANGE_THRESHOLD);
            bool distanceChanged    = Mathf.Abs(agent.MovementController._navMeshAgent.remainingDistance - lastDistance) > DESTINATION_CHANGE_THRESHOLD;

            // check if we are already at our goal and stop the task
            if (lastDistance < this.tolerance)
            {
                if (stopOnTolerance || (!destinationChanged && !distanceChanged))
                {
                    // reached the goal
                    stopAndCleanUp(true);
                    return;
                }
            }
            else if (!destinationChanged && !distanceChanged)
            {
                if (failedChecks++ > DESTINATION_CHANGE_MAX_CHECKS)
                {
                    // could not reach the goal for whatever reason
                    stopAndCleanUp(false);
                    return;
                }
            }
            else
            {
                failedChecks = 0;
            }

            lastDestination = agent.MovementController._navMeshAgent.destination;
            lastDistance    = agent.MovementController._navMeshAgent.remainingDistance;
        }