Ejemplo n.º 1
0
        /// <summary>
        /// Load a ScriptableObject instance from a Resources subpath, for example:
        ///   MyExampleScriptableObject_Instance1.asset is located in Assets/Ui/Resources/MyFolderX
        ///   -> The path must be "MyFolderX/MyExampleScriptableObject_Instance1"
        /// </summary>
        public static T LoadScriptableObjectInstance <T>(string pathInResourcesFolder) where T : ScriptableObject
        {
            var so = LoadV2 <T>(pathInResourcesFolder);

            AssertV2.IsNotNull(so, "ScriptableObject (" + typeof(T) + ") instance " + pathInResourcesFolder);
            return(so);
        }
Ejemplo n.º 2
0
 private static void AssertResponseLooksNormal <T>(UnityWebRequest self, Response <T> resp)
 {
     AssertV2.IsNotNull(self, "WebRequest object was null: " + resp);
     if (self != null)
     {
         AssertV2.IsTrue(self.isDone, "Request never finished: " + resp);
         if (self.isNetworkError)
         {
             Log.w("isNetworkError=true for " + resp);
         }
         if (self.error != null)
         {
             Log.w("error=" + self.error + " for " + resp);
         }
         if (self.isHttpError)
         {
             Log.w("isHttpError=true for " + resp);
         }
         if (self.responseCode < 200 || self.responseCode >= 300)
         {
             Log.w("responseCode=" + self.responseCode + " for " + resp);
         }
         if (self.isNetworkError && self.responseCode == 0 && self.useHttpContinue)
         {
             Log.w("useHttpContinue flag was true, request might work if its set to false");
         }
     }
 }
Ejemplo n.º 3
0
 private static void SetupDownloadAndUploadHanders <T>(UnityWebRequest self, Response <T> resp)
 {
     self.downloadHandler = resp.createDownloadHandler();
     switch (self.method)
     {
     case UnityWebRequest.kHttpVerbPUT:
     case UnityWebRequest.kHttpVerbPOST:
         AssertV2.IsNotNull(self.uploadHandler, "Put/Post-request had no uploadHandler set");
         break;
     }
 }
Ejemplo n.º 4
0
        /// <summary> Connects a model with a view </summary>
        /// <returns> A task that can be awaited on, that returns the fully setup presenter </returns>
        public static async Task <T> LoadModelIntoView <T>(this Presenter <T> self, T model)
        {
            AssertV2.IsNotNull(self.targetView, "presenter.targetView");
            var name = self.GetType().Name + "_((" + model.GetType().Name + "))";

            AppFlow.TrackEvent(EventConsts.catPresenter, "Load-start:" + name, self, model);
            await self.OnLoad(model);

            AppFlow.TrackEvent(EventConsts.catPresenter, "Load-done:" + name, self, model);
            return(model);
        }
Ejemplo n.º 5
0
 public void ExecuteOnMainThread(Action a)
 {
     AssertV2.IsNotNull(mainThreadRef, "mainThreadRef");
     if (WasInitializedWhilePlaying)
     {
         actionsForMainThread.Enqueue(a);
     }
     else if (!Application.isPlaying)
     {
         Log.w("ExecuteOnMainThread: Application not playing, action will be instantly executed now");
         a();
     }
     else
     {
         throw Log.e("MainThread not initialized via MainThread.instance");
     }
 }
Ejemplo n.º 6
0
        /// <summary> Connects a model with a view </summary>
        /// <returns> A task that can be awaited on, that returns the fully setup presenter </returns>
        public static async Task <T> LoadModelIntoView <T>(this Presenter <T> self, T model)
        {
            AssertV2.IsNotNull(self.targetView, "presenter.targetView");
            AssertV2.IsNotNull(model, $"model (type={typeof(T)})");

            var presenterName = self.GetType().Name;
            var modelName     = model.GetType().Name;
            var viewName      = self.targetView.name;
            var name          = $"{presenterName}({modelName})--{viewName}";

#if UNITY_EDITOR // In the Unity editor always try to use the Visual Assert system by default:
            await AssertVisually.AssertNoVisualChange(name);
#endif
            EventBus.instance.Publish(EventConsts.catPresenter + EventConsts.START, name, self, model);
            await self.OnLoad(model);

            EventBus.instance.Publish(EventConsts.catPresenter + EventConsts.DONE, name, self, model);
            return(model);
        }
Ejemplo n.º 7
0
 private async Task LoadTranslationDataForLocale()
 {
     AssertV2.IsNotNull(localeLoader, "localeLoader");
     translationData = await localeLoader(currentLocale);
 }