Ejemplo n.º 1
0
        public static void CreateImageGroup()
        {
            // split path name and file name
            var path = EditorUtils.GetSelectedDirectory();

            CreateImageGroup(path, EditorUtils.PathOfSelectedSprites());
        }
Ejemplo n.º 2
0
        public static void CreateListForAllBackgroundGroups()
        {
            var path      = EditorUtils.GetSelectedDirectory();
            var listPaths = AssetDatabase.FindAssets("t:BackgroundGroupList", new[] { path });
            BackgroundGroupList list;

            if (listPaths.Length == 0)
            {
                list = CreateInstance <BackgroundGroupList>();
                var pathName = Path.GetFileNameWithoutExtension(path);
                AssetDatabase.CreateAsset(list, Path.Combine(path, pathName + "_bg_group_list.asset"));
            }
            else
            {
                list = AssetDatabase.LoadAssetAtPath <BackgroundGroupList>(
                    AssetDatabase.GUIDToAssetPath(listPaths.First()));
            }

            list.groups = AssetDatabase.FindAssets("t:BackgroundGroup", new[] { path })
                          .Select(AssetDatabase.GUIDToAssetPath)
                          .Select(AssetDatabase.LoadAssetAtPath <BackgroundGroup>)
                          .ToList();

            EditorUtility.SetDirty(list);
        }
Ejemplo n.º 3
0
        public static void CreateUncroppedStandingWithSelectedSprites()
        {
            const string assetName = "UncroppedStanding";
            var          parent    = new GameObject(assetName);

            ResetTransform(parent.transform);
            parent.AddComponent <UncroppedStanding>();

            foreach (var spritePath in EditorUtils.PathOfSelectedSprites())
            {
                var go             = new GameObject("Standing Component");
                var spriteRenderer = go.AddComponent <SpriteRenderer>();
                var sprite         = spriteRenderer.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(spritePath);
                var cropper        = go.AddComponent <SpriteCropper>();
                cropper.cropRect = new RectInt(0, 0, sprite.texture.width, sprite.texture.height);
                go.transform.SetParent(parent.transform);
                ResetTransform(go.transform);
            }

            var currentDir = EditorUtils.GetSelectedDirectory();

            PrefabUtility.SaveAsPrefabAsset(parent,
                                            Path.Combine(currentDir, AssetDatabase.GenerateUniqueAssetPath(assetName + ".prefab")));
            DestroyImmediate(parent);
        }
Ejemplo n.º 4
0
        public static void CreateMusicEntryForAllAudioClips()
        {
            var paths  = new[] { EditorUtils.GetSelectedDirectory() };
            var guids  = AssetDatabase.FindAssets("t:AudioClip", paths);
            var assets = guids.Select((guid, index) => AssetDatabase.GUIDToAssetPath(guid));

            foreach (var asset in assets)
            {
                if (!asset.Contains("_head") && !asset.Contains("_loop"))
                {
                    CreateMusicEntry(asset);
                }
            }
        }
Ejemplo n.º 5
0
        public static void CreateMusicEntryForAllAudioClips()
        {
            var dir   = EditorUtils.GetSelectedDirectory();
            var paths = AssetDatabase.FindAssets("t:AudioClip", new[] { dir })
                        .Select(AssetDatabase.GUIDToAssetPath);

            foreach (var path in paths)
            {
                if (!path.Contains("_head") && !path.Contains("_loop"))
                {
                    CreateMusicEntry(path);
                }
            }
        }
Ejemplo n.º 6
0
        public static void CreateListForAllMusicEntries()
        {
            var            path      = EditorUtils.GetSelectedDirectory();
            var            listPaths = AssetDatabase.FindAssets("t:MusicEntryList", new[] { path });
            MusicEntryList list;

            if (listPaths.Length == 0)
            {
                list = CreateInstance <MusicEntryList>();
                var pathName = Path.GetFileNameWithoutExtension(path);
                AssetDatabase.CreateAsset(list, Path.Combine(path, pathName + "_music_list.asset"));
            }
            else
            {
                list = AssetDatabase.LoadAssetAtPath <MusicEntryList>(AssetDatabase.GUIDToAssetPath(listPaths.First()));
            }

            list.entries = AssetDatabase.FindAssets("t:MusicEntry", new[] { path })
                           .Select(AssetDatabase.GUIDToAssetPath)
                           .Select(AssetDatabase.LoadAssetAtPath <MusicEntry>)
                           .ToList();

            EditorUtility.SetDirty(list);
        }
