コード例 #1
0
        protected override void DrawInspectorGUI()
        {
            DrawText($"Json Version: {_jsonVersion}", LDtkIconUtility.LoadWorldIcon());

            DrawCountOfItems(_levelCount, "Level", "Levels", LDtkIconUtility.LoadLevelIcon());
            if (_levelCount > 0)
            {
                DrawCountOfItems(_levelFieldsCount, "Level Fields", "Level Fields", LDtkIconUtility.LoadLevelIcon());
            }

            DrawCountOfItems(_layerCount, "Layer Definition", "Layer Definitions", LDtkIconUtility.LoadLayerIcon());

            DrawCountOfItems(_entityCount, "Entity Definition", "Entity Definitions", LDtkIconUtility.LoadEntityIcon());
            if (_entityFieldsCount > 0)
            {
                DrawCountOfItems(_entityFieldsCount, "Entity Field", "Entity Fields", LDtkIconUtility.LoadEntityIcon());
            }

            DrawCountOfItems(_enumCount, "Enum", "Enums", LDtkIconUtility.LoadEnumIcon());
            if (_enumValueCount > 0)
            {
                DrawCountOfItems(_enumValueCount, "Enum Value", "Enum Values", LDtkIconUtility.LoadEnumIcon());
            }

            DrawCountOfItems(_tilesetCount, "Tileset", "Tilesets", LDtkIconUtility.LoadTilesetIcon());
        }
コード例 #2
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            LDtkLevelFile levelFile = ReadAssetText(ctx);

            ctx.AddObjectToAsset("levelFile", levelFile, LDtkIconUtility.LoadLevelFileIcon());
            ctx.SetMainObject(levelFile);
        }
コード例 #3
0
        private void TryDrawProjectReferenceButton()
        {
            if (!_projectAsset)
            {
                DrawBreakingError();
                return;
            }

            GUIContent buttonContent = new GUIContent()
            {
                text  = "LDtk Project",
                image = LDtkIconUtility.LoadProjectFileIcon()
            };


            using (new EditorGUILayout.HorizontalScope())
            {
                using (new EditorGUI.DisabledScope(true))
                {
                    using (new LDtkIconSizeScope(16))
                    {
                        EditorGUILayout.ObjectField(buttonContent, _projectAsset, typeof(GameObject), false);
                    }
                }

                if (GUILayout.Button(ReimportProjectButton, GUILayout.Width(105)))
                {
                    string assetPath = AssetDatabase.GetAssetPath(_projectAsset);
                    AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
                }
            }
        }
コード例 #4
0
        private Texture2D GetIconForRenderType()
        {
            Texture2D icon = null;

            switch (_data.RenderMode)
            {
            case RenderMode.Cross:
                icon = LDtkIconUtility.LoadCrossIcon();
                break;

            case RenderMode.Ellipse:
                icon = LDtkIconUtility.LoadCircleIcon();
                break;

            case RenderMode.Rectangle:
                icon = LDtkIconUtility.LoadSquareIcon();
                break;

            case RenderMode.Tile:
                //todo get the cool icon that is used for the scene drawer (when entities can eventually get its tile through definition, not just instance)
                icon = LDtkIconUtility.LoadSquareIcon();
                break;
            }
            return(icon);
        }
コード例 #5
0
 protected override void DrawInspectorGUI()
 {
     DrawCountOfItems(_layerCount, "Layer", "Layers", LDtkIconUtility.LoadLayerIcon());
     DrawCountOfItems(_intGridValueCount, "Int Grid Value", "Int Grid Values", LDtkIconUtility.LoadIntGridIcon());
     DrawCountOfItems(_entityCount, "Entity", "Entities", LDtkIconUtility.LoadEntityIcon());
     DrawCountOfItems(_gridTileCount, "Grid Tile", "Grid Tiles", LDtkIconUtility.LoadTilesetIcon());
     DrawCountOfItems(_autoTileCount, "Auto Tile", "Auto Tiles", LDtkIconUtility.LoadAutoLayerIcon());
 }
