示例#1
0
        private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            List <string> list = new List <string>(deletedAssets);

            list.AddRange(movedFromAssetPaths);
            foreach (string current in list)
            {
                if (Path.GetExtension(current).Equals(".tpsheet"))
                {
                    TexturePackerImporter.spriteSheets.unloadSheetData(current);
                }
            }
            List <string> list2 = new List <string>(importedAssets);

            list2.AddRange(movedAssets);
            foreach (string current2 in list2)
            {
                Dbg.Log("OnPostprocessAllAssets: " + current2);
                if (Path.GetExtension(current2).Equals(".tpsheet") && TexturePackerImporter.spriteSheets.loadSheetData(current2))
                {
                    SettingsDatabase instance = SettingsDatabase.getInstance();
                    string           path     = instance.spriteFileForDataFile(current2);
                    AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
                    string text = instance.normalsFileForDataFile(current2);
                    if (text != null)
                    {
                        AssetDatabase.ImportAsset(text, ImportAssetOptions.ForceUpdate);
                    }
                }
            }
        }
示例#2
0
 private static void updateSpriteMetaData(TextureImporter importer, SpriteMetaData[] metaData)
 {
     Dbg.Log("PNG has type " + importer.textureType);
     if (importer.textureType != TextureImporterType.Advanced)
     {
         importer.textureType = TextureImporterType.Sprite;
     }
     importer.spriteImportMode = SpriteImportMode.Multiple;
     SpriteMetaData[] spritesheet = importer.spritesheet;
     for (int i = 0; i < metaData.Length; i++)
     {
         SpriteMetaData[] array = spritesheet;
         for (int j = 0; j < array.Length; j++)
         {
             SpriteMetaData spriteMetaData = array[j];
             if (spriteMetaData.name == metaData[i].name)
             {
                 if (!SettingsDatabase.getInstance().importPivotPoints())
                 {
                     metaData[i].pivot     = spriteMetaData.pivot;
                     metaData[i].alignment = spriteMetaData.alignment;
                 }
                 metaData[i].border = spriteMetaData.border;
                 break;
             }
         }
     }
     importer.spritesheet = metaData;
 }
示例#3
0
 public static SettingsDatabase getInstance()
 {
     if (SettingsDatabase.instance == null)
     {
         SettingsDatabase.updateFileLocations();
         SettingsDatabase.instance = ScriptableObject.CreateInstance <SettingsDatabase>();
         AssetDatabase.CreateAsset(SettingsDatabase.instance, SettingsDatabase.assetFilePath);
     }
     return(SettingsDatabase.instance);
 }
示例#4
0
            public override void OnInspectorGUI()
            {
                SettingsDatabase instance = SettingsDatabase.getInstance();
                bool             flag     = EditorGUILayout.Toggle("Always import pivot points", instance.importPivots, new GUILayoutOption[0]);

                if (flag != instance.importPivots)
                {
                    instance.importPivots = flag;
                    instance.saveDatabase();
                }
            }
示例#5
0
 private void loadDatabase()
 {
     if (SettingsDatabase.databaseFilePath == null)
     {
         return;
     }
     try
     {
         Dbg.Log("Loading database " + SettingsDatabase.databaseFilePath);
         StreamReader streamReader = new StreamReader(SettingsDatabase.databaseFilePath);
         string       text;
         while ((text = streamReader.ReadLine()) != null)
         {
             string[] array = text.Split(new char[]
             {
                 ':'
             });
             string a = array[0].Trim();
             string s = array[1].Trim();
             if (a == "version")
             {
                 this.version = int.Parse(s);
             }
             else if (a == "importPivots")
             {
                 this.importPivots = (int.Parse(s) != 0);
             }
             else if (a == "tpsheetFileNames")
             {
                 this.tpsheetFileNames = SettingsDatabase.readStringList(streamReader);
             }
             else if (a == "textureFileNames")
             {
                 this.textureFileNames = SettingsDatabase.readStringList(streamReader);
             }
             else if (a == "normalmapFileNames")
             {
                 this.normalmapFileNames = SettingsDatabase.readStringList(streamReader);
             }
         }
         string str = string.Empty;
         Dbg.Log(this.tpsheetFileNames.ToCustomString(new char[] { '-' }));
         Dbg.Log(this.textureFileNames.ToCustomString(new char[] { '-' }));
         Dbg.Log(this.normalmapFileNames.ToCustomString(new char[] { '-' }));
         streamReader.Close();
     }
     catch (IOException)
     {
     }
 }
