Пример #1
0
    void CreatePatternTexture()
    {
        int patternPixelWidth  = _editor.GetCanvas().pixelWidth * 3;
        int patternPixelHeight = _editor.GetCanvas().pixelHeight * 3;

        float aspect = (float)patternPixelWidth / (float)patternPixelHeight;
        float scale  = PlayerPrefs.GetFloat("patternZoom", PATTERN_DEFAULT_SCALE);

        _patternPlane.transform.localScale = new Vector3(scale, scale / aspect, 1.0f);

        if (_patternTexture)
        {
            _patternTexture = null;
        }

        // create texture
        _patternTexture            = new Texture2D(patternPixelWidth, patternPixelHeight, TextureFormat.ARGB32, false);
        _patternTexture.filterMode = FilterMode.Point;
        _patternPlane.renderer.material.mainTexture = _patternTexture;

        // -------------------------------------------------------------------------
        // BORDER
        // -------------------------------------------------------------------------
        float xScaleIncrease = 0.10f;
        float yScaleIncrease = xScaleIncrease * aspect;

        _patternBorderPlane.transform.localScale = new Vector3(1.0f + xScaleIncrease, 1.0f + yScaleIncrease, 1.0f);

        // -------------------------------------------------------------------------
        // GRID
        // -------------------------------------------------------------------------
        Texture2D gridTexture = new Texture2D(patternPixelWidth, patternPixelHeight, TextureFormat.ARGB32, false);

        gridTexture.filterMode = FilterMode.Point;

        for (int y = 0; y < patternPixelHeight; y++)
        {
            for (int x = 0; x < patternPixelWidth; x++)
            {
                bool yOdd = y % 2 != 0;
                bool xOdd = x % 2 != 0;

                byte grey = (yOdd && xOdd || !yOdd && !xOdd) ? PixelEditorScreen.CANVAS_CHECKERS_EVEN_SHADE : PixelEditorScreen.CANVAS_CHECKERS_ODD_SHADE;

                gridTexture.SetPixel(x, y, new Color32(grey, grey, grey, 255));
            }
        }

        gridTexture.Apply();
        _gridPlane.renderer.material.mainTexture = gridTexture;
    }
Пример #2
0
 public void SetCurrentFrame(int frameNumber)
 {
     _currentFrame = frameNumber;
     HighlightCurrentFramePreview();
     _editor.GetCanvas().DirtyPixels = true;
     _editor.GetCanvas().RefreshOnionSkin();
 }