Ejemplo n.º 7
0
        private void OnGUI()
        {
            imageFolder = EditorGUILayout.TextField("Character Image Folder", imageFolder);

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Load Selected Folder"))
            {
                imageFolder = EditorUtils.GetSelectedDirectory();
                uncropped   = imageFolder.ToLower().Contains("uncrop");
                layers.Clear();
                dirty = true;
            }

            uncropped = GUILayout.Toggle(uncropped, "Uncropped");
            GUILayout.EndHorizontal();

            if (!uncropped)
            {
                referenceSize = EditorGUILayout.Vector2IntField("Reference Size", referenceSize);
                pixelsPerUnit = EditorGUILayout.FloatField("Pixels Per Unit", pixelsPerUnit);
            }

            reorderableList.DoLayoutList();

            if (GUILayout.Button("Refresh"))
            {
                dirty = true;
            }

            if (dirty)
            {
                dirty = false;

                var sprites = layers.Where(p => !string.IsNullOrEmpty(p.name)).Select(p => p.sprite).ToList();
                if (sprites.Count == 0)
                {
                    texture = null;
                }
                else
                {
                    if (uncropped)
                    {
                        var sprite = sprites[0].sprite;
                        merger.referenceSize = new Vector2Int(sprite.texture.width, sprite.texture.height);
                        merger.pixelsPerUnit = sprite.pixelsPerUnit;
                    }
                    else
                    {
                        merger.referenceSize = referenceSize;
                        merger.pixelsPerUnit = pixelsPerUnit;
                    }

                    texture = merger.GetMergedTexture(name, sprites);
                }
            }

            if (texture == null)
            {
                return;
            }

            GUILayout.Label("Composed Pose Lua Table", EditorStyles.boldLabel);
            var luaTable = LayersToLuaTable(layers);

            EditorGUILayout.SelectableLabel(luaTable);
            if (GUILayout.Button("Copy"))
            {
                EditorGUIUtility.systemCopyBuffer = luaTable;
            }

            GUILayout.Label("Preview", EditorStyles.boldLabel);

            useCaptureBox = GUILayout.Toggle(useCaptureBox, "Use Capture Box");
            if (useCaptureBox)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Capture Box");
                captureBox = EditorGUILayout.RectIntField(captureBox);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                captureDest = EditorGUILayout.TextField("Capture Destination", captureDest);

                if (GUILayout.Button("Capture"))
                {
                    Texture2D tex = new Texture2D(captureBox.width, captureBox.height, TextureFormat.ARGB32, false);
                    RenderTexture.active = texture as RenderTexture;
                    tex.ReadPixels(new Rect(captureBox.x, captureBox.y, captureBox.width, captureBox.height), 0, 0);
                    RenderTexture.active = null;
                    tex.Apply();

                    var absoluteCaptureDest = Path.Combine(Path.GetDirectoryName(Application.dataPath), captureDest);
                    Directory.CreateDirectory(Path.GetDirectoryName(absoluteCaptureDest));
                    File.WriteAllBytes(absoluteCaptureDest, tex.EncodeToPNG());
                    EditorUtility.DisplayDialog("Capture Finished", $"Saved at {absoluteCaptureDest}", "OK");
                }

                GUILayout.EndHorizontal();
            }

            var previewRect =
                EditorGUILayout.GetControlRect(false, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            previewRect.size = Utils.GetContentSize(previewRect.size, (float)texture.width / texture.height);
            var scale = previewRect.width / texture.width;

            EditorGUI.DrawTextureTransparent(previewRect, texture);

            if (useCaptureBox)
            {
                EditorUtils.DrawPreviewCaptureFrame(previewRect, captureBox.ToRect(), scale, false, Color.red);
            }
        }