예제 #1
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"));
        }
예제 #2
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();
        }
예제 #3
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"),
            };
        }
        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);
            }
        }
예제 #5
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);
            }
        }
예제 #6
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;
                }
            }
        }