コード例 #1
0
ファイル: UPASession.cs プロジェクト: wagnermps/UPAToolkit
    public static void CreateImage(int w, int h)
    {
        string path = EditorUtility.SaveFilePanel("Create UPAImage",
                                                  "Assets/", "Pixel Image.asset", "asset");

        if (path == "")
        {
            return;
        }

        path = FileUtil.GetProjectRelativePath(path);

        UPAImage img = ScriptableObject.CreateInstance <UPAImage>();

        AssetDatabase.CreateAsset(img, path);

        AssetDatabase.SaveAssets();

        img.Init(w, h);
        EditorUtility.SetDirty(img);
        UPAEditorWindow.CurrentImg = img;

        EditorPrefs.SetString("currentImgPath", AssetDatabase.GetAssetPath(img));

        if (UPAEditorWindow.window != null)
        {
            UPAEditorWindow.window.Repaint();
        }
        else
        {
            UPAEditorWindow.Init();
        }

        img.gridSpacing = 10 - Mathf.Abs(img.width - img.height) / 100f;
    }
コード例 #2
0
    static UPAImage customCreateImage(int w, int h, bool isTemplate)
    {
        //TODO: want to pass in the same path that the image was pulled from, so you don't have to navigate back
        string path = EditorUtility.SaveFilePanel("Create UPAImage",
                                                  "Assets/", "Pixel Image.asset", "asset");

        if (path == "")
        {
            return(null);
        }

        Debug.Log("creating custom image");
        Debug.Log(path);

        path = FileUtil.GetProjectRelativePath(path);
        Debug.Log(path);

        UPAImage img = ScriptableObject.CreateInstance <UPAImage>();

        AssetDatabase.CreateAsset(img, path);

        AssetDatabase.SaveAssets();

        img.Init(w, h);
        EditorUtility.SetDirty(img);



        if (isTemplate)
        {
            EditorPrefs.SetString("templateImgPath", AssetDatabase.GetAssetPath(img));
            UPAEditorWindow.TemplateImage = img;
        }
        else
        {
            EditorPrefs.SetString("currentImgPath", AssetDatabase.GetAssetPath(img));
            UPAEditorWindow.CurrentImg = img;
        }

        if (UPAEditorWindow.window != null)
        {
            UPAEditorWindow.window.Repaint();
        }
        else
        {
            UPAEditorWindow.Init();
        }

        img.gridSpacing = 10 - Mathf.Abs(img.width - img.height) / 100f;
        return(img);
    }
コード例 #3
0
    public static List <UPAImage> OpenAnimationsFromFolder(bool isTemplate, string path = "")
    {
        if (path.Length == 0)
        {
            path = EditorUtility.OpenFolderPanel(
                "Choose Animation Folder",
                "Assets/Sprites",
                "");
        }



        if (path.Length != 0)
        {
            List <UPAImage> animation = new List <UPAImage>();

            DirectoryInfo dir  = new DirectoryInfo(path);
            FileInfo[]    info = dir.GetFiles("*.asset");
            Debug.Log("length = " + info.Length);



            if (info.Length > 0)
            {
                Debug.Log("info length greator than 0");

                Debug.Log(path);

                //We have some asset files, so lets load those in, instead of creating new ones
                //TODO: i dont know if these frames are loaded in order, may need to sort
                for (int i = 0; i < info.Length; i++)
                {
                    string newPath;

                    newPath = path + "/" + (i + 1) + ".asset";
                    newPath = FileUtil.GetProjectRelativePath(newPath);

                    Debug.Log("expected path = Assets / Sprites / Front RunTest / 1.asset");

                    Debug.Log("new path = ");



                    //newPath = "Assets/Sprites/Front RunTest/1";

                    Debug.Log(newPath);

                    UPAImage frameImage = OpenFrameAtPath(newPath);

                    frameImage.LoadAllTexsFromMaps();

                    frameImage.setAllNormalAlpha();

                    //frameImage.initilizeAlphas();
                    animation.Add(frameImage);
                }
            }
            else
            {
                info = dir.GetFiles("*.png");

                List <FileInfo[]> frames = sortFrames(info);

                int frameNumber = 1;


                foreach (FileInfo[] frame in frames)
                {
                    string newPath = path + "\\" + frameNumber + ".asset";

                    UPAImage i = loadImageFromFileInfo(frame, isTemplate, newPath);
                    i.initilizeAlphas();
                    animation.Add(i);

                    frameNumber += 1;
                }
            }



            UPAImage img = animation[0];

            Debug.Log(img.GetType());

            EditorPrefs.SetString("currentAnimationPath", path);
            UPAEditorWindow.CurrentImg = img;


            if (UPAEditorWindow.window != null)
            {
                UPAEditorWindow.window.Repaint();
            }
            else
            {
                UPAEditorWindow.Init();
            }



            return(animation);
        }

        return(null);
    }