Esempio n. 1
0
        private static string TemplateTextMatcher(Match match)
        {
            string text;

            string textFunctionName = match.Groups[3].Value;

            switch (textFunctionName)
            {
            case "Text":
                text = TileLang.Text(match.Groups[4].Value);
                break;

            case "ParticularText":
                text = TileLang.ParticularText(match.Groups[4].Value, match.Groups[6].Value);
                break;

            default:
                throw new KeyNotFoundException(string.Format("Unexpected text function '{0}'.", textFunctionName));
            }

            if (match.Groups[2].Value == "OpensWindow")
            {
                text = TileLang.OpensWindow(text);
            }

            text = "\"" + text + "\"";

            if (!match.Groups[2].Success)
            {
                // No wrapping function was added, so any trailing parenthesis does not
                // belong to that, simply copy to output.
                text = text + match.Groups[7].Value;
            }

            return(text);
        }
Esempio n. 2
0
        protected override void OnApplyChanges()
        {
            // Do not proceed if no atlas texture was selected.
            if (this.inputNewAutotileArtwork == null)
            {
                EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Error", "Autotile artwork was not specified"),
                    TileLang.Text("Please select artwork for autotile before proceeding."),
                    TileLang.ParticularText("Action", "Close")
                    );
                return;
            }

            // Warn user if modified atlas will contain impossible brushes.
            if (BrushUtility.WouldHaveImpossibleTilesetBrushes(this.tileset, this.inputTileWidth, this.inputTileHeight, this.inputBorderSize))
            {
                if (!EditorUtility.DisplayDialog(
                        TileLang.Text("Warning, brushes will be deleted"),
                        TileLang.Text("Modified atlas contains fewer tiles than previously. Previously created brushes that are out of range will be deleted.\n\nWould you like to proceed?"),
                        TileLang.ParticularText("Action", "Yes"),
                        TileLang.ParticularText("Action", "No")
                        ))
                {
                    return;
                }
            }

            bool refreshProceduralMeshes = !this.inputProcedural && this.autotileTileset.procedural;

            // If raw uncompressed variation of autotile is not defined generate from
            // current selection.
            if (this.inputNewAutotileArtworkUncompressed == null)
            {
                if (this.inputNewAutotileArtwork == null)
                {
                    Debug.LogError(TileLang.ParticularText("Error", "Invalid autotile artwork was specified."));
                    return;
                }
                this.inputNewAutotileArtworkUncompressed = EditorInternalUtility.LoadTextureUncompressed(this.inputNewAutotileArtwork);
            }

            this.ExpandAutotileArtwork(this.inputBorderSize);

            string tilesetBasePath = this.tilesetRecord.AssetPath.Substring(0, this.tilesetRecord.AssetPath.LastIndexOf('/') + 1);

            // Save texture asset.
            string assetPath = AssetDatabase.GetAssetPath(this.autotileTileset.AtlasTexture);

            if (string.IsNullOrEmpty(assetPath) || !assetPath.StartsWith(tilesetBasePath))
            {
                assetPath = AssetDatabase.GenerateUniqueAssetPath(tilesetBasePath + "atlas.png");
            }

            this.autotileTileset.AtlasTexture = EditorInternalUtility.SavePngAsset(assetPath, this.expandedAutotileAtlas);

            // Update and save material asset.
            if (this.autotileTileset.AtlasMaterial == null)
            {
                this.autotileTileset.AtlasMaterial             = new Material(Shader.Find("Rotorz/Tileset/Opaque Unlit"));
                this.autotileTileset.AtlasMaterial.mainTexture = this.autotileTileset.AtlasTexture;

                assetPath = AssetDatabase.GenerateUniqueAssetPath(tilesetBasePath + "atlas.mat");
                AssetDatabase.CreateAsset(this.autotileTileset.AtlasMaterial, assetPath);
                AssetDatabase.ImportAsset(assetPath);
            }
            else
            {
                this.autotileTileset.AtlasMaterial.mainTexture = this.autotileTileset.AtlasTexture;
                EditorUtility.SetDirty(this.autotileTileset.AtlasMaterial);
            }

            // Calculate metrics for tileset.
            var metrics = new TilesetMetrics(this.autotileTileset.AtlasTexture, this.inputTileWidth, this.inputTileHeight, this.inputBorderSize, this.inputDelta);

            // Update properties of tileset.
            this.autotileTileset.procedural      = this.inputProcedural;
            this.autotileTileset.ForceClampEdges = this.inputClampEdges;
            this.autotileTileset.rawTexture      = this.inputNewAutotileArtwork;
            this.autotileTileset.SetMetricsFrom(metrics);

            this.ClearExpandedAutotileAtlas();

            EditorUtility.SetDirty(this.autotileTileset);

            // Delete "impossible" tile brushes in tileset.
            // For example, an extra brush for a tile that no longer exists.
            BrushUtility.DeleteImpossibleTilesetBrushes(this.tileset);

            // Ensure that non-procedural meshes are pre-generated if missing.
            if (refreshProceduralMeshes)
            {
                BrushUtility.RefreshNonProceduralMeshes(this.tileset);
            }

            ToolUtility.RepaintBrushPalette();

            // Update procedural meshes for tile systems in scene if necessary.
            // Note: Only update if procedural mode of tileset was not modified.
            if (this.inputProcedural && this.tileset.procedural)
            {
                foreach (TileSystem tileSystem in Object.FindObjectsOfType(typeof(TileSystem)))
                {
                    tileSystem.UpdateProceduralTiles(true);
                }
            }
        }
