Пример #1
0
    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
    public static void Init()
    {
        // Get existing open window or if none, make new one
        window = (UPAEditorWindow)EditorWindow.GetWindow (typeof (UPAEditorWindow));
        window.title = "Pixel Art Editor";

        string path = EditorPrefs.GetString ("currentImgPath", "");

        if (path.Length != 0)
            CurrentImg = UPASession.OpenImageAtPath (path);
    }
Пример #3
0
    public static void Init()
    {
        // Get existing open window or if none, make new one
        window       = (UPAEditorWindow)EditorWindow.GetWindow(typeof(UPAEditorWindow));
        window.title = "Pixel Art Editor";

        string path = EditorPrefs.GetString("currentImgPath", "");

        if (path.Length != 0)
        {
            CurrentImg = UPASession.OpenImageAtPath(path);
        }
    }
Пример #4
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);
    }
Пример #5
0
	public static void Init () {
		// Get existing open window or if none, make new one
		window = (UPAEditorWindow)EditorWindow.GetWindow (typeof (UPAEditorWindow));
		#if UNITY_4_3
		window.title = "Pixel Art Editor";
		#elif UNITY_4_6
		window.title = "Pixel Art Editor";
		#else
		window.titleContent = new GUIContent ("Pixel Art Editor");
		#endif
		
		string path = EditorPrefs.GetString ("currentImgPath", "");
		
		if (path.Length != 0)
			CurrentImg = UPASession.OpenImageAtPath (path);
	}
Пример #6
0
    public static void Init()
    {
        // Get existing open window or if none, make new one
        window = (UPAEditorWindow)EditorWindow.GetWindow(typeof(UPAEditorWindow));
                #if UNITY_4_3
        window.title = "Pixel Art Editor";
                #elif UNITY_4_6
        window.title = "Pixel Art Editor";
                #else
        window.titleContent = new GUIContent("Pixel Art Editor");
                #endif

        string path = EditorPrefs.GetString("currentImgPath", "");

        if (path.Length != 0)
        {
            CurrentImg = UPASession.OpenImageAtPath(path);
        }
    }
Пример #7
0
    public static void Init()
    {
        selectedTool = UPATool.Map;

        EditorPrefs.SetString("templateImgPath", "");
        EditorPrefs.SetString("currentAnimationPath", "");
        // Get existing open window or if none, make new one
        window = (UPAEditorWindow)EditorWindow.GetWindow(typeof(UPAEditorWindow));
                #if UNITY_4_3
        window.title = "Pixel Art Editor";
                #elif UNITY_4_6
        window.title = "Pixel Art Editor";
                #else
        window.titleContent = new GUIContent("Pixel Art Editor");
                #endif

        string path = EditorPrefs.GetString("currentAnimationPath", "");

        Debug.Log(path);


        string templatePath = EditorPrefs.GetString("templateImgPath", "");

        Debug.Log(templatePath);

        if (path.Length != 0)
        {
            Debug.Log("opening image at path");
            animation = UPASession.OpenAnimationsFromFolder(false, path);
            //CurrentImg.initilizeAlphas();
            animationIndex = 0;
        }

        if (templatePath.Length != 0)
        {
            Debug.Log("opening image at path");
            TemplateImage = UPASession.OpenImageAtPath(templatePath, true);
            //TemplateImage.initilizeAlphas();
            TemplateImage.loopThroughImage();
        }
    }
Пример #8
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);
    }