Esempio n. 1
0
    public void killPeasant(int i = -1, int j = -1)
    {
        DrawGrid dg = GameObject.Find("Controller").GetComponent <DrawGrid>();

        if (i != -1 && j != -1)
        {
            foreach (GameObject gj in dg.ExistingPeasents)
            {
                int xx = gj.GetComponent <PeasentScript>().posx, yy = gj.GetComponent <PeasentScript>().posy;
                if (yy == i && xx == j)
                {
                    gj.GetComponent <PeasentScript>().PeasentDeath();
                }
            }
        }
        PeasantsAlive--;

        /*
         * //Display Number of living peasants
         * if(Score + PeasantsAlive < WinCondition)
         * {
         *      //Lose
         * }
         */
    }
    void GridUpdate(SceneView sceneview)
    {
        e = Event.current;

        //Make sure MapData has been loaded
        _MapData = EditorHelper.CheckMapData(_MapData);

        //If a Grid exists place tiles
        if (EditorHelper.GridExsists())
        {
            if(grid == null)
            {
                grid = GameObject.FindObjectOfType<DrawGrid>();
            }

            if (EditorHelper.InsideGrid(EditorHelper.GetMousePosition(e)))
            {
                //if input is from a mouse and the mouse button was a left click event
                if (e.button == 0 && e.isMouse && e.type == EventType.MouseDown)
                {
                    PaintTile();
                }
            }
        }
    }
Esempio n. 3
0
        private void addMapButton_Click(object sender, EventArgs e)
        {
            int index = Convert.ToInt32(addMapIndex.Value);
            int value = Convert.ToInt32(addMapValue.Value);

            if (index >= createdMap.Count)
            {
                MessageBox.Show("Index nie może być większy niż max index: " + (createdMap.Count - 1).ToString() + ".\n" + "Aby dodać element na końcu zbioru wpisz index: -1 ");
            }
            else if (index == -1)
            {
                createdMap.Add(new multiSet()
                {
                    elementOfmultiSet = value
                });
                DrawGrid.Refresh();
            }
            else
            {
                createdMap.Insert(index, new multiSet()
                {
                    elementOfmultiSet = value
                });
                DrawGrid.Refresh();
            }
        }
Esempio n. 4
0
 private void Awake()
 {
     dGrid            = GetComponent <DrawGrid>();
     camTransform     = GetComponentInChildren <Camera>().transform;
     currentPos       = transform.position;
     Cursor.lockState = CursorLockMode.Locked;
 }
Esempio n. 5
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        DrawGrid gridObj = (DrawGrid)target;

        gridObj.m_obstaclePrefab = EditorGUILayout.ObjectField("选择障碍物", gridObj.m_obstaclePrefab, typeof(GameObject), true) as GameObject;
    }
Esempio n. 6
0
 public static void Done()
 {
     if (_inst != null)
     {
         _inst.DestroyTexture();
         _inst = null;
     }
 }
Esempio n. 7
0
 public static void Draw(Rect rect, Vector2 offset)
 {
     if (_inst == null)
     {
         _inst = new DrawGrid();
         _inst.InitTexture();
     }
     GUI.DrawTextureWithTexCoords(rect, _inst._gridTexture, new Rect(-offset.x / TextureSize, (offset.y - rect.height) / TextureSize, rect.width / TextureSize, rect.height / TextureSize), false);
 }
Esempio n. 8
0
    private void Awake()
    {
        if (instance != null)
        {
            Destroy(this);
        }

        instance = this;
    }
Esempio n. 9
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        DrawGrid baseClass = target as DrawGrid;

        if (GUILayout.Button("Navigate to Grid Settings"))
        {
            ProjectWindowUtil.ShowCreatedAsset(baseClass.gridSystem);
        }
    }
    public void OnEnable()
    {
        //load MapData resource
        EditorHelper.CreateMapData(out _MapData);

        if (EditorHelper.GridExsists())
        {
            grid = (DrawGrid)target;
        }
        SceneView.onSceneGUIDelegate = GridUpdate;
    }
Esempio n. 11
0
 // ------------- DELETE FROM GRID -------------
 private void DrawGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex < 0)
     {
         return;
     }
     if (e.ColumnIndex == 1)
     {
         createdMap.RemoveAt(e.RowIndex);
         DrawGrid.Refresh();
     }
 }
