Ejemplo n.º 1
0
        public static bool InitiateAutoPacking()
        {
            bool HasPacked = false;

            if (Running)
            {
                return(true);
            }
            Running = true;
            TextureAutoPackerData data = TextureAutoPackerData.GetInstance();

            if (!data.active)
            {
                return(false);
            }
            data.activeModules.ForEach(m =>
            {
                if (!m)
                {
                    goto Skip;
                }

                SerializedObject module = new SerializedObject(m);
                module.Update();
                for (int i = 0; i < m.packedTextures.Count; i++)
                {
                    if (m.packedTextures[i].WasModified())
                    {
                        HasPacked             = true;
                        string newTexturePath = m.packedTextures[i].Pack();

                        if (string.IsNullOrEmpty(newTexturePath))
                        {
                            goto Skip;
                        }

                        SerializedProperty packedTexture = module.FindProperty("packedTextures").GetArrayElementAtIndex(i);
                        SerializedProperty hashes        = packedTexture.FindPropertyRelative("channelsHashes");
                        for (int j = 0; j < 4; j++)
                        {
                            hashes.GetArrayElementAtIndex(j).stringValue = string.Empty;
                            if (m.packedTextures[i].channels[j].texture)
                            {
                                hashes.GetArrayElementAtIndex(j).stringValue = m.packedTextures[i].channels[j].texture.imageContentsHash.ToString();
                            }
                        }
                        packedTexture.FindPropertyRelative("forceModified").boolValue = false;
                        AssetDatabase.ImportAsset(newTexturePath, ImportAssetOptions.ForceUpdate);
                        TextureAutoPackerProcessor.PathToProperty.Add(new System.Tuple <string, SerializedProperty>(newTexturePath, packedTexture.FindPropertyRelative("packed")));
                    }
                }
                module.ApplyModifiedPropertiesWithoutUndo();

                Skip:;
            });
            Running = false;

            return(HasPacked);
        }
Ejemplo n.º 2
0
 private void OnEnable()
 {
     data             = TextureAutoPackerData.GetInstance();
     serializedObject = new SerializedObject(data);
     _active          = serializedObject.FindProperty("active");
     _activeModules   = serializedObject.FindProperty("activeModules");
     modulesList      = new UnityEditorInternal.ReorderableList(serializedObject, _activeModules, true, true, true, false)
     {
         drawElementCallback = DrawElement,
         drawHeaderCallback  = DrawHeader
     };
 }