コード例 #1
0
    void GenerateGrid(Vector2 startNode, int xSize, int ySize)
    {
        startNode = Vector2.zero;
        for (int x = 0; x < xSize; x++)
        {
            for (int y = 0; y < ySize; y++)
            {
                GameObject go = new GameObject(string.Format("NODE-:{0}|{1}", x.ToString(), y.ToString()));
                go.transform.SetParent(this.transform);
                go.transform.SetPositionAndRotation(new Vector3(x + this.transform.position.x, transform.position.y, y + this.transform.position.z), Quaternion.identity);
                go.AddComponent <MeshRenderer>().enabled = false;
                go.AddComponent <MeshFilter>();

                Color col = new Color();
                switch ((x + y) % 2)
                {
                case 0:
                    col = Color.green;
                    break;

                case 1:
                    col = Color.gray;
                    break;
                }
                col.a = 0.01f;
                CubeGenerator.makeCube(go, col);
                go.AddComponent <MeshCollider>().sharedMesh = go.GetComponent <MeshFilter>().mesh;
                go.AddComponent <Node>();
                Vector2 v = go.GetComponent <Node>().pos;
            }
        }
    }
コード例 #2
0
ファイル: UIManager.cs プロジェクト: cyc1209/ARproject
    //싱글톤
    void Awake()
    {
        if (UIManager.instance == null)
        {
            UIManager.instance = this;
        }

        cubeGenerator = GameObject.Find("CubeGenerator").GetComponent <CubeGenerator>();
    }
コード例 #3
0
 public override void OnInspectorGUI()
 {
     targetGenerator = (CubeGenerator)target;
     base.OnInspectorGUI();
     targetGenerator.GenerateMesh();
     /*
     EditorGUILayout.LabelField("Damage Per Shot", string.Format("{0:f2}", targetGun.GetDamagePerShot()));
     EditorGUILayout.LabelField("Damage Per Second", string.Format("{0:f2}", targetGun.GetDamagePerSecond()));
     */
 }
コード例 #4
0
ファイル: RedBehavior.cs プロジェクト: dwajdy/ColorShooter
 // Red cube removes all surroung cubes when shot.
 public override void Hit(CubesWallHandler cubesWallHandler, CubeGenerator cubeGenerator)
 {
     for (uint row = y == 0 ? 0 : y - 1; row <= y + 1; ++row)
     {
         for (uint col = x == 0 ? 0 :x - 1; col <= x + 1; ++col)
         {
             cubesWallHandler.Remove(col, row, col == x && row == y ? false : true);
         }
     }
 }
コード例 #5
0
        public (ParticipatingMediaComponent, TransformComponent) Create(int resolutionWidth, int resolutionHeight)
        {
            var entity = this.Entities.Create();
            var cube   = CubeGenerator.Generate(this.Device);

            var participatingMedia = ParticipatingMediaComponent.Create(entity, this.Device, cube, resolutionWidth, resolutionHeight, 1.0f, Color.White);
            var transform          = new TransformComponent(entity);

            this.Components.Add(participatingMedia);
            this.Components.Add(transform);

            return(participatingMedia, transform);
        }
コード例 #6
0
ファイル: Player.cs プロジェクト: cnoco1at3/ayayeye
 // Use this for initialization
 void Start()
 {
     generator_now = StartGenerator.GetComponent <CubeGenerator> ();
     generator_now.SetMoving(true);
     cube_now = generator_now.cube.GetComponent <CubeBehavior>();
     if (cube_now.GetDir() == 0)
     {
         target = null;
     }
     else
     {
         target = generator_now.neighbors[cube_now.GetDir() - 1];
     }
 }
コード例 #7
0
ファイル: WhiteBehavior.cs プロジェクト: dwajdy/ColorShooter
    // White cube replaces all surroung cubes when shot, with 1 basic color.
    public override void Hit(CubesWallHandler cubesWallHandler, CubeGenerator cubeGenerator)
    {
        cubeGenerator.GetRandomBasicColor(out var colorMaterial, out var colorAnimation);

        for (uint row = y == 0 ? 0 : y - 1; row <= y + 1; ++row)
        {
            for (uint col = x == 0 ? 0 :x - 1; col <= x + 1; ++col)
            {
                cubesWallHandler.Replace(col, row, colorMaterial, colorAnimation, "CubeBehavior");
            }
        }

        cubesWallHandler.Remove(x, y);
    }
