public void RuntimeProperties_CanAddValue()
        {
            AddressablesRuntimeProperties.ClearCachedPropertyValues();
            AddressablesRuntimeProperties.SetPropertyValue("name", "val");

            Assert.AreEqual(1, AddressablesRuntimeProperties.GetCachedValueCount());
        }
        /// <summary>
        /// Build the specified data with the provided builderInput.  This is the public entry point.
        ///  Child class overrides should use <see cref="BuildDataImplementation{TResult}"/>
        /// </summary>
        /// <typeparam name="TResult">The type of data to build.</typeparam>
        /// <param name="builderInput">The builderInput object used in the build.</param>
        /// <returns>The build data result.</returns>
        public TResult BuildData <TResult>(AddressablesDataBuilderInput builderInput) where TResult : IDataBuilderResult
        {
            if (!CanBuildData <TResult>())
            {
                var message = "Data builder " + Name + " cannot build requested type: " + typeof(TResult);
                Debug.LogError(message);
                return(AddressableAssetBuildResult.CreateResult <TResult>(null, 0, message));
            }

            m_Log = (builderInput.Logger != null) ? builderInput.Logger : new BuildLog();

            AddressablesRuntimeProperties.ClearCachedPropertyValues();

            TResult result;

            // Append the file registry to the results
            using (m_Log.ScopedStep(LogLevel.Info, $"Building {this.Name}"))
            {
                result = BuildDataImplementation <TResult>(builderInput);
                if (result != null)
                {
                    result.FileRegistry = builderInput.Registry;
                }
            }

            if (builderInput.Logger == null && m_Log != null)
            {
                WriteBuildLog((BuildLog)m_Log, Path.GetDirectoryName(Application.dataPath) + "/Library/com.unity.addressables");
            }

            return(result);
        }
        /// <summary>
        /// Build the specified data with the provided builderInput.  This is the public entry point.
        ///  Child class overrides should use <see cref="BuildDataImplementation{TResult}"/>
        /// </summary>
        /// <typeparam name="TResult">The type of data to build.</typeparam>
        /// <param name="builderInput">The builderInput object used in the build.</param>
        /// <returns>The build data result.</returns>
        public TResult BuildData <TResult>(AddressablesDataBuilderInput builderInput) where TResult : IDataBuilderResult
        {
            if (!CanBuildData <TResult>())
            {
                var message = "Data builder " + Name + " cannot build requested type: " + typeof(TResult);
                Debug.LogError(message);
                return(AddressableAssetBuildResult.CreateResult <TResult>(null, 0, message));
            }

            BuildLog log = new BuildLog();

            m_Log = log;
            AddressablesRuntimeProperties.ClearCachedPropertyValues();

            TResult result;

            // Append the file registry to the results
            using (log.ScopedStep(LogLevel.Info, $"Building {this.Name}"))
            {
                result = BuildDataImplementation <TResult>(builderInput);
                if (result != null)
                {
                    result.FileRegistry = builderInput.Registry;
                }
            }

            var perfOutputDirectory = Path.GetDirectoryName(Application.dataPath) + "/Library/com.unity.addressables";

            File.WriteAllText(Path.Combine(perfOutputDirectory, "AddressablesBuildTEP.json"), log.FormatAsTraceEventProfiler());
            File.WriteAllText(Path.Combine(perfOutputDirectory, "AddressablesBuildLog.txt"), log.FormatAsText());

            return(result);
        }
        public void RuntimeProperties_CanEvaluateReflection()
        {
            AddressablesRuntimeProperties.ClearCachedPropertyValues();
            string expectedResult = ReflectableStringValue;
            string actualResult   = AddressablesRuntimeProperties.EvaluateProperty("AddrRuntimePropertiesTests.AddrRuntimePropertiesTests.ReflectableStringValue");

            Assert.AreEqual(expectedResult, actualResult);
        }
        public void RuntimeProperties_EvaluatePropertyCanEvaluateSetValue()
        {
            AddressablesRuntimeProperties.ClearCachedPropertyValues();
            string expectedResult = "myVal";
            string key            = "myName";

            AddressablesRuntimeProperties.SetPropertyValue(key, expectedResult);

            string actualResult = AddressablesRuntimeProperties.EvaluateProperty(key);

            Assert.AreEqual(expectedResult, actualResult);
        }
        /// <summary>
        /// Build the specified data with the provided builderInput.  This is the public entry point.
        ///  Child class overrides should use <see cref="BuildDataImplementation{TResult}"/>
        /// </summary>
        /// <typeparam name="TResult">The type of data to build.</typeparam>
        /// <param name="builderInput">The builderInput object used in the build.</param>
        /// <returns>The build data result.</returns>
        public TResult BuildData <TResult>(AddressablesDataBuilderInput builderInput) where TResult : IDataBuilderResult
        {
            if (!CanBuildData <TResult>())
            {
                var message = "Data builder " + Name + " cannot build requested type: " + typeof(TResult);
                Debug.LogError(message);
                return(AddressableAssetBuildResult.CreateResult <TResult>(null, 0, message));
            }

            m_Log = (builderInput.Logger != null) ? builderInput.Logger : new BuildLog();

            AddressablesRuntimeProperties.ClearCachedPropertyValues();

            TResult result = default;

            // Append the file registry to the results
            using (m_Log.ScopedStep(LogLevel.Info, $"Building {this.Name}"))
            {
                try
                {
                    result = BuildDataImplementation <TResult>(builderInput);
                }
                catch (Exception e)
                {
                    string errMessage;
                    if (e.Message == "path")
                    {
                        errMessage = "Invalid path detected during build. Check for unmatched brackets in your active profile's variables.";
                    }
                    else
                    {
                        errMessage = e.Message;
                    }

                    Debug.LogError(errMessage);
                    return(AddressableAssetBuildResult.CreateResult <TResult>(null, 0, errMessage));
                }
                if (result != null)
                {
                    result.FileRegistry = builderInput.Registry;
                }
            }

            if (builderInput.Logger == null && m_Log != null)
            {
                WriteBuildLog((BuildLog)m_Log, Path.GetDirectoryName(Application.dataPath) + "/" + Addressables.LibraryPath);
            }

            return(result);
        }
        /// <summary>
        /// Build the specified data with the provided builderInput.  This is the public entry point.
        ///  Child class overrides should use <see cref="BuildDataImplementation{TResult}"/>
        /// </summary>
        /// <typeparam name="TResult">The type of data to build.</typeparam>
        /// <param name="builderInput">The builderInput object used in the build.</param>
        /// <returns>The build data result.</returns>
        public TResult BuildData <TResult>(AddressablesDataBuilderInput builderInput) where TResult : IDataBuilderResult
        {
            if (!CanBuildData <TResult>())
            {
                var message = "Data builder " + Name + " cannot build requested type: " + typeof(TResult);
                Debug.LogError(message);
                return(AddressableAssetBuildResult.CreateResult <TResult>(null, 0, message));
            }

            AddressablesRuntimeProperties.ClearCachedPropertyValues();

            // Append the file registry to the results
            var result = BuildDataImplementation <TResult>(builderInput);

            if (result != null)
            {
                result.FileRegistry = builderInput.Registry;
            }

            return(result);
        }