Esempio n. 12
0
    public void InitPlayer(TeamSet tSet)
    {
        _team.InitTeam(tSet);

        _drawGrid   = DrawGrid.instance;
        _groundMask = LayerMask.GetMask("Ground");

        _hoverTimer = 0;

        flagEnemy     = levelScript.GetEnemyFlag(_team);
        flagAlly      = _team.flagPosition;
        totalDistance = path.GetDistance(flagAlly, flagEnemy);
    }
Esempio n. 13
0
 void InitGrids()
 {
     for (int r = 0; r < RowNum; r++)
     {
         for (int c = 0; c < ColNum; c++)
         {
             AllGrids[r, c] = new DrawGrid
             {
                 type = GridType.Blank,
                 i    = r,
                 j    = c,
                 rect = new Rectangle(c * GridSize, r * GridSize, GridSize, GridSize)
             };
         }
     }
 }
Esempio n. 14
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        DrawGrid grid = (DrawGrid)target;

        if (grid.nodePrefab == null)
        {
            EditorGUILayout.HelpBox("The Tile prefab is missing", MessageType.Warning, true);
        }

        if (grid.gridLayout == null)
        {
            EditorGUILayout.HelpBox("The gridLayout reference is missing", MessageType.Warning, true);
        }
    }
Esempio n. 15
0
 public static PluginsLoader GetInstance()
 {
     Config.GetInstance();
     DrawGrid.GetInstance();
     UICommandQueue.GetInstance().InitFromGlThread();
     HeightMapPersistence.GetInstance();
     SlopeMapPersistence.GetInstance();
     MouseFilterSdlMouseCache.GetInstance();
     KeyFilterSdlKeyCache.GetInstance();
     KeyFilterConfigMappingsFactory.GetInstance();
     MainUI.GetInstance();
     HeightEditor.GetInstance();
     Camera.GetInstance();
     Framerate.GetInstance();
     FrustrumCulling.GetInstance();
     return(instance);
 }
Esempio n. 16
0
        public Outer()
        {
            mblnHadInitialized = false;
            this.IsDrawAllPage = false;

            mdrawGrid = new DrawGrid();

            mdrawGrid.AlignMent = AlignFlag.Left;
            mdrawGrid.ColsAlignString = "";
            mdrawGrid.Border = GridBorderFlag.None;
            mdrawGrid.Line = GridLineFlag.None;
            mdrawGrid.Merge = GridMergeFlag.None;

            this.Font = new Font("����",11);

            mdrawGrid.RowHeight = this.Font.Height + 10;
            mdrawGrid.Initialize(0,0);
        }
Esempio n. 17
0
        private void cmdDrawGrid_Click(object sender, EventArgs e)
        {
            int MeasureX = 0;
            int MeasureY = 0;

            if (rbGridmm.Checked)
            {
                int.TryParse(tGridXmm.Text, out MeasureX);
                int.TryParse(tGridYmm.Text, out MeasureY);
            }
            else
            {
                int.TryParse(tGridXlines.Text, out MeasureX);
                int.TryParse(tGridYLines.Text, out MeasureY);
            }

            DrawGrid?.Invoke(GridType, MeasureX, MeasureY);
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);
            int c    = e.X / GridSize;
            int r    = e.Y / GridSize;
            var grid = AllGrids[r, c];

            if (e.Button == MouseButtons.Left)
            {
                if (grid.type == GridType.Blank)
                {
                    grid.type = GridType.Block;

                    if (startDown)
                    {
                        if (startGrid != null)
                        {
                            startGrid.type = GridType.Blank;
                        }
                        grid.type = GridType.Start;
                        startGrid = grid;
                    }
                    else if (endDown)
                    {
                        if (endGrid != null)
                        {
                            endGrid.type = GridType.Blank;
                        }
                        grid.type = GridType.End;
                        endGrid   = grid;
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (grid.type == GridType.Block)
                {
                    grid.type = GridType.Blank;
                }
            }

            Invalidate();
        }
Esempio n. 20
0
        public Top()
        {
            this.IsDrawAllPage = true;

            _text = "";
            mdrawGrid = new DrawGrid();

            //mdrawGrid.AlignMent = AlignFlag.Left;
            mdrawGrid.ColsAlignString = "LCR";
            mdrawGrid.Border = GridBorderFlag.None;
            mdrawGrid.Line = GridLineFlag.None;
            mdrawGrid.Merge = GridMergeFlag.None;

            this.Font = new Font("����",12);

            mdrawGrid.RowHeight = this.Font.Height + 10;

            mdrawGrid.Initialize(1,3);
        }
Esempio n. 21
0
    private void Awake()
    {
        nodeDiameter = nodeRadius * 2;
        gridSizeX    = Mathf.RoundToInt(gridWorldSize.x / nodeDiameter); //how many nodes we can fit in the X
        gridSizeY    = Mathf.RoundToInt(gridWorldSize.y / nodeDiameter);

        foreach (TerrainType region in walkableRegions)
        {
            walkableMask.value |= region.terrainMask.value;
            walkableRegionsDictionary.Add((int)Mathf.Log(region.terrainMask.value, 2), region.terrainPenalty);
        }

        gridDrawing = GetComponent <DrawGrid>();
        gridDrawing.CreateGrid(this, gridSizeX, gridSizeY);

        playableItemsMask = LayerMask.GetMask("PlayableItem");

        CreateGrid();
    }
Esempio n. 22
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");
        }
    }
        public void Add(CurveGraphModel model)
        {
            if (Items != null)
            {
                Items.Clear();
                modelitems = null;
            }
            else
            {
                Items      = new ObservableCollection <FrameworkElement>();
                modelitems = new CurveGraphModel();
            }

            modelitems = model;

            GraphGrid grid = DrawGrid.RenderGrid(model, camera);

            model.Item.Grid = grid;

            if (UpdateRender != null)
            {
                UpdateRender(this, EventArgs.Empty);
            }
        }
