Exemplo n.º 1
0
        public static string[] GetDependencies(string assetBundleName)
        {
            string[] dependencies;

            if (DependenciesCache.TryGetValue(assetBundleName, out dependencies))
            {
                return(dependencies);
            }

            if (Define.IsAsync)
            {
                dependencies = ResourcesComponent.AssetBundleManifestObject.GetAllDependencies(assetBundleName);
            }
            else
            {
                dependencies = AssetDatabaseHelper.GetAssetBundleDependencies(assetBundleName, true);
            }

            if (dependencies != null)
            {
                DependenciesCache.Add(assetBundleName, dependencies);
            }

            return(dependencies);
        }
 private void LoadTextureRepositories()
 {
     _textureRepositories    = AssetDatabaseHelper.LoadAllAssets <TextureRepository>();
     _textureRepositoryNames = _textureRepositories.Select(x => x.name).ToArray();
     if (_textureRepositories.Count > 0)
     {
         _textureRepository = _textureRepositories[0];
     }
 }
        private void OnEnable()
        {
            _myTarget = (EntityTypeDefinition)target;

            _rootElement = new VisualElement();

            _visualTree = AssetDatabaseHelper.LoadFirstAssetByFilter <VisualTreeAsset>("EntityTypeDefinitionTemplate", null);
            var styleSheet = AssetDatabaseHelper.LoadFirstAssetByFilter <StyleSheet>("EntityTypeDefinitionStyle", null);

            _rootElement.styleSheets.Add(styleSheet);
        }
Exemplo n.º 4
0
        public static void Save(Type infoType, IInfo info)
        {
            InfoAttribute infoAttribute = infoType.GetCustomAttribute <InfoAttribute>();

            if (infoAttribute == null)
            {
                throw new Exception("Info attribute not found");
            }
            if (infoAttribute.Editor)
            {
                string infoLocation          = GetInfoLocation(infoType);
                string resourceDirectoryName = Path.GetDirectoryName(infoLocation);
                AssetDatabaseHelper.CreateFolderRecursive(resourceDirectoryName);
                FortScriptableObject fortScriptableObject =
                    AssetDatabase.LoadAssetAtPath <FortScriptableObject>(infoLocation);
                bool newCreation = false;
                if (fortScriptableObject == null)
                {
                    fortScriptableObject = (FortScriptableObject)ScriptableObject.CreateInstance(infoAttribute.ScriptableType);
                    AssetDatabase.CreateAsset(fortScriptableObject, infoLocation);
                    newCreation = true;
                }
                if (!newCreation)
                {
                    fortScriptableObject.Save(info);
                    EditorUtility.SetDirty(fortScriptableObject);
                }
            }
            else
            {
                FortScriptableObject fortInfoScriptable = Resources.Load <FortScriptableObject>(InfoResolver.GetInfoResourceRelativeLocation(infoType));
                bool newCreation = false;

                if (fortInfoScriptable == null)
                {
                    string infoResourceFullLocation = InfoResolver.GetInfoResourceFullLocation(infoType);
                    string resourceDirectoryName    = Path.GetDirectoryName(infoResourceFullLocation);
                    AssetDatabaseHelper.CreateFolderRecursive(resourceDirectoryName);

                    fortInfoScriptable = (FortScriptableObject)ScriptableObject.CreateInstance(infoAttribute.ScriptableType);
                    AssetDatabase.CreateAsset(fortInfoScriptable, infoResourceFullLocation);
                    newCreation = true;
                }
                if (!newCreation)
                {
                    fortInfoScriptable.Save(info);
                    EditorUtility.SetDirty(fortInfoScriptable);
                }
            }
        }
Exemplo n.º 5
0
        public static OpCodesInfo Load()
        {
            try
            {
                var path = AssetDatabaseHelper.RelativeToScript(nameof(OpCodesInfo), "ilopcodes_v2.json");
                var json = File.ReadAllText(path);
                return(JsonUtility.FromJson <OpCodesInfo>(json));
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }

            return(null);
        }
