Beispiel #1
0
    private void processTextures()
    {
        if (isAvailable)
        {
            string dirName  = Path.GetDirectoryName(assetPath);
            var    textures = GAFAssetUtils.findAssetsAtPath <Texture2D>(dirName, "*.png");
            foreach (var texture in textures)
            {
                if (!string.IsNullOrEmpty(m_TexturesNames.Find(name => name == texture.name)))
                {
                    string          texturePath     = AssetDatabase.GetAssetPath(texture);
                    TextureImporter textureImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter;
                    if (hasCorrectImportSettings(textureImporter))
                    {
                        addTexture(texture);
                    }
                    else if (!GAFPostprocessorHelper.instance.busyTextures.Contains(textureImporter.assetPath))
                    {
                        reimportTexture(textureImporter);
                    }
                }
            }

            if (missingTextures.Count == 0)
            {
                createSharedData();
            }

            AssetDatabase.SaveAssets();
        }
    }
Beispiel #2
0
    public Material getMaterial(GAFAnimationAsset _Asset, uint _ObjectID, string _TextureName)
    {
        if (!System.Object.Equals(_Asset, null))
        {
            if (_Asset.maskedObjects.Contains((int)_ObjectID))
            {
                Material material = new Material(Shader.Find(m_sMaskedObjectShaderPath));
                material.color       = new Color(1f, 1f, 1f, 1f);
                material.mainTexture = getTexture(_TextureName);
                return(material);
            }
            else if (_Asset.coloredObjects.Contains((int)_ObjectID))
            {
                Material material = new Material(Shader.Find(m_sColorizedObjectShaderPath));
                material.color       = new Color(1f, 1f, 1f, 1f);
                material.mainTexture = getTexture(_TextureName);
                return(material);
            }
            else if (_Asset.batchableObjects.Contains((int)_ObjectID))
            {
#if UNITY_EDITOR
                if (!GAFAssetUtils.checkAssets(ref m_SharedMaterials) ||
                    m_SharedMaterials.Find(material => material.name == _TextureName) == null)
                {
                    createSharedData();
                    AssetDatabase.SaveAssets();
                }
#endif // UNITY_EDITOR

                return(m_SharedMaterials.Find(material => material.name == _TextureName));
            }
        }

        return(null);
    }
Beispiel #3
0
    public static void OnPostprocessAllAssets(
        string[] importedAssets
        , string[] deletedAssets
        , string[] movedAssets
        , string[] movedFromAssetPaths)
    {
        foreach (string assetName in importedAssets)
        {
            if (assetName.EndsWith(".gaf"))
            {
                byte [] fileBytes = null;
                using (BinaryReader freader = new BinaryReader(File.OpenRead(assetName)))
                {
                    fileBytes = freader.ReadBytes((int)freader.BaseStream.Length);
                }

                if (fileBytes.Length > sizeof(int))
                {
                    int header = System.BitConverter.ToInt32(fileBytes.Take(4).ToArray(), 0);
                    if (GAFHeader.isCorrectHeader((GAFHeader.CompressionType)header))
                    {
                        GAFAnimationAsset animationAsset = ScriptableObject.CreateInstance <GAFAnimationAsset>();
                        animationAsset = GAFAssetUtils.saveAsset(animationAsset, Path.GetDirectoryName(assetName) + "/" + Path.GetFileNameWithoutExtension(assetName) + ".asset");
                        animationAsset.init(fileBytes);

                        GAFTracking.sendAssetCreatedRequest(assetName);
                    }
                }
            }
        }
    }
Beispiel #4
0
        public static void createResources(GAFAnimationAsset _Asset)
        {
            var assetPath = AssetDatabase.GetAssetPath(_Asset);

            if (!string.IsNullOrEmpty(assetPath))
            {
                GAFSystemEditor.getCachePath();

                var assetGUID             = AssetDatabase.AssetPathToGUID(assetPath);
                var resourceTexturesNames = new Dictionary <KeyValuePair <float, float>, List <string> >();

                _Asset.resetGUID(assetGUID);

                foreach (var timeline in _Asset.getTimelines())
                {
                    foreach (var atlas in timeline.atlases)
                    {
                        foreach (var data in atlas.texturesData.Values)
                        {
                            foreach (var textureInfo in data.files)
                            {
                                string textureName = Path.GetFileNameWithoutExtension(textureInfo.Value);
                                var    key         = new KeyValuePair <float, float>(atlas.scale, textureInfo.Key);

                                if (!resourceTexturesNames.ContainsKey(key))
                                {
                                    resourceTexturesNames[key] = new List <string>();
                                }

                                resourceTexturesNames[key].Add(textureName);
                            }
                        }
                    }
                }

                m_Resources.RemoveAll(resource => resource == null || !resource.isValid);

                foreach (var pair in resourceTexturesNames)
                {
                    var name          = _Asset.getResourceName(pair.Key.Key, pair.Key.Value) + ".asset";
                    var path          = GAFSystemEditor.getCachePath() + name;
                    var initialResDir = Path.GetDirectoryName(assetPath).Replace('\\', '/') + "/";

                    var resource = ScriptableObject.CreateInstance <GAFTexturesResource>();
                    resource = GAFAssetUtils.saveAsset(resource, path);
                    resource.initialize(_Asset, pair.Value.Distinct().ToList(), pair.Key.Key, pair.Key.Value, initialResDir);
                    EditorUtility.SetDirty(resource);

                    findResourceTextures(resource, true);

                    if (!resource.isReady)
                    {
                        m_Resources.Add(resource);
                    }
                }

                EditorUtility.SetDirty(_Asset);
            }
        }
