Пример #1
0
    public static void CreateVersion()
    {
        string fileName = "version";

        string playerVersion = AddressableAssetSettingsDefaultObject.Settings.PlayerBuildVersion;

        string profileId = AddressableAssetSettingsDefaultObject.Settings.activeProfileId;

        AddressableAssetProfileSettings profileSettings = AddressableAssetSettingsDefaultObject.Settings.profileSettings;

        string updateTimes = AddressableConfig.UpdateTimes.ToString();

        string remoteBuildPath = profileSettings.EvaluateString(profileId, profileSettings.GetValueByName(profileId, "RemoteBuildPath"));

        string filePath = remoteBuildPath + "/" + fileName;

        if (!Directory.Exists(remoteBuildPath))
        {
            Directory.CreateDirectory(remoteBuildPath);
        }

        using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
        {
        }

        using (StreamWriter writer = new StreamWriter(filePath, false))
        {
            writer.WriteLine(playerVersion + "." + updateTimes);
        }
    }
Пример #2
0
        public void GenerateUniqueName_AlwaysReturnUniqueNames()
        {
            int count = 5;
            var list  = new List <string>(count);

            for (int i = 0; i < count; i++)
            {
                list.Add(AddressableAssetProfileSettings.GenerateUniqueName("base", list));
            }

            Assert.AreEqual(count, list.Distinct().Count());
        }
Пример #3
0
        private static void CreateAddressableSettings(bool localMode, int releaseChannel)
        {
            AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.GetSettings(true);

            settings.ActivePlayModeDataBuilderIndex = localMode ? 0 : 2;
            settings.BuildRemoteCatalog             = true;
            settings.DisableCatalogUpdateOnStartup  = true;
            settings.ContiguousBundles             = true;
            settings.IgnoreUnsupportedFilesInBuild = true;
            settings.ShaderBundleNaming            = ShaderBundleNaming.Custom;

            // don't include built-in data, causes shader issues
            settings.groups.ForEach(g =>
            {
                PlayerDataGroupSchema schema = g.GetSchema <PlayerDataGroupSchema>();
                if (schema != null)
                {
                    schema.IncludeBuildSettingsScenes = false;
                    schema.IncludeResourcesFolders    = false;
                }
            });

            // setup profiles
            AddressableAssetProfileSettings profile = settings.profileSettings;

            // activate and (re)group assets
            foreach (string dir in GetWorldPaths())
            {
                string worldName = Path.GetFileName(dir);
                bool   isBase    = worldName == "Base";

                // create one profile per world
                string profileId = profile.GetProfileId(worldName);
                if (string.IsNullOrEmpty(profileId))
                {
                    profileId = profile.AddProfile(worldName, settings.activeProfileId);
                }

                string guid = AssetDatabase.AssetPathToGUID($"Assets/Worlds/{worldName}");

                // create group if non-existent
                AddressableAssetGroup group = settings.groups.FirstOrDefault(g => g.name == worldName);
                if (group == null)
                {
                    group = CreateAssetGroup <BundledAssetGroupSchema>(settings, worldName);
                }
                if (group.CanBeSetAsDefault())
                {
                    settings.DefaultGroup = group;                            // default group ensures there is no accidental local default group resulting in local paths being baked into addressable for shaders
                }
                // set correct path
                AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, group);
                entry.SetAddress($"Worlds/{worldName}");

                // set variables
                string localRoot    = Application.dataPath + $"/../traVRsal/{worldName}/[BuildTarget]";
                string remoteTarget = null;
                switch (releaseChannel)
                {
                case 0:
                    remoteTarget = AWSUtil.S3CDNRoot_Live;
                    break;

                case 1:
                    remoteTarget = AWSUtil.S3CDNRoot_Beta;
                    break;

                case 2:
                    remoteTarget = AWSUtil.S3CDNRoot_Alpha;
                    break;
                }
                profile.SetValue(profileId, AddressableAssetSettings.kLocalBuildPath, localRoot);
                profile.SetValue(profileId, AddressableAssetSettings.kLocalLoadPath, localRoot);
                profile.SetValue(profileId, AddressableAssetSettings.kRemoteBuildPath, $"ServerData/Worlds/{worldName}/[BuildTarget]");
                profile.SetValue(profileId, AddressableAssetSettings.kRemoteLoadPath, $"{remoteTarget}Worlds/{worldName}/[BuildTarget]");

                // ensure correct group settings
                BundledAssetGroupSchema groupSchema = group.GetSchema <BundledAssetGroupSchema>();
                groupSchema.UseAssetBundleCache = true;
                groupSchema.UseAssetBundleCrc   = false;
                groupSchema.IncludeInBuild      = isBase;
                groupSchema.RetryCount          = 3;
                groupSchema.BundleNaming        = BundledAssetGroupSchema.BundleNamingStyle.NoHash; // hash to disambiguate identically named files yields same error messages, e.g. standard shaders
                groupSchema.BundleMode          = BundledAssetGroupSchema.BundlePackingMode.PackTogether;
                groupSchema.Compression         = BundledAssetGroupSchema.BundleCompressionMode.LZ4;
                groupSchema.BuildPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalBuildPath : AddressableAssetSettings.kRemoteBuildPath);
                groupSchema.LoadPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalLoadPath : AddressableAssetSettings.kRemoteLoadPath);
            }
        }