Exemplo n.º 6
0
        public static void Build()
        {
            LanguageFixPreprocessBuild.FixLanguage();
            string bundleVersion = PlayerSettings.bundleVersion;

            AssetDatabaseHelper.CreateFolderRecursive("/Assets/Fort/Resources");
            string path = Path.Combine(Application.dataPath, "Fort/Resources/Version.txt");

            using (StreamWriter writer = new StreamWriter(path))
            {
                writer.Write(bundleVersion);
            }
            AssetDatabase.Refresh();
            BuildPipeline.BuildPlayer(EditorBuildSettings.scenes.Select(scene => scene.path).ToArray(), EditorUserBuildSettings.GetBuildLocation(EditorUserBuildSettings.activeBuildTarget), EditorUserBuildSettings.activeBuildTarget, BuildOptions.None);
            string buildLocation = EditorUserBuildSettings.GetBuildLocation(EditorUserBuildSettings.activeBuildTarget);
            string argument      = "/select, \"" + buildLocation.Replace("/", "\\") + "\"";

            Process.Start("explorer.exe", argument);
        }
Exemplo n.º 7
0
        private static LocalizationImporter GetImporter(string name, Type type)
        {
            var guids = AssetDatabaseHelper.FindAsset <LocalizationImporter>();

            if (guids.Length == 0)
            {
                var instance = (LocalizationImporter)ScriptableObject.CreateInstance(type);

                var fileName = string.Format("LocalizationPrefs.{0}.asset", name);
                AssetDatabaseHelper.CreateFolder(EditorLocalizationSettings.prefsDefaultPath);
                AssetDatabase.Refresh();
                AssetDatabaseHelper.CreateAsset(instance, fileName, EditorLocalizationSettings.prefsDefaultPath);

                return(instance);
            }
            else
            {
                var path = AssetDatabase.GUIDToAssetPath(guids[0]);
                return(AssetDatabase.LoadAssetAtPath <LocalizationImporter>(path));
            }
        }
Exemplo n.º 8
0
        public async Task LoadOneBundleAsync(string assetBundleName)
        {
            ABInfo abInfo;

            if (bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                return;
            }

            if (Define.IsAsync)
            {
                string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);

                AssetBundle assetBundle = null;

                if (!File.Exists(p))
                {
                    p = Path.Combine(PathHelper.AppResPath, assetBundleName);
                }

                using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = EntityFactory.Create <AssetsBundleLoaderAsync>(Domain))
                {
                    assetBundle = await assetsBundleLoaderAsync.LoadAsync(p);
                }

                if (assetBundle == null)
                {
                    throw new Exception($"assets bundle not found: {assetBundleName}");
                }

                if (!assetBundle.isStreamedSceneAssetBundle)
                {
                    // 异步load资源到内存cache住
                    UnityEngine.Object[] assets;

                    using (AssetsLoaderAsync assetsLoaderAsync = EntityFactory.Create <AssetsLoaderAsync, AssetBundle>(Domain, assetBundle))
                    {
                        assets = await assetsLoaderAsync.LoadAllAssetsAsync();
                    }

                    foreach (UnityEngine.Object asset in assets)
                    {
                        AddResource(assetBundleName, asset.name, asset);
                    }
                }

                abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle);
                bundles[assetBundleName] = abInfo;
            }
            else
            {
                var assetPaths = AssetDatabaseHelper.GetAssetPathsFromAssetBundle(assetBundleName);

                if (assetPaths != null)
                {
                    foreach (string s in assetPaths)
                    {
                        string             assetName = Path.GetFileNameWithoutExtension(s);
                        UnityEngine.Object resource  = AssetDatabaseHelper.LoadAssetAtPath(s);
                        AddResource(assetBundleName, assetName, resource);
                    }
                }

                abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null);
                bundles[assetBundleName] = abInfo;
            }
        }
