コード例 #1
0
        /// <summary>
        /// get string from native code.
        /// </summary>
        /// <returns>value</returns>
        /// <param name="key">key</param>
        public static string GetString(string key)
        {
            UniKeyModuleString data;

            #if UNITY_IOS && !UNITY_EDITOR
            data = getString(key);
            #elif UNITY_ANDROID && !UNITY_EDITOR
            using (var module = new AndroidJavaClass(PackageName))
                using (var obj = module.CallStatic <AndroidJavaObject>("getString", key)) {
                    data           = new UniKeyModuleString();
                    data.value     = obj.Get <string>("value");
                    data.errorCode = obj.Get <int>("errorCode");
                }
            #else
            data = UniKeyModuleOther.GetString(key);
            #endif

            switch ((ErrorCode)data.errorCode)
            {
            case ErrorCode.None: return(data.value);

            case ErrorCode.ItemNotFound: return(null);
            }
            throw new UniKeyModuleException((ErrorCode)data.errorCode);
        }
コード例 #2
0
        /// <summary>
        /// get value from cache.
        /// </summary>
        /// <returns>value + error code.</returns>
        /// <param name="key">key</param>
        public static UniKeyModuleString GetString(string key)
        {
            var data = new UniKeyModuleString();

            if (!File.Exists(GetFilePath()))
            {
                data.errorCode = (int)ErrorCode.ItemNotFound;
                return(data);
            }
            var index = cache.FindIndex((d) => { return(d.key == key); });

            if (index == -1)
            {
                data.value     = null;
                data.errorCode = (int)ErrorCode.ItemNotFound;
            }
            else
            {
                data.value     = cache[index].value;
                data.errorCode = (int)ErrorCode.None;
            }
            return(data);
        }