Esempio n. 24
0
    public void OnSceneGUI()
    {
        Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
        RaycastHit hitInfo;
        bool       isDown = false;
        LayerMask  mask   = 1 << 9 | 1 << 10;

        if (Physics.Raycast(ray, out hitInfo, 2000, ~mask)) //这里设置层
        {
            if (hitInfo.collider.tag == "Floor")
            {
                float x = hitInfo.point.x;
                float y = hitInfo.point.y;
                Event e = Event.current;
                if (!isDown && e.type == EventType.KeyDown)
                {
                    if (e.keyCode == KeyCode.LeftShift)
                    {
                        isDown = true;
                        GameObject prefab    = ((DrawGrid)target).m_obstaclePrefab;
                        Vector3    initPoint = ((DrawGrid)target).IdentifyCenter(hitInfo.point);

                        if (initPoint.x >= 0)
                        {
                            GameObject newobj = Instantiate(prefab, initPoint, Quaternion.Euler(0, 0, 0), ((DrawGrid)target).transform) as GameObject;                              //设置障碍
                            Debug.Log(newobj.transform.localScale);
                            //newobj.transform.localScale = new Vector3(((DrawGrid)target).m_gridSize, ((DrawGrid)target).m_gridSize,((DrawGrid)target).m_gridSize);
                            newobj.transform.localScale = ((DrawGrid)target).m_gridSize * newobj.transform.localScale;
                            Undo.RegisterCreatedObjectUndo(newobj, "NewObject");
                        }
                    }
                }
            }
            else if (hitInfo.collider.tag == "Cube")
            {
                float x = hitInfo.point.x;
                float y = hitInfo.point.y;
                Event e = Event.current;
                if (!isDown && e.type == EventType.KeyDown)
                {
                    if (e.keyCode == KeyCode.LeftControl)
                    {
                        isDown = true;
                        Undo.DestroyObjectImmediate(hitInfo.transform.gameObject);
                    }
                    else if (e.keyCode == KeyCode.LeftShift)
                    {
                        isDown = true;
                        Transform  bottom    = hitInfo.transform;
                        DrawGrid   drawgrid  = bottom.gameObject.GetComponentInParent <DrawGrid>();
                        GameObject prefab    = drawgrid.m_obstaclePrefab;
                        Vector3    initPoint = bottom.position;
                        initPoint.y += drawgrid.m_gridSize;
                        GameObject newobj = Instantiate(prefab, initPoint, Quaternion.Euler(0, 0, 0), ((DrawGrid)target).transform) as GameObject;          //设置障碍
                        newobj.transform.localScale = newobj.transform.localScale = ((DrawGrid)target).m_gridSize * newobj.transform.localScale;
                        Undo.RegisterCreatedObjectUndo(newobj, "NewObject");
                    }
                }
            }
        }
    }
