Esempio n. 1
0
 private void Start()
 {
     target = GameObject.FindGameObjectWithTag("Player");
     debug  = WaypointGraph.Get("debug");
     origin = transform.position;
     Path   = debug.QueryPath(transform.position, target.transform.position);
 }
Esempio n. 2
0
    //// TODO: remove when done testing
    //void Start()
    //{
    //    isNPCLeader = false;

    //    // targetTransform = null;

    //    // SetUpTactialAreas();
    //    // SetUpAgentAndAnim();

    //    // GoToNearestCoverAround();

    //    //targetTransform = null;

    //    SetUpTactialAreas();
    //    SetUpAgentAndAnim();

    //    //GoToNearestAmbushAround();
    //    //GoToNearestCoverAround();
    //    //GoToCapturePoint(CapturePoint.CapturePointId.H, TacticalWaypoint.WaypointType.AmbushPoint, true);
    //}

    // Use this for initialization
    void Awake()
    {
        isNPCLeader     = false;
        isPlayerGrouped = false;

        waypointGraph   = GameObject.FindGameObjectWithTag("WaypointGraph").GetComponent <WaypointGraph>();
        capturePointMap = GameObject.FindGameObjectWithTag("CapturePointMap").GetComponent <CapturePointMap>();

        // targetTransform = null;

        // SetUpTactialAreas();
        // SetUpAgentAndAnim();

        // GoToNearestCoverAround();

        //targetTransform = null;

        SetUpTactialAreas();
        SetUpAgentAndAnim();

        //GoToNearestAmbushAround();
        //GoToNearestCoverAround();
        // GoToCapturePoint(CapturePoint.CapturePointId.A, TacticalWaypoint.WaypointType.AmbushPoint, true);



        // Start behavior tree
        bt = new BehaviorTree(Application.dataPath + "/GameScene/Scripts/npc_firing.xml", this);
        bt.Start();
    }
Esempio n. 3
0
        /// <summary>
        /// Creates a pod with the given characteristics.
        /// </summary>
        /// <param name="id">The ID of the pod.</param>
        /// <param name="tier">The initial position (tier).</param>
        /// <param name="waypoint">The waypoint to place the pod at.</param>
        /// <param name="radius">The radius of the pod.</param>
        /// <param name="orientation">The initial orientation of the pod.</param>
        /// <param name="capacity">The capacity of the pod.</param>
        /// <returns>The newly created pod.</returns>
        public Pod CreatePod(int id, Tier tier, Waypoint waypoint, double radius, double orientation, double capacity)
        {
            // Consider override values
            if (SettingConfig.OverrideConfig != null && SettingConfig.OverrideConfig.OverridePodCapacity)
            {
                capacity = SettingConfig.OverrideConfig.OverridePodCapacityValue;
            }
            // Create the pod
            Pod pod = new Pod(this)
            {
                ID = id, Tier = tier, Radius = radius, X = waypoint.X, Y = waypoint.Y, Orientation = orientation, Capacity = capacity, Waypoint = waypoint
            };

            Pods.Add(pod);
            tier.AddPod(pod);
            _idToPods[pod.ID] = pod;
            // Set volatile ID
            SetVolatileIDForPod(pod);
            // Emulate setdown operation
            WaypointGraph.PodSetdown(pod, waypoint);
            // Notify listeners
            NewPod(pod);
            // Return it
            return(pod);
        }
Esempio n. 4
0
 void Rule_Nav()
 {
     if (NavWaypointGraph(flyGraph = GetDsgVar <WaypointGraph>("Graph_3"), true))
     {
         SetRule("");
     }
 }
    // Use this for initialization
    void Start()
    {
        //Find waypoint graph
        graphNodes = GameObject.FindGameObjectWithTag("waypoint graph").GetComponent <WaypointGraph>();

        //Initial node index to move to
        currentPath.Add(currentNodeIndex);
    }
Esempio n. 6
0
 void Start()
 {
     gridchecker = waypointSet.GetComponent <GridCreator>();
     //while (!gridchecker.finished) { }
     waypoints           = new WaypointGraph(waypointSet);
     path                = new List <int>();
     pathfinder          = createPathfinder();
     pathfinder.navGraph = waypoints.navGraph;
 }
