示例#1
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);
            }
        }
示例#2
0
        public static void deleteResources(GAFAnimationAsset _Asset)
        {
            var assetPath = AssetDatabase.GetAssetPath(_Asset);

            if (!string.IsNullOrEmpty(assetPath))
            {
                var resourcePaths = _Asset.resourcesPaths;
                foreach (var path in resourcePaths)
                {
                    AssetDatabase.DeleteAsset(path);
                }

                _Asset.resetGUID(AssetDatabase.AssetPathToGUID(assetPath));
                EditorUtility.SetDirty(_Asset);
            }
        }