Beispiel #1
0
        public override bool Tick()
        {
            Entity       agent = context.agent;
            WaypointPath path  = context.path;

            Debug.Assert(path != null, nameof(path) + " != null");

            WaypointTracker tracker       = path.GetTrackerForEntity(context.agent.index);
            int             completedLaps = tracker.CompletedLaps;

            Vector3 waypoint = tracker.CurrentWaypoint;

            float distSquared = agent.transformInfo.DistanceToSquared(waypoint);

            if (distSquared < 20 * 20)   // todo replace with a radius per waypoint
            {
                tracker.Progress();
            }

            waypoint = tracker.CurrentWaypoint;
            ApproachType approachType = tracker.IsFinalWaypoint ? ApproachType.Arrive : ApproachType.Normal;

            agent.FlightSystem.SetTargetPosition(waypoint, approachType);
            return(tracker.CompletedLaps != completedLaps);
        }
Beispiel #2
0
            public WaypointPath Copy()
            {
                WaypointPath path = new WaypointPath();

                path.waypoints = new List <Waypoint>(this.waypoints);
                return(path);
            }
Beispiel #3
0
        bool LoadPath(uint entry)
        {
            if (HasEscortState(SmartEscortState.Escorting))
            {
                return(false);
            }

            WaypointPath path = Global.SmartAIMgr.GetPath(entry);

            if (path == null || path.nodes.Empty())
            {
                GetScript().SetPathId(0);
                return(false);
            }

            _path       = new WaypointPath();
            _path.id    = path.id;
            _path.nodes = path.nodes;
            foreach (WaypointNode waypoint in _path.nodes)
            {
                GridDefines.NormalizeMapCoord(ref waypoint.x);
                GridDefines.NormalizeMapCoord(ref waypoint.y);
                waypoint.moveType = mRun ? WaypointMoveType.Run : WaypointMoveType.Walk;
            }

            GetScript().SetPathId(entry);
            return(true);
        }
        public void GetPathLength(DefinitionNode[] definitionNodes, int[] path, float expectedPathLength)
        {
            var nodePath   = new WaypointPath(definitionNodes, path, new Transformer(new Vector2(1f, 1f)));
            var pathLength = nodePath.GetPathLength();

            Assert.Equal(expectedPathLength, pathLength, 3);
        }
Beispiel #5
0
    void Start()
    {
        // Random Number
        randomNumber = Random.Range(0f,3.0f);

        // Get Path
        if(randomNumber <= 1f){
            pathPoint = GameObject.Find("Path_1");
        }

         	if(randomNumber >= 1.0f && randomNumber <= 2.0f){
            pathPoint = GameObject.Find("Path_2");
        }

        if(randomNumber > 2.0f){
            pathPoint = GameObject.Find("Path_3");
        }

        // Load GameObjects
        spawner = GameObject.FindGameObjectWithTag("Spawner");
        view = GameObject.FindGameObjectWithTag("View");

        // Load Scripts
        viewScript = view.GetComponent<ViewScript>();
        wave = spawner.gameObject.GetComponent<WaveSysteem>();
        varW = pathPoint.gameObject.GetComponent<WaypointPath>();
    }
Beispiel #6
0
        // call back
        private static void Callback(object sender, EventArgs e)
        {
            SusbcribeEventEventArgs messageEvent = e as SusbcribeEventEventArgs;

            if (messageEvent == null)
            {
                return;
            }
            if (messageEvent.MessageResult == null)
            {
                return;
            }
            Debug.Log("message received");
            Dictionary <string, object> message = messageEvent.MessageResult.Payload as Dictionary <string, object>;

            if (message == null)
            {
                return;
            }
            if (messageEvent.MessageResult.Channel.Equals("route-to-fire"))
            {
                Path.Clear();
                foreach (string road in (string[])message["path"])
                {
                    Debug.Log(road);
                    WaypointPath roadWp = GameObject.Find(road).GetComponent <WaypointPath>();
                    Path.Add(roadWp);
                }
                IsSomethingOnFire = true;
                UpdatePath();
            }
        }
Beispiel #7
0
 private void CreateLocalPaths(LocalWaypoint w)
 {
     foreach (Waypoint w2 in w.LocalWaypoints)
     {
         WaypointPath path = CreatePath(w, w2);
         path.pathColor = Color.blue;
     }
 }