Esempio n. 7
0
    public void UpdateWaypointGraph()
    {
        graph = GetComponent <WaypointGraphGeneration>().GenerateGraph();

        foreach (var edge in graph.Edges)
        {
            edge.Calculate(graph.Nodes);
        }
    }
Esempio n. 8
0
 void Start()
 {
     if(player == null)
         player = GameObject.FindGameObjectWithTag("Player").transform;
     if(graph == null)
         graph = GameObject.FindGameObjectWithTag("GameController").GetComponent<WaypointGraph>();
     path = new List<Vector3>();
     havePath = false;
 }
Esempio n. 9
0
    //Timer specific

    protected override void OnCreate()
    {
        base.OnCreate();

        _waypointGraph = WaypointGraph.Instance;

        //Timer specific
        timerRecoder = new TimeRecorder("PathFinderSystem");
        //Timer specific
    }
Esempio n. 10
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(this);
     }
 }
Esempio n. 11
0
    //------------------------------------------------------------------------
    // awake callbacks
    //------------------------------------------------------------------------

    public void Awake()
    {
        gameManager = GameManager.Instance;
        walkerBody  = GetComponent <Rigidbody>();

        GameObject planet = GameObject.FindGameObjectWithTag(Tags.Planet);

        graph = planet.GetComponent <WaypointGraph>();
        topo  = planet.GetComponent <PlanetTopography>();
        awake();
    }
Esempio n. 12
0
    void Start()
    {
        sprite        = transform.FindChild("EnemyPlaceholder").GetComponent <SpriteRenderer>();
        minimapSprite = transform.FindChild("Minimap EnemyPlaceholder").GetComponent <SpriteRenderer>();
        LoSCollider   = transform.FindChild("LineOfSight");
        player        = GameObject.Find("Player").GetComponent <Player> ();
        playerTrail   = player.GetComponent <PlayerTrail>();
        waypointGraph = GameObject.Find("WaypointGraph").GetComponent <WaypointGraph>();


        StartCoroutine("Patrol");
    }
Esempio n. 13
0
    // Use this for initialization
    void Update()
    {
        if (done)
        {
            return;
        }
        graph      = GetComponent <WaypointGraph> ();
        topography = GetComponent <PlanetTopography> ();

        nodePellet = new HashSet <int> ();
        int count = 0;

        print(graph.edges.Count);

        foreach (WaypointEdge edge in graph.edges)
        {
            if (edge.one.pacmanWalkable && edge.two.pacmanWalkable)
            {
                List <Vector3> positions = new List <Vector3> ();
                topography.getPelletPositions(edge.one, edge.two, out positions);
                for (int i = 1; i < positions.Count - 1; ++i)
                {
                    Instantiate(pellet, positions[i], Quaternion.identity);
                    count++;
                }
                if (!nodePellet.Contains(edge.one.GetInstanceID()))
                {
                    nodePellet.Add(edge.one.GetInstanceID());
                    GameObject p = pellet;
                    if (edge.one.powerPellet)
                    {
                        p = powerPellet;
                    }
                    Instantiate(p, positions[0], Quaternion.identity);
                    count++;
                }
                if (!nodePellet.Contains(edge.two.GetInstanceID()))
                {
                    nodePellet.Add(edge.two.GetInstanceID());
                    GameObject p = pellet;
                    if (edge.two.powerPellet)
                    {
                        p = powerPellet;
                    }
                    Instantiate(p, positions[positions.Count - 1], Quaternion.identity);
                    count++;
                }
            }
        }
        GameManager.Instance.levelData.pelletsTotal = count;

        done = true;
    }
Esempio n. 14
0
 void Start()
 {
     if (player == null)
     {
         player = GameObject.FindGameObjectWithTag("Player").transform;
     }
     if (graph == null)
     {
         graph = GameObject.FindGameObjectWithTag("GameController").GetComponent <WaypointGraph>();
     }
     path     = new List <Vector3>();
     havePath = false;
 }