Exemplo n.º 9
0
        public void LoadOneBundle(string assetBundleName)
        {
            //Log.Debug($"---------------load one bundle {assetBundleName}");
            ABInfo abInfo;

            if (bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                return;
            }

            if (Define.IsAsync)
            {
                string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);

                AssetBundle assetBundle;

                if (File.Exists(p))
                {
                    assetBundle = AssetBundle.LoadFromFile(p);
                }
                else
                {
                    p           = Path.Combine(PathHelper.AppResPath, assetBundleName);
                    assetBundle = AssetBundle.LoadFromFile(p);
                }

                if (assetBundle == null)
                {
                    throw new Exception($"assets bundle not found: {assetBundleName}");
                }

                if (!assetBundle.isStreamedSceneAssetBundle)
                {
                    // 异步load资源到内存cache住
                    UnityEngine.Object[] assets = assetBundle.LoadAllAssets();

                    foreach (UnityEngine.Object asset in assets)
                    {
                        AddResource(assetBundleName, asset.name, asset);
                    }
                }

                abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle);
                bundles[assetBundleName] = abInfo;
            }
            else
            {
                var assetPaths = AssetDatabaseHelper.GetAssetPathsFromAssetBundle(assetBundleName);

                if (assetPaths != null)
                {
                    foreach (string s in assetPaths)
                    {
                        string             assetName = Path.GetFileNameWithoutExtension(s);
                        UnityEngine.Object resource  = AssetDatabaseHelper.LoadAssetAtPath(s);
                        AddResource(assetBundleName, assetName, resource);
                    }
                }

                abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null);
                bundles[assetBundleName] = abInfo;
            }
        }
Exemplo n.º 10
0
 private string GetPersistentFilePath(string fileName) => AssetDatabaseHelper.RelativeToScript(nameof(ILNavigator), SaveFolderName, fileName);
Exemplo n.º 11
0
        public static string TryFindPathToType(string typeName)
        {
            var scriptPath = AssetDatabaseHelper.FindScriptPath(typeName);

            return(scriptPath);
        }
 private void InitPublishDescriptions()
 {
     _publishDescriptions = AssetDatabaseHelper.LoadAllAssets <PublishDescription>();
 }
 private void InitTextureDescriptions()
 {
     _textureDescriptions = AssetDatabaseHelper.LoadAllAssets <TextureDescription>();
 }