Beispiel #8
0
 public WaypointMovementGenerator(WaypointPath _path, bool _repeating = true)
 {
     nextMoveTime  = new TimeTrackerSmall(0);
     isArrivalDone = false;
     pathId        = 0;
     repeating     = _repeating;
     loadedFromDB  = false;
     path          = _path;
 }
Beispiel #9
0
    private WaypointPath CreatePath(Waypoint w1, Waypoint w2)
    {
        WaypointPath newPath = Instantiate(_pathTemplate, Vector3.zero, Quaternion.identity, transform);

        newPath.waypoint1 = w1;
        newPath.waypoint2 = w2;
        ConnectWaypoints(w1, w2);
        _paths.Add(newPath);
        return(newPath);
    }
Beispiel #10
0
        public WaypointMovementGenerator(WaypointPath path, bool repeating = true)
        {
            _nextMoveTime = new TimeTrackerSmall(0);
            _repeating    = repeating;
            _path         = path;

            Mode          = MovementGeneratorMode.Default;
            Priority      = MovementGeneratorPriority.Normal;
            Flags         = MovementGeneratorFlags.InitializationPending;
            BaseUnitState = UnitState.Roaming;
        }
        public MoveCameraAlongWaypointPathAction(ScriptAction action, SceneSettings sceneSettings)
        {
            _waypointPath = sceneSettings.WaypointPaths[action.Arguments[0].StringValue];

            _direction = _waypointPath.End.Position - _waypointPath.Start.Position;

            _duration = TimeSpan.FromSeconds(action.Arguments[1].FloatValue.Value);

            // TODO: What is this?
            _shutter = action.Arguments[2].FloatValue.Value;
        }
        public MoveCameraAlongWaypointPathAction(ScriptAction action, SceneSettings sceneSettings)
        {
            var firstNode = sceneSettings.Waypoints[action.Arguments[0].StringValue];

            _waypointPath = sceneSettings.WaypointPaths[firstNode];

            _duration = TimeSpan.FromSeconds(action.Arguments[1].FloatValue.Value);

            // TODO: What is this?
            _shutter = action.Arguments[2].FloatValue.Value;
        }
        public EscortAI(Creature creature) : base(creature)
        {
            _pauseTimer        = 2500;
            _playerCheckTimer  = 1000;
            _maxPlayerDistance = 50;
            _activeAttacker    = true;
            _despawnAtEnd      = true;
            _despawnAtFar      = true;

            _path = new WaypointPath();
        }
Beispiel #14
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            WaypointPath waypointPath = target as WaypointPath;

            if (waypointPath == null)
            {
                return;
            }

            Transform transform = waypointPath.transform;

            Transform[] children = transform.GetChildren();

            int tagColorIdx = Mathf.Clamp(waypointPath.tagColorIndex, -1, 7);

            int newSelection = EditorGUILayout.IntPopup("Set Tag Color", tagColorIdx, colorNames, colorValues);

            if (tagColorIdx != newSelection)
            {
                waypointPath.tagColorIndex = newSelection;
                children.ForEach((child) => IconManager.SetIcon(child.gameObject, (IconManager.LabelIcon)newSelection));
            }

            EditorGUILayout.BeginHorizontal();
            if (tagColorIdx == -1 && GUILayout.Button("Show Tags"))
            {
                children.ForEach((child) => IconManager.SetIcon(child.gameObject, (IconManager.LabelIcon)tagColorIdx));
            }
            else if (tagColorIdx != -1 && GUILayout.Button("Hide Tags"))
            {
                children.ForEach((child) => IconManager.SetIcon(child.gameObject, IconManager.LabelIcon.None));
                waypointPath.tagColorIndex = -1;
            }

            if (GUILayout.Button("Name Children"))
            {
                Array.Sort(children, (a, b) => {
                    float aDist = a.DistanceToSquared(transform.position);
                    float bDist = b.DistanceToSquared(transform.position);
                    return(aDist < bDist ? -1 : 1);
                });

                children.ForEachIndex((child, index) => {
                    child.SetSiblingIndex(index);
                    child.name = transform.name + "[" + index + "]";
                });
            }

            EditorGUILayout.EndHorizontal();
        }