Beispiel #5
0
    public Texture2D getTexture(string _Name)
    {
#if UNITY_EDITOR
        GAFAssetUtils.checkAssets(ref m_Textures);
#endif // UNITY_EDITOR

        return(m_Textures.Find(texture => texture.name == _Name));
    }
Beispiel #6
0
    private void initResources()
    {
        Dictionary <KeyValuePair <float, float>, List <string> > resourceTexturesNames = new Dictionary <KeyValuePair <float, float>, List <string> >();

        m_ResourcePaths.Clear();

        GAFSystem.getCachePath();

        foreach (var timeline in m_SharedData.timelines.Values)
        {
            foreach (var atlas in timeline.atlases)
            {
                foreach (var data in atlas.texturesData.Values)
                {
                    foreach (var textureInfo in data.files)
                    {
                        string textureName = Path.GetFileNameWithoutExtension(textureInfo.Value);
                        var    key         = new KeyValuePair <float, float>(atlas.scale, textureInfo.Key);

                        if (!resourceTexturesNames.ContainsKey(key))
                        {
                            resourceTexturesNames[key] = new List <string>();
                        }

                        resourceTexturesNames[key].Add(textureName);
                    }
                }
            }
        }

        foreach (var pair in resourceTexturesNames)
        {
            string name = m_GUID + "_" + pair.Key.Key.ToString() + "_" + pair.Key.Value.ToString();
            string path = GAFSystem.getCachePath() + name + ".asset";

            var resource = ScriptableObject.CreateInstance <GAFTexturesResource>();
            resource = GAFAssetUtils.saveAsset(resource, path);
            resource.init(this, pair.Value, pair.Key.Key, pair.Key.Value);
            m_ResourcePaths.Add(path);
        }

        EditorUtility.SetDirty(this);
    }
Beispiel #7
0
        public static Material getSharedMaterial(Texture2D _Texture)
        {
            string texturePath = AssetDatabase.GetAssetPath(_Texture);
            string path        = Path.GetDirectoryName(texturePath) + "/" + Path.GetFileNameWithoutExtension(texturePath) + ".mat";

            var material = AssetDatabase.LoadAssetAtPath(path, typeof(Material)) as Material;

            if (material == null)
            {
                material             = new Material(Shader.Find("GAF/GAFObjectsGroup"));
                material.mainTexture = _Texture;
                material             = GAFAssetUtils.saveAsset(material, path);
            }
            else
            {
                material.mainTexture = _Texture;
            }

            return(material);
        }
Beispiel #8
0
        public static void OnPostprocessAllAssets(
            string[] importedAssets
            , string[] deletedAssets
            , string[] movedAssets
            , string[] movedFromAssetPaths)
        {
            foreach (string assetName in importedAssets)
            {
                if (assetName.EndsWith(".gaf"))
                {
                    byte[] fileBytes = null;
                    using (BinaryReader freader = new BinaryReader(File.OpenRead(assetName)))
                    {
                        fileBytes = freader.ReadBytes((int)freader.BaseStream.Length);
                    }

                    if (fileBytes.Length > sizeof(int))
                    {
                        int header = System.BitConverter.ToInt32(fileBytes.Take(4).ToArray(), 0);
                        if (GAFHeader.isCorrectHeader((GAFHeader.CompressionType)header))
                        {
                            var path = Path.GetDirectoryName(assetName) + "/" + Path.GetFileNameWithoutExtension(assetName) + ".asset";

                            var asset = AssetDatabase.LoadAssetAtPath(path, typeof(GAFAnimationAsset)) as GAFAnimationAsset;
                            if (asset == null)
                            {
                                asset = ScriptableObject.CreateInstance <GAFAnimationAsset>();
                                asset = GAFAssetUtils.saveAsset(asset, path);
                            }

                            asset.name = Path.GetFileNameWithoutExtension(assetName);
                            asset.initialize(fileBytes, AssetDatabase.AssetPathToGUID(path));
                            EditorUtility.SetDirty(asset);
                            GAFResourceManager.createResources(asset);

                            GAFTracking.sendAssetCreatedRequest(assetName);
                        }
                    }
                }
            }
        }
Beispiel #9
0
        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);
                        }
                    }
                }
            }
        }
Beispiel #10
0
    private void createSharedData()
    {
        if (isAvailable)
        {
            if (m_Asset.batchableObjects.Count > 0)
            {
                m_SharedMaterials.Clear();

                foreach (var texture in m_Textures)
                {
                    Material material = new Material(Shader.Find(m_sBatchableObjectShaderPath));
                    material.color       = new Color(1f, 1f, 1f, 1f);
                    material.mainTexture = texture;

                    string path = Path.GetDirectoryName(assetPath) + "/" + texture.name + ".mat";
                    material = GAFAssetUtils.saveAsset(material, path);

                    m_SharedMaterials.Add(material);
                }

                EditorUtility.SetDirty(this);
            }
        }
    }
Beispiel #11
0
    private bool containsTexture(Texture2D _Texture)
    {
        GAFAssetUtils.checkAssets(ref m_Textures);

        return(m_Textures.Contains(_Texture) || m_Textures.Find(texture => texture.name == _Texture.name) != null);
    }