Ejemplo n.º 1
0
    void Start()
    {
        _audioMaterial = new Material[8];
        _colourOne     = new Color[8];
        _colourTwo     = new Color[8];

        for (int i = 0; i < 8; i++)
        {
            _colourOne[i]     = _gradientOne.Evaluate((1.0f / 8.0f) * i);
            _colourTwo[i]     = _gradientTwo.Evaluate((1.0f / 8.0f) * i);
            _audioMaterial[i] = new Material(_material);
        }

        _audioManager = FindObjectOfType <AudioManager>();
        DebugHelper.debugHelper.IsValidObject(_audioManager);

        _flowField = GetComponent <FlowField>();

        int bandCount = 0;

        for (int i = 0; i < _flowField.NumberOfParticles; i++)
        {
            //Create a more even distribution across the frequency bands
            int band = bandCount % 8;
            _flowField.ParticleMeshRenderers[i].material = _audioMaterial[band];
            _flowField.Particles[i].AudioBand            = band;
            bandCount++;
        }
    }
Ejemplo n.º 2
0
 private void InitializeFlowField()
 {
     curFlowField = new FlowField(cellRadius, gridSize);
     curFlowField.CreateGrid();
     print(curFlowField);
     gridDebug.SetFlowField(curFlowField);
 }
Ejemplo n.º 3
0
 public void SetUp()
 {
     raw_tileData = new List <TileNode[, ]>();
     mapHolder    = this.GetComponent <MapBlockManager>();
     mapHolder.OnAddMapComponent += OnAddBlock;
     _flowField = new FlowField();
 }
Ejemplo n.º 4
0
        public override void Redraw(float currentTime, float elapsedTime)
        {
            // selected vehicle (user can mouse click to select another)
            IVehicle selected = Demo.SelectedVehicle;

            Demo.UpdateCamera(elapsedTime, selected);
            Demo.GridUtility(Vector3.Zero);

            //Draw flow field
            const float RANGE   = 50;
            const int   SAMPLES = 25;

            for (int i = 0; i < SAMPLES; i++)
            {
                for (int j = 0; j < SAMPLES; j++)
                {
                    Vector3 location = new Vector3(RANGE / SAMPLES * i - RANGE / 2, 0, RANGE / SAMPLES * j - RANGE / 2);
                    var     flow     = FlowField.Sample(location);
                    Annotations.Line(location, location + flow, Color.Black.ToVector3().FromXna());
                }
            }

            // draw vehicles
            foreach (var vehicle in _followers)
            {
                vehicle.Draw();
            }
        }
 private void InitializeFlowField()
 {
     Debug.Log($"Generating grid of size: {gridSize.ToString()}");
     curFlowField = new FlowField(cellRadius, gridSize);
     curFlowField.CreateGrid();
     gridDebug.SetFlowField(curFlowField);
 }
Ejemplo n.º 6
0
        public void Create_Grid()
        {
            FlowField testFlowField = A.FlowField.WithCellRadius(0.5f).WithSize(10, 10);

            testFlowField.CreateGrid();
            testFlowField.grid.Length.Should().Be(100);
        }
Ejemplo n.º 7
0
    // Use this for initialization
    void Start()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        CreateGroundPlane();

        Debug.Log("Generating terrain...");
        CreateTerrain();
        Debug.Log("Done!");

        Debug.Log("Separating terrain...");
        CreateTerrainGroups();
        Debug.Log("Done!");

        CreateDebugShapes();

        FlowField.InitUnitField();
        FlowField.InitWallCostField();

        debugMode = 0;
    }
Ejemplo n.º 8
0
        public void Get_Cells_At_Relative_Pos_On_Corner_Cells()
        {
            FlowField testFlowField = A.FlowField.WithCellRadius(0.5f).WithSize(10, 10);

            testFlowField.CreateGrid();

            Vector2Int originCellIndex1 = new Vector2Int(0, 0);
            Vector2Int originCellIndex2 = new Vector2Int(9, 9);

            List <Cell> neighborCells1 = testFlowField.GetNeighborCells(originCellIndex1, GridDirection.CardinalAndIntercardinalDirections);
            List <Cell> neighborCells2 = testFlowField.GetNeighborCells(originCellIndex2, GridDirection.CardinalAndIntercardinalDirections);

            List <Cell> expectedCells1 = new List <Cell>();

            expectedCells1.Add(testFlowField.grid[0, 1]);
            expectedCells1.Add(testFlowField.grid[1, 1]);
            expectedCells1.Add(testFlowField.grid[1, 0]);

            List <Cell> expectedCells2 = new List <Cell>();

            expectedCells2.Add(testFlowField.grid[9, 8]);
            expectedCells2.Add(testFlowField.grid[8, 8]);
            expectedCells2.Add(testFlowField.grid[8, 9]);

            neighborCells1.Should().BeEquivalentTo(expectedCells1);
            neighborCells2.Should().BeEquivalentTo(neighborCells2);
        }