示例#6
0
        public SheetInfo sheetInfoForSpriteFile(string textureFile)
        {
            string text = SettingsDatabase.getInstance().dataFileForSpriteFile(textureFile);

            if (text == null)
            {
                return(null);
            }
            if (!this.spriteSheetData.ContainsKey(text))
            {
                this.loadSheetData(text);
            }
            return(this.spriteSheetData[text]);
        }
示例#7
0
        public void OnPostprocessTexture(Texture2D texture)
        {
            TextureImporter textureImporter = base.assetImporter as TextureImporter;
            int             num;
            int             num2;

            TexturePackerImporter.GetOrigImageSize(texture, textureImporter, out num, out num2);
            Dbg.Log(string.Concat(new object[]
            {
                "OnPostprocessTexture(",
                base.assetPath,
                "), ",
                texture.width,
                "x",
                texture.height,
                ", orig:",
                num,
                "x",
                num2
            }));
            SettingsDatabase instance = SettingsDatabase.getInstance();

            if (instance.isSpriteSheet(base.assetPath))
            {
                SheetInfo sheetInfo = TexturePackerImporter.spriteSheets.sheetInfoForSpriteFile(base.assetPath);
                if (sheetInfo.width > 0 && sheetInfo.height > 0 && (sheetInfo.width != num || sheetInfo.height != num2))
                {
                    textureImporter.spriteImportMode = SpriteImportMode.Single;
                    Dbg.Log("Inconsistent sheet size in png/tpsheet");
                }
                else
                {
                    TexturePackerImporter.updateSpriteMetaData(textureImporter, sheetInfo.metadata);
                    Dbg.Log("Updated SpriteMetaData for " + base.assetPath);
                }
            }
            if (instance.isNormalmapSheet(base.assetPath))
            {
                if (textureImporter.textureType != TextureImporterType.Advanced)
                {
                    textureImporter.textureType = TextureImporterType.Bump;
                }
                TexturePackerImporter.createMaterialForNormalmap(base.assetPath, instance.spriteFileForNormalsFile(base.assetPath));
            }
        }
示例#8
0
        private void saveDatabase()
        {
            if (SettingsDatabase.databaseFilePath == null)
            {
                return;
            }
            Dbg.Log("Saving database " + SettingsDatabase.databaseFilePath);
            StreamWriter streamWriter = new StreamWriter(SettingsDatabase.databaseFilePath);

            streamWriter.WriteLine(string.Format("version: {0}", this.version));
            streamWriter.WriteLine(string.Format("importPivots: {0}", (!this.importPivots) ? 0 : 1));
            streamWriter.WriteLine("tpsheetFileNames:");
            SettingsDatabase.writeStringList(streamWriter, this.tpsheetFileNames);
            streamWriter.WriteLine("textureFileNames:");
            SettingsDatabase.writeStringList(streamWriter, this.textureFileNames);
            streamWriter.WriteLine("normalmapFileNames:");
            SettingsDatabase.writeStringList(streamWriter, this.normalmapFileNames);
            streamWriter.Close();
        }
示例#9
0
 private static void NewMenuOption()
 {
     Selection.activeObject = SettingsDatabase.getInstance();
 }
示例#10
0
 public void unloadSheetData(string dataFile)
 {
     this.spriteSheetData.Remove(dataFile);
     SettingsDatabase.getInstance().removeSheet(dataFile, true);
 }
