コード例 #1
0
        public void SetBoard()
        {
            //draw empty board
            grid.InitializeBoard(_board);

            //draw grid with ships as they are placed
            Console.WriteLine("\t **********\\/ Place Your Ships \\/**********");
            grid.Draw(_board);
            _placement.SetShip(_board, ShipType.Carrier);
            Console.Clear();

            Console.WriteLine("\t *********\\/ Place Your Ships \\/**********");
            grid.DrawShips(_board);
            _placement.SetShip(_board, ShipType.Battleship);
            Console.Clear();

            Console.WriteLine("\t *********\\/ Place Your Ships \\/**********");
            grid.DrawShips(_board);
            _placement.SetShip(_board, ShipType.Cruiser);
            Console.Clear();

            Console.WriteLine("\t *********\\/ Place Your Ships \\/**********");
            grid.DrawShips(_board);
            _placement.SetShip(_board, ShipType.Submarine);
            Console.Clear();

            Console.WriteLine("\t *********\\/ Place Your Ships \\/*********");
            grid.DrawShips(_board);
            _placement.SetShip(_board, ShipType.Destroyer);
            Console.Clear();

            grid.DrawShips(_board);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Hamikadze/ComputerGraphics
        private void timer1_Tick(object sender, EventArgs e)
        {
            grid = new DrawGrid
            {
                RotateX = tX.Value,
                RotateY = tY.Value,
                RotateZ = tZ.Value
            };
            Bitmap  img     = new Bitmap(pictureBoxMain.Width, pictureBoxMain.Height);
            Surface surface = new Surface(new[]
            {
                new Math3D.Point3D(numericUpDown3.Value, numericUpDown2.Value, numericUpDown1.Value),
                new Math3D.Point3D(numericUpDown6.Value, numericUpDown5.Value, numericUpDown4.Value),
                new Math3D.Point3D(numericUpDown9.Value, numericUpDown8.Value, numericUpDown7.Value),
                new Math3D.Point3D(numericUpDown12.Value, numericUpDown11.Value, numericUpDown10.Value),
            });

            pictureBoxMain.Image = grid.Draw(img, DrawOriginDefault, OriginPoints, surface);
        }
コード例 #3
0
    private void OnGUI()
    {
        if (_etcAlphaInfos != null && _etcAlphaInfos.Length > 0)
        {
            int y = 10;
            for (int i = 0; i < _etcAlphaInfos.Length; ++i)
            {
                DrawGrid.Draw(new Rect(10, y, 100, 100));
                GUI.DrawTexture(new Rect(10, y, 100, 100), _etcAlphaInfos[i].SourceTexture);
                GUI.Label(new Rect(10, y + 100, 100, 20), Path.GetFileName(_etcAlphaInfos[i].SourcePath));
                DrawGrid.Draw(new Rect(160, y, 100, 100));
                if (_etcAlphaInfos[i].AlphaTexture != null)
                {
                    GUI.DrawTexture(new Rect(160, y, 100, 100), _etcAlphaInfos[i].AlphaTexture);
                    GUI.Label(new Rect(160, y + 100, 100, 20), Path.GetFileName(_etcAlphaInfos[i].AlphaPath));
                }
                if (_arrowTexture2D == null)
                {
#if UNIT_5_2 || UNITY_5_1
                    _arrowTexture2D = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/3rd/ETC+Alpha/Editor/Texture/arrow.png");
#else
                    _arrowTexture2D = AssetDatabase.LoadAssetAtPath("Assets/3rd/ETC+Alpha/Editor/Texture/arrow.png", typeof(Texture2D)) as Texture2D;
#endif
                }
                GUI.DrawTexture(new Rect(120, y + (100 - _arrowTexture2D.height) / 2, _arrowTexture2D.width, _arrowTexture2D.height), _arrowTexture2D);
                GUI.Label(new Rect(270, y + 20, 120, 20), "Format");
                _etcAlphaInfos[i].AlphaFormat = EditorGUI.Popup(new Rect(270, y + 40, 140, 20), "", _etcAlphaInfos[i].AlphaFormat, _alphaFormats);

                if (GUI.Button(new Rect(270, y + 60, 140, 20), "Generate"))
                {
                    GenAlphaTex(_etcAlphaInfos[i], false);
                }
                y += 120;
            }
        }
        else
        {
            GUI.Label(_textRect, "Please select texture in project view");
        }
    }
コード例 #4
0
    private void OnGUI()
    {
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Width(80)))
        {
            _textureR = null;
            _textureG = null;
            _textureB = null;
        }
        GUILayout.Label("", EditorStyles.toolbarButton);
        if (GUILayout.Button("Combine", EditorStyles.toolbarButton, GUILayout.Width(80)))
        {
            #region RGB

            if (_textureR != null && _textureG != null && _textureB != null)
            {
                string filename = EditorUtility.SaveFilePanel("Combine Texture", Application.dataPath,
                                                              "Combine_Texture_RGB_Channel.png", "png");
                if (!String.IsNullOrEmpty(filename) && filename.Contains(Application.dataPath))
                {
                    string assetName = filename.Replace(Application.dataPath, "Assets");

                    string          pathR            = AssetDatabase.GetAssetPath(_textureR);
                    string          pathG            = AssetDatabase.GetAssetPath(_textureG);
                    string          pathB            = AssetDatabase.GetAssetPath(_textureB);
                    TextureImporter textureImporterR = AssetImporter.GetAtPath(pathR) as TextureImporter;
                    TextureImporter textureImporterG = AssetImporter.GetAtPath(pathG) as TextureImporter;
                    TextureImporter textureImporterB = AssetImporter.GetAtPath(pathB) as TextureImporter;
                    textureImporterR.isReadable = true;
                    textureImporterR.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                    AssetDatabase.ImportAsset(pathR);
                    textureImporterG.isReadable = true;
                    textureImporterG.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                    AssetDatabase.ImportAsset(pathG);
                    textureImporterB.isReadable = true;
                    textureImporterB.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                    AssetDatabase.ImportAsset(pathB);

                    int maxWidth  = Mathf.Max(_textureR.width, _textureG.width, _textureB.width);
                    int maxHeigth = Mathf.Max(_textureR.height, _textureG.height, _textureB.height);
                    _textureCombine = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);

                    Color32[] rColor32S = _textureR.GetPixels32();
                    Color32[] gColor32S = _textureG.GetPixels32();
                    Color32[] bColor32S = _textureB.GetPixels32();

                    if (_textureR.width != maxWidth || _textureR.height != maxHeigth)
                    {
                        float     com2Rw      = (float)_textureR.width / (float)maxWidth;
                        float     com2Rh      = (float)_textureR.height / (float)maxHeigth;
                        Texture2D newTextureR = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);
                        for (int x = 0; x < maxWidth; ++x)
                        {
                            int xR = Mathf.Min(Mathf.RoundToInt(x * com2Rw), _textureR.width);
                            for (int y = 0; y < maxHeigth; ++y)
                            {
                                int yR = Mathf.Min(Mathf.RoundToInt(y * com2Rh), _textureR.height);
                                newTextureR.SetPixel(x, y, _textureR.GetPixel(xR, yR));
                            }
                        }
                        newTextureR.Apply();
                        rColor32S = newTextureR.GetPixels32();
                    }

                    if (_textureG.width != maxWidth || _textureG.height != maxHeigth)
                    {
                        float     com2Gw      = (float)_textureG.width / (float)maxWidth;
                        float     com2Gh      = (float)_textureG.height / (float)maxHeigth;
                        Texture2D newTextureG = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);
                        for (int x = 0; x < maxWidth; ++x)
                        {
                            int xG = Mathf.Min(Mathf.RoundToInt(x * com2Gw), _textureG.width);
                            for (int y = 0; y < maxHeigth; ++y)
                            {
                                int yG = Mathf.Min(Mathf.RoundToInt(y * com2Gh), _textureG.height);
                                newTextureG.SetPixel(x, y, _textureG.GetPixel(xG, yG));
                            }
                        }
                        newTextureG.Apply();
                        gColor32S = newTextureG.GetPixels32();
                    }

                    if (_textureB.width != maxWidth || _textureB.height != maxHeigth)
                    {
                        float     com2Bw      = (float)_textureB.width / (float)maxWidth;
                        float     com2Bh      = (float)_textureB.height / (float)maxHeigth;
                        Texture2D newTextureB = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);
                        for (int x = 0; x < maxWidth; ++x)
                        {
                            int xB = Mathf.Min(Mathf.RoundToInt(x * com2Bw), _textureB.width);
                            for (int y = 0; y < maxHeigth; ++y)
                            {
                                int yB = Mathf.Min(Mathf.RoundToInt(y * com2Bh), _textureB.height);
                                newTextureB.SetPixel(x, y, _textureB.GetPixel(xB, yB));
                            }
                        }
                        newTextureB.Apply();
                        bColor32S = newTextureB.GetPixels32();
                    }

                    Color32[] comColor32S = new Color32[maxWidth * maxHeigth];

                    for (int i = 0, imax = comColor32S.Length; i < imax; ++i)
                    {
                        comColor32S[i] = new Color32(rColor32S[i].r, gColor32S[i].g, bColor32S[i].b, 0);
                    }

                    _textureCombine.SetPixels32(comColor32S);
                    _textureCombine.Apply(false);
                    File.WriteAllBytes(filename, _textureCombine.EncodeToPNG());
                    while (!File.Exists(filename))
                    {
                        ;
                    }
                    AssetDatabase.Refresh(ImportAssetOptions.Default);
                    TextureImporter textureImporter =
                        AssetImporter.GetAtPath(assetName) as TextureImporter;
                    while (textureImporter == null)
                    {
                        textureImporter = AssetImporter.GetAtPath(assetName) as TextureImporter;
                    }
                    textureImporter.textureType = TextureImporterType.Default;
                    textureImporter.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGB16);
                    AssetDatabase.ImportAsset(assetName);
                    _textureCombine = AssetDatabase.LoadAssetAtPath(assetName, typeof(Texture)) as Texture2D;
                    AssetDatabase.SetLabels(_textureCombine, new string[]
                    {
                        "ETC+Alpha combine texture for RGB channel"
                    });

                    textureImporterR.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(pathR);
                    textureImporterG.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(pathG);
                    textureImporterB.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(pathB);
                }
            }

            #endregion

            #region RG

            else if (_textureR != null && _textureG != null)
            {
                string filename = EditorUtility.SaveFilePanel("Combine Texture", Application.dataPath,
                                                              "Combine_Texture_RG_Channel.png", "png");
                if (!String.IsNullOrEmpty(filename) && filename.Contains(Application.dataPath))
                {
                    string assetName = filename.Replace(Application.dataPath, "Assets");

                    string pathR = AssetDatabase.GetAssetPath(_textureR);
                    string pathG = AssetDatabase.GetAssetPath(_textureG);

                    TextureImporter textureImporterR = AssetImporter.GetAtPath(pathR) as TextureImporter;
                    TextureImporter textureImporterG = AssetImporter.GetAtPath(pathG) as TextureImporter;

                    textureImporterR.isReadable = true;
                    textureImporterR.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                    AssetDatabase.ImportAsset(pathR);
                    textureImporterG.isReadable = true;
                    textureImporterG.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                    AssetDatabase.ImportAsset(pathG);

                    int maxWidth  = Mathf.Max(_textureR.width, _textureG.width);
                    int maxHeigth = Mathf.Max(_textureR.height, _textureG.height);
                    _textureCombine = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);

                    Color32[] rColor32S = _textureR.GetPixels32();
                    Color32[] gColor32S = _textureG.GetPixels32();

                    if (_textureR.width != maxWidth || _textureR.height != maxHeigth)
                    {
                        float     com2Rw      = (float)_textureR.width / (float)maxWidth;
                        float     com2Rh      = (float)_textureR.height / (float)maxHeigth;
                        Texture2D newTextureR = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);
                        for (int x = 0; x < maxWidth; ++x)
                        {
                            int xR = Mathf.Min(Mathf.RoundToInt(x * com2Rw), _textureR.width);
                            for (int y = 0; y < maxHeigth; ++y)
                            {
                                int yR = Mathf.Min(Mathf.RoundToInt(y * com2Rh), _textureR.height);
                                newTextureR.SetPixel(x, y, _textureR.GetPixel(xR, yR));
                            }
                        }
                        newTextureR.Apply();
                        rColor32S = newTextureR.GetPixels32();
                    }

                    if (_textureG.width != maxWidth || _textureG.height != maxHeigth)
                    {
                        float     com2Gw      = (float)_textureG.width / (float)maxWidth;
                        float     com2Gh      = (float)_textureG.height / (float)maxHeigth;
                        Texture2D newTextureG = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);
                        for (int x = 0; x < maxWidth; ++x)
                        {
                            int xG = Mathf.Min(Mathf.RoundToInt(x * com2Gw), _textureG.width);
                            for (int y = 0; y < maxHeigth; ++y)
                            {
                                int yG = Mathf.Min(Mathf.RoundToInt(y * com2Gh), _textureG.height);
                                newTextureG.SetPixel(x, y, _textureG.GetPixel(xG, yG));
                            }
                        }
                        newTextureG.Apply();
                        gColor32S = newTextureG.GetPixels32();
                    }

                    Color32[] comColor32S = new Color32[maxWidth * maxHeigth];

                    for (int i = 0, imax = comColor32S.Length; i < imax; ++i)
                    {
                        comColor32S[i] = new Color32(rColor32S[i].r, gColor32S[i].g, 0, 0);
                    }

                    _textureCombine.SetPixels32(comColor32S);
                    _textureCombine.Apply(false);
                    File.WriteAllBytes(filename, _textureCombine.EncodeToPNG());
                    while (!File.Exists(filename))
                    {
                        ;
                    }
                    AssetDatabase.Refresh(ImportAssetOptions.Default);
                    TextureImporter textureImporter =
                        AssetImporter.GetAtPath(assetName) as TextureImporter;
                    while (textureImporter == null)
                    {
                        textureImporter = AssetImporter.GetAtPath(assetName) as TextureImporter;
                    }
                    textureImporter.textureType = TextureImporterType.Default;
                    textureImporter.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(assetName);
                    _textureCombine = AssetDatabase.LoadAssetAtPath(assetName, typeof(Texture)) as Texture2D;
                    AssetDatabase.SetLabels(_textureCombine, new string[]
                    {
                        "ETC+Alpha combine texture for RG channel"
                    });

                    textureImporterR.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(pathR);
                    textureImporterG.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(pathG);
                }
            }

            #endregion

            #region GB

            else if (_textureG != null && _textureB != null)
            {
                string filename = EditorUtility.SaveFilePanel("Combine Texture", Application.dataPath,
                                                              "Combine_Texture_GB_Channel.png", "png");
                if (!String.IsNullOrEmpty(filename) && filename.Contains(Application.dataPath))
                {
                    Repaint();
                    string assetName = filename.Replace(Application.dataPath, "Assets");

                    string          pathG            = AssetDatabase.GetAssetPath(_textureG);
                    string          pathB            = AssetDatabase.GetAssetPath(_textureB);
                    TextureImporter textureImporterG = AssetImporter.GetAtPath(pathG) as TextureImporter;
                    TextureImporter textureImporterB = AssetImporter.GetAtPath(pathB) as TextureImporter;

                    textureImporterG.isReadable = true;
                    textureImporterG.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                    AssetDatabase.ImportAsset(pathG);
                    textureImporterB.isReadable = true;
                    textureImporterB.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                    AssetDatabase.ImportAsset(pathB);

                    int maxWidth  = Mathf.Max(_textureG.width, _textureB.width);
                    int maxHeigth = Mathf.Max(_textureG.height, _textureB.height);
                    _textureCombine = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);

                    Color32[] gColor32S = _textureG.GetPixels32();
                    Color32[] bColor32S = _textureB.GetPixels32();

                    if (_textureG.width != maxWidth || _textureG.height != maxHeigth)
                    {
                        float     com2Gw      = (float)_textureG.width / (float)maxWidth;
                        float     com2Gh      = (float)_textureG.height / (float)maxHeigth;
                        Texture2D newTextureG = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);
                        for (int x = 0; x < maxWidth; ++x)
                        {
                            int xG = Mathf.Min(Mathf.RoundToInt(x * com2Gw), _textureG.width);
                            for (int y = 0; y < maxHeigth; ++y)
                            {
                                int yG = Mathf.Min(Mathf.RoundToInt(y * com2Gh), _textureG.height);
                                newTextureG.SetPixel(x, y, _textureG.GetPixel(xG, yG));
                            }
                        }
                        newTextureG.Apply();
                        gColor32S = newTextureG.GetPixels32();
                    }

                    if (_textureB.width != maxWidth || _textureB.height != maxHeigth)
                    {
                        float     com2Bw      = (float)_textureB.width / (float)maxWidth;
                        float     com2Bh      = (float)_textureB.height / (float)maxHeigth;
                        Texture2D newTextureB = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);
                        for (int x = 0; x < maxWidth; ++x)
                        {
                            int xB = Mathf.Min(Mathf.RoundToInt(x * com2Bw), _textureB.width);
                            for (int y = 0; y < maxHeigth; ++y)
                            {
                                int yB = Mathf.Min(Mathf.RoundToInt(y * com2Bh), _textureB.height);
                                newTextureB.SetPixel(x, y, _textureB.GetPixel(xB, yB));
                            }
                        }
                        newTextureB.Apply();
                        bColor32S = newTextureB.GetPixels32();
                    }

                    Color32[] comColor32S = new Color32[maxWidth * maxHeigth];

                    for (int i = 0, imax = comColor32S.Length; i < imax; ++i)
                    {
                        comColor32S[i] = new Color32(0, gColor32S[i].g, bColor32S[i].b, 0);
                    }

                    _textureCombine.SetPixels32(comColor32S);
                    _textureCombine.Apply(false);
                    File.WriteAllBytes(filename, _textureCombine.EncodeToPNG());
                    while (!File.Exists(filename))
                    {
                        ;
                    }
                    AssetDatabase.Refresh(ImportAssetOptions.Default);
                    TextureImporter textureImporter =
                        AssetImporter.GetAtPath(assetName) as TextureImporter;
                    while (textureImporter == null)
                    {
                        textureImporter = AssetImporter.GetAtPath(assetName) as TextureImporter;
                    }
                    textureImporter.textureType = TextureImporterType.Default;
                    textureImporter.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(assetName);
                    _textureCombine = AssetDatabase.LoadAssetAtPath(assetName, typeof(Texture)) as Texture2D;
                    AssetDatabase.SetLabels(_textureCombine, new string[]
                    {
                        "ETC+Alpha combine texture for GB channel"
                    });

                    textureImporterG.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(pathG);
                    textureImporterB.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(pathB);
                }
            }

            #endregion

            #region RB

            else if (_textureR != null && _textureB != null)
            {
                string filename = EditorUtility.SaveFilePanel("Combine Texture", Application.dataPath,
                                                              "Combine_Texture_RB_Channel.png", "png");
                if (!String.IsNullOrEmpty(filename) && filename.Contains(Application.dataPath))
                {
                    string assetName = filename.Replace(Application.dataPath, "Assets");

                    string          pathR            = AssetDatabase.GetAssetPath(_textureR);
                    string          pathB            = AssetDatabase.GetAssetPath(_textureB);
                    TextureImporter textureImporterR = AssetImporter.GetAtPath(pathR) as TextureImporter;
                    TextureImporter textureImporterB = AssetImporter.GetAtPath(pathB) as TextureImporter;
                    textureImporterR.isReadable = true;
                    textureImporterR.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                    AssetDatabase.ImportAsset(pathR);
                    textureImporterB.isReadable = true;
                    textureImporterB.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                    AssetDatabase.ImportAsset(pathB);

                    int maxWidth  = Mathf.Max(_textureR.width, _textureB.width);
                    int maxHeigth = Mathf.Max(_textureR.height, _textureB.height);
                    _textureCombine = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);

                    Color32[] rColor32S = _textureR.GetPixels32();
                    Color32[] bColor32S = _textureB.GetPixels32();

                    if (_textureR.width != maxWidth || _textureR.height != maxHeigth)
                    {
                        float     com2Rw      = (float)_textureR.width / (float)maxWidth;
                        float     com2Rh      = (float)_textureR.height / (float)maxHeigth;
                        Texture2D newTextureR = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);
                        for (int x = 0; x < maxWidth; ++x)
                        {
                            int xR = Mathf.Min(Mathf.RoundToInt(x * com2Rw), _textureR.width);
                            for (int y = 0; y < maxHeigth; ++y)
                            {
                                int yR = Mathf.Min(Mathf.RoundToInt(y * com2Rh), _textureR.height);
                                newTextureR.SetPixel(x, y, _textureR.GetPixel(xR, yR));
                            }
                        }
                        newTextureR.Apply();
                        rColor32S = newTextureR.GetPixels32();
                    }

                    if (_textureB.width != maxWidth || _textureB.height != maxHeigth)
                    {
                        float     com2Bw      = (float)_textureB.width / (float)maxWidth;
                        float     com2Bh      = (float)_textureB.height / (float)maxHeigth;
                        Texture2D newTextureB = new Texture2D(maxWidth, maxHeigth, TextureFormat.RGBA32, false);
                        for (int x = 0; x < maxWidth; ++x)
                        {
                            int xB = Mathf.Min(Mathf.RoundToInt(x * com2Bw), _textureB.width);
                            for (int y = 0; y < maxHeigth; ++y)
                            {
                                int yB = Mathf.Min(Mathf.RoundToInt(y * com2Bh), _textureB.height);
                                newTextureB.SetPixel(x, y, _textureB.GetPixel(xB, yB));
                            }
                        }
                        newTextureB.Apply();
                        bColor32S = newTextureB.GetPixels32();
                    }

                    Color32[] comColor32S = new Color32[maxWidth * maxHeigth];

                    for (int i = 0, imax = comColor32S.Length; i < imax; ++i)
                    {
                        comColor32S[i] = new Color32(rColor32S[i].r, 0, bColor32S[i].b, 0);
                    }

                    _textureCombine.SetPixels32(comColor32S);
                    _textureCombine.Apply(false);
                    File.WriteAllBytes(filename, _textureCombine.EncodeToPNG());
                    while (!File.Exists(filename))
                    {
                        ;
                    }
                    AssetDatabase.Refresh(ImportAssetOptions.Default);
                    TextureImporter textureImporter =
                        AssetImporter.GetAtPath(assetName) as TextureImporter;
                    while (textureImporter == null)
                    {
                        textureImporter = AssetImporter.GetAtPath(assetName) as TextureImporter;
                    }
                    textureImporter.textureType = TextureImporterType.Default;
                    textureImporter.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(assetName);
                    _textureCombine = AssetDatabase.LoadAssetAtPath(assetName, typeof(Texture)) as Texture2D;
                    AssetDatabase.SetLabels(_textureCombine, new string[]
                    {
                        "ETC+Alpha combine texture for RB channel"
                    });

                    textureImporterR.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(pathR);
                    textureImporterB.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                    AssetDatabase.ImportAsset(pathB);
                }
            }

            #endregion
        }
        GUILayout.EndHorizontal();
        DrawGrid.Draw(_rectR);
        DrawGrid.Draw(_rectG);
        DrawGrid.Draw(_rectB);
        if (_textureR != null)
        {
            GUI.DrawTexture(_rectR, _textureR);
        }
        if (_textureG != null)
        {
            GUI.DrawTexture(_rectG, _textureG);
        }
        if (_textureB != null)
        {
            GUI.DrawTexture(_rectB, _textureB);
        }
        if (_combineNavigationTexture == null)
        {
#if UNIT_5_2 || UNITY_5_1
            _combineNavigationTexture = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/ETC+Alpha/Editor/Texture/combine.png");
#else
            _combineNavigationTexture = AssetDatabase.LoadAssetAtPath("Assets/ETC+Alpha/Editor/Texture/combine.png", typeof(Texture2D)) as Texture2D;
#endif
        }
        GUI.DrawTexture(_rectNavigation, _combineNavigationTexture);

        DrawGrid.Draw(_rectCombine);
        if (_textureCombine != null)
        {
            GUI.DrawTexture(_rectCombine, _textureCombine);
        }

        Event curEvent = Event.current;
        if (_rectR.Contains(curEvent.mousePosition))
        {
            if (curEvent.type == EventType.DragPerform)
            {
                foreach (var v in DragAndDrop.objectReferences)
                {
                    var type = v.GetType();
                    if (type == typeof(Texture2D))
                    {
                        _textureR = v as Texture2D;
                        break;
                    }
                }
            }
            else if (curEvent.type == EventType.DragUpdated)
            {
                if (IsValidDragPayload(0))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.None;
                }
            }
        }
        else if (_rectG.Contains(curEvent.mousePosition))
        {
            if (curEvent.type == EventType.DragPerform)
            {
                foreach (var v in DragAndDrop.objectReferences)
                {
                    var type = v.GetType();
                    if (type == typeof(Texture2D))
                    {
                        _textureG = v as Texture2D;
                        break;
                    }
                }
            }
            else if (curEvent.type == EventType.DragUpdated)
            {
                if (IsValidDragPayload(1))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.None;
                }
            }
        }
        else if (_rectB.Contains(curEvent.mousePosition))
        {
            if (curEvent.type == EventType.DragPerform)
            {
                foreach (var v in DragAndDrop.objectReferences)
                {
                    var type = v.GetType();
                    if (type == typeof(Texture2D))
                    {
                        _textureB = v as Texture2D;
                        break;
                    }
                }
            }
            else if (curEvent.type == EventType.DragUpdated)
            {
                if (IsValidDragPayload(2))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.None;
                }
            }
        }
    }
