private void Handle_Completed(AssetOperationHandle obj) { if (_handle.AssetObject == null) { return; } Go = _handle.InstantiateObject; // 设置父类 GameObject uiDesktop = UIManager.Instance.UIDesktop; Go.transform.SetParent(uiDesktop.transform, false); // 获取组件 _manifest = Go.GetComponent <UIManifest>(); if (_manifest == null) { GameLogger.Error($"Not found {nameof(UIManifest)} in window {WindowType}"); return; } // 获取组件 _canvas = Go.GetComponent <Canvas>(); if (_canvas == null) { GameLogger.Error($"Not found {nameof(Canvas)} in window {WindowType}"); return; } _canvas.overrideSorting = true; // 获取组件 _raycaster = Go.GetComponent <GraphicRaycaster>(); if (_raycaster == null) { GameLogger.Error($"Not found {nameof(GraphicRaycaster)} in window {WindowType}"); return; } // 获取组件 _childCanvas = Go.GetComponentsInChildren <Canvas>(true); _childRaycaster = Go.GetComponentsInChildren <GraphicRaycaster>(true); // 虚函数 if (IsPrepare == false) { IsPrepare = true; OnCreate(); } // 最后设置是否激活 Go.SetActive(IsOpen); // 通知UI管理器 _userCallback?.Invoke(this); }
/// <summary> /// Add listeners to the MainMenu buttons /// </summary> private void InitializeButtons() { // TODO fill me in foreach (Button button in Go.GetComponentsInChildren <Button>()) { switch (button.name) { case "GameResumeBtn": button.onClick.AddListener(() => DanmakuController.Instance.Resume()); break; case "Quit": // button.onClick.AddListener(() => Game.Ctx.QuitGame()); break; } } }
/// <summary> /// Add listeners to the Pause Menu buttons /// </summary> private void InitializeButtons() { // DONE Button[] All_Pause_Button = Go.GetComponentsInChildren <Button>(); for (int i = 0; i < All_Pause_Button.Length; i++) { if (All_Pause_Button[i].name == "Resume") { Button resume = All_Pause_Button[i]; resume.onClick.AddListener(Game.Ctx.Clock.Unpause); } if (All_Pause_Button[i].name == "Main Menu") { Button main_menu = All_Pause_Button[i]; main_menu.onClick.AddListener(BackToMain); } } }
/// <summary> /// Add listeners to the MainMenu buttons /// </summary> private void InitializeButtons() { // DONE Button[] All_Button = Go.GetComponentsInChildren <Button>(); for (int i = 0; i < All_Button.Length; i++) { if (All_Button[i].name == "Start") { Button start = All_Button[i]; start.onClick.AddListener(Game.Ctx.StartGame); } if (All_Button[i].name == "Quit") { Button quit = All_Button[i]; quit.onClick.AddListener(Game.Ctx.QuitGame); } } }
/// <summary> /// This method should be called after the GameObject has finished loading its content /// It will scrape the subtree for all mesh renderers and colliders /// </summary> public void Initialize(bool createColliders) { // Update layer of child game objects to match the parent var childTransforms = this.Go.GetComponentsInChildren <Transform>(true); for (int i = 0; i < childTransforms.Length; i++) { childTransforms[i].gameObject.layer = this.Go.layer; } this.renderers = this.Go.GetComponentsInChildren <MeshRenderer>(); var meshFilters = this.Go.GetComponentsInChildren <MeshFilter>(); if (createColliders) { for (int i = 0; i < meshFilters.Length; i++) { var mf = meshFilters[i]; if (mf.sharedMesh.GetTopology(0) == MeshTopology.Triangles) { var mc = mf.gameObject.AddComponent <MeshCollider>(); mc.sharedMesh = mf.sharedMesh; } } // Need to toggle active and then inactive to bake collider data // We do this here so that we can control the number of bakes per frame // otherwise we can have lots of colliders bake in one frame if many tiles become // active for the first time Go.SetActive(true); Go.SetActive(false); } for (int i = 0; i < meshFilters.Length; i++) { var m = meshFilters[i].sharedMesh; if (m.GetTopology(0) == MeshTopology.Triangles) { FaceCount += m.triangles.Length / 3; } } int maxPixels = 0; for (int i = 0; i < renderers.Length; i++) { var r = renderers[i]; for (int j = 0; j < r.materials.Length; j++) { if (r.materials[j].HasProperty("_MainTex")) { var t = r.materials[j].mainTexture; if (t != null) { int pixels = t.width * t.height; if (pixels > maxPixels) { MaxTextureSize = new Vector2Int(t.width, t.height); } PixelCount += pixels; TextureCount += 1; } } } } colliders = Go.GetComponentsInChildren <Collider>(); collidersEnabled = true; renderersEnabled = true; }