Esempio n. 15
0
        protected override void OnStart()
        {
            grabDist = GetDsgVar <float>("Float_6");
            flyGraph = GetDsgVar <WaypointGraph>("Graph_3");

            maxHitPoints = float.PositiveInfinity;
            HealFull();

            anim.Set(Anim.Purple);
            if (flyGraph != null)
            {
                SetRule("Nav");
            }
        }
Esempio n. 16
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //Timer specific
        var startTimerJob = new StartTimerJob();
        var handle        = startTimerJob.Schedule(inputDeps);

        //Timer specific

        if (_waypointGraph == null)
        {
            _waypointGraph = WaypointGraph.Instance;
        }

        EntityQuery query = GetEntityQuery(ComponentType.ReadOnly(typeof(PathFindingRequest)));

        if (query.CalculateEntityCount() == 0)
        {
            //Timer specific
            var endTimerJob2 = new EndTimerJob();
            timerRecoder.RegisterTimeInMS(time);
            //Timer specific

            return(endTimerJob2.Schedule(handle));
        }

        ArchetypeChunkBufferType <PathPositions>         pathPositionBufferChunk = GetArchetypeChunkBufferType <PathPositions>();
        ArchetypeChunkComponentType <PathFindingRequest> pathFindingRequestChunk =
            GetArchetypeChunkComponentType <PathFindingRequest>(true);
        ArchetypeChunkComponentType <PathIndex> pathIndexChunk = GetArchetypeChunkComponentType <PathIndex>();

        //Update quadrants data
        FindPathJob2 findPathJob = new FindPathJob2()
        {
            waypoints = _waypointGraph.Waypoints,
            Neighbors = _waypointGraph.Neighbors,
            pathFindingRequestType = pathFindingRequestChunk,
            pathPositionType       = pathPositionBufferChunk,
            pathIndexType          = pathIndexChunk
        };

        var handle2 = findPathJob.Schedule(query, handle);

        //Timer specific
        var endTimerJob = new EndTimerJob();

        timerRecoder.RegisterTimeInMS(time);
        //Timer specific

        return(endTimerJob.Schedule(handle2));
    }
Esempio n. 17
0
        private void OnEnable()
        {
            graphProperty     = serializedObject.FindProperty("graph");
            movingObstacleTag = serializedObject.FindProperty("movingObstacleTag");
            nodegraph         = (WaypointGraph)target;

            gearsTex   = Resources.Load <Texture>("gears");
            plusTex    = Resources.Load <Texture>("plus");
            penTex     = Resources.Load <Texture>("pen");
            removeTex  = Resources.Load <Texture>("remove");
            clearTex   = Resources.Load <Texture>("clear");
            cancelTex  = Resources.Load <Texture>("cancel");
            bulkTex    = Resources.Load <Texture>("bulk");
            confirmTex = Resources.Load <Texture>("confirm");
        }
Esempio n. 18
0
        /// <summary>
        /// Creates a new waypoint that serves as the handover point for an elevator.
        /// </summary>
        /// <param name="id">The ID of the waypoint.</param>
        /// <param name="tier">The position (tier).</param>
        /// <param name="x">The position (x-coordinate).</param>
        /// <param name="y">The position (y-coordinate).</param>
        /// <param name="elevator">The elevator.</param>
        /// <param name="isQueueWaypoint">Indicates whether this waypoint is also a queue waypoint.</param>
        /// <returns>The newly created waypoint.</returns>
        public Waypoint CreateWaypoint(int id, Tier tier, Elevator elevator, double x, double y, bool isQueueWaypoint)
        {
            Waypoint wp = new Waypoint(this)
            {
                ID = id, X = x, Y = y, Elevator = elevator, IsQueueWaypoint = isQueueWaypoint
            };

            tier.AddWaypoint(wp);
            Waypoints.Add(wp);
            WaypointGraph.Add(wp);
            _idToWaypoint[wp.ID] = wp;
            // Set volatile ID
            SetVolatileIDForWaypoint(wp);
            // Return
            return(wp);
        }