Exemplo n.º 14
0
        public static Promise SyncAssetBundles()
        {
            //BacktoryCloudUrl.Url = "http://localhost:8086";
            Deferred            deferred            = new Deferred();
            string              outputPath          = Path.Combine(EditorAssetBundleUtility.AssetBundlesOutputPath, EditorAssetBundleUtility.GetPlatformName());
            AssetBundleManifest assetBundleManifest = Build();

            EditorUtility.DisplayProgressBar("Get server asset bundles", "Get server asset bundles", 0);
            InfoResolver.Resolve <FortInfo>()
            .ServerConnectionProvider.EditorConnection.Call <ServerAssetBundle[]>("GetAssetBundles", new { Platform = EditorAssetBundleUtility.GetPlatformName() }).Then(
                serverBundles =>
            {
                List <AssetNameVersion> addedAssets                    = new List <AssetNameVersion>();
                List <ServerAssetBundle> finalAssetBundles             = new List <ServerAssetBundle>(serverBundles);
                Dictionary <string, ServerAssetBundleVersion> finalMap = new Dictionary <string, ServerAssetBundleVersion>();
                EditorUtility.ClearProgressBar();
                foreach (
                    var source in
                    assetBundleManifest.GetAllAssetBundles()
                    .Select(s => new { Name = s, Hash = assetBundleManifest.GetAssetBundleHash(s) })
                    .Where(
                        arg1 =>
                        !serverBundles.Any(
                            bundle =>
                            bundle.Name == arg1.Name &&
                            bundle.Versions.Any(version => version.Hash == arg1.Hash.ToString())))
                    )
                {
                    AssetNameVersion assetNameVersion = new AssetNameVersion
                    {
                        Name    = source.Name,
                        Version = new ServerAssetBundleVersion
                        {
                            Hash = source.Hash.ToString(),
                            Path = ResolveAssetBundlePath(source.Name, source.Hash.ToString()),
                            Size = GetBundleFileSize(source.Name)
                        }
                    };
                    ServerAssetBundle serverAssetBundle = finalAssetBundles.FirstOrDefault(bundle => bundle.Name == source.Name);
                    if (serverAssetBundle == null)
                    {
                        serverAssetBundle = new ServerAssetBundle
                        {
                            Name     = source.Name,
                            Versions = new[]
                            {
                                assetNameVersion.Version
                            }
                        };
                        finalAssetBundles.Add(serverAssetBundle);
                    }
                    else
                    {
                        serverAssetBundle.Versions =
                            serverAssetBundle.Versions.Concat(new[]
                        {
                            assetNameVersion.Version
                        }).ToArray();
                    }
                    addedAssets.Add(assetNameVersion);
                }
                foreach (string bundleName in assetBundleManifest.GetAllAssetBundles())
                {
                    string hash = assetBundleManifest.GetAssetBundleHash(bundleName).ToString();
                    ServerAssetBundleVersion serverAssetBundleVersion = finalAssetBundles.Where(bundle => bundle.Name == bundleName).SelectMany(bundle => bundle.Versions).First(version => version.Hash == hash);
                    finalMap.Add(bundleName, serverAssetBundleVersion);
                }
                EditorUtility.DisplayProgressBar("Uploading Asset Bundles", "Uploading Asset Bundles", 0);
                InfoResolver.Resolve <FortInfo>()
                .ServerConnectionProvider.EditorConnection.SendFilesToStorage(
                    addedAssets.Select(version => new StorageFile
                {
                    FileName = Path.GetFileName(version.Version.Path),
                    Path     = Path.GetDirectoryName(version.Version.Path) + "/",
                    Stream   = File.OpenRead(Path.Combine(outputPath, version.Name))
                }).ToArray(), f =>
                {
                    EditorUtility.DisplayProgressBar("Uploading Asset Bundles", "Uploading Asset Bundles", f);
                }).Then(files =>
                {
                    for (int i = 0; i < addedAssets.Count; i++)
                    {
                        addedAssets[i].Version.Path = files[i];
                    }
                    EditorUtility.DisplayProgressBar("Updating server Asset bundle list", "Updating server Asset bundle list", 0);
                    InfoResolver.Resolve <FortInfo>()
                    .ServerConnectionProvider.EditorConnection
                    .Call <UpdateServerAchievementResoponse>("UpdateAssetBundles",
                                                             new
                    {
                        AssetBundles = finalAssetBundles.ToArray(),
                        Platform     = EditorAssetBundleUtility.GetPlatformName()
                    })
                    .Then(resoponse =>
                    {
                        EditorUtility.ClearProgressBar();
                        string fullDirectory = string.Format("/Assets/Fort/Resources/BundleConfig/{0}",
                                                             EditorAssetBundleUtility.GetPlatformName());
                        string inAssetPath = string.Format("/Fort/Resources/BundleConfig/{0}",
                                                           EditorAssetBundleUtility.GetPlatformName());
                        if (!Directory.Exists(fullDirectory))
                        {
                            AssetDatabaseHelper.CreateFolderRecursive(fullDirectory);
                        }
                        string jsonFile = Application.dataPath + inAssetPath + "/AssetBundleBundleInfo.json";
                        using (StreamWriter writer = new StreamWriter(jsonFile))
                        {
                            writer.Write(JsonConvert.SerializeObject(finalMap));
                        }
                        //AssetDatabase.ImportAsset(fullDirectory+"/AssetBundleBundleInfo.json");
                        AssetDatabase.Refresh();
                        deferred.Resolve();
                    }, error =>
                    {
                        EditorUtility.ClearProgressBar();
                        deferred.Reject();
                        throw new Exception("Cannot update server asset bundle list");
                    });
                }, () =>
                {
                    EditorUtility.ClearProgressBar();
                    deferred.Reject();
                    throw new Exception("Cannot Upload asset bundles to storage");
                });
            }, error =>
            {
                EditorUtility.ClearProgressBar();
                deferred.Reject();
                throw new Exception("Cannot resolve asset bundles from server");
            });
            return(deferred.Promise());
        }
        public Sprite Create(SpriteAssetFactoryInputData data)
        {
            if (!string.IsNullOrEmpty(data.Name) && !string.IsNullOrEmpty(data.Path) && data.Reference != null)
            {
                EditorFileUtils.CreateDirectories(data.Path);

                var directoryInfo = new DirectoryInfo(data.Path);
                var fullPath      = Path.Combine(directoryInfo.FullName, $"{data.Name}.png");
                var relativePath  = Path.Combine(data.Path, $"{data.Name}.png");

                var bytes = data.Reference.EncodeToPNG();
                File.WriteAllBytes(fullPath, bytes);

                AssetDatabase.Refresh();

                _importerSettings         = data.ImporterSettings;
                _importerPlatformSettings = data.ImporterPlatformSettings;

                var importer = AssetImporter.GetAtPath(relativePath);
                if (importer != null && importer is TextureImporter textureImporter)
                {
                    if (_importerSettings != null)
                    {
                        textureImporter.textureType         = _importerSettings.textureType;
                        textureImporter.spritePixelsPerUnit = _importerSettings.spritePixelsPerUnit;
                        textureImporter.spritePivot         = _importerSettings.spritePivot;
                        textureImporter.sRGBTexture         = _importerSettings.sRGBTexture;
                        textureImporter.alphaSource         = _importerSettings.alphaSource;
                        textureImporter.alphaIsTransparency = _importerSettings.alphaIsTransparency;
                        textureImporter.isReadable          = _importerSettings.readable;
                        textureImporter.mipmapEnabled       = _importerSettings.mipmapEnabled;
                        textureImporter.wrapMode            = _importerSettings.wrapMode;
                        textureImporter.filterMode          = _importerSettings.filterMode;
                        textureImporter.anisoLevel          = _importerSettings.aniso;

                        var importerSettings = new TextureImporterSettings();
                        textureImporter.ReadTextureSettings(importerSettings);

                        importerSettings.spriteMode      = _importerSettings.spriteMode;
                        importerSettings.spriteMeshType  = _importerSettings.spriteMeshType;
                        importerSettings.spriteExtrude   = _importerSettings.spriteExtrude;
                        importerSettings.spriteAlignment = _importerSettings.spriteAlignment;
                        importerSettings.spriteGenerateFallbackPhysicsShape = _importerSettings.spriteGenerateFallbackPhysicsShape;

                        textureImporter.SetTextureSettings(importerSettings);

                        foreach (var platformSettings in _importerPlatformSettings)
                        {
                            var existingSettings = textureImporter.GetPlatformTextureSettings(platformSettings.name);

                            existingSettings.overridden                  = platformSettings.overridden;
                            existingSettings.maxTextureSize              = platformSettings.maxTextureSize;
                            existingSettings.resizeAlgorithm             = platformSettings.resizeAlgorithm;
                            existingSettings.format                      = platformSettings.format;
                            existingSettings.textureCompression          = platformSettings.textureCompression;
                            existingSettings.crunchedCompression         = platformSettings.crunchedCompression;
                            existingSettings.compressionQuality          = platformSettings.compressionQuality;
                            existingSettings.allowsAlphaSplitting        = platformSettings.allowsAlphaSplitting;
                            existingSettings.androidETC2FallbackOverride = platformSettings.androidETC2FallbackOverride;

                            textureImporter.SetPlatformTextureSettings(existingSettings);
                        }
                    }
                    else
                    {
                        textureImporter.mipmapEnabled = false;

                        textureImporter.isReadable  = true;
                        textureImporter.textureType = TextureImporterType.Sprite;
                        textureImporter.spritePivot = new Vector2(0.5f, 0.5f);

                        textureImporter.filterMode          = _settings.FilterMode;
                        textureImporter.mipmapEnabled       = _settings.GenerateMipMaps;
                        textureImporter.crunchedCompression = _settings.UseCrunchCompression;
                        textureImporter.compressionQuality  = _settings.CompressionQuality;
                        textureImporter.textureCompression  = _settings.Compression;
                    }

                    textureImporter.SaveAndReimport();
                }

                AssetDatabase.Refresh();
                AssetDatabaseHelper.TryGetAsset <Sprite>(relativePath, out var sprite);

                return(sprite);
            }

            return(null);
        }