Beispiel #1
0
        /// <summary>
        /// confirm that cache contains key
        /// </summary>
        /// <returns>value + error code</returns>
        /// <param name="key">key</param>
        public static UniKeyModuleBoolean HasKey(string key)
        {
            var data = new UniKeyModuleBoolean();

            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     = false;
                data.errorCode = (int)ErrorCode.ItemNotFound;
            }
            else
            {
                data.value     = true;
                data.errorCode = (int)ErrorCode.None;
            }
            return(data);
        }
        /// <summary>
        /// confirm that received key exists in native code.
        /// </summary>
        /// <returns>whether key contains native code, or not.</returns>
        /// <param name="key">key</param>
        public static bool HasKey(string key)
        {
            UniKeyModuleBoolean data;

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

            switch ((ErrorCode)data.errorCode)
            {
            case ErrorCode.None:
            case ErrorCode.ItemNotFound: return(data.value);
            }
            throw new UniKeyModuleException((ErrorCode)data.errorCode);
        }