예제 #1
0
    public static void MakeAltas()
    {
        string           path     = "/TestSprite/Res/Image";
        List <Texture2D> textures = GetAllTexture(path);

        int width  = 0;
        int height = 0;

        GetAllTexture(ref textures, ref width, ref height);

        Debug.Log(width + " : " + height);

        GameObject    obj   = new GameObject("altas");
        F3SpriteAltas altas = obj.AddComponent <F3SpriteAltas>(); //ScriptableObject.CreateInstance<F3SpriteAltas>();

        altas.Init(width, height);

        int x = 0, y = 0;

        for (int i = 0; i < textures.Count; i++)
        {
            altas.GetPos(textures[i], ref x, ref y);
            altas.AddTexture(textures[i].name, textures[i], ref x, ref y);
        }

        //AssetDatabase.CreateAsset(obj, "Assets/TestSprite/Res/Image/f3altals");

        byte[] textBytes = altas.text2d.EncodeToPNG();

        System.IO.File.WriteAllBytes("Assets/TestSprite/Res/Altas/f3altals.png", textBytes);
        obj = PrefabUtility.SaveAsPrefabAssetAndConnect(obj, "Assets/TestSprite/Res/Altas/f3altals.prefab", InteractionMode.AutomatedAction);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        Debug.Log(AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/TestSprite/Res/Altas/f3altals.png"));

        obj.GetComponent <F3SpriteAltas>().text2d   = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/TestSprite/Res/Image/f3altals.png");
        obj.GetComponent <F3SpriteAltas>().material = AssetDatabase.LoadAssetAtPath <Material>("Assets/TestSprite/Res/Altas/F3SpriteMat.mat");
        EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        //PrefabUtility.SavePrefabAsset(obj);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }