Esempio n. 1
0
            /// <summary>
            /// Finishes the specified item if there was an explicit error or request is done.
            /// Returns whether finish process was done.
            /// </summary>
            private bool FinishRequest(NetkoItem item)
            {
                if (item.RequestInfo.IsFinished)
                {
                    // Request count management.
                    CurrentProcessCount--;

                    // OnFinished callack.
                    item.DispatchEvent(2);

                    // If item wasn't flagged for retry (IsProcessing == true), we should terminate it.
                    if (item.RequestInfo.IsProcessing)
                    {
                        item.Terminate();
                    }
                    // Flagged retry
                    else
                    {
                        //If attempted termination after calling retry, this is an invalid action.
                        if (item.RequestInfo.IsTerminated)
                        {
                            RenLog.LogWarning(
                                "Netko.Updater.FinishRequest - You should not call item.Terminate() directly after " +
                                "retrying! Forcing retry..."
                                );
                            // Force retry.
                            item.Retry();
                        }
                    }
                    return(true);
                }
                return(false);
            }
Esempio n. 2
0
        /// <summary>
        /// Removes all scripts related to specifeid MVC view.
        /// </summary>
        public static void RemoveScripts(MvcConfig.View view)
        {
            // Delete base autogen file
            string autoGenFile = MvcViewAutoGen.GetBaseScriptPath(
                MvcWorkspace.AutogenCodePath,
                view.Name
                );

            if (File.Exists(autoGenFile))
            {
                File.Delete(autoGenFile);
            }
            else
            {
                RenLog.Log("MvcViewRemover.RemoveScripts - Base file missing: " + autoGenFile);
            }

            // Delete the folder
            string directory = MvcViewAutoGen.GetDirectoryPath(
                MvcWorkspace.WorkspacePath,
                view.Name
                );

            if (Directory.Exists(directory))
            {
                Directory.Delete(directory, true);
            }
            else
            {
                RenLog.Log("MvcViewRemover.RemoveScripts - Scripts directory missing: " + directory);
            }

            // Refresh the project view
            AssetDatabase.Refresh();
        }