コード例 #8
0
    //this Gameobject array is returned to tileGenerator with all the values for the cubes to be stored in the ChunkArray, aswell as tellingthe CubeGenerator script where to offset the cubes
    public GameObject[,,] CubeMake(int length, int depth, int height, float[,] heightMap, int chunkX, int chunkY)
    {
        //paramters are obtained from the tileGenrator script and they specift the exact size of the chunk, then the script runs through each value in the nested loops to check
        //with the heightmap values whether a cube should be spawned in that x,y,z coordinate or not

        cubeArray = new GameObject[length, height, depth];
        for (int xIndex = 0; xIndex < length; xIndex++)
        {
            for (int zIndex = 0; zIndex < depth; zIndex++)
            {
                for (int yIndex = 0; yIndex < height; yIndex++)
                {
                    int xOffset = chunkX * length;
                    int zOffset = chunkY * depth;

                    // height map is 0-1 also divided by 2.0 as a seondary map scale a heigher number will be smoother a lower number is more tall and rigid,
                    // y/height is in decimal form which will be 0-1.

                    //if the heighmap values at the zIndex and yIndex postions are greater then the yIndex devided by the total height specified example 4/10 will be 0.4
                    //then the perlin noise values will be in float form for example 0.5, then it will spawn a cube here
                    if (heightMap[xIndex + xOffset, zIndex + zOffset] / 2.0 > yIndex / (double)height)
                    {
                        //runs the funtion to infrom the cubeGenerator script if there are neihgbors to the sides or not
                        Sides neighbours = CalculateNeighbours(heightMap, new Vector3(xIndex + xOffset, yIndex / (float)height, zIndex + zOffset));

                        //each cube will no be made a gameobject with this line we creat a gameobject then later its assigned to a cube
                        GameObject go = new GameObject();

                        //gameobject that was just made is added to the index of the aray wherever the nested loops are currently at
                        //so if this statment doesnt run form the if statment it will be simply empty space with nothing in it but the array is intialized to be a certain size so thats how we can add blocks into the map and onto the array
                        cubeArray[xIndex, yIndex, zIndex] = go;

                        //sending all parameters to the CubeGeneator script norde rto initialize a cube in the world

                        CubeGenerator.CreateCube(go, new Vector3(0, 0, 0), textureAtlas,
                                                 ChooseTerrainType(heightMap[xIndex + xOffset, zIndex + zOffset]), neighbours);

                        //these sections allow each face to have a coordinate position and lets us set up a naming convention to indicate the chunk and x,y,z place of each cube within the unity hierachy
                        go.transform.position = new Vector3(xIndex + xOffset, yIndex, zIndex + zOffset);

                        go.name = string.Format("Chunk(x:{0:D2} y:{1:D2})Index(x:{2:D2}y:{3:D2}z:{4:D2})",
                                                chunkX, chunkY, xIndex, yIndex, zIndex);
                    }
                }
            }
        }

        return(cubeArray);
    }
コード例 #9
0
ファイル: Player.cs プロジェクト: cnoco1at3/ayayeye
 public void SwitchG(GameObject next_generator)
 {
     generator_now.SetMoving(false);
     next_generator.GetComponent <CubeGenerator> ().SetLast(generator_now.gameObject);
     generator_now = next_generator.GetComponent <CubeGenerator>();
     generator_now.SetMoving(true);
     cube_now = generator_now.cube.GetComponent <CubeBehavior>();
     if (cube_now.GetDir() == 0)
     {
         target = null;
     }
     else
     {
         target = generator_now.neighbors[cube_now.GetDir() - 1];
     }
 }
