Esempio n. 1
0
        public GAFTexturesResource getResource(float _Scale, float _CSF)
        {
            GAFTexturesResource resource = null;

            var key = new KeyValuePair <float, float>(_Scale, _CSF);

            if (m_LoadedResources.ContainsKey(key) &&
                m_LoadedResources[key] != null)
            {
                resource = m_LoadedResources[key];
            }
            else
            {
                string resourcePath = "Cache/" + getResourceName(_Scale, _CSF);
                resource = Resources.Load <GAFTexturesResource>(resourcePath);
                if (resource != null)
                {
                    m_LoadedResources[key] = resource;
                }
            }

            return(resource);
        }
        private void relocateResourceData(GAFTexturesResource _Resource, string _NewPath)
        {
            foreach (var data in _Resource.data)
            {
                var texturePath		= AssetDatabase.GetAssetPath(data.sharedTexture);
                var materialPath	= AssetDatabase.GetAssetPath(data.sharedMaterial);

                var newTexturePath	= _NewPath + Path.GetFileName(texturePath);
                var newMaterialPath = _NewPath + Path.GetFileName(materialPath);

                AssetDatabase.MoveAsset(texturePath, newTexturePath);
                AssetDatabase.MoveAsset(materialPath, newMaterialPath);
            }

            _Resource.currentDataPath = _NewPath;

            EditorUtility.SetDirty(_Resource);
        }
        private static void changeTextureImportSettings(TextureImporter _Importer, GAFTexturesResource _Resource)
        {
            if (!m_ImportList.Contains(_Importer.assetPath))
            {
                _Importer.textureType			= TextureImporterType.Advanced;
                _Importer.npotScale				= TextureImporterNPOTScale.None;
                _Importer.maxTextureSize		= 4096;
                _Importer.alphaIsTransparency	= true;
                _Importer.mipmapEnabled			= false;

                TextureImporterSettings st = new TextureImporterSettings();
                _Importer.ReadTextureSettings(st);
                st.wrapMode = TextureWrapMode.Clamp;
                _Importer.SetTextureSettings(st);

                m_ImportList.Add(_Importer.assetPath);
            }
        }
 private static bool hasCorrectImportSettings(TextureImporter _Importer, GAFTexturesResource _Resource)
 {
     return  _Importer.textureType			== TextureImporterType.Advanced &&
             _Importer.npotScale				== TextureImporterNPOTScale.None &&
             _Importer.maxTextureSize		== 4096 &&
             _Importer.alphaIsTransparency	== true &&
             _Importer.mipmapEnabled			== false;
 }
 public static void findResourceTextures(GAFTexturesResource _Resource, bool _Reimport)
 {
     var resourcePath = AssetDatabase.GetAssetPath(_Resource);
     if (!string.IsNullOrEmpty(resourcePath))
     {
         var textures = GAFAssetUtils.findAssetsAtPath<Texture2D>(_Resource.currentDataPath, "*.png");
         foreach (var texture in textures)
         {
             var data = _Resource.missingData.Find(_data => _data.name == texture.name);
             if (data != null)
             {
                 if (_Reimport)
                 {
                     var texturePath = AssetDatabase.GetAssetPath(texture);
                     var textureImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter;
                     if (hasCorrectImportSettings(textureImporter, _Resource))
                     {
                         data.set(texture, getSharedMaterial(texture));
                         m_ImportList.Remove(texturePath);
                         EditorUtility.SetDirty(_Resource);
                     }
                     else
                     {
                         changeTextureImportSettings(textureImporter, _Resource);
                         AssetDatabase.ImportAsset(textureImporter.assetPath, ImportAssetOptions.ForceUpdate);
                     }
                 }
                 else
                 {
                     data.set(texture, getSharedMaterial(texture));
                     EditorUtility.SetDirty(_Resource);
                 }
             }
         }
     }
 }