Esempio n. 3
0
 /// <summary>
 /// Method for outputting debug messages.
 /// </summary>
 public static void LogMessage(object message)
 {
     if (IAP.DebugMessage)
     {
         RenLog.Log(LogLevel.Info, message);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Copies the contents of this object to specified array from index.
        /// </summary>
        public void CopyTo(KeyValuePair <string, JsonData>[] array, int arrayIndex)
        {
            if (array == null)
            {
                RenLog.Log(LogLevel.Warning, "JsonObject.CopyTo - Parameter 'array' can't be null!");
                return;
            }
            int loopCount = Mathf.Clamp(
                objectData.Count,
                0,
                Mathf.Min(objectData.Count, array.Length - arrayIndex)
                );
            int looped = 0;

            foreach (var pair in objectData)
            {
                //Set reference
                array[looped + arrayIndex] = pair;

                //Change index
                looped++;
                if (looped >= loopCount)
                {
                    break;
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Resets the specified item to its re-usable state.
 /// </summary>
 public virtual void Reset(T item)
 {
     if (item == null)
     {
         RenLog.Log(LogLevel.Warning, "BaseRecycler.Reset - Parameter 'item' can't be null!");
         return;
     }
     FireOnReset(item);
 }
Esempio n. 6
0
 /// <summary>
 /// Returns whether the specified item is valid (active).
 /// </summary>
 public virtual bool IsItemValid(T item)
 {
     if (item == null)
     {
         RenLog.Log(LogLevel.Warning, "BaseRecycler.IsItemActive - Parameter 'item' can't be null!");
         return(true);
     }
     return(FireOnCheckValid(item));
 }
Esempio n. 7
0
        /// <summary>
        /// Creates a new Color with string values.
        /// Supported formats:
        /// #{rr}{gg}{bb}{aa}
        /// #{rr}{gg}{bb}
        /// ** Cases are non-sensitive.
        /// ** Hashtag (#) not required.
        /// </summary>
        public static Color Create(string str)
        {
            int r = 255, g = 255, b = 255, a = 255;

            if (str[0] == '#')
            {
                str = str.Substring(1);
            }

            switch (str.Length)
            {
            case 3:
            {
                r = ParseHex(str[0]) * 16 + ParseHex(str[0]);
                g = ParseHex(str[1]) * 16 + ParseHex(str[1]);
                b = ParseHex(str[2]) * 16 + ParseHex(str[2]);
                break;
            }

            case 4:
            {
                r = ParseHex(str[0]) * 16 + ParseHex(str[0]);
                g = ParseHex(str[1]) * 16 + ParseHex(str[1]);
                b = ParseHex(str[2]) * 16 + ParseHex(str[2]);
                a = ParseHex(str[3]) * 16 + ParseHex(str[3]);
                break;
            }

            case 6:
            {
                r = ParseHex(str[0]) * 16 + ParseHex(str[1]);
                g = ParseHex(str[2]) * 16 + ParseHex(str[3]);
                b = ParseHex(str[4]) * 16 + ParseHex(str[5]);
                break;
            }

            case 8:
            {
                r = ParseHex(str[0]) * 16 + ParseHex(str[1]);
                g = ParseHex(str[2]) * 16 + ParseHex(str[3]);
                b = ParseHex(str[4]) * 16 + ParseHex(str[5]);
                a = ParseHex(str[6]) * 16 + ParseHex(str[7]);
                break;
            }

            default:
                RenLog.Log(LogLevel.Warning, "HexColor.Create - Invalid string given: " + str);
                break;
            }

            return(new Color(
                       r * ByteReciprocal,
                       g * ByteReciprocal,
                       b * ByteReciprocal,
                       a * ByteReciprocal
                       ));
        }
Esempio n. 8
0
 /// <summary>
 /// Specifies which crypto method to use.
 /// </summary>
 public static void SetCryptoMethod(ICrypto crypto)
 {
     if (crypto == null)
     {
         RenLog.Log(LogLevel.Warning, "SecurePrefs.SetCryptoMethod - Parameter 'crypto' may not be null!");
         return;
     }
     Crypto = crypto;
 }
Esempio n. 9
0
 /// <summary>
 /// Opens the native gallery for a video and returns its path to the specified callback.
 /// </summary>
 public static void PickVideo(VideoResultHandler callback)
 {
     if (I == null)
     {
         RenLog.Log(LogLevel.Warning, "GalleryPicker.PickVideo - You must initialize this module first!");
         return;
     }
     I.onVideoResult = callback;
     I.galleryPlugin.PickVideo();
 }
Esempio n. 10
0
 /// <summary>
 /// Destroys (disposes) the specified item for removal.
 /// Returns whether it's a success or failure.
 /// </summary>
 public virtual bool Destroy(T item)
 {
     if (item == null)
     {
         RenLog.Log(LogLevel.Warning, "BaseRecycler.Destroy - Parameter 'item' can't be null!");
         return(false);
     }
     FireOnDestroy(item);
     return(true);
 }
Esempio n. 11
0
 /// <summary>
 /// Opens the native gallery for an image and returns its path to the specified callback.
 /// </summary>
 public static void PickImage(CropOption cropOption, ImageResultHandler callback)
 {
     if (I == null)
     {
         RenLog.Log(LogLevel.Warning, "GalleryPicker.PickImage - You must initialize this module first!");
         return;
     }
     I.onImageResult = callback;
     I.galleryPlugin.PickImage(cropOption);
 }
Esempio n. 12
0
 /// <summary>
 /// Checks for any request error.
 /// </summary>
 public void CheckError()
 {
     //Timeout error
     if (IsTimeOut)
     {
         SetError("The request has timed out.");
         RenLog.Log(
             "NetkoRequest.CheckError - Timeout error at url: {1}" + Url
             );
     }
 }
Esempio n. 13
0
            /// <summary>
            /// Starts the task and returns this instance.
            /// May return null if this task was already invoked once.
            /// </summary>
            public Task Start()
            {
                if (alreadyStarted)
                {
                    RenLog.Log(LogLevel.Warning, "Tentacle.Task.Start - A task can't be called more than once on the same instance!");
                    return(null);
                }

                alreadyStarted = true;
                workerThread.Start();
                return(this);
            }
Esempio n. 14
0
        /// <summary>
        /// Loads the config file from resources and returns it.
        /// </summary>
        public static MvcConfig LoadFromResources()
        {
            TextAsset file = ResourceLoader.LoadTextAsset(
                MvcResources.GetConfigFilePath(false)
                );

            if (file == null)
            {
                RenLog.Log(LogLevel.Info, "MvcConfig.LoadFromResources - Text asset not found. Returning default configuration.");
                return(DefaultConfig);
            }
            return(new MvcConfig(file.text));
        }
Esempio n. 15
0
        /// <summary>
        /// Creates prefabs for all views in specified config if not already exists.
        /// </summary>
        public static void CreatePrefabs(MVC mvc, MvcConfig config)
        {
            if (mvc.ViewParent == null)
            {
                RenLog.LogWarning("CreatePrefab - You must assign the ViewParent property on MVC object first.");
                return;
            }

            for (int i = 0; i < config.Views.Count; i++)
            {
                Create(mvc, config.Views[i]);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Creates a new MVC view prefab for specified view.
        /// </summary>
        private static void Create(MVC mvc, MvcConfig.View view)
        {
            // If prefab file already exists, return
            if (File.Exists(view.GetResourcePath(true)))
            {
                return;
            }

            // Create a new object to make prefab.
            GameObject prefab = new GameObject(view.GetViewName());

            InitializeTransform(prefab, mvc.ViewParent.transform);

            // Create a child _Holder object.
            GameObject child = new GameObject("Container");

            InitializeTransform(child, prefab.transform);

            // Attach the UIPanel component first, then WidgetContainer.
            // Even though MVC Views require them as a dependency, it doesn't really look nice with the
            // component order all mixed up.
            prefab.AddComponent <UIPanel>();
            prefab.AddComponent <UIWidgetContainer>();

            // Find view's type and attach a view component on it.
            Type type        = null;
            var  checkResult = MvcValidator.CheckTypeExists(view.GetViewName(), out type);

            if (checkResult != ValidationResult.Success || type == null)
            {
                RenLog.LogWarning(string.Format(
                                      "MvcPrefabMaker.Create - Failed to find type: {0}. Make sure the configuration is applied.",
                                      view.GetViewName()
                                      ));
                GameObject.DestroyImmediate(prefab);
                return;
            }
            prefab.AddComponent(type);

            // Get UIPanel
            var panel = prefab.GetComponent <UIPanel>();

            panel.clipping = UIDrawCall.Clipping.ConstrainButDontClip;
            panel.SetRect(0f, 0f, mvc.BaseResolution.x, mvc.BaseResolution.y);

            // Create prefab
            string path = "Assets/Resources/" + view.GetResourcePath(false) + ".prefab";

            PrefabUtility.CreatePrefab(path, prefab, ReplacePrefabOptions.ConnectToPrefab);
        }
Esempio n. 17
0
 /// <summary>
 /// Adds the specified item.
 /// If null, the OnCreateHandler event will be fired.
 /// Returns the added item.
 /// </summary>
 public virtual T Add(T item = null)
 {
     if (item == null)
     {
         item = FireOnCreate();
     }
     if (item == null)
     {
         RenLog.Log(LogLevel.Warning, "BaseRecycler.Add - OnCreateHandler and the specified item is null!");
         return(null);
     }
     items.Add(item);
     return(item);
 }
Esempio n. 18
0
 public void Initialize(string objectName)
 {
                 #if UNITY_EDITOR
     try {
         pickerObject = GameObject.FindObjectOfType <GalleryPicker>().gameObject;
     }
     catch (Exception e) {
         RenLog.Log(
             LogLevel.Warning,
             "EditorGallery.Initialize - GalleryPicker instance is not found in scene!\n" + e.Message
             );
     }
                 #endif
 }
Esempio n. 19
0
 /// <summary>
 /// Adds the given key and value if key doesn't already exist.
 /// Returns true if successfully added.
 /// </summary>
 private bool AddIfNotExists(string key, JsonData value)
 {
     if (key == null)
     {
         RenLog.Log(LogLevel.Warning, "JsonObject.AddIfNotExists - Parameter 'key' can't be null.");
         return(false);
     }
     if (objectData.ContainsKey(key))
     {
         return(false);
     }
     objectData.Add(key, GetNullSafeData(value));
     return(true);
 }
Esempio n. 20
0
        void ShowInitialView()
        {
            if (!EditorApplication.isPlaying)
            {
                return;
            }
            if (firstViewType == null)
            {
                RenLog.Log(LogLevel.Warning, "MVC.ShowInitialView - The initial view type is not defined.");
                return;
            }

            ShowView(firstViewType);
        }
Esempio n. 21
0
        /// <summary>
        /// The key used for encryption / decryption.
        /// </summary>
        public void SetKey(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                RenLog.Log(LogLevel.Warning, "CryptoAES.SetKey - Key can't be null or empty.");
                return;
            }
            if (key.Length != 16)
            {
                RenLog.Log(LogLevel.Warning, "CryptoAES.SetKey - Key length must be 16.");
                return;
            }

            passByte = Encoding.UTF8.GetBytes(key);
        }
Esempio n. 22
0
        /// <summary>
        /// Removes the view prefab linked to specified view config from resources.
        /// </summary>
        public static void RemovePrefab(MvcConfig.View view)
        {
            string prefabPath = view.GetResourcePath(true, true);

            if (File.Exists(prefabPath))
            {
                File.Delete(prefabPath);
            }
            else
            {
                RenLog.Log("MvcViewRemover.RemoveScripts - Prefab file missing: " + prefabPath);
            }

            // Refresh the project view
            AssetDatabase.Refresh();
        }
Esempio n. 23
0
        /// <summary>
        /// Fires the OnCreate handler and returns new item.
        /// </summary>
        protected override T FireOnCreate()
        {
            T item = base.FireOnCreate();

            if (item != null)
            {
                return(item);
            }
            //Prefab and its component (T) should exist.
            if (Prefab == null || Prefab.GetComponent <T>() == null)
            {
                RenLog.Log(LogLevel.Warning, "UnityRecycler.FireOnCreate - Prefab must contain the corresponding component.");
                return(null);
            }
            return(GameObject.Instantiate(Prefab, Parent).GetComponent <T>());
        }
Esempio n. 24
0
        /// <summary>
        /// Returns whether specified json data is safe, according to checks filtered with options.
        /// </summary>
        public static bool IsJsonSafe(JsonData data, JsonSerializeOptions options)
        {
            // No checks required.
            if (options.IgnoreSafetyChecks)
            {
                return(true);
            }

            // Circular reference check.
            if (!options.IgnoreCircularReference && IsCircularReference(data))
            {
                RenLog.Log(LogLevel.Error, "JsonSerializeSafety.IsJsonSafe - Failed to pass circular reference check.");
                return(false);
            }

            // Everything looks good
            return(true);
        }
Esempio n. 25
0
        /// <summary>
        /// Takes a new photo and saves at specified file path.
        /// On iOS, the photo will be saved to the library along with documents directory,
        /// as you can't directly access files in the photo library.
        /// </summary>
        public static void TakePhoto(SaveOption saveOptions, CropOption cropOptions, PhotoResultHandler callback)
        {
            if (I == null)
            {
                RenLog.Log(LogLevel.Warning, "NativeCamera.TakePhoto - You must initialize this module first!");
                return;
            }
            if (saveOptions == null)
            {
                saveOptions = new SaveOption();
            }
            if (cropOptions == null)
            {
                cropOptions = new CropOption();
            }

            I.onPhotoResult = callback;
            I.camPlugin.TakePhoto(saveOptions, cropOptions);
        }
Esempio n. 26
0
 /// <summary>
 /// Gets or sets data at specified index.
 /// This property returns null JsonData if index is out of range.
 /// This property will automatically resize the array if index >= item count.
 /// </summary>
 public JsonData this[int index] {
     get {
         if (index >= listData.Count || index < 0)
         {
             return(new JsonData(null));
         }
         return(listData[index]);
     }
     set {
         if (index < 0)
         {
             RenLog.Log(LogLevel.Warning, "JsonArray.this[] - Index can't be less than 0.");
             return;
         }
         //Add dummy items to avoid index out of range exception
         AddDummy(index + 1 - listData.Count);
         listData[index] = GetNullSafeData(value);
     }
 }
Esempio n. 27
0
 public string FinalizePhoto(string filePath)
 {
     // If the photo is saved in persistent datapath and image should be cropped,
     // We must get rid of the original image before cropping.
     if (lastSaveOption != null && lastCropOption != null &&
         !lastSaveOption.SaveToLibrary && lastCropOption.IsCropping)
     {
         string originalPath = string.Format(
             "{0}/{1}.jpg",
             Application.persistentDataPath,
             lastSaveOption.FileName
             );
         if (File.Exists(originalPath))
         {
             RenLog.Log(LogLevel.Info, "AndroidCamera.FinalizePhoto - Removing original photo: " + originalPath);
             File.Delete(originalPath);
         }
     }
     return(filePath);
 }
Esempio n. 28
0
 public T this[int index] {
     get {
         if (index < 0 || index >= items.Count)
         {
             throw new IndexOutOfRangeException();
         }
         return(items[index]);
     }
     set {
         if (index < 0 || index >= items.Count)
         {
             throw new IndexOutOfRangeException();
         }
         if (value == null)
         {
             RenLog.Log(LogLevel.Warning, "BaseRecycler.this - value can't be null!");
             return;
         }
         items[index] = value;
     }
 }
Esempio n. 29
0
        /// <summary>
        /// Deserializes the specified JsonData for a specific type.
        /// Highly recommended to use Json.Parse with Type parameter instead.
        /// </summary>
        public static object Deserialize(Type t, object instance, JsonObject data)
        {
            object adaptorResult = JsonAdaptor.Deserialize(t, data);

            if (adaptorResult != null)
            {
                return(adaptorResult);
            }

            //IJsonable method requires an instance to be present.
            if (instance == null)
            {
                instance = DynamicService.CreateObject(t);
                if (instance == null)
                {
                    RenLog.Log(LogLevel.Error, string.Format(
                                   "JsonDeserializer.Deserialize - Failed to instantiate a dynamic object of type ({0}). If possible, try adding a parameterless constructor.",
                                   t.Name
                                   ));
                    return(null);
                }
            }

            IJsonable jsonable = instance as IJsonable;

            if (jsonable != null)
            {
                jsonable.FromJsonObject(data);
                return(instance);
            }

            //No deserializer is available.
            RenLog.Log(LogLevel.Warning, string.Format(
                           "JsonDeserializer.Deserialize - There is no deserializer available for type ({0}). Returning null."
                           ));
            return(null);
        }
Esempio n. 30
0
        /// <summary>
        /// Finalizes the awake process.
        /// </summary>
        void FinalizeAwake()
        {
            // No initialization, no MVC
            if (!isCoreInitialized)
            {
                RenLog.Log(LogLevel.Error, "MVC.FinalizeAwake - Core MVC components are not initialized!");
                Destroy(gameObject);
                return;
            }
            // View parent is not set.
            // If user really wants to MVC without the parent, ShowView should be called manually.
            if (ViewParent == null)
            {
                RenLog.LogWarning("MVC.FinalizeAwake - ViewParent property is null! " +
                                  "Call MVC.ShowView after setting the property.");
                return;
            }

            // Show first view, then we're finished :D
            if (InitialViewOnAwake && firstViewType != null)
            {
                ShowView(firstViewType);
            }
        }