Beispiel #15
0
    void GetWaypoints()
    {
        myWayPath = target as WaypointPath;

        if (myWayPath.wayPointArray != null)
        {
            optionsList = new string[myWayPath.wayPointArray.Length];

            for (int i = 0; i < optionsList.Length; i++)
            {
                optionsList[i] = myWayPath.wayPointArray[i].name;
            }
        }
    }
        protected override float Score(WaypointContext context)
        {
            WaypointPath path = context.path;

            if (path == null)
            {
                return(0);
            }
            WaypointTracker tracker     = path.GetTrackerForEntity(context.agent.index);
            Vector3         waypoint    = tracker.CurrentWaypoint;
            float           distSquared = context.agent.transformInfo.DistanceToSquared(waypoint);

            return(MathUtil.PercentageOfRangeClamped(distSquared, minDist * minDist, maxDist * maxDist));
        }
Beispiel #17
0
 // Update is called once per frame
 void OnPathComplete(WaypointPath p)
 {
     if (p.HasError())
     {
         Debug.LogError("Noes, could not find the path!");
         return;
     }
     else
     {
         List <Vector3> vp = p.vectorPath;
         for (int i = 0; i < vp.Count - 1; i++)
         {
             Debug.DrawLine(vp[i], vp[i + 1], Color.red, 20);
         }
     }
 }
Beispiel #18
0
        public void NextWaypoint(DefinitionNode[] definitionNodes, int[] path, float expectedPathLength)
        {
            var nodePath  = new WaypointPath(definitionNodes, path, new Transformer(new Vector2(1f, 1f)));
            var waypoints = new List <Vector2>();
            var position  = definitionNodes[path[0]].Position;

            do
            {
                var heading = nodePath.GetHeading(position);
                position += heading;
                waypoints.Add(position);
            } while (!nodePath.NextWaypoint());

            Assert.Equal(path.Length, waypoints.Count);
            Assert.Equal(path.Select(i => definitionNodes[i].Position), waypoints);
        }
Beispiel #19
0
    private void AddWaypoint(WaypointPath waypointPath)
    {
        if (waypointPath.points == null)
        {
            waypointPath.points = new List <Waypoint>();
        }

        var newWaypoint = new Waypoint();

        newWaypoint.position = Vector3.left;
        CreateWaypointElement(waypointPath.points.Count.ToString(), newWaypoint);

        waypointPath.points.Add(newWaypoint);
        serializedObject.Update();
        MarkSceneAsDirty();
    }
Beispiel #20
0
    public void bind()
    {
        if (null == path)
        {
            GameObject root = new GameObject("path");
            GameObject node = new GameObject("node");

            root.hideFlags = HideFlags.HideInHierarchy;
            node.transform.parent = root.transform;

            path = root.AddComponent<WaypointPath>();

            root.transform.position = transform.position;
        }
        else
        {
            path.GetNode(0).position = transform.position;
        }
    }
        void FillPointMovementListForCreature()
        {
            WaypointPath path = Global.WaypointMgr.GetPath(me.GetEntry());

            if (path == null)
            {
                return;
            }

            foreach (WaypointNode value in path.nodes)
            {
                WaypointNode node = value;
                GridDefines.NormalizeMapCoord(ref node.x);
                GridDefines.NormalizeMapCoord(ref node.y);
                node.moveType = _running ? WaypointMoveType.Run : WaypointMoveType.Walk;

                _path.nodes.Add(node);
            }
        }
Beispiel #22
0
            public static WaypointPath[] Trace(Waypoint ws, WaypointPath wp, Connection[] ca)
            {
                //  Create a basic path
                if (wp == null)
                {
                    wp = new WaypointPath();
                }

                //  Create the local list
                List <WaypointPath> wpl = new List <WaypointPath>();

                //  If we already have this point, we dont need to continue on it's path
                if (wp.waypoints.Contains(ws))
                {
                    return(wpl.ToArray());
                }

                wp = wp.Copy();
                wp.waypoints.Add(ws);

                //  If we have more points than 1, add it to the list so it's returned
                if (wp.waypoints.Count > 1)
                {
                    wpl.Add(wp);
                }

                //  Go through each connection and find ones that have our node
                foreach (Connection c in ca)
                {
                    if (c.A == ws)
                    {
                        wpl.AddRange(Trace(c.B, wp, ca));
                    }
                    if (c.B == ws)
                    {
                        wpl.AddRange(Trace(c.A, wp, ca));
                    }
                }

                //  Give our list back
                return(wpl.ToArray());
            }
