示例#1
0
        /// <summary>
        ///     Defines an asset bundle. If a Leanplum variable with the same name and type exists,
        ///     this will return the existing variable.
        /// </summary>
        /// <returns>Leanplum variable.</returns>
        /// <param name="name">Name of variable.</param>
        /// <param name="realtimeUpdating">Setting it to <c>false</c> will prevent Leanplum from
        /// reloading assetbundles as they change in development mode.</param>
        /// <param name="iosBundleName">Filename of iOS assetbundle.</param>
        /// <param name="androidBundleName">Filename of Android assetbundle.</param>
        /// <param name="standaloneBundleName">Filename of Standalone assetbundle.</param>
        public override Var <AssetBundle> DefineAssetBundle(string name, bool realtimeUpdating = true,
                                                            string iosBundleName        = "",
                                                            string androidBundleName    = "",
                                                            string standaloneBundleName = "")
        {
            string kind       = Constants.Kinds.FILE;
            string actualName = "__Unity Resources.Android.Assets." + name;

            string fullPath = /*Application.dataPath + "/"*/ "assets/" + androidBundleName;

            // Check if existing
            if (AndroidVarCache.ContainsKey(actualName))
            {
                if (AndroidVarCache[actualName].Kind != kind)
                {
                    Debug.LogError("Leanplum Error: \"" + name +
                                   "\" was already defined with a different kind");
                    return(null);
                }
                return((Var <AssetBundle>)AndroidVarCache[actualName]);
            }
            Var <AssetBundle> result = new AndroidVar <AssetBundle>(actualName, kind, null, fullPath);

            AndroidVarCache[actualName] = result;
            LeanplumAndroid.NativeSDK.CallStatic("defineVar", actualName, "file", fullPath);
            return(result);
        }
示例#2
0
        /// <summary>
        ///     Defines a new variable with a default value. If a Leanplum variable with the same name
        ///     and type exists, this will return the existing variable.
        /// </summary>
        /// <param name="name"> Name of the variable. </param>
        /// <param name="defaultValue"> Default value of the variable. Can't be null. </param>
        public override Var <U> Define <U>(string name, U defaultValue)
        {
            string kind = null;

            if (defaultValue is int || defaultValue is long || defaultValue is short ||
                defaultValue is char || defaultValue is sbyte || defaultValue is byte)
            {
                kind = Constants.Kinds.INT;
            }
            else if (defaultValue is float || defaultValue is double || defaultValue is decimal)
            {
                kind = Constants.Kinds.FLOAT;
            }
            else if (defaultValue is string)
            {
                kind = Constants.Kinds.STRING;
            }
            else if (defaultValue is IList || defaultValue is Array)
            {
                kind = Constants.Kinds.ARRAY;
            }
            else if (defaultValue is IDictionary)
            {
                kind = Constants.Kinds.DICTIONARY;
            }
            else if (defaultValue is bool)
            {
                kind = Constants.Kinds.BOOLEAN;
            }
            else
            {
                Debug.LogError("Leanplum Error: Default value for \"" + name +
                               "\" not recognized or supported.");
                return(null);
            }

            // Check if existing
            if (AndroidVarCache.ContainsKey(name))
            {
                if (AndroidVarCache[name].Kind != kind)
                {
                    Debug.LogError("Leanplum Error: \"" + name +
                                   "\" was already defined with a different kind");
                    return(null);
                }
                return((Var <U>)AndroidVarCache[name]);
            }

            // Define in native SDK
            LeanplumAndroid.NativeSDK.CallStatic("defineVar", name, kind, Json.Serialize(defaultValue));
            Var <U> result = new AndroidVar <U>(name, kind, defaultValue);

            // Register in Cache
            AndroidVarCache[name] = result;
            return(result);
        }