コード例 #5
0
    private void OnGUI()
    {
        if (_etcAlphaInfos != null && _etcAlphaInfos.Length > 0)
        {
            int y = 10;
            for (int i = 0; i < _etcAlphaInfos.Length; ++i)
            {
                DrawGrid.Draw(new Rect(10, y, 100, 100));
                GUI.DrawTexture(new Rect(10, y, 100, 100), _etcAlphaInfos[i].SourceTexture);
                GUI.Label(new Rect(10, y + 100, 100, 20), Path.GetFileName(_etcAlphaInfos[i].SourcePath));
                DrawGrid.Draw(new Rect(160, y, 100, 100));
                if (_etcAlphaInfos[i].AlphaTexture != null)
                {
                    GUI.DrawTexture(new Rect(160, y, 100, 100), _etcAlphaInfos[i].AlphaTexture);
                    GUI.Label(new Rect(160, y + 100, 100, 20), Path.GetFileName(_etcAlphaInfos[i].AlphaPath));
                }
                if (_arrowTexture2D == null)
                {
                    _arrowTexture2D = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/ETC+Alpha/Editor/Texture/arrow.png");
                }
                GUI.DrawTexture(new Rect(120, y + (100 - _arrowTexture2D.height) / 2, _arrowTexture2D.width, _arrowTexture2D.height), _arrowTexture2D);
                GUI.Label(new Rect(270, y + 20, 120, 20), "Format");
                _etcAlphaInfos[i].AlphaFormat = EditorGUI.Popup(new Rect(270, y + 40, 140, 20), "", _etcAlphaInfos[i].AlphaFormat, _alphaFormats);

                if (GUI.Button(new Rect(270, y + 60, 140, 20), "Generate"))
                {
                    try
                    {
                        _etcAlphaInfos[i].SoureTextureImporter.isReadable = true;
                        _etcAlphaInfos[i].SoureTextureImporter.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.RGBA32);
                        AssetDatabase.ImportAsset(_etcAlphaInfos[i].SourcePath);

                        _etcAlphaInfos[i].AlphaTexture = new Texture2D(_etcAlphaInfos[i].SourceTexture.width,
                                                                       _etcAlphaInfos[i].SourceTexture.height, TextureFormat.RGBA32, false);
                        Color32[] color32S    = _etcAlphaInfos[i].AlphaTexture.GetPixels32();
                        Color32[] srcColor32S = _etcAlphaInfos[i].SourceTexture.GetPixels32();

                        if (_etcAlphaInfos[i].AlphaFormat == 0)
                        {
                            for (int n = 0; n < color32S.Length; ++n)
                            {
                                color32S[n] = new Color32(srcColor32S[n].a, 0, 0, 0);
                            }
                        }
                        else if (_etcAlphaInfos[i].AlphaFormat == 1)
                        {
                            for (int n = 0; n < color32S.Length; ++n)
                            {
                                color32S[n] = new Color32(0, srcColor32S[n].a, 0, 0);
                            }
                        }
                        else
                        {
                            for (int n = 0; n < color32S.Length; ++n)
                            {
                                color32S[n] = new Color32(0, 0, srcColor32S[n].a, 0);
                            }
                        }
                        _etcAlphaInfos[i].AlphaTexture.SetPixels32(color32S);
                        _etcAlphaInfos[i].AlphaTexture.Apply(false);
                        string fileName = Application.dataPath.Substring(0, Application.dataPath.Length - 6) +
                                          _etcAlphaInfos[i].AlphaPath;
                        File.WriteAllBytes(fileName, _etcAlphaInfos[i].AlphaTexture.EncodeToPNG());
                        while (!File.Exists(fileName))
                        {
                            ;
                        }
                        AssetDatabase.Refresh(ImportAssetOptions.Default);
                        _etcAlphaInfos[i].AlphaTextureImporter =
                            AssetImporter.GetAtPath(_etcAlphaInfos[i].AlphaPath) as TextureImporter;
                        while (_etcAlphaInfos[i].AlphaTextureImporter == null)
                        {
                            _etcAlphaInfos[i].AlphaTextureImporter =
                                AssetImporter.GetAtPath(_etcAlphaInfos[i].AlphaPath) as TextureImporter;
                        }
                        _etcAlphaInfos[i].AlphaTextureImporter.textureType = TextureImporterType.Advanced;
                        _etcAlphaInfos[i].AlphaTextureImporter.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);
                        _etcAlphaInfos[i].SoureTextureImporter.SetPlatformTextureSettings("Android", 2048, TextureImporterFormat.ETC_RGB4);

                        AssetDatabase.ImportAsset(_etcAlphaInfos[i].SourcePath);
                        AssetDatabase.ImportAsset(_etcAlphaInfos[i].AlphaPath);

                        _etcAlphaInfos[i].AlphaTexture = AssetDatabase.LoadAssetAtPath(_etcAlphaInfos[i].AlphaPath, typeof(Texture)) as Texture2D;

                        if (_etcAlphaInfos[i].AlphaFormat == 0)
                        {
                            AssetDatabase.SetLabels(_etcAlphaInfos[i].AlphaTexture, new string[] { "ETC+Alpha using R channel for " + Path.GetFileName(_etcAlphaInfos[i].SourcePath) });
                        }
                        else if (_etcAlphaInfos[i].AlphaFormat == 1)
                        {
                            AssetDatabase.SetLabels(_etcAlphaInfos[i].AlphaTexture, new string[] { "ETC+Alpha using G channel for " + Path.GetFileName(_etcAlphaInfos[i].SourcePath) });
                        }
                        else
                        {
                            AssetDatabase.SetLabels(_etcAlphaInfos[i].AlphaTexture, new string[] { "ETC+Alpha using B channel for " + Path.GetFileName(_etcAlphaInfos[i].SourcePath) });
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning(e);
                    }
                }
                y += 120;
            }
        }
        else
        {
            GUI.Label(_textRect, "Please select texture in project view");
        }
    }