コード例 #6
0
        private void CreateArtifactAsset()
        {
            //the bank for storing the auto-generated items.
            _artifacts      = ScriptableObject.CreateInstance <LDtkArtifactAssets>();
            _artifacts.name = AssetName + "_Assets";

            ImportContext.AddObjectToAsset("artifacts", _artifacts, (Texture2D)LDtkIconUtility.GetUnityIcon("Tilemap"));
        }
コード例 #7
0
 public LDtkSectionIntGrids(SerializedObject serializedObject) : base(serializedObject)
 {
     _buttonContent = new GUIContent()
     {
         text    = "+",
         image   = LDtkIconUtility.LoadIntGridIcon(),
         tooltip = "Create a new IntGrid tile asset."
     };
 }
コード例 #8
0
        private static LDtkNativeExportWindow ConstructWindow()
        {
            LDtkNativeExportWindow window = GetWindow <LDtkNativeExportWindow>();

            window.titleContent = new GUIContent()
            {
                text  = "Export",
                image = LDtkIconUtility.LoadSimpleIcon()
            };
            window.minSize = new Vector2(250, 140);

            return(window);
        }
コード例 #9
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.HelpBox("After finished editing, Save Project to reimport all LDtk projects that use this tile", MessageType.None);

                GUIContent saveButtonLabel = new GUIContent
                {
                    tooltip = "Save Project",
                    image   = LDtkIconUtility.GetUnityIcon("SaveAs", "")
                };
                if (GUILayout.Button(saveButtonLabel, GUILayout.Width(30), GUILayout.ExpandHeight(true)))
                {
                    AssetDatabase.SaveAssets();
                }
            }

            LDtkEditorGUIUtility.DrawDivider();

            serializedObject.DrawField(LDtkIntGridTile.PROPERTY_TAG, _tagLabel);
            serializedObject.DrawField(LDtkIntGridTile.PROPERTY_LAYERMASK, _layerMaskLabel);
            serializedObject.DrawField(LDtkIntGridTile.PROPERTY_PHYSICS_MATERIAL, _physicsMaterialLabel);

            LDtkEditorGUIUtility.DrawDivider();

            SerializedProperty colliderTypeProp = serializedObject.DrawField(LDtkIntGridTile.PROPERTY_COLLIDER_TYPE, _colliderLabel);

            if (colliderTypeProp.enumValueIndex == (int)Tile.ColliderType.Sprite || serializedObject.isEditingMultipleObjects)
            {
                SerializedProperty physicsSpriteProp = serializedObject.DrawField(LDtkIntGridTile.PROPERTY_CUSTOM_PHYSICS_SPRITE, _spriteLabel);
                if (physicsSpriteProp.objectReferenceValue != null && !serializedObject.isEditingMultipleObjects)
                {
                    DrawCollisionShape((Sprite)physicsSpriteProp.objectReferenceValue);
                }
            }

            LDtkEditorGUIUtility.DrawDivider();

            SerializedProperty gameObjectProp = serializedObject.DrawField(LDtkIntGridTile.PROPERTY_GAME_OBJECT, _gameObjectLabel);

            LDtkSectionDrawer.DenyPotentialResursiveGameObjects(gameObjectProp);

            if (gameObjectProp.objectReferenceValue != null && !serializedObject.isEditingMultipleObjects)
            {
                DrawGameObjectPreview((GameObject)gameObjectProp.objectReferenceValue);
            }

            serializedObject.ApplyModifiedProperties();
        }