Esempio n. 25
0
        public void UpdateDrawTiles()
        {
            IsTilesUpdating = true;
            TilesUpdateLock.AcquireWriterLock(1000);
            try
            {
                if (ScreenArea != null)
                {
                    var width  = TilesArea.Width;
                    var height = TilesArea.Height;



                    var pointLeftTopPix = TileCenterPix.GetOffSet(-width / 2, -height / 2); //左上角像素坐标
                    var tileXYLeftTop   = MercatorHelper.PixelToTileXY(pointLeftTopPix);    //左上角的瓦片索引
                    var tilePixLeftTop  = MercatorHelper.TileXYToPixel(tileXYLeftTop);      //左上角瓦片像素坐标
                    //var tileDrawPositionLeftTop = new PointInt((int)(tilePixLeftTop.X - pointLeftTopPix.X + 0.5), (int)(tilePixLeftTop.Y - pointLeftTopPix.Y + 0.5));//屏幕坐标系下左上角瓦片的屏幕坐标
                    var tileDrawPositionLeftTop = TilesArea.LeftTop.GetOffSet((int)(tilePixLeftTop.X - pointLeftTopPix.X), (int)(tilePixLeftTop.Y - pointLeftTopPix.Y));

                    var tileXYCenter = MercatorHelper.PixelToTileXY(TileCenterPix);//中心瓦片索引
                    //var tilePixCenter = MercatorHelper.TileXYToPixel(tileXYCenter);//中心瓦片左上角所在像素坐标

                    var xCount = (int)Math.Ceiling((double)width / TileSize.Width) + 1;   //X方向的瓦片数量
                    var yCount = (int)Math.Ceiling((double)height / TileSize.Height) + 1; //Y方向的瓦片数量

                    RectTilesBitmap         = new RectInt(tileDrawPositionLeftTop, xCount * TileSize.Width, yCount * TileSize.Height);
                    tileDrawPositionLeftTop = new PointInt(0, 0);
                    GridInfo = new DrawGrid
                    {
                        GridSize    = TileSize,
                        LeftTop     = RectTilesBitmap.LeftTop,
                        RightBottom = RectTilesBitmap.RightBottom,
                        XCount      = xCount,
                        YCount      = yCount,
                    };

                    //计算要显示的绘图瓦片
                    if (DicDrawTile == null)
                    {
                        DicDrawTile = new Dictionary <Tile, DrawTile>();
                    }
                    DicDrawTile.Clear();

                    var             minTileIndex  = MapHelper.GetTileMatrixMinXY(Zoom);
                    var             maxTileIndex  = MapHelper.GetTileMatrixMaxXY(Zoom);
                    List <Tile>     lstWantToLoad = new List <Tile>();
                    List <DrawTile> lstDrawTile   = new List <DrawTile>();
                    //DateTime rt = DateTime.Now;
                    for (int x = 0; x < xCount; x++)
                    {
                        for (int y = 0; y < yCount; y++)
                        {
                            var drawPostiton = tileDrawPositionLeftTop.GetOffSet(x * TileSize.Width, y * TileSize.Height);
                            //Tile t = new Tile(tileXYLeftTop.X + x, tileXYLeftTop.Y + y, Zoom);
                            Tile t = TileManager.Singleton.GetTile(Zoom, new PointInt64(tileXYLeftTop.X + x, tileXYLeftTop.Y + y));
                            if (t == null)
                            {
                                t = new Tile(tileXYLeftTop.X + x, tileXYLeftTop.Y + y, Zoom);
                            }
                            if (t.TileIndex.X >= minTileIndex.Width && t.TileIndex.Y >= minTileIndex.Height &&
                                t.TileIndex.X <= maxTileIndex.Width && t.TileIndex.Y <= maxTileIndex.Height)   //范围判断
                            {
                                var rt = new DrawTile()
                                {
                                    DrawPosition = drawPostiton,
                                    Tile         = t
                                };
                                lstDrawTile.Add(rt);
                                ////if (RotationAngle == 0 || MapHelper.CheckTileCrossRect(new RectInt(dt.DrawPosition.GetOffSet(TilesArea.LeftTop.X, TilesArea.LeftTop.Y), TileSize.Width, TileSize.Height), ScreenArea, RotationAngle))
                                //{
                                //    //DicDrawTile.Add(t, rt);
                                //    lstDrawTile.Add(rt);
                                //    //if (t.TileImg == null)
                                //    //{
                                //    //    lstWantToLoad.Add(t);

                                //    //}
                                //}
                            }
                        }
                    }
                    lstDrawTile = lstDrawTile.OrderBy(d => Math.Abs(d.Tile.TileIndex.X - tileXYCenter.X) + Math.Abs(d.Tile.TileIndex.Y - tileXYCenter.Y)).ToList();
                    foreach (var item in lstDrawTile)
                    {
                        if (item.Tile.State == TileState.New)
                        {
                            TileManager.Singleton.AddTile(item.Tile);
                        }
                        if (item.Tile.TileImg == null)
                        {
                            lstWantToLoad.Add(item.Tile);
                        }
                        item.Tile.ReadTime = DateTime.Now;
                        DicDrawTile.Add(item.Tile, item);
                    }



                    lstWantToLoad.ForEach(a => { TileManager.Singleton.LoadTile(a); });

                    //_lastTilesRect = tilesRect;
                    //TileDrawOffset = new PointInt(0,0);

                    if (TilesUpdateComplete != null)
                    {
                        TilesUpdateComplete(DicDrawTile);
                    }
                }
            }
            finally
            {
                IsTilesUpdating = false;
                TilesUpdateLock.ReleaseWriterLock();
            }
        }
    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;
                }
            }
        }
    }
    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");
        }
    }
 private void OnDesroy()
 {
     DrawGrid.Done();
 }