コード例 #10
0
ファイル: CubeGenerator.cs プロジェクト: nigglev/QuadTree
        public override void OnInspectorGUI()
        {
            CubeGenerator CGScript = (CubeGenerator)target;

            CGScript._plane_size   = EditorGUILayout.FloatField("Plane Size", CGScript._plane_size);
            CGScript._cubes_number = EditorGUILayout.IntField("Number of Cubes", CGScript._cubes_number);

            CGScript._box_size_min = EditorGUILayout.FloatField("Minimum Box Size", CGScript._box_size_min);
            CGScript._box_size_max = EditorGUILayout.FloatField("Maximum Box Size", CGScript._box_size_max);

            CGScript._tree_depth = EditorGUILayout.IntField("Tree Depth", CGScript._tree_depth);


            CGScript._cube_prefab     = (GameObject)EditorGUILayout.ObjectField("Prefab", CGScript._cube_prefab, typeof(GameObject), true);
            CGScript._number_of_tests = EditorGUILayout.IntField("Number of Tests", CGScript._number_of_tests);


            //CGScript._brute_force_alg = EditorGUILayout.Toggle("Brute Force", CGScript._brute_force_alg);
            //CGScript._quad_tree_alg = EditorGUILayout.Toggle("QuadTree", CGScript._quad_tree_alg);
        }
コード例 #11
0
    public IEnumerator Start()
    {
        Instance = this;

        num = Random.Range(1, num);
        while (cubes.Count < num)
        {
            var bc = BonedCube.Make();
            bc.transform.SetParent(this.transform);             // The cubes are children of this transform so they can be placed on a ground plane in AR
            bc.a.transform.position = this.transform.position + new Vector3(LeModular.GetClosest(Random.Range(minXZ, maxXZ)), LeModular.GetClosest(Random.Range((maxHeight * -1), maxHeight)), LeModular.GetClosest(Random.Range(minXZ, maxXZ)));
            bc.Set(Random.Range(minXZ, maxXZ), Random.Range(minXZ, maxXZ), Random.Range(minXZ, maxXZ));
            cubes.Add(bc);
        }

        int count = 0;

        foreach (var bc in cubes)
        {
            if (bc == null)
            {
                continue;
            }

            // Add ModulorAgent script that will handle it's building behaviour
            var modulorAgent = bc.gameObject.AddComponent <ModulorAgent>();
            modulorAgent.bc = bc;
            modulorAgent.id = alphabet[count];
            agentDict.Add(modulorAgent, new List <Vector3>());
            // transform the world position of this transform to the local space of bc
            if (bc.a.position.y < this.transform.position.y)
            {
                // if i'm 10 meters tall and located at -1 then the visible section of me is going to be 4
                // if 10 meters tall and locate at +1 then the visible section of me is going to be 6
                float val = Random.Range(0f, 1f);
                Color col = val > 0.5f ? Color.white : Color.black;
                col.a = 0.5f;
                bc.GetComponentInChildren <Renderer>().material.color = col;
                bc.a.position          = new Vector3(bc.a.transform.position.x, this.transform.position.y, bc.a.transform.position.z);
                bc.b.position          = new Vector3(bc.b.transform.position.x, this.transform.position.y, bc.b.transform.position.z);
                modulorAgent.offGround = false;
            }
            else
            {
                float val = Random.Range(0f, 1f);
                Color col = val > 0.5f ? Color.blue : Color.red;
                col.a = 0.5f;
                bc.GetComponentInChildren <Renderer>().material.color = col;
                modulorAgent.offGround = true;
            }
            count++;
        }
        yield return(new WaitUntil(() => ready == cubes.Count));

        yield return(new WaitForSeconds(0.5f));

        Dictionary <float, Level> tmpLevels = new Dictionary <float, Level>();
        List <float> heights = new List <float>();

        foreach (Vector3 point in CubeGenerator.Instance.points)
        {
            if (!tmpLevels.ContainsKey(point.y))
            {
                tmpLevels.Add(point.y, new Level(point));
                tmpLevels[point.y].vertexPoints.Add(new Vertex(point));
            }
            else
            {
                tmpLevels[point.y].points.Add(point);
                tmpLevels[point.y].vertexPoints.Add(new Vertex(point));
            }
        }
        heights.AddRange(tmpLevels.Keys);
        heights.Sort();
        foreach (var f in heights)
        {
            Debug.Log(string.Format("Level {0}", f));
        }
        var tmpHeights = new List <float>();

        for (int i = 0; i < heights.Count; i++)
        {
            if (i < heights.Count - 1 && heights[i] != -1.1f)
            {
                var dif = heights[i + 1] - heights[i];
                if (dif > 0.6)
                {
                    if (tmpLevels.ContainsKey(heights[i]))
                    {
                        levels.Add(heights[i], tmpLevels[heights[i]]);
                    }
                }
                else
                {
                    if (tmpLevels.ContainsKey(heights[i]))
                    {
                        tmpLevels[heights[i]].vertexPoints.AddRange(tmpLevels[heights[i + 1]].vertexPoints);
                        levels.Add(heights[i], tmpLevels[heights[i]]);
                        heights[i + 1] = 1.1f;
                    }
                }
            }
        }
        indexLevels.AddRange(levels.Values);
        foreach (var entry in levels)
        {
            entry.Value.convexVertexes = JarvisMarchAlgorithm.GetConvexHull(entry.Value.vertexPoints);
            Debug.Log(string.Format("Merged Levels {0}", entry.Key));
        }
        foreach (var item in indexLevels)
        {
            if (item.convexVertexes == null)
            {
                continue;
            }

            var go = new GameObject();
            lrGos.Add(go);
            go.transform.SetParent(this.transform);
            LineRenderer lr = go.AddComponent <LineRenderer>();
            lr.material      = new Material(Shader.Find("Sprites/Default"));
            lr.positionCount = item.GetPointsFromVertexes().Count;
            lr.SetPositions(item.GetPointsFromVertexes().ToArray());
            lr.loop       = true;
            lr.startWidth = 0.1f;
            lr.endWidth   = 0.1f;
        }
        // this.transform.localScale = Vector3.one * scale;
        // Debug.Log(string.Format("Ready {0}", cubes.Count));
    }