コード例 #10
0
        public PathDrawer(SerializedProperty pathProp, GUIContent labelContent, string originalPath, string folderButtonTooltip, string extension = "", string filePanelDescription = "Select location")
        {
            _labelContent         = labelContent;
            _pathProp             = pathProp;
            _originalPath         = originalPath;
            _extension            = extension;
            _filePanelDescription = filePanelDescription;

            _folderButtonContent = new GUIContent()
            {
                tooltip = folderButtonTooltip,
                image   = LDtkIconUtility.GetUnityIcon("Folder"),
            };
        }
コード例 #11
0
        private static void DrawSection(SerializedProperty tilesProp, string type)
        {
            EditorGUIUtility.SetIconSize(Vector2.one * 16);
            Texture image = LDtkIconUtility.GetUnityIcon(type);

            GUIContent tilesContent = new GUIContent()
            {
                text  = $"{tilesProp.arraySize} {type}s",
                image = image
            };

            EditorGUILayout.LabelField(tilesContent);

            using (new LDtkIndentScope())
            {
                DrawElements(tilesProp, image);
            }
        }
コード例 #12
0
        private static void DrawSection(SerializedProperty tilesProp, string icon, string label)
        {
            EditorGUIUtility.SetIconSize(Vector2.one * 16);
            Texture image = LDtkIconUtility.GetUnityIcon(icon);

            string     pluralizedText = $"{tilesProp.arraySize} {label}" + (tilesProp.arraySize > 1 ? "s" : "");
            GUIContent tilesContent   = new GUIContent()
            {
                text  = pluralizedText,
                image = image
            };

            EditorGUILayout.LabelField(tilesContent);

            using (new LDtkIndentScope())
            {
                DrawElements(tilesProp, image);
            }
        }
コード例 #13
0
        private void DrawPathField()
        {
            SerializedProperty enumPathProp = SerializedObject.FindProperty(LDtkProjectImporter.ENUM_PATH);

            string assetPath       = AssetDatabase.GetAssetPath(Importer);
            string defaultFileName = Path.ChangeExtension(assetPath, ".cs");

            const float buttonWidth = 26;

            Rect rect = PropertyFieldWithDefaultText(enumPathProp, _pathLabel, defaultFileName, buttonWidth + 2);

            GUIContent buttonContent = new GUIContent()
            {
                tooltip = "Set the path for the location that the enum file will be generated",
                image   = LDtkIconUtility.GetUnityIcon("Folder"),
            };

            Rect buttonRect = new Rect(rect)
            {
                xMin = rect.xMax - buttonWidth
            };

            if (GUI.Button(buttonRect, buttonContent, EditorStyles.miniButton))
            {
                string fileName = EditorUtility.SaveFilePanel("Location for generated C# file",
                                                              Path.GetDirectoryName(defaultFileName),
                                                              Path.GetFileName(defaultFileName), "cs");

                if (!string.IsNullOrEmpty(fileName))
                {
                    if (fileName.StartsWith(Application.dataPath))
                    {
                        fileName = "Assets/" + fileName.Substring(Application.dataPath.Length + 1);
                    }

                    enumPathProp.stringValue = fileName;
                }
            }
        }
コード例 #14
0
 //allows some of the editor icons to be for the correct corresponding editor theme, instead of always being white/black
 public sealed override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
 {
     return(LDtkIconUtility.GetRenderStaticPreview(StaticPreview, width, height));
 }
コード例 #15
0
        public void Import(LdtkJson json)
        {
            //set the data class's levels correctly, regardless if they are external levels or not
            json.Levels = GetLevelData(json);


            LDtkProjectBuilder builder = new LDtkProjectBuilder(_importer, json);

            builder.BuildProject();
            GameObject projectGameObject = builder.RootObject;

            if (projectGameObject == null)
            {
                _importer.ImportContext.LogImportError("LDtk: Project GameObject null, not building correctly");
                return;
            }

            _importer.ImportContext.AddObjectToAsset("rootGameObject", projectGameObject, LDtkIconUtility.LoadProjectFileIcon());
            _importer.ImportContext.SetMainObject(projectGameObject);
        }