Ejemplo n.º 9
0
 public void Create(Tile destination, IntegrationField integrationField, FlowField flowField, int key)
 {
     Destination      = destination;
     IntegrationField = integrationField;
     FlowField        = flowField;
     Key = key;
 }
Ejemplo n.º 10
0
    //Generate a flowfield texture
    private Texture GenerateFlowFieldTexture(float[,] flowField, bool[,] isObstacle, bool isBlackWhite)
    {
        //Assume the flow field is always square
        int mapWidth = flowField.GetLength(0);

        //Create a texture on which we will display the information
        Texture2D texture = GenerateNewDebugTexture(mapWidth);

        //Debug flow field by changing the color of the cells
        //To display the grid with a grayscale, we need the max distance to the node furthest away
        float maxDistance = FlowField.GetMaxDistance(flowField);


        //Generate the colors
        //More efficient to generate the colors once and then add the array to the texture
        Color[] colors = new Color[mapWidth * mapWidth];

        for (int x = 0; x < mapWidth; x++)
        {
            for (int z = 0; z < mapWidth; z++)
            {
                //Default, meaning unreachable cell
                Color thisColor = Color.blue;

                float distance = flowField[x, z];

                if (isObstacle[x, z])
                {
                    thisColor = Color.black;
                }
                //If this is not an obstacle or a cell that was unreachable in the flowfield
                else if (distance < float.MaxValue)
                {
                    float rgb = 1f - (distance / maxDistance);

                    if (isBlackWhite)
                    {
                        thisColor = new Vector4(rgb, rgb, rgb, 1.0f);
                    }
                    //Red-green scale
                    else
                    {
                        thisColor = new Vector4(1f - rgb, rgb, 0f, 1.0f);
                    }
                }

                colors[z * mapWidth + x] = thisColor;
            }
        }


        //Add the colors to the texture
        texture.SetPixels(colors);

        texture.Apply();


        return(texture);
    }
Ejemplo n.º 11
0
 private void InitializeFlowField()
 {
     team1_flowfield = new FlowField(cellRadius, gridSize);
     team1_flowfield.CreateGrid();
     team2_flowfield = new FlowField(cellRadius, gridSize);
     team2_flowfield.CreateGrid();
     gridDebug.SetFlowField(team1_flowfield);
 }
Ejemplo n.º 12
0
    // Use this for initialization
    public override void Start()
    {
        base.Start();

        flowFieldFollowers = manager.GetComponent <ExerciseManager>().flowFieldFollowers;
        flowScript         = manager.GetComponent <FlowField>();
        obstacles          = manager.GetComponent <ExerciseManager>().obstacles;
    }
Ejemplo n.º 13
0
    public Vector3 Flow(FlowField flow)
    {
        m_dv   = Vector3.zero;
        m_dv   = flow.GetFlowDirection(transform.position) * maxSpeed;
        m_dv.y = 0;

        return(m_dv);
    }
Ejemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(1))
        {
            foreach (KeyValuePair <int, GameObject> pair in selected)
            {
                //Will need to change this - each unit will need to store their own flow field
                //Make a new GridController?

                //If we make a new controller gotta make sure we set the x and the y


                //gridController.gridSize.x = 50;
                //gridController.gridSize.y = 50;



                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit = new RaycastHit();

                //If it hits something
                if (Physics.Raycast(ray, out hit, 50000.0f, 1 << 8))
                {
                    gridController = GetComponent <GridController>();

                    GameObject  gameobj   = pair.Value;
                    AIBehaviour behaviour = gameobj.GetComponent <AIBehaviour>();



                    //Flow field handling


                    flowfield = gridController.InitializeFlowField(hit.point);


                    Unit unit = gameobj.GetComponent <Unit>();

                    ///Don't like this
                    unit.ai.finalDest = hit.point;
                    //unit.ai.gridController = gridController;
                    unit.ai.curFlowField = flowfield;

                    //behaviour.dest = Vector3.zero;
                    //behaviour.target = null;



                    unit.state = Unit.State.moving;
                    //behaviour.stop();

                    //behaviour.dest = hit.point;
                }
            }
        }
    }