コード例 #12
0
ファイル: CubeBehavior.cs プロジェクト: dwajdy/ColorShooter
 /// <summary>
 /// Represents the action to take once a cube is shot.
 /// For basic cubes, the default behaviour is to remove the cube.
 /// Other classes might override this behaviour such as red and white cubes.
 /// </summary>
 virtual public void Hit(CubesWallHandler cubesWallHandler, CubeGenerator cubeGenerator)
 {
     cubesWallHandler.Remove(x, y);
 }
コード例 #13
0
    public void RayDetect()
    {
        //creates a ray based on the position of the player Camera
        Debug.DrawRay(playerCamera.transform.position, playerCamera.transform.forward * 10, Color.green);

        //adding a block on left click
        if (Input.GetMouseButtonDown(0))
        {   //sends out a ray in direction of player
            if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, 10))
            {
                Debug.Log(hit.collider.name);
                //hit.collider.gameObject.GetComponent<MeshRenderer>().material.color = Color.red;


                //this bunch of TryParse's read off the postion of the long string name of each cube in the hierachy
                //we can access the number for the chunk its in as well as the x,y,z spot of each cube
                int xIn;
                int.TryParse(hit.transform.parent.name.Substring(24, 2), out xIn);
                int yIn;
                int.TryParse(hit.transform.parent.name.Substring(28, 2), out yIn);
                int zIn;
                int.TryParse(hit.transform.parent.name.Substring(32, 2), out zIn);

                int xChunk;
                int.TryParse(hit.transform.parent.name.Substring(8, 2), out xChunk);
                int yChunk;
                int.TryParse(hit.transform.parent.name.Substring(13, 2), out yChunk);

                Debug.Log($"x: {xIn} y: {yIn} z: {zIn}");
                Debug.Log("Chunk X = " + xChunk + "Chunk Y =" + yChunk);
                Debug.Log(hit.transform.position);

                //if we hit a ibject with the raycast we create a new gamobject which will have faces added to it
                GameObject go = new GameObject();
                go.transform.position = new Vector3(0, 0, 0);

                //we ge the chunkarray from tileGenerator script and add the gamobject to to the spot the collider hit
                tileGeneratorScript.chunkArray[xChunk, yChunk][xIn, yIn, zIn] = go;

                Debug.Log("this is before if: " + textureX + " " + textureY);

                //the if clusters identifys which face we hit with the ray and then we run the createcube function from cubeGenerator script to instatiate and entire new cube ajacent to the face we hit
                // on this first if statment if we hit the right face then we add a block on the xindex plus one or to the right of the hit object. we parse in all necesary paramters to make a cube and
                //we run a sperate neighbour check function that is on this script instead
                if (hit.collider.name == "rightFace")
                {
                    CubeGenerator.CreateCube(go, new Vector3((xIn + 1) + (xChunk * 10), yIn, zIn + (yChunk * 10)), hit.collider.gameObject.GetComponent <MeshRenderer>().material, new Vector2(textureX, textureY), CalculateNeighbours(go, cubeSpawnScript.cubeArray));

                    go.name = string.Format("Chunk(x:{0:D2} y:{1:D2})Index(x:{2:D2}y:{3:D2}z:{4:D2})", xChunk, yChunk, xIn + 1, yIn, zIn);
                    Debug.Log("this is after if: " + textureX + " " + textureY);
                }
                if (hit.collider.name == "leftFace")
                {
                    CubeGenerator.CreateCube(go, new Vector3((xIn - 1) + (xChunk * 10), yIn, zIn + (yChunk * 10)), hit.collider.gameObject.GetComponent <MeshRenderer>().material, new Vector2(textureX, textureY), CalculateNeighbours(go, cubeSpawnScript.cubeArray));
                    go.name = string.Format("Chunk(x:{0:D2} y:{1:D2})Index(x:{2:D2}y:{3:D2}z:{4:D2})", xChunk, yChunk, xIn - 1, yIn, zIn);
                }
                if (hit.collider.name == "topFace")
                {
                    CubeGenerator.CreateCube(go, new Vector3(xIn + (xChunk * 10), yIn + 1, zIn + (yChunk * 10)), hit.collider.gameObject.GetComponent <MeshRenderer>().material, new Vector2(textureX, textureY), CalculateNeighbours(go, cubeSpawnScript.cubeArray));
                    go.name = string.Format("Chunk(x:{0:D2} y:{1:D2})Index(x:{2:D2}y:{3:D2}z:{4:D2})", xChunk, yChunk, xIn, yIn + 1, zIn);
                    Debug.Log("this is after if: " + textureX + " " + textureY);
                }
                if (hit.collider.name == "frontFace")
                {
                    CubeGenerator.CreateCube(go, new Vector3(xIn + (xChunk * 10), yIn, (zIn + (yChunk * 10)) + 1), hit.collider.gameObject.GetComponent <MeshRenderer>().material, new Vector2(textureX, textureY), CalculateNeighbours(go, cubeSpawnScript.cubeArray));
                    go.name = string.Format("Chunk(x:{0:D2} y:{1:D2})Index(x:{2:D2}y:{3:D2}z:{4:D2})", xChunk, yChunk, xIn, yIn, zIn + 1);
                }
                if (hit.collider.name == "backFace")
                {
                    CubeGenerator.CreateCube(go, new Vector3(xIn + (xChunk * 10), yIn, (zIn - 1) + (yChunk * 10)), hit.collider.gameObject.GetComponent <MeshRenderer>().material, new Vector2(textureX, textureY), CalculateNeighbours(go, cubeSpawnScript.cubeArray));
                    go.name = string.Format("Chunk(x:{0:D2} y:{1:D2})Index(x:{2:D2}y:{3:D2}z:{4:D2})", xChunk, yChunk, xIn, yIn, zIn - 1);
                }

                if (hit.collider.name == "bottomFace")
                {
                    CubeGenerator.CreateCube(go, new Vector3(xIn + (xChunk * 10), yIn - 1, zIn + (yChunk * 10)), hit.collider.gameObject.GetComponent <MeshRenderer>().material, new Vector2(textureX, textureY), CalculateNeighbours(go, cubeSpawnScript.cubeArray));
                    go.name = string.Format("Chunk(x:{0:D2} y:{1:D2})Index(x:{2:D2}y:{3:D2}z:{4:D2})", xChunk, yChunk, xIn, yIn - 1, zIn);
                }
            }
        }
        //removing a block on right click
        else if (Input.GetMouseButtonDown(1))
        {
            if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, 10))
            {
                int xIn;
                int.TryParse(hit.transform.parent.name.Substring(24, 2), out xIn);
                int yIn;
                int.TryParse(hit.transform.parent.name.Substring(28, 2), out yIn);
                int zIn;
                int.TryParse(hit.transform.parent.name.Substring(32, 2), out zIn);

                int xChunk;
                int.TryParse(hit.transform.parent.name.Substring(8, 2), out xChunk);
                int yChunk;
                int.TryParse(hit.transform.parent.name.Substring(13, 2), out yChunk);


                CubeGenerator.CreateCube(tileGeneratorScript.chunkArray[xChunk, yChunk][(xIn - 1), yIn, zIn], new Vector3((xIn - 1) + (xChunk * 10), yIn, zIn + (yChunk * 10)), hit.collider.gameObject.GetComponent <MeshRenderer>().material
                                         , new Vector2(3, 16), CalculateNeighbours(tileGeneratorScript.chunkArray[xChunk, yChunk][(xIn - 1), yIn, zIn], cubeSpawnScript.cubeArray));


                tileGeneratorScript.chunkArray[xChunk, yChunk][xIn, yIn, zIn] = null;
                Destroy(hit.transform.parent.gameObject);
            }
        }
    }