Beispiel #23
0
        private void Paths_Generate()
        {
            //  Working waypointPath array
            List <WaypointPath> wpl = new List <WaypointPath>();
            List <Map.Path>     pl  = new List <Map.Path>();

            //  Trace out our paths
            foreach (Waypoint waypoint in waypointsList)
            {
                wpl.AddRange(WaypointPath.Trace(waypoint, null, connectionList.ToArray()));
            }

            Debug.Log("Temporary waypoint paths:" + wpl.Count);

            foreach (WaypointPath wp in wpl)
            {
                pl.Add(wp.GetPath(connectionList.ToArray(), map));
            }

            pathList = new List <Map.Path>(Map.Path.Optimize(pl.ToArray()));

            Debug.Log("Paths:" + pathList.Count);
        }
Beispiel #24
0
 public TeamFollowWaypointsExactAction(ScriptAction action, SceneSettings sceneSettings)
 {
     _teamName     = action.Arguments[0].StringValue;
     _waypointPath = sceneSettings.WaypointPaths[action.Arguments[1].StringValue];
     _asTeam       = action.Arguments[2].IntValueAsBool;
 }
Beispiel #25
0
 private void DestroyPath(WaypointPath path)
 {
     DisconnectWaypoints(path.waypoint1, path.waypoint2);
     _paths.Remove(path);
     Destroy(path.gameObject);
 }
Beispiel #26
0
 public WaypointMovementGenerator(WaypointPath path, bool repeating = true)
 {
     _nextMoveTime = new TimeTrackerSmall(0);
     _repeating    = repeating;
     _path         = path;
 }
Beispiel #27
0
 public WaypointPath GetDefaultPath(IPathfindNodeNetwork <DijkstraNode> nodeNetwork, IPathRequest pathRequest) => WaypointPath.GetEmptyPath(nodeNetwork, pathRequest.PathStart);
Beispiel #28
0
 public bool ValidatePath(IPathfindNodeNetwork <DijkstraNode> nodeNetwork, IPathRequest pathRequest, WaypointPath path) => true;
Beispiel #29
0
 public WaypointContext(Entity agent, WaypointPath path) : base(agent)
 {
     this.path = path;
 }
Beispiel #30
0
    public override VisualElement CreateInspectorGUI()
    {
        t = target as WaypointPath;

        var root = rootElement;

        root.Clear();

        box = new Box();
        box.style.minHeight = 100;
        box.RegisterCallback <MouseDownEvent>(OnBoxClicked);

        var toolbar = new Toolbar();

        var addButton = new ToolbarButton(() => { AddWaypoint(target as WaypointPath); })
        {
            text = "Add Point"
        };

        bezierToggle = new ToolbarToggle()
        {
            text = "Draw Bezier"
        };
        bezierToggle.value = t.drawBezier;
        bezierToggle.RegisterCallback <ChangeEvent <bool> >(OnToggleValueChange);

        var spacer = new ToolbarSpacer();

        spacer.style.flexGrow = 1;

        var clearButton = new ToolbarButton(ClearWaypoints)
        {
            text = "Clear Points"
        };

        toolbar.Add(addButton);
        toolbar.Add(bezierToggle);
        toolbar.Add(spacer);
        toolbar.Add(clearButton);

        actionContainer = new ScrollView();
        actionContainer.showHorizontal = false;
        box.Add(toolbar);
        box.Add(actionContainer);

        //TODO: Add previously added tasks to the box

        root.Add(box);

        var button = new Button(() => { t.UpdateWorldPoints(); });

        button.text = "Update World Points";
        root.Add(button);

        if (t.points != null)
        {
            for (int i = 0; i < t.points.Count; i++)
            {
                CreateWaypointElement(i.ToString(), t.points[i]);
            }
        }

        return(root);
    }
Beispiel #31
0
 public void MovePath(WaypointPath path, bool repeatable)
 {
     StartMovement(new WaypointMovementGenerator(path, repeatable), MovementSlot.Idle);
 }