Ejemplo n.º 15
0
 private void InitAPI()
 {
     TileHelp.Init(this);
     SectorHelp.Init(this);
     AStar.Init(this);
     FlowField.Init(this);
     JumpFlowFiled.Init(this);
     IggPathFinder.Init(this);
     MapChangeManger.Init(this);
 }
Ejemplo n.º 16
0
 public void StartMoving(FlowField FF)
 {
     MyField = FF;
     if (!ismoving)
     {
         Arrived  = false;
         ismoving = true;
         StartCoroutine(Transverse());
     }
 }
Ejemplo n.º 17
0
    //Probably want to put this somewhere better
    private FlowField genFlowField(Vector3 desti)
    {
        gridController = sys.GetComponent <GridController>();


        FlowField flowfield = gridController.InitializeFlowField(desti);


        return(flowfield);
    }
Ejemplo n.º 18
0
 public FactoryBot(Vector2Int myTile)
 {
     position         = new Vector2(myTile.x + Random.Range(-.5f, .5f), myTile.y + Random.Range(-.5f, .5f));
     radius           = .15f;
     hitCount         = 0;
     navigator        = null;
     targetCrafter    = null;
     movingToResource = false;
     holdingResource  = false;
 }
Ejemplo n.º 19
0
 public FactoryBot(Vector2 myPosition)
 {
     position         = myPosition;
     radius           = .15f;
     hitCount         = 0;
     navigator        = null;
     targetCrafter    = null;
     movingToResource = false;
     holdingResource  = false;
 }
Ejemplo n.º 20
0
    private void Awake()
    {
        selfUnit      = GetComponent <Unit>();
        selfRigidbody = selfUnit.selfRigidbody;
        selfCollider  = selfUnit.selfCollider;
        UnitSpawner spawner = GetComponentInParent <UnitSpawner>();

        map       = spawner.map;
        flowField = spawner.flowField;
    }
Ejemplo n.º 21
0
        public void Test_Getting_Cell_From_World_Position_Off_Grid_Max()
        {
            FlowField testFlowField = A.FlowField.WithCellRadius(0.5f).WithSize(10, 10);

            testFlowField.CreateGrid();
            Vector3 worldPos     = new Vector3(100f, 0, 100f);
            Cell    testCell     = testFlowField.GetCellFromWorldPos(worldPos);
            Cell    expectedCell = testFlowField.grid[9, 9];

            testCell.Should().Be(expectedCell);
        }
Ejemplo n.º 22
0
/*
 *  //New Additions
 *  public float current_temp;
 *  public float initial_temp = 100f;
 *  float lcl;
 *  public float dewpoint = 40f;*/
    public void constructVehicle(float ms, float mf, FlowField flow)
    {
        //r = 3.0f;
        maxspeed     = ms;
        maxforce     = mf;
        acceleration = Vector3.zero;
        velocity     = Vector3.zero;
        flowfield    = flow;/*
                             * current_temp = initial_temp;
                             * lcl = (initial_temp - dewpoint) / 8.3f;*/
    }
Ejemplo n.º 23
0
    // Implementing Reynolds' flow field following algorithm
    // http://www.red3d.com/cwr/steer/FlowFollow.html
    public void follow(FlowField flow)
    {
        // What is the vector at that spot in the flow field?
        Vector3 desired = flow.lookup(this.gameObject.transform.localPosition);

        // Scale it up by maxspeed
        desired *= maxspeed;
        // Steering is desired minus velocity
        Vector3 steer = desired - velocity;

        steer = Vector3.ClampMagnitude(steer, maxforce);
        ApplyForce(steer);
    }
Ejemplo n.º 24
0
        public void Check_Walkable_Cell()
        {
            FlowField testFlowField = A.FlowField.WithCellRadius(0.5f).WithSize(10, 10);

            testFlowField.CreateGrid();
            Cell testCell = testFlowField.grid[5, 5];

            Cell destinationCell = testFlowField.grid[0, 0];

            testFlowField.CreateIntegrationField(destinationCell);

            testCell.bestCost.Should().NotBe(ushort.MaxValue);
        }