示例#11
0
        public bool loadSheetData(string dataFile)
        {
            if (this.spriteSheetData.ContainsKey(dataFile))
            {
                this.unloadSheetData(dataFile);
            }
            string[]  array     = File.ReadAllLines(dataFile);
            int       num       = 30302;
            string    text      = null;
            string    text2     = null;
            SheetInfo sheetInfo = new SheetInfo();

            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string text3 = array2[i];
                if (text3.StartsWith(":format="))
                {
                    num = int.Parse(text3.Remove(0, 8));
                }
                if (text3.StartsWith(":normalmap="))
                {
                    text2 = text3.Remove(0, 11);
                }
                if (text3.StartsWith(":texture="))
                {
                    text = text3.Remove(0, 9);
                }
                if (text3.StartsWith(":size="))
                {
                    string[] array3 = text3.Remove(0, 6).Split(new char[]
                    {
                        'x'
                    });
                    sheetInfo.width  = int.Parse(array3[0]);
                    sheetInfo.height = int.Parse(array3[1]);
                }
                if (text3.StartsWith("# Sprite sheet: "))
                {
                    text = text3.Remove(0, 16);
                    text = text.Remove(text.LastIndexOf("(") - 1);
                }
            }
            bool flag = array[0].StartsWith("{");

            if (num > 40000 || flag)
            {
                EditorUtility.DisplayDialog("Please update TexturePacker Importer", "Your TexturePacker Importer is too old to import '" + dataFile + "', \nplease load a new version from the asset store!", "Ok");
                return(false);
            }
            text = Path.GetDirectoryName(dataFile) + "/" + text;
            if (text2 != null)
            {
                text2 = Path.GetDirectoryName(dataFile) + "/" + text2;
            }
            SettingsDatabase.getInstance().addSheet(dataFile, text, text2);
            Dictionary <string, SpriteMetaData> dictionary = new Dictionary <string, SpriteMetaData>();

            string[] array4 = array;
            for (int j = 0; j < array4.Length; j++)
            {
                string text4 = array4[j];
                if (!string.IsNullOrEmpty(text4) && !text4.StartsWith("#") && !text4.StartsWith(":"))
                {
                    string[] array5 = text4.Split(new char[]
                    {
                        ';'
                    });
                    int num2 = 0;
                    if (array5.Length < 7)
                    {
                        EditorUtility.DisplayDialog("File format error", "Failed to import '" + dataFile + "'", "Ok");
                        return(false);
                    }
                    SpriteMetaData value = default(SpriteMetaData);
                    value.name = this.unescapeName(array5[num2++]);
                    if (dictionary.ContainsKey(value.name))
                    {
                        string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(dataFile);
                        EditorUtility.DisplayDialog("Sprite sheet import failed", string.Concat(new string[]
                        {
                            "Name conflict: Sprite sheet '",
                            fileNameWithoutExtension,
                            "' contains multiple sprites with name '",
                            value.name,
                            "'"
                        }), "Abort");
                        return(false);
                    }
                    float x    = float.Parse(array5[num2++], CultureInfo.InvariantCulture);
                    float y    = float.Parse(array5[num2++], CultureInfo.InvariantCulture);
                    float num3 = float.Parse(array5[num2++], CultureInfo.InvariantCulture);
                    float num4 = float.Parse(array5[num2++], CultureInfo.InvariantCulture);
                    float num5 = float.Parse(array5[num2++], CultureInfo.InvariantCulture);
                    float num6 = float.Parse(array5[num2++], CultureInfo.InvariantCulture);
                    value.rect  = new Rect(x, y, num3, num4);
                    value.pivot = new Vector2(num5, num6);
                    if (num5 == 0f && num6 == 0f)
                    {
                        value.alignment = 6;
                    }
                    else if ((double)num5 == 0.5 && num6 == 0f)
                    {
                        value.alignment = 7;
                    }
                    else if (num5 == 1f && num6 == 0f)
                    {
                        value.alignment = 8;
                    }
                    else if (num5 == 0f && (double)num6 == 0.5)
                    {
                        value.alignment = 4;
                    }
                    else if ((double)num5 == 0.5 && (double)num6 == 0.5)
                    {
                        value.alignment = 0;
                    }
                    else if (num5 == 1f && (double)num6 == 0.5)
                    {
                        value.alignment = 5;
                    }
                    else if (num5 == 0f && num6 == 1f)
                    {
                        value.alignment = 1;
                    }
                    else if ((double)num5 == 0.5 && num6 == 1f)
                    {
                        value.alignment = 2;
                    }
                    else if (num5 == 1f && num6 == 1f)
                    {
                        value.alignment = 3;
                    }
                    else
                    {
                        value.alignment = 9;
                    }
                    dictionary.Add(value.name, value);
                    if (Application.unityVersion[0] == '4')
                    {
                        if (num2 < array5.Length)
                        {
                            EditorUtility.DisplayDialog("Sprite sheet import failed.", "Import of polygon sprites requires Unity 5!", "Abort");
                            return(false);
                        }
                    }
                    else
                    {
                        SpriteGeometry spriteGeometry = new SpriteGeometry();
                        if (num2 < array5.Length)
                        {
                            num2 = spriteGeometry.parse(array5, num2);
                            if (num2 < 0)
                            {
                                Debug.LogError("format error in file " + dataFile);
                                return(false);
                            }
                        }
                        else
                        {
                            spriteGeometry.setQuad((int)num3, (int)num4);
                        }
                        this.spriteGeometries.addGeometry(text, value.name, spriteGeometry);
                    }
                }
            }
            sheetInfo.metadata = new SpriteMetaData[dictionary.Count];
            dictionary.Values.CopyTo(sheetInfo.metadata, 0);
            this.spriteSheetData[dataFile] = sheetInfo;
            return(true);
        }