public static void ShowPanel(string panelTitle) { try { if (ProgressBarAssetBundle == null) { Logger.LogWithDate("Assets not loaded. Cannot display panel!"); return; } var canvasPrefab = ProgressBarAssetBundle.LoadAsset <GameObject>("ProgressBar_Canvas"); GameObject canvasGO = Instantiate(canvasPrefab); GameObject panelTitleGO = GameObject.Find("ProgressBar_Title"); if (panelTitleGO != null) { panelTitleGO.GetComponent <Text>().text = panelTitle; } GameObject progressBarSliderTextGO = GameObject.Find("ProgressBar_Slider_Text"); Text progressBarSliderText = progressBarSliderTextGO != null?progressBarSliderTextGO.GetComponent <Text>() : null; if (progressBarSliderText == null) { Logger.LogWithDate("Error loading ProgressBar_Slider_Text"); return; } GameObject progressBarLoadingTextGO = GameObject.Find("ProgressBar_Loading_Text"); Text progressBarLoadingText = progressBarLoadingTextGO != null?progressBarLoadingTextGO.GetComponent <Text>() : null; if (progressBarLoadingText == null) { Logger.LogWithDate("Error loading ProgressBar_Loading_Text"); return; } // Hook up the progress behavior to ProgressBar_Slider; GameObject progressBarSliderGO = GameObject.Find("ProgressBar_Slider"); if (progressBarSliderGO != null) { ProgressBarLoadingBehavior progressBarLoadingBehavior = progressBarSliderGO.AddComponent <ProgressBarLoadingBehavior>(); progressBarLoadingBehavior.SliderText = progressBarSliderText; progressBarLoadingBehavior.LoadingText = progressBarLoadingText; progressBarLoadingBehavior.FinishAction = (() => { ProgressBarAssetBundle.Unload(true); Destroy(canvasGO); TriggerGameLoading(); }); } } catch (Exception e) { Logger.LogWithDate(string.Format("Excception encountered initializing panel. Exception={0}", e)); } }
public static void SubmitWork(Func <IEnumerator <ProgressReport> > workFunc) { // Hook up the progress behavior to ProgressBar_Slider; GameObject progressBarSliderGO = GameObject.Find("ProgressBar_Slider"); if (progressBarSliderGO != null) { ProgressBarLoadingBehavior progressBarLoadingBehavior = progressBarSliderGO.GetComponent <ProgressBarLoadingBehavior>(); progressBarLoadingBehavior.SubmitWork(workFunc); } else { Logger.Log("ProgressPanel not found: Performing work on current thread"); IEnumerator <ProgressReport> workEnumerator = workFunc.Invoke(); while (workEnumerator.MoveNext()) { // do nothing -- drain the enumeration -- complete the work on this thread immediately } } }
internal static bool Initialize(string assetDirectory, string panelTitle) { var assetBundle = AssetBundle.LoadFromFile(Path.Combine(assetDirectory, ASSET_BUNDLE_NAME)); if (assetBundle == null) { Log($"Error loading asset bundle {ASSET_BUNDLE_NAME}"); return(false); } var canvasPrefab = assetBundle.LoadAsset <GameObject>("ProgressBar_Canvas"); var canvasGameObject = UnityEngine.Object.Instantiate(canvasPrefab); var panelTitleText = GameObject.Find("ProgressBar_Title")?.GetComponent <Text>(); var sliderText = GameObject.Find("ProgressBar_Slider_Text")?.GetComponent <Text>(); var loadingText = GameObject.Find("ProgressBar_Loading_Text")?.GetComponent <Text>(); var sliderGameObject = GameObject.Find("ProgressBar_Slider"); if (panelTitleText == null || sliderText == null || loadingText == null || sliderGameObject == null) { Log("Error loading a GameObject from asset bundle"); return(false); } var slider = sliderGameObject.GetComponent <Slider>(); panelTitleText.text = panelTitle; loadingBehavior = sliderGameObject.AddComponent <ProgressBarLoadingBehavior>(); loadingBehavior.SliderText = sliderText; loadingBehavior.LoadingText = loadingText; loadingBehavior.Slider = slider; loadingBehavior.FinishAction = () => { assetBundle.Unload(true); UnityEngine.Object.Destroy(canvasGameObject); TriggerGameLoading(); }; return(true); }