Ejemplo n.º 1
0
 private void Awake()
 {
     texture = new Texture2D(resolution, resolution) {filterMode = FilterMode.Point};
     texture.Clear(Color.clear);
     debugTexture = new Texture2D(resolution, resolution) {filterMode = FilterMode.Point};
     debugTexture.Clear(Color.clear);
 }
Ejemplo n.º 2
0
        public static void NineCrop(this Texture2D source, int gutter, TextureFormat format = TextureFormat.RGBA32)
        {
            if (source.width != source.height)
            {
                throw new Exception("Failed to nine crop image, source image width and height must be equal.");
            }
            int realSize     = source.width;
            int realOffset   = source.width - 1;
            int canvasWidth  = source.width * 3;
            int canvasHeight = source.width * 3;

            Color[]   canvasPixels  = source.GetPixels(0, 0, realSize, realSize);
            Texture2D canvasTexture = new Texture2D(canvasWidth, canvasHeight, format, false);

            canvasTexture.SetPixels((realOffset * 0), (realOffset * 0), realSize, realSize, canvasPixels);
            canvasTexture.SetPixels((realOffset * 0), (realOffset * 1), realSize, realSize, canvasPixels);
            canvasTexture.SetPixels((realOffset * 0), (realOffset * 2), realSize, realSize, canvasPixels);
            canvasTexture.SetPixels((realOffset * 1), (realOffset * 0), realSize, realSize, canvasPixels);
            canvasTexture.SetPixels((realOffset * 1), (realOffset * 1), realSize, realSize, canvasPixels);
            canvasTexture.SetPixels((realOffset * 1), (realOffset * 2), realSize, realSize, canvasPixels);
            canvasTexture.SetPixels((realOffset * 2), (realOffset * 0), realSize, realSize, canvasPixels);
            canvasTexture.SetPixels((realOffset * 2), (realOffset * 1), realSize, realSize, canvasPixels);
            canvasTexture.SetPixels((realOffset * 2), (realOffset * 2), realSize, realSize, canvasPixels);
            canvasTexture.Apply();
            int cropSize   = realSize * 2;
            int cropOffset = (canvasWidth - cropSize) / 2;

            Color[]   centerPixels  = canvasTexture.GetPixels(cropOffset, cropOffset, cropSize, cropSize);
            Texture2D centerTexture = new Texture2D(cropSize, cropSize, format, false);

            centerTexture.SetPixels(centerPixels);
            centerTexture.Apply();
            if (gutter > 0)
            {
                int gutterSize   = realSize - (gutter * 2);
                int gutterOffset = (gutter - 1);
                centerTexture.Scale(gutterSize, gutterSize);
                Color[] gutterPixels  = centerTexture.GetPixels(0, 0, gutterSize, gutterSize);
                var     gutterTexture = new Texture2D(realSize, realSize, format, false);
                gutterTexture.Clear(Color.green);
                gutterTexture.SetPixels(gutterOffset, gutterOffset, gutterSize, gutterSize, gutterPixels);
                gutterTexture.Apply();
                source.Resize(realSize, realSize);
                source.SetPixels(gutterTexture.GetPixels());
                source.Apply();
            }
            else
            {
                centerTexture.Scale(realSize, realSize);
                source.Resize(realSize, realSize);
                source.SetPixels(centerTexture.GetPixels());
                source.Apply();
            }
        }
Ejemplo n.º 3
0
        private void Awake()
        {
            texture = new Texture2D(width, height, TextureFormat.ARGB32, false, true)
            {
                filterMode = FilterMode.Point
            };
            texture.Clear(Color.clear);
            texture.Apply();
            image.texture = texture;

            header = InstantiateControl<TextControl>(leftPanel);
            header.transform.SetAsFirstSibling();

            var rulesetName = RulesetName.Life;
            SelectRuleset(rulesetName);

            for (int i = 0; i < rulesetNames.Length; i++)
            {
                RulesetName currentName = rulesetNames[i];
                var toggle = InstantiateControl<ToggleControl>(toggleGroup.transform);
                toggle.Initialize(
                    header: currentName.ToString(),
                    value: currentName == rulesetName,
                    onValueChanged: isOn =>
                    {
                        if (isOn)
                        {
                            SelectRuleset(currentName);
                            Generate();
                        }
                    },
                    toggleGroup: toggleGroup);
            }

            InstantiateControl<SliderControl>(leftPanel).Initialize("Start noise", 0, 1, startNoise, value =>
            {
                startNoise = value;
                Generate();
            });

            InstantiateControl<ToggleControl>(leftPanel).Initialize("Alive borders", aliveBorders, value =>
            {
                aliveBorders = value;
                Generate();
            });

            InstantiateControl<ButtonControl>(leftPanel).Initialize("Generate", Generate);

            Generate();
        }
        private void Generate()
        {
            StopAllCoroutines();

            texture = new Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false, true)
            {
                filterMode = FilterMode.Point
            };
            texture.Clear(Color.black);
            texture.Apply();
            mazeImage.texture = texture;

            mazeGenerator = new MazeGenerator(textureWidth, textureHeight, cellSize, wallSize);

            StartCoroutine(GenerateCoroutine());
        }
Ejemplo n.º 5
0
        private IEnumerator GenerateCoroutine()
        {
            texture = new Texture2D(mazeWidth, mazeHeight, TextureFormat.ARGB32, false, true)
            {
                filterMode = FilterMode.Point
            };
            cellWidth = (mazeWidth - cellWallSize)/(cellSize + cellWallSize);
            cellHeight = (mazeHeight - cellWallSize)/(cellSize + cellWallSize);
            maze = new Maze(cellWidth, cellHeight);

            var origin = new Cell {x = Random.Range(0, cellWidth), y = Random.Range(0, cellHeight)};
            maze[origin] = Directions.None;
            edges = new List<Edge>(maze.GetEdges(origin));

            texture.Clear(Color.black);
            yield return null;

            switch (mazeAlgorithm)
            {
                case MazeAlgorithm.None:
                    if (RandomE.Chance(0.5f))
                    {
                        yield return StartCoroutine(RandomTraversal());
                    }
                    else
                    {
                        yield return StartCoroutine(RandomDepthFirstTraversal());
                    }
                    break;
                case MazeAlgorithm.RandomTraversal:
                    yield return StartCoroutine(RandomTraversal());
                    break;
                case MazeAlgorithm.RandomDepthFirstTraversal:
                    yield return StartCoroutine(RandomDepthFirstTraversal());
                    break;
            }

            texture.Apply();
        }