Esempio n. 19
0
        /// <summary>
        /// Creates a typical waypoint.
        /// </summary>
        /// <param name="id">The ID of the waypoint.</param>
        /// <param name="tier">The position (tier).</param>
        /// <param name="x">The position (x-coordinate).</param>
        /// <param name="y">The position (y-coordinate).</param>
        /// <param name="podStorageLocation">Indicates whether the waypoint serves as a storage location.</param>
        /// <param name="isQueueWaypoint">Indicates whether the waypoint belongs to a queue.</param>
        /// <returns>The newly created waypoint.</returns>
        public Waypoint CreateWaypoint(int id, Tier tier, double x, double y, bool podStorageLocation, bool isQueueWaypoint)
        {
            Waypoint wp = new Waypoint(this)
            {
                ID = id, Tier = tier, X = x, Y = y, PodStorageLocation = podStorageLocation, IsQueueWaypoint = isQueueWaypoint
            };

            tier.AddWaypoint(wp);
            Waypoints.Add(wp);
            WaypointGraph.Add(wp);
            _idToWaypoint[wp.ID] = wp;
            // Set volatile ID
            SetVolatileIDForWaypoint(wp);
            // Return
            return(wp);
        }
Esempio n. 20
0
        protected void Rule_Default()
        {
            if (level != "" && DistTo(rayman) < radius)
            {
                SetRule("");

                if ((graph = GetDsgVar <WaypointGraph>("Graph_1")) != null)
                {
                    rayman.ForceNav(graph, () => ChangeMap(level));
                }
                else
                {
                    ChangeMap(level);
                }
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Creates a new waypoint that serves as a storage location.
        /// </summary>
        /// <param name="id">The ID of the waypoint.</param>
        /// <param name="tier">The position (tier).</param>
        /// <param name="pod">The pod currently stored at it.</param>
        /// <returns>The newly created waypoint.</returns>
        public Waypoint CreateWaypoint(int id, Tier tier, Pod pod)
        {
            Waypoint wp = new Waypoint(this)
            {
                ID = id, X = pod.X, Y = pod.Y, Radius = pod.Radius, PodStorageLocation = true, Pod = pod
            };

            pod.Waypoint = wp;
            tier.AddWaypoint(wp);
            Waypoints.Add(wp);
            WaypointGraph.Add(wp);
            _idToWaypoint[wp.ID] = wp;
            // Set volatile ID
            SetVolatileIDForWaypoint(wp);
            // Return
            return(wp);
        }
Esempio n. 22
0
        /// <summary>
        /// Creates a new waypoint that serves as the handover point for an output station.
        /// </summary>
        /// <param name="id">The ID of the waypoint.</param>
        /// <param name="tier">The position (tier).</param>
        /// <param name="station">The station.</param>
        /// <param name="isQueueWaypoint">Indicates whether this waypoint is also a queue waypoint.</param>
        /// <returns>The newly created waypoint.</returns>
        public Waypoint CreateWaypoint(int id, Tier tier, OutputStation station, bool isQueueWaypoint)
        {
            Waypoint wp = new Waypoint(this)
            {
                ID = id, X = station.X, Y = station.Y, Radius = station.Radius, OutputStation = station, IsQueueWaypoint = isQueueWaypoint
            };

            station.Waypoint = wp;
            tier.AddWaypoint(wp);
            Waypoints.Add(wp);
            WaypointGraph.Add(wp);
            _idToWaypoint[wp.ID] = wp;
            // Set volatile ID
            SetVolatileIDForWaypoint(wp);
            // Return
            return(wp);
        }
Esempio n. 23
0
        private void OnEnable()
        {
            graphProperty     = serializedObject.FindProperty("MainGraph");
            movingObstacleTag = serializedObject.FindProperty("movingObstacleTag");
            autoRebuild       = serializedObject.FindProperty("m_autoRebuild");
            graphState        = serializedObject.FindProperty("State");
            graph             = (WaypointGraph)target;

            plusTex   = LoadContent("plus", "Place Waypoint Node");
            penTex    = LoadContent("pen", "Edit Waypoint Node");
            removeTex = LoadContent("remove", "Remove Waypoint Node");
            clearTex  = LoadContent("clear", "Clear Waypoints");
            //cancelTex = Resources.Load<Texture>("cancel");
            //bulkTex = Resources.Load<Texture>("bulk");
            //confirmTex = Resources.Load<Texture>("confirm");
            btnUp   = Resources.Load <Texture2D>("button-up");
            btnDown = Resources.Load <Texture2D>("button-down");
        }
Esempio n. 24
0
 /// <summary>
 /// Creates a new task allocation manager instance.
 /// </summary>
 /// <param name="instance">The instance the manager belongs to.</param>
 public BotManager(Instance instance)
 {
     // Init if not already done
     Instance      = instance;
     waypointGraph = instance.WaypointGraph;
     foreach (var bot in instance.Bots)
     {
         _taskQueues[bot] = new DummyTask(instance, bot);
     }
     foreach (var bot in instance.Bots)
     {
         _lastTaskEnqueued[bot] = null;
     }
     // Subscribe to order assignment updates (in order to add more work on-the-fly)
     instance.OrderAllocated  += OrderAllocated;
     instance.BundleAllocated += BundleAllocated;
     instance.PodPickup       += PodPickup;
 }
    void InitWaypoints()
    {
        Waypoints   = GetComponentsInChildren <WaypointNode>();
        m_Entrances = new List <WaypointNode>();
        Debug.Log($"Found {Waypoints.Length} Waypoints");

        // Clear any existing edges
        foreach (var wp in Waypoints)
        {
            wp.simulation = this;
            wp.Edges.Clear();
            if (wp.waypointType == WaypointNode.WaypointType.Entrance)
            {
                m_Entrances.Add(wp);
            }
        }
        m_WaypointGraph = new WaypointGraph(Waypoints);

        var startTicks = DateTime.Now.Ticks;

        // TODO avoid duplication with the gizmos code by passing a delegate?
        foreach (var wp in Waypoints)
        {
            foreach (var otherWaypoint in Waypoints)
            {
                if (wp == otherWaypoint)
                {
                    continue;
                }

                var validConnection = wp.ShouldConnect(OneWayAisles, otherWaypoint);
                if (validConnection)
                {
                    wp.Edges.Add(otherWaypoint);
                }
            }
        }
        var endTicks = DateTime.Now.Ticks;

        Debug.Log($"Raycasting between Waypoints took {(endTicks - startTicks) * s_TicksToSeconds} seconds");
    }
        public void WaypointPathfinding()
        {
            var waypointData = new WaypointData();
            var waypoint     = new Waypoint[32];

            for (int i = 0; i < waypoint.Length; ++i)
            {
                waypoint[i] = new Waypoint()
                {
                    link     = new List <int>(4),
                    position = new Vector2(0, i),
                };
            }
            waypoint[0].link.Add(1);
            waypoint[0].link.Add(2);
            waypoint[1].link.Add(6);
            waypoint[2].link.Add(6);
            waypoint[2].link.Add(3);
            waypoint[3].link.Add(4);
            waypoint[4].link.Add(5);
            waypoint[6].link.Add(7);
            waypoint[7].link.Add(8);
            waypoint[7].link.Add(9);
            waypointData.waypoint = waypoint;
            waypointData.MakeBidirectional();
            var graph = new WaypointGraph(waypointData);
            var astar = new AStarPathfinding();

            astar.FindPath(graph, 0, 9);
            CheckPath(astar.FormattedPath(), "path:9-7-6-2-0");
            astar.FindPath(graph, 5, 8);
            CheckPath(astar.FormattedPath(), "path:8-7-6-2-3-4-5");
            astar.FindPath(graph, 5, 31);
            CheckPath(astar.FormattedPath(), "path:31-x-9-7-6-2-3-4-5");

            astar.FindPath(graph, 0, -1);
            CheckPath(astar.FormattedPath(9), "path:9-7-6-2-0");
            CheckPath(astar.FormattedPath(6), "path:6-2-0");
            CheckPath(astar.FormattedPath(4), "path:4-3-2-0");
            CheckPath(astar.FormattedPath(11), "path:11-x-9-7-6-2-0");
        }
Esempio n. 27
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        waypointGraph = (WaypointGraph)target;

        if (waypointGraph == null || waypointGraph.waypoints == null || waypointGraph.edges == null)
        {
            waypointGraph.InitializeGraph();
        }
        else if (waypointGraph.isEmpty())
        {
            waypointGraph.PopulateGraph();
        }

        waypointStr = EditorGUILayout.TextField("Waypoint: ", waypointStr);

        if (GUILayout.Button("Add Waypoint"))
        {
            waypointGraph.CreateWaypoint(waypointStr);

            waypointStr = "";
            Repaint();
        }

        fromStr = EditorGUILayout.TextField("From: ", fromStr);
        toStr   = EditorGUILayout.TextField("To: ", toStr);

        if (GUILayout.Button("Add Edge"))
        {
            waypointGraph.CreateEdge(fromStr, toStr);

            fromStr = "";
            toStr   = "";
            Repaint();
        }

        SceneView.RepaintAll();
    }
Esempio n. 28
0
    public void Start()
    {
        if (!doMagic)
        {
            return;
        }
        SphereCollider col   = GetComponent <SphereCollider> ();
        WaypointGraph  graph = GameObject.FindGameObjectWithTag("Planet").GetComponent <WaypointGraph>();

        Ray          ray;
        RaycastHit   hit;
        WaypointNode other;
        WaypointEdge edge;

        string[]  masks = { "Waypoint" };
        LayerMask mask  = LayerMask.GetMask(masks);

        if (right == null)
        {
            if (Physics.Raycast(transform.position, Vector3.right, out hit, 50.0f, mask.value))
            {
                other = hit.collider.gameObject.GetComponent <WaypointNode> ();
                if (other != null)
                {
                    right      = other;
                    other.left = this;
                    edge       = new WaypointEdge();
                    edge.one   = this;
                    edge.two   = other;
                    graph.edges.Add(edge);
                }
            }
        }
        if (left == null)
        {
            ray = new Ray(transform.position, Vector3.left);
            if (Physics.Raycast(transform.position, Vector3.left, out hit, 50.0f, mask.value))
            {
                other = hit.collider.gameObject.GetComponent <WaypointNode> ();
                if (other != null)
                {
                    left        = other;
                    other.right = this;
                    edge        = new WaypointEdge();
                    edge.one    = this;
                    edge.two    = other;
                    graph.edges.Add(edge);
                }
            }
        }
        if (front == null)
        {
            ray = new Ray(transform.position, Vector3.forward);
            if (Physics.Raycast(transform.position, Vector3.forward, out hit, 50.0f, mask.value))
            {
                other = hit.collider.gameObject.GetComponent <WaypointNode> ();
                if (other != null)
                {
                    front      = other;
                    other.back = this;
                    edge       = new WaypointEdge();
                    edge.one   = this;
                    edge.two   = other;
                    graph.edges.Add(edge);
                }
            }
        }
        if (back == null)
        {
            ray = new Ray(transform.position, Vector3.back);
            if (Physics.Raycast(transform.position, Vector3.back, out hit, 50.0f, mask.value))
            {
                other = hit.collider.gameObject.GetComponent <WaypointNode> ();
                if (other != null)
                {
                    back        = other;
                    other.front = this;
                    edge        = new WaypointEdge();
                    edge.one    = this;
                    edge.two    = other;
                    graph.edges.Add(edge);
                }
            }
        }
    }
Esempio n. 29
0
 public Waypoint(GameObject obj, WaypointGraph graph)
 {
     m_obj   = obj;
     m_graph = graph;
 }
Esempio n. 30
0
    void GenerateMap()
    {
        map = new int[width, height];
        //RandomFillMap ();
        // create the initial perlin noise map
        PerlinFillMap();
        IdentifyPoints();

        // Generate the main rooms
        List<Vector2> rooms = GenerateRoomCenters(roomsToGen, roomSize, 2);
        rooms = ForceDirectRooms (rooms, roomSize, 0.1f, 80, width, height, 20);
        for (int i = 0; i < rooms.Count; i++) {
            EmptyCircle((int) rooms[i].x, (int) rooms[i].y, 15);
        }

        for (int i = 0; i < 5; i++) {
            // use cellular automata to smooth out the map
            SmoothMap ();
        }

        // add in the spawn point
        if (useRandomSeed) {
            seed = Time.time.ToString ();
        }
        System.Random prng = new System.Random (seed.GetHashCode ());
        int spawnIndex = prng.Next (0, rooms.Count);
        CreateSpawnPoint(rooms [spawnIndex]);
        rooms.RemoveAt (spawnIndex);
        if (pvp) {
            CreateSpawnPoint(rooms [spawnIndex]);
        } else {
            // spawn in a single enemy
            int enemyIndex = prng.Next (0, rooms.Count);
            StoreEnemySpawns (rooms);
        }

        // add a border around the map
        int borderSize = 5;
        int[,] borderedMap = new int[width + borderSize * 2, height + borderSize * 2];
        for (int x = 0; x < borderedMap.GetLength(0); x++) {
            for (int y = 0; y < borderedMap.GetLength(1); y++) {
                if (x >= borderSize && x < width + borderSize && y >= borderSize && y < height + borderSize) {
                    borderedMap[x,y] = map[x-borderSize,y-borderSize];
                } else {
                    borderedMap[x,y] = 1;
                }
            }
        }

        // generate the mesh
        GetComponent<MeshGenerator> ().GenerateMesh (borderedMap, 1);

        // see which nodes are connected
        // note that we need to call debug perlin first for this to work
        graph = new WaypointGraph (debugPoints, width, height);
        // test the waypoint graph a bit
        Waypoint startPoint = graph.waypoints[prng.Next(0, graph.waypoints.Count)];
        Waypoint endPoint = graph.waypoints[prng.Next(0, graph.waypoints.Count)];
        // attach the waypoint graph to the ai manager
        aiManager.setWaypointGraph(graph);
    }
 public void setWaypointGraph(WaypointGraph graph)
 {
     this.graph = graph;
 }
Esempio n. 32
0
 // Use this for initialization
 void Start()
 {
     //Find waypoint graph
     graphNodes = GameObject.FindGameObjectWithTag("waypoint graph").GetComponent <WaypointGraph>();
 }
Esempio n. 33
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        WaypointGraph instance = (WaypointGraph)target;

        if (GUILayout.Button("Build waypoint graph distance"))
        {
            var tmpWaypoints = instance.GetComponentsInChildren <WaypointEditor>();

            foreach (var waypointEditor in tmpWaypoints)
            {
                waypointEditor.maxDistance = new List <float>();

                for (var index = 0; index < waypointEditor.neighbors.Count; index++)
                {
                    var     neighbor = waypointEditor.neighbors[index];
                    Vector3 startPos = waypointEditor.transform.position;
                    Vector3 endPos   = neighbor.transform.position;
                    Vector3 dir      = (endPos - startPos).normalized;

                    Vector3 perp = new Vector3(dir.z, 0, -dir.x);

                    Vector3 offset = Vector3.zero;

                    for (int i = 0; i < 10; i++)
                    {
                        Physics.Raycast(startPos + dir * i, perp, out RaycastHit hit);
                    }

                    float maxDistance = float.MaxValue;

                    while (Vector3.Distance(startPos + offset, startPos) < Vector3.Distance(startPos, endPos))
                    {
                        offset += dir;

                        if (Physics.Raycast(startPos + offset, perp, out RaycastHit hit))
                        {
                            float distance = Vector3.Distance(startPos + offset, hit.point);

                            if (distance < maxDistance)
                            {
                                maxDistance = distance;
                            }
                        }

                        if (Physics.Raycast(startPos + offset, -perp, out RaycastHit hit2))
                        {
                            float distance = Vector3.Distance(startPos + offset, hit2.point);

                            if (distance < maxDistance)
                            {
                                maxDistance = distance;
                            }
                        }
                    }

                    waypointEditor.maxDistance.Add(maxDistance);
                }
            }
        }
    }