Esempio n. 3
0
        public static void UseAsPrefabOffset()
        {
            var attachedGameObject = GetPrefabInstance();

            if (attachedGameObject == null || attachedGameObject != Selection.activeGameObject)
            {
                return;
            }

            var attachedTransform = attachedGameObject.transform;
            var tileTransform     = GetTileGameObject(attachedTransform);

            if (tileTransform == null)
            {
                return;
            }

            // Get chunk component.
            var chunk = tileTransform.parent.GetComponent <Chunk>();

            if (chunk.TileSystem == null)
            {
                return;
            }

            var prefab = PrefabUtility.GetCorrespondingObjectFromSource(attachedGameObject) as GameObject;
            //var prefab = PrefabUtility.GetPrefabParent(attachedGameObject) as GameObject;
            var prefabTransform = prefab.transform;

            var tileSystem = chunk.TileSystem;

            // Find object within chunk.
            TileIndex index = chunk.FindTileIndexFromGameObject(attachedTransform);

            if (index != TileIndex.invalid)
            {
                TileData tile = tileSystem.GetTile(index);
                if (tile.brush == null)
                {
                    return;
                }

                Vector3    positionOffset, scaleOffset;
                Quaternion rotationOffset;

                // Convert matrix of attachment into local space of tile system.
                Matrix4x4 matrix = Matrix4x4.TRS(attachedTransform.localPosition, attachedTransform.localRotation, attachedTransform.localScale);
                if (attachedTransform.parent != tileSystem.transform)
                {
                    matrix = tileSystem.transform.worldToLocalMatrix * attachedTransform.parent.localToWorldMatrix * matrix;
                }
                tile.brush.CalculatePrefabOffset(tileSystem, index.row, index.column, tile.Rotation, matrix, out positionOffset, out rotationOffset, out scaleOffset);

                Undo.RecordObject(prefabTransform, TileLang.ParticularText("Action", "Use as Prefab Offset"));
                prefabTransform.localPosition = positionOffset;
                prefabTransform.localRotation = rotationOffset;
                prefabTransform.localScale    = scaleOffset;

                EditorUtility.SetDirty(prefabTransform);

                // Should "Apply Prefab Transform" be enabled for brush?
                if (!tile.brush.applyPrefabTransform)
                {
                    if (EditorUtility.DisplayDialog(
                            TileLang.ParticularText("Action", "Apply Prefab Transform"),
                            string.Format(
                                /* 0: name of brush */
                                TileLang.Text("Prefab offset will have no effect unless 'Apply Prefab Transform' is enabled for brush.\n\nWould you like to enable this for '{0}'?"),
                                tile.brush.name
                                ),
                            TileLang.ParticularText("Action", "Yes"),
                            TileLang.ParticularText("Action", "No")
                            ))
                    {
                        Undo.RecordObject(tile.brush, "");

                        tile.brush.applyPrefabTransform = true;
                        EditorUtility.SetDirty(tile.brush);

                        // Designer window should be repainted since the toggle may be exposed!
                        RotorzWindow.RepaintIfShown <DesignerWindow>();
                    }
                }
            }
        }
        protected virtual void OnApplyChanges()
        {
            // Do not proceed if no atlas texture was selected.
            if (this.inputAtlasTexture == null)
            {
                EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Error", "Atlas texture was not specified"),
                    TileLang.Text("Please select an atlas texture before proceeding."),
                    TileLang.ParticularText("Action", "Close")
                    );
                return;
            }

            // Warn user if modified atlas will contain impossible brushes.
            if (BrushUtility.WouldHaveImpossibleTilesetBrushes(this.tileset, this.inputTileWidth, this.inputTileHeight, this.inputBorderSize))
            {
                if (!EditorUtility.DisplayDialog(
                        TileLang.Text("Warning, brushes will be deleted"),
                        TileLang.Text("Modified atlas contains fewer tiles than previously. Previously created brushes that are out of range will be deleted.\n\nWould you like to proceed?"),
                        TileLang.ParticularText("Action", "Yes"),
                        TileLang.ParticularText("Action", "No")
                        ))
                {
                    return;
                }
            }

            bool refreshNonProceduralMeshes = !this.inputProcedural && this.tileset.procedural;

            string tilesetBasePath = this.tilesetRecord.AssetPath.Substring(0, this.tilesetRecord.AssetPath.LastIndexOf('/') + 1);

            // Update and save material asset.
            if (this.tileset.AtlasMaterial == null)
            {
                this.tileset.AtlasMaterial             = new Material(Shader.Find("Rotorz/Tileset/Opaque Unlit"));
                this.tileset.AtlasMaterial.mainTexture = this.inputAtlasTexture;

                string assetPath = AssetDatabase.GenerateUniqueAssetPath(tilesetBasePath + "atlas.mat");
                AssetDatabase.CreateAsset(this.tileset.AtlasMaterial, assetPath);
                AssetDatabase.ImportAsset(assetPath);
            }
            else
            {
                this.tileset.AtlasMaterial.mainTexture = this.inputAtlasTexture;
                EditorUtility.SetDirty(this.tileset.AtlasMaterial);
            }

            this.tileset.AtlasTexture = this.inputAtlasTexture;

            // Calculate metrics for tileset.
            this.RecalculateMetrics();

            // Update properties of tileset.
            this.tileset.procedural = this.inputProcedural;
            this.tileset.SetMetricsFrom(this.inputTilesetMetrics);

            EditorUtility.SetDirty(this.tileset);

            // Delete "impossible" tile brushes in tileset.
            // For example, an extra brush for a tile that no longer exists.
            BrushUtility.DeleteImpossibleTilesetBrushes(this.tileset);

            // Ensure that non-procedural meshes are pre-generated if missing.
            if (refreshNonProceduralMeshes)
            {
                BrushUtility.RefreshNonProceduralMeshes(this.tileset);
            }

            ToolUtility.RepaintBrushPalette();

            // Update procedural meshes for tile systems in scene if necessary.
            // Note: Only update if procedural mode of tileset was not modified.
            if (this.inputProcedural && this.tileset.procedural)
            {
                foreach (TileSystem system in Object.FindObjectsOfType(typeof(TileSystem)))
                {
                    system.UpdateProceduralTiles(true);
                }
            }
        }
        public void OnSideGUI()
        {
            var atlasTexture = this.tileset.AtlasTexture;

            float restoreLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 85;

            Rect position = EditorGUILayout.BeginVertical(GUILayout.Width(210));

            GUILayout.Space(6);

            this.scrollingInfo = EditorGUILayout.BeginScrollView(this.scrollingInfo, RotorzEditorStyles.Instance.PaddedScrollView);

            if (this.autotileTileset != null)
            {
                GUILayout.Label(TileLang.Text("Autotile Atlas"), RotorzEditorStyles.Instance.BoldLabel);
            }
            else
            {
                GUILayout.Label(TileLang.Text("Atlas"), RotorzEditorStyles.Instance.BoldLabel);
            }

            ++EditorGUI.indentLevel;

            if (this.autotileTileset != null)
            {
                EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Layout"), this.autotileTileset.AutotileLayout.ToString());
                EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Inner Joins"), TileLang.FormatYesNoStatus(this.autotileTileset.HasInnerJoins));
                GUILayout.Space(6);
            }

            EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Type"), this.tileset.procedural ? TileLang.Text("Procedural") : TileLang.Text("Non-Procedural"));

            if (atlasTexture != null)
            {
                EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Width"), TileLang.FormatPixelMetric(atlasTexture.width));
                EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Height"), TileLang.FormatPixelMetric(atlasTexture.height));
                GUILayout.Space(6);
            }

            EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Rows"), this.tileset.Rows.ToString());
            EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Columns"), this.tileset.Columns.ToString());
            --EditorGUI.indentLevel;

            GUILayout.Space(6);

            GUILayout.Label(TileLang.ParticularText("Property", "Tile Size"), RotorzEditorStyles.Instance.BoldLabel);
            ++EditorGUI.indentLevel;
            EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Width"), TileLang.FormatPixelMetric(this.tileset.TileWidth));
            EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Height"), TileLang.FormatPixelMetric(this.tileset.TileHeight));
            --EditorGUI.indentLevel;

            GUILayout.Space(6);

            GUILayout.Label(TileLang.Text("Edge Correction"), RotorzEditorStyles.Instance.BoldLabel);
            ++EditorGUI.indentLevel;
            EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Border"), TileLang.FormatPixelMetric(this.tileset.BorderSize));
            EditorGUILayout.LabelField(TileLang.ParticularText("Property", "Delta"), TileLang.FormatPixelFractionMetric(this.tileset.Delta));
            --EditorGUI.indentLevel;

            EditorGUILayout.EndScrollView();

            EditorGUILayout.EndVertical();

            if (Event.current.type == EventType.Repaint)
            {
                RotorzEditorStyles.Instance.HorizontalSplitter.Draw(
                    new Rect(position.x, position.y, position.width - 6, position.height),
                    GUIContent.none,
                    false, false, false, false
                    );
            }

            EditorGUIUtility.labelWidth = restoreLabelWidth;
        }
Esempio n. 6
0
 public static void CheckPreferredLanguage(string languageCultureName, string languageVer)
 {
     if (languageCultureName != PackageLanguageManager.PreferredCulture.Name || languageVer != TileLang.Text("__LanguageVer__"))
     {
         // Unity integration script probably needs to be updated!
         Debug.Log("Localizing Unity integration...");
         Regenerate();
         Debug.Log("Localizing complete.");
     }
 }