示例#1
0
    protected override void SpawnCubes()
    {
        var size     = CubePrefab.GetComponent <BoxCollider>().size;
        var cubeSize = size * CubeSize;

        //we want the cube of cubes to be centered on this game object
        var centerOffset = cubeSize * (SideLength / 2f) * GapFactor;

        centerOffset = new Vector3(centerOffset.x, centerOffset.y, 0f);
        var cubeOffset = (cubeSize * GapFactor / 2f);

        cubeOffset = new Vector3(cubeOffset.x, cubeOffset.y, 0f);
        var finalOffset = /*transform.position */ -centerOffset + cubeOffset;

        for (var j = 0; j < SideLength; j++)
        {
            for (var i = 0; i < SideLength; i++)
            {
                var pos  = (new Vector3(cubeSize.x * i, cubeSize.y * j, 0) * GapFactor) + finalOffset;
                var cube = (GameObject)Instantiate(CubePrefab, pos, Quaternion.identity);
                cube.transform.localScale = new Vector3(CubeSize, CubeSize, CubeSize);
                cube.transform.SetParent(transform, false);

                PreCubeSpawned(cube, i, j);

                Cubes.Add(cube);
                NetworkServer.Spawn(cube);

                RpcSetAsChild(cube);

                PostCubeSpawned(cube);
            }
        }
    }
示例#2
0
            public int RunChallenge(List <string> input)
            {
                // Also consider qubes next to initial state
                input.Insert(0, new String('.', input[0].Length));
                input.Add(new String('.', input[0].Length));
                input = input.Select(s => s = '.' + s + '.').ToList();

                for (int y = 0; y < input.Count; y++)
                {
                    for (int x = 0; x < input[0].Length; x++)
                    {
                        var active = input[y][x] == '#';

                        for (int z = -1; z <= 1; z++)
                        {
                            for (int w = -1; w <= 1; w++)
                            {
                                var value = (z == 0 && w == 0) ? active : false;
                                Cubes.Add(new Coordinate4D {
                                    X = x, Y = y, Z = z, W = w
                                }, value);
                            }
                        }
                    }
                }

                for (int cycle = 0; cycle < 6; cycle++)
                {
                    NextCubes = new Dictionary <Coordinate4D, bool>();
                    foreach (var cube in Cubes)
                    {
                        var neighbors = GetNeighbors(cube.Key).Count(n => n);
                        if (cube.Value)
                        {
                            if (neighbors == 2 || neighbors == 3)
                            {
                                NextCubes.Add(cube.Key, true);
                            }
                            else
                            {
                                NextCubes.Add(cube.Key, false);
                            }
                        }
                        else
                        {
                            if (neighbors == 3)
                            {
                                NextCubes.Add(cube.Key, true);
                            }
                            else
                            {
                                NextCubes.Add(cube.Key, false);
                            }
                        }
                    }
                    Cubes = NextCubes;
                }
                return(Cubes.Values.Count(z => z));
            }
示例#3
0
    private void RpcOnCubeSpawned(GameObject cube)
    {
        if (cube == null)
        {
            return;
        }

        Cubes.Add(cube);
    }
示例#4
0
        private void cubesAddButton_Click(object sender, EventArgs e)
        {
            var cube = new Cube("New item");

            Cubes.Add(cube);
            SelectedServer.Cubes.Add(cube);
            cubesListView.SelectObject(cube);
            cubesListView.StartCellEdit(cubesListView.SelectedItem, 0);
        }
示例#5
0
 public void Init(Tetromino definition)
 {
     tetrominoDefinition = definition;
     for (int i = 0; i < transform.childCount; i++)
     {
         Cubes.Add(transform.GetChild(i).gameObject);
     }
     tetrominoDefinition.Reset();
     UpdateBottomPart();
 }
示例#6
0
        public void AddCube(Point position, bool isFormationLeader)
        {
            var cube = new Cube(this, position, isFormationLeader);

            cube.LoadContent();
            Cubes.Add(cube);

            var projection = new CubeProjection(this, cube);

            projection.LoadContent();
            Projections.Add(projection);
        }
示例#7
0
    protected virtual void SetSideLength(uint length)
    {
        if (SideLength == length)
        {
            return;
        }

        SideLength = Math.Min(SIDE_LENGTH_MAX, length);
        RpcSetSideLength(length);
        var newSize = (int)(SideLength * SideLength);

        //Shrinking
        if (newSize < Cubes.Count)
        {
            for (var i = newSize; i < Cubes.Count; i++)
            {
                //Destroy(Cubes[i]);
                NetworkServer.Destroy(Cubes[i]);
            }
            Cubes = Cubes.GetRange(0, newSize);
            RpcClearNullCubes();
            RepositionCubes();
        }
        //Getting bigger
        else
        {
            while (Cubes.Count < newSize)
            {
                //Spawn at Zero, will reposition outside of the while loop
                var cube = (GameObject)Instantiate(CubePrefab, Vector3.zero, Quaternion.identity);
                cube.transform.parent = transform;

                Cubes.Add(cube);
                PreCubeSpawned(cube, (int)(Cubes.Count - (Cubes.Count / SideLength)), (int)(Cubes.Count / SideLength));

                NetworkServer.Spawn(cube);

                RpcSetAsChild(cube);

                PostCubeSpawned(cube);
            }

            RepositionCubes();
        }
    }
