UISpoits.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /****************************************************************************
  2. * 2022.1 SK-20211220VCWK
  3. ****************************************************************************/
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using QFramework;
  9. using UniRx;
  10. namespace QFramework.MREditor
  11. {
  12. public partial class UISpoits : UIElement
  13. {
  14. private void Awake()
  15. {
  16. }
  17. protected override void OnBeforeDestroy()
  18. {
  19. }
  20. private ToggleGroup group;
  21. private List<SpoitBtn> listbtns;
  22. private UIMaterials uIMaterials1;
  23. public void Initialized(List<SpoitValue> listSpoits ,SpoitBtn spoitBtn ,MaterialBtn materialBtn , UIMaterials uIMaterials)
  24. {
  25. listbtns = new List<SpoitBtn>();
  26. this.uIMaterials1 = uIMaterials;
  27. group = UISpoitContent.GetComponent<ToggleGroup>();
  28. listSpoits.ForEach(item =>
  29. {
  30. spoitBtn.Instantiate()
  31. .Parent(UISpoitContent)
  32. .Identity()
  33. .ApplySelfTo(btn =>
  34. {
  35. Toggle toggle = btn.GetComponent<Toggle>();
  36. toggle.onValueChanged.AddListener(state =>
  37. {
  38. if (state)
  39. {
  40. SendMsg(new OnSelectObjName(item.name,item.name, item.name));
  41. uIMaterials.SelectSpoit(item.name);
  42. }
  43. });
  44. toggle.group = group;
  45. btn.Text.text = item.name;
  46. listbtns.Add(btn);
  47. })
  48. .Show();
  49. Debug.Log("$$$ " + item.name);
  50. spoitBtn.Identity();
  51. uIMaterials.Initialized(item.name, item.material, materialBtn);
  52. });
  53. uIMaterials.InitBtn();
  54. BtnInit();
  55. }
  56. public void BtnInit()
  57. {
  58. Debug.Log("BtnInit");
  59. listbtns.ForEach(item =>
  60. {
  61. Vector3 pos = item.GetComponent<RectTransform>().anchoredPosition3D;
  62. item.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(pos.x, pos.y, 0);
  63. });
  64. }
  65. public void SelectSpoitObj(string name)
  66. {
  67. uIMaterials1.SelectSpoit(name);
  68. }
  69. }
  70. }