Ejemplo n.º 25
0
    public void setFlowField(FlowField flowField)
    {
        if (this.flowField == null)
        {
            FlowField.AddUnit(this.transform.position, this.separationRadius, this.separationFactor);
        }

        this.flowField = flowField;


        //this.flowField.AddSeparation( this.transform.position, this.separationRadius, this.separationFactor );
        //this.flowField.AddSeparation( this.transform.position, this.cohesionRadius, this.cohesionFactor );
    }
Ejemplo n.º 26
0
    //Todo - Probably move this to the flowfield script and pull requests from there
    public void moveTo(Vector3 destination)
    {
        moving = true;

        FlowField ff = genFlowField(destination);

        //Move to a gold node
        moveai.finalDest = destination;
        //worker.ai.finalDest = dest;
        moveai.curFlowField = ff;
        //worker.ai.curFlowField = flowfield;
        moveai.state = moveAI.State.Moving;
        //worker.state = Worker.State.moving;
    }
    void Update()
    {
        // get a desiredVelocity from the flow field, based on our current position
        Vector3 desiredVelocity = FlowField.GetFlowAtPos(transform.position);

        // change our velocity
        velocity += (desiredVelocity - velocity) * 0.25f;

        // make sure we don't take off
        velocity.y = 0;

        // update our position
        transform.position = transform.position + velocity;
    }
Ejemplo n.º 28
0
    //FOLLOW FLOW FIELDS
    public Vector3 FollowField(Vector3 position)
    {
        GameObject target = GameObject.Find("Plane");
        FlowField  script = target.GetComponent <FlowField>();

        position += script.GetFlowDirection(position);
        Vector3 desired = position - vehiclePosition;

        desired.Normalize();
        desired = desired * maxSpeed;
        Vector3 steeringForce = desired - velocity;

        return(steeringForce);
    }
Ejemplo n.º 29
0
 public void Awake()
 {
     btn_generate.onClick.AddListener(GenerateCubeMap);
     btn_setend.onClick.AddListener(SetEnd);
     btn_setstart.onClick.AddListener(SetStart);
     btn_ff.onClick.AddListener(GenerateFlowField);
     btn_go.onClick.AddListener(GoFF);
     ff = new FlowField();
     //left, leftup, up, rightup, right, rightdown, down, leftdown
     direction = new Direction[8] {
         new Direction(-1, 0), new Direction(0, 1), new Direction(1, 0), new Direction(0, -1),
         new Direction(-1, 1), new Direction(1, 1), new Direction(1, -1), new Direction(-1, -1)
     };
 }
Ejemplo n.º 30
0
    public static FlowFieldNode[,] GenerateFlowField(Map map, IntVector2 targetPos)
    {
        //The final flow field will be stored here, so init it
        FlowFieldNode[,] nodesArray = new FlowFieldNode[map.MapWidth, map.MapWidth];

        for (int x = 0; x < map.MapWidth; x++)
        {
            for (int z = 0; z < map.MapWidth; z++)
            {
                bool isWalkable = !map.cellData[x, z].isObstacleInCell;

                //bool isWalkable = true;

                FlowFieldNode node = new FlowFieldNode(isWalkable, map.cellData[x, z].centerPos, new IntVector2(x, z));

                nodesArray[x, z] = node;
            }
        }


        //A flow field can have several start nodes
        List <FlowFieldNode> startNodes = new List <FlowFieldNode>();

        //To a single target
        //startNodes.Add(nodesArray[targetPos.x, targetPos.z]);

        //To all obstacles
        for (int x = 0; x < map.MapWidth; x++)
        {
            for (int z = 0; z < map.MapWidth; z++)
            {
                if (map.cellData[x, z].isObstacleInCell)
                {
                    startNodes.Add(nodesArray[x, z]);
                }
            }
        }



        //Generate the flow field
        FlowField.Generate(startNodes, nodesArray, includeCorners: true);

        //Debug.Log("Distance flow field: " + nodesArray[targetPos.x, targetPos.z].totalCostFlowField);
        //Debug.Log("Distance flow field: " + nodesArray[0, 0].totalCostFlowField);


        return(nodesArray);
    }
Ejemplo n.º 31
0
    public Vector3 Flow( FlowField flow )
    {
        m_dv = Vector3.zero;
        m_dv = flow.GetFlowDirection( transform.position ) * maxSpeed;
        m_dv.y = 0;

        return m_dv;
    }