示例#8
0
 public static void CreateCubesMono(bool aIsWithScript)
 {
     WatchStart();
     for (int i = 0; i < mCreateCountMono; i++)
     {
         var pos  = RandomPos();
         var cube = GameObject.Instantiate(CubePrefab, pos, Quaternion.identity);
         if (aIsWithScript)
         {
             cube.AddComponent <BallMoveMono>();
             Cubes.Add(cube);
         }
         else
         {
             CubesWithScript.Add(cube);
         }
     }
     Debug.Log("Cost " + WatchStop() + " Milliseconds Creating " + mCreateCountMono + " MonoCubes.");
 }
        /// <summary>
        /// Generates an AR marker and puts it in the scene
        /// The marker starts rotated in the scene, so it can't be read at this stage
        /// </summary>
        public override void Generate()
        {
            Texture2D marker = GetMarker();

            // Assume the marker is square
            int markerRes = marker.width;

            for (int x = 0; x < (MarkerResolutionInSquares + 2) * 2; x++)
            {
                for (int y = 0; y < (MarkerResolutionInSquares + 2) * 2; y++)
                {
                    int xCoord = ((x * (markerRes / ((MarkerResolutionInSquares + 2) * 2))) + (markerRes / ((MarkerResolutionInSquares + 2) * 4)));
                    int yCoord = ((y * (markerRes / ((MarkerResolutionInSquares + 2) * 2))) + (markerRes / ((MarkerResolutionInSquares + 2) * 4)));

                    float col = marker.GetPixel(xCoord, yCoord).r;
                    var   res = 1f;

                    var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    cube.layer = gameObject.layer;
                    var height = 0.0f;
                    cube.transform.parent        = transform;
                    cube.transform.localPosition = new Vector3((float)xCoord / (float)markerRes - 0.5f, height, (float)yCoord / (float)markerRes - 0.5f);
                    var scale = 1.0f / ((MarkerResolutionInSquares + 2) * 2) / res;
                    scale += 0.001f;
                    cube.transform.localScale = new Vector3(scale, scale, scale);

                    Cubes.Add(cube);
                    if (col > 0.1f)
                    {
                        cube.GetComponent <Renderer>().enabled = false;
                    }
                    else
                    {
                        cube.GetComponent <Renderer>().sharedMaterial = BlackMaterial;
                    }
                }
            }

            transform.localRotation = Quaternion.Euler(-40f, -65f, 55f);

            BlackMaterial.SetFloat("_TransitionCompletion", 0.0f);
        }
示例#10
0
        /// <summary>
        /// Generates a marker from a randomly selected texture and puts it in the scene
        /// </summary>
        public override void Generate()
        {
            foreach (GameObject cube in Cubes)
            {
                Destroy(cube);
            }
            Cubes.Clear();

            Texture2D marker = GetMarker();

            // Assume the marker is square
            int markerRes = marker.width;

            for (int x = 0; x < (MarkerResolutionInSquares + 2); x++)
            {
                for (int y = 0; y < (MarkerResolutionInSquares + 2); y++)
                {
                    int        xCoord = ((x * (markerRes / ((MarkerResolutionInSquares + 2)))) + (markerRes / ((MarkerResolutionInSquares + 2) * 2)));
                    int        yCoord = ((y * (markerRes / ((MarkerResolutionInSquares + 2)))) + (markerRes / ((MarkerResolutionInSquares + 2) * 2)));
                    GameObject cube   = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    float      col    = marker.GetPixel(xCoord, yCoord).r;
                    float      res    = 1;

                    float scale = 1.0f / ((MarkerResolutionInSquares + 2)) / res;
                    scale += 0.001f;
                    cube.transform.parent        = transform;
                    cube.transform.localPosition = new Vector3((float)xCoord / (float)markerRes - 0.5f, 0.0f, (float)yCoord / (float)markerRes - 0.5f);
                    cube.transform.localScale    = new Vector3(scale, scale, scale);

                    Cubes.Add(cube);
                    if (col > 0.1f)
                    {
                        cube.GetComponent <Renderer>().sharedMaterial = WhiteMaterial;
                    }
                    else
                    {
                        cube.GetComponent <Renderer>().sharedMaterial = BlackMaterial;
                    }
                }
            }
        }
示例#11
0
            public void BootProcess(int cycles = 6)
            {
                for (int cycle = 0; cycle < cycles; cycle++)
                {
                    foreach (var(ind, cube) in Cubes)
                    {
                        int  activeNeighbours = ActiveNeighbors(cube);
                        bool nextState        = cube.SetNextState(activeNeighbours);
                        // if the new state of the cube is inactive, then remove
                        if (!nextState)
                        {
                            CubesToRemove.Add(ind, cube);
                        }
                    }

                    // only add if the newCubeState is active
                    foreach (var(ind, cube) in NewCubes)
                    {
                        int activeNeighbours = ActiveNeighbors(cube, false);
                        var nextState        = cube.SetNextState(activeNeighbours);
                        if (nextState)
                        {
                            Cubes.Add(ind, cube);
                        }
                    }

                    foreach (var(ind, cube) in CubesToRemove)
                    {
                        Cubes.Remove(ind);
                    }

                    foreach (var(ind, cube) in Cubes)
                    {
                        cube.ExecuteSwap();
                    }

                    NewCubes      = new Dictionary <string, Cube>();
                    CubesToRemove = new Dictionary <string, Cube>();
                }
            }
示例#12
0
 private void OnAddCube(AddCubeEventArgs args)
 {
     Cubes.Add(args.Cube);
 }
示例#13
0
 public void AddCube(Cube cube)
 {
     cube.Server = this;
     Cubes.Add(cube);
 }