Esempio n. 29
0
 private void Awake()
 {
     grid = GetComponent <DrawGrid>();
 }
    private void PlaceDoneGames()
    {
        doneGameParent = new GameObject("DoneGameParent");

        // Add a draw grid to the doneGame
        DrawGrid dg = doneGameParent.AddComponent <DrawGrid>();

        dg.DisableClickHandler = true;
        dg.lineObject          = Resources.Load <GameObject>("Prefabs/Line");
        dg.gridManagerParent   = doneGameParent.transform;

        // Add disabler
        doneGameDisabler = doneGameParent.AddComponent <DoneGameDisabler>();

        DontDestroyOnLoad(doneGameParent);

        float areaMultiplier = 2.5f;

        int xAt;
        int yAt = (int)(-radius * areaMultiplier);

        // We place a donegame then we allocate a areaMultiplier times bigger space it needs in a square We place it there randomly then move on to the next one in the row
        // We do it until row is full the we take the max height of that row and move down by that much to form a new row
        // Then we start again
        // We do it until all the rows are filled
        while (yAt <= (int)(radius * areaMultiplier))
        {
            int maxHeight = 0;
            xAt = (int)(-radius * areaMultiplier);

            while (xAt <= (int)(radius * areaMultiplier))
            {
                int            idInArray   = Random.Range(0, doneGamePrefabs.Length);
                GameObject     newDoneGame = Instantiate(doneGamePrefabs[idInArray], doneGameParent.transform);
                DoneGameScript dgs         = newDoneGame.GetComponent <DoneGameScript>();

                // Decide which length of the dgs's size is bigger
                int biggerSize     = dgs.height > dgs.width ? dgs.height : dgs.width;
                int allocatedSpace = (int)(biggerSize * areaMultiplier);

                // Where we should place the dgs
                // Get the middle of the allocated space then pick a random point in a circle
                Vector2 position = new Vector2(xAt + biggerSize / 2f, yAt + biggerSize / 2f) + Random.insideUnitCircle * (biggerSize * (areaMultiplier - 1f) / 2f);
                // It needs to be placed on 0.5 pos
                position.x = (int)position.x + 0.5f;
                position.y = (int)position.y + 0.5f;

                // Move to the next position of x and store y if it's bigger than before
                xAt += allocatedSpace;
                if (maxHeight <= allocatedSpace)
                {
                    maxHeight = allocatedSpace;
                }

                // Set the new pos if the dgs
                newDoneGame.transform.position = position;

                // Set random rotation 90 180 270 or 0
                newDoneGame.transform.Rotate(new Vector3(0, 0, possibleRotation[Random.Range(0, possibleRotation.Length)]));
            }

            // Move on y axis
            yAt += maxHeight;
        }
    }
Esempio n. 31
0
 private void Start()
 {
     _grid = GetComponent <DrawGrid>();
     SpawnRandom();
 }