Пример #4
0
        public static string GetReflectionProfilePath(AddressableAssetProfileSettings pSettings, string profileID, string varName)
        {
            string path = pSettings.GetValueByName(profileID, varName);

            var asms = AppDomain.CurrentDomain.GetAssemblies();

            int pFrom = 0;
            int pTo   = 0;

            int lastDotIdx = 0;

            string assemblyQualifiedName = null;
            string propertyName          = null;

            while (IsContainsBracket(path))
            {
                pFrom = path.IndexOf("[") + "[".Length;
                pTo   = path.IndexOf("]");
                if (pFrom >= pTo)
                {
                    continue;
                }

                String extractStr = path.Substring(pFrom, pTo - pFrom);
                if (pSettings.GetVariableNames().Contains(extractStr))
                {
                    string _pValue = pSettings.GetValueByName(profileID, extractStr);
                    path = path.Replace($"[{extractStr}]", _pValue);
                    continue;
                }

                lastDotIdx = extractStr.LastIndexOf('.');

                assemblyQualifiedName = extractStr.Substring(0, lastDotIdx);
                propertyName          = extractStr.Substring(lastDotIdx + 1);

                Debug.Log($"assemblyQualifiedName : {assemblyQualifiedName}, propertyName : {propertyName}");

                object findObject = null;
                string fullName   = null;


                foreach (var asm in asms)
                {
                    fullName = asm.FullName;
                    //Debug.Log($"FullName : {fullName}");
                    Type _checkT = Type.GetType($"{assemblyQualifiedName}, {fullName}");
                    if (_checkT != null)
                    {
                        PropertyInfo _pI = _checkT.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Static);
                        findObject = _pI.GetValue(null, null);
                        break;
                    }
                }

                if (findObject != null)
                {
                    path = path.Replace($"[{extractStr}]", findObject.ToString());
                }
                else
                {
                    path = path.Replace($"[{extractStr}]", extractStr);
                }
            }

            return(path);
        }
Пример #5
0
        private void CreateAddressableSettings(bool localMode)
        {
            AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.GetSettings(true);

            settings.ActivePlayModeDataBuilderIndex = localMode ? 0 : 2;
            settings.BuildRemoteCatalog             = true;
            settings.DisableCatalogUpdateOnStartup  = true;

            // don't include built-in data, causes shader issues
            settings.groups.ForEach(g =>
            {
                PlayerDataGroupSchema schema = g.GetSchema <PlayerDataGroupSchema>();
                if (schema != null)
                {
                    schema.IncludeBuildSettingsScenes = false;
                    schema.IncludeResourcesFolders    = false;
                }
            });

            // setup profiles
            AddressableAssetProfileSettings profile = settings.profileSettings;

            // activate and (re)group assets
            foreach (string dir in GetLevelPaths())
            {
                string levelName = Path.GetFileName(dir);
                bool   isBase    = levelName == "Base";

                // create one profile per level
                string profileId = profile.GetProfileId(levelName);
                if (string.IsNullOrEmpty(profileId))
                {
                    profileId = profile.AddProfile(levelName, settings.activeProfileId);
                }

                string guid = AssetDatabase.AssetPathToGUID($"Assets/Levels/{levelName}");

                // create group if non-existent
                AddressableAssetGroup group = settings.groups.Where(g => g.name == levelName).FirstOrDefault();
                if (group == null)
                {
                    group = CreateAssetGroup <BundledAssetGroupSchema>(settings, levelName);
                }

                // set correct path
                AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, group);
                entry.SetAddress($"Levels/{levelName}");

                // set variables
                string localRoot = Application.dataPath + $"/../Library/com.unity.addressables/aa/Windows/Levels/{levelName}/[BuildTarget]";
                profile.SetValue(profileId, AddressableAssetSettings.kLocalBuildPath, localRoot);
                profile.SetValue(profileId, AddressableAssetSettings.kLocalLoadPath, localRoot);
                profile.SetValue(profileId, AddressableAssetSettings.kRemoteBuildPath, $"ServerData/Levels/{levelName}/[BuildTarget]");
                profile.SetValue(profileId, AddressableAssetSettings.kRemoteLoadPath, $"{AWSUtil.S3Root}Levels/{levelName}/[BuildTarget]");

                // ensure correct group settings
                BundledAssetGroupSchema groupSchema = group.GetSchema <BundledAssetGroupSchema>();
                groupSchema.UseAssetBundleCache = true;
                groupSchema.UseAssetBundleCrc   = false;
                groupSchema.IncludeInBuild      = isBase ? true : false;
                groupSchema.BundleNaming        = BundledAssetGroupSchema.BundleNamingStyle.NoHash; // hash to disimbiguate identically named files yields same error messages, e.g. standard shaders
                groupSchema.BundleMode          = BundledAssetGroupSchema.BundlePackingMode.PackTogether;
                groupSchema.Compression         = BundledAssetGroupSchema.BundleCompressionMode.LZ4;
                groupSchema.BuildPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalBuildPath : AddressableAssetSettings.kRemoteBuildPath);
                groupSchema.LoadPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalLoadPath : AddressableAssetSettings.kRemoteLoadPath);
            }
        }