コード例 #14
0
        public void Load(ContentStack content)
        {
            var red = new Texture2D(this.Device, 1, 1);

            red.SetData(new Color[] { Color.White });
            content.Link(red);

            var white = new Texture2D(this.Device, 1, 1);

            white.SetData(new Color[] { Color.White });
            content.Link(white);

            var black = new Texture2D(this.Device, 1, 1);

            black.SetData(new Color[] { Color.Black });
            content.Link(black);

            var normal = new Texture2D(this.Device, 1, 1);

            normal.SetData(new Color[] { new Color(0.5f, 0.5f, 1.0f) });
            content.Link(normal);

            var blue  = content.Load <Texture2D>("Textures/Blue");
            var bumps = content.Load <Texture2D>("Textures/Bricks_Normal");

            var rows     = 7;
            var columns  = 7;
            var spacing  = 2.5f;
            var geometry = SphereGenerator.Generate(this.Device, 15);

            for (var row = 0; row < rows; row++)
            {
                var metalicness = row / (float)rows;

                var metalicnessTexture = new Texture2D(this.Device, 1, 1);
                metalicnessTexture.SetData(new Color[] { new Color(Vector3.One * metalicness) });
                content.Link(metalicnessTexture);

                for (var col = 0; col < columns; col++)
                {
                    var roughness        = Math.Clamp(col / (float)columns, 0.05f, 1.0f);
                    var roughnessTexture = new Texture2D(this.Device, 1, 1);
                    roughnessTexture.SetData(new Color[] { new Color(Vector3.One * roughness) });
                    content.Link(roughnessTexture);

                    var material = new Material(red, normal, metalicnessTexture, roughnessTexture, white);

                    var position = new Vector3((col - (columns / 2.0f)) * spacing, (row - (rows / 2.0f)) * spacing, 0.0f);
                    this.CreateSphere(geometry, material, position, Vector3.One);
                }
            }

            var backgroundGeometry = CubeGenerator.Generate(this.Device);

            this.CreateSphere(backgroundGeometry, new Material(bumps, GeneratedAssets.NormalPixel(), black, white, white), Vector3.Forward * 20, new Vector3(200, 200, 1));

            this.CreateLight(new Vector3(-10, 10, 10), Color.Red, 30.0f);
            this.CreateLight(new Vector3(10, 10, 10), Color.Blue, 30.0f);
            this.CreateLight(new Vector3(-10, -10, 10), Color.Green, 30.0f);
            this.CreateLight(new Vector3(10, -10, 10), Color.White, 30.0f);

            this.CreateSpotLight(new Vector3(0, 0, 10), Vector3.Forward, 1500.0f);
        }
コード例 #15
0
    // Use this for initialization
    void Start()
    {
        cube = GameObject.Find("CubeCore");
        cameraTarget = cube.transform;
        cg = cube.GetComponent<CubeGenerator>();
        cubeWidth = cg.xSize * cg.Offset;
        distance = cubeWidth + 3.0f;

        Vector3 angles = transform.eulerAngles;
        x = angles.y;
        y = angles.x;
        PositionCamera();
    }