Exemple #1
0
        private void DrawStandardStatusGUI()
        {
            var       activeTileSystem = ToolUtility.ActiveTileSystem;
            TileIndex activeTileIndex  = ToolUtility.ActiveTileIndex;
            TileData  activeTile       = ToolUtility.ActiveTile;

            string statusLabel = string.Format(

                /* 0: zero-based index of row
                 * 1: zero-based index of column */
                TileLang.Text("Row: {0,5}    Column: {1,5}"),
                activeTileIndex.row, activeTileIndex.column
                );

            Rect outRect = new Rect(5, 20, 205, 17);

            GUI.Label(outRect, statusLabel, EditorStyles.whiteLabel);

            outRect.x     = 203;
            outRect.width = 190;

            statusLabel = "-";
            if (activeTile != null)
            {
                if (activeTile.brush != null)
                {
                    if (activeTile.tileset != null)
                    {
                        statusLabel = string.Format(

                            /* 0: name of brush
                             * 1: zero-based index of associated tile in tileset */
                            TileLang.Text("{0} : {1}"),
                            activeTile.brush.name, activeTile.tilesetIndex
                            );
                    }
                    else
                    {
                        statusLabel = activeTile.brush.name;
                    }
                }
                else if (activeTile.tileset != null)
                {
                    statusLabel = string.Format(

                        /* 0: name of tileset
                         * 1: zero-based index of tile in tileset */
                        TileLang.Text("{1} from {0}"),
                        activeTile.tileset.name, activeTile.tilesetIndex
                        );
                }
            }
            GUI.Label(outRect, statusLabel, EditorStyles.whiteLabel);

            if (activeTile != null && Event.current.type == EventType.Repaint)
            {
                int actualOrientation = activeTile.orientationMask;

                // Get oriented brush component of tile.
                var orientedBrush = activeTile.OrientedBrush;
                if (activeTile.brush is AliasBrush)
                {
                    orientedBrush = activeTile.AliasBrush.target as OrientedBrush;
                }
                // Determine actual orientation of active tile.
                if (orientedBrush != null)
                {
                    actualOrientation = OrientationUtility.DetermineTileOrientation(activeTileSystem, activeTileIndex, activeTile.brush, activeTile.PaintedRotation);
                }

                Color restoreBackground = GUI.backgroundColor;
                Color activeColor       = activeTile.PaintedRotation != 0 ? new Color(0, 40, 255) : Color.green;

                outRect.x      = 180;
                outRect.y      = 19;
                outRect.width  = 5;
                outRect.height = 5;

                int bit = 1;
                for (int i = 0; i < 9; ++i)
                {
                    if (i == 4)
                    {
                        // Draw center box!
                        GUI.backgroundColor = Color.black;
                        RotorzEditorStyles.Instance.TransparentBox.Draw(outRect, GUIContent.none, false, false, false, false);

                        if (activeTile.PaintedRotation != 0)
                        {
                            GUI.backgroundColor = activeColor;
                            RotorzEditorStyles.Instance.TransparentBox.Draw(new Rect(outRect.x + 1, outRect.y + 1, 3, 3), GUIContent.none, false, false, false, false);
                        }
                    }
                    else
                    {
                        // Green  : Matching part of orientation
                        // Cyan   : Matching part of orientation with rotation applied
                        // Red    : Surplus part of orientation
                        // Gray   : Missing part of orientation

                        if ((actualOrientation & bit) != (activeTile.orientationMask & bit))
                        {
                            // Orientation of tile is invalid.
                            GUI.backgroundColor = (activeTile.orientationMask & bit) != 0 ? Color.red : Color.gray;
                        }
                        else
                        {
                            // Orientation of tile is valid.
                            GUI.backgroundColor = (activeTile.orientationMask & bit) != 0 ? activeColor : Color.white;
                        }

                        RotorzEditorStyles.Instance.TransparentBox.Draw(outRect, GUIContent.none, false, false, false, false);

                        bit <<= 1;
                    }

                    if (i % 3 == 2)
                    {
                        outRect.x  = 180;
                        outRect.y += 6;
                    }
                    else
                    {
                        outRect.x += 6;
                    }
                }

                GUI.backgroundColor = restoreBackground;
            }
        }
    /// <summary>
    /// Upgrade tile system from v1.0.0-v1.0.8 to v2.0.0.
    /// </summary>
    /// <remarks>
    /// <para>Replicates upgrade process that was included in v1.0.9+ but converts straight
    /// to v2.0.0 instead of v1.0.9.</para>
    /// </remarks>
    /// <param name="v1">Old tile system.</param>
    public static void UpgradeTileSystemA(MonoBehaviour v1)
    {
        RtsUpgradedBrushMap map = RtsBrushUpgradeUtility.BrushMappings;

        EditorUtility.DisplayProgressBar("Upgrade Tile System", "Initializing new data structure...", 0.0f);
        try {
            PropertyInfo piTileData_hasGameObject = typeof(TileData).GetProperty("HasGameObject", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            Vector3 tileSize = (Vector3)_fiTileSystem_tileSize.GetValue(v1);
            int     rows     = (int)_fiTileSystem_rows.GetValue(v1);
            int     columns  = (int)_fiTileSystem_columns.GetValue(v1);

            // Create v2.x tile system.
            TileSystem v2 = v1.gameObject.AddComponent <TileSystem>();
            v2.CreateSystem(tileSize.x, tileSize.y, tileSize.z, rows, columns, 30, 30);
            CopyProperties(v1, v2);

            // Assume value that was consistent with original default settings
            v2.applyRuntimeStripping = true;
            v2.StrippingPreset       = StrippingPreset.NoStripping;
            v2.BeginBulkEdit();

            Component[] instanceComponents = v1.GetComponentsInChildren(_tyTileInstance, true);

            float task      = 0.0f;
            float taskCount = instanceComponents.Length;
            float taskRatio = 1.0f / taskCount;

            TileData tile = new TileData();

            // Retrieve all tile instance components
            foreach (MonoBehaviour instance in instanceComponents)
            {
                EditorUtility.DisplayProgressBar("Upgrade Tile System", "Processing tile data...", (task++) * taskRatio);

                int row    = (int)_fiTileInstance_row.GetValue(instance);
                int column = (int)_fiTileInstance_column.GetValue(instance);

                tile.Clear();

                // Create and assign tile data
                tile.brush           = map.Lookup((Object)_piTileInstance_brush.GetValue(instance, null));
                tile.orientationMask = (byte)OrientationUtility.MaskFromName((string)_fiTileInstance_orientationName.GetValue(instance));
                tile.variationIndex  = (byte)(int)_fiTileInstance_variationIndex.GetValue(instance);
                tile.Empty           = false;
                tile.gameObject      = instance.gameObject;
                piTileData_hasGameObject.SetValue(tile, true, null);

                v2.SetTileFrom(row, column, tile);

                Chunk chunk = v2.GetChunkFromTileIndex(row, column);
                ForceRepaintForAtlasTiles(v2.GetTile(row, column), chunk);
                if (instance == null)
                {
                    continue;
                }

                // Cleanup original tile instance?
                if (!StrippingUtility.StripEmptyGameObject(instance.transform))
                {
                    // Reparent game object to its shiny new chunk!
                    instance.gameObject.transform.parent = chunk.transform;
                }

                // Destroy unwanted tile instance component
                Object.DestroyImmediate(instance);
            }

            int count = v2.EndBulkEdit();
            RemoveTileSystem(v1);

            if (count > 0)
            {
                Debug.Log(string.Format("Upgrade of tile system '{0}' completed and {1} tile(s) were force refreshed.", v2.name, count));
            }
            else
            {
                Debug.Log(string.Format("Upgrade of tile system '{0}' completed.", v2.name));
            }
        }
        finally {
            EditorUtility.ClearProgressBar();
        }
    }