PopBase.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class PopBase : UIBase
  6. {
  7. private Color backgroundColor = new Color(10.0f / 255.0f, 10.0f / 255.0f, 10.0f / 255.0f, 0.6f);
  8. private GameObject m_background;//背景遮罩板子
  9. private RectTransform rect_transform = null;
  10. private CanvasGroup canvas_group = null;
  11. protected override void Awake()
  12. {
  13. base.Awake();
  14. rect_transform = GetComponent<RectTransform>();
  15. canvas_group = GetComponent<CanvasGroup>();
  16. }
  17. protected override void Start () {
  18. base.Start();
  19. }
  20. protected override void OnDestroy()
  21. {
  22. base.OnDestroy();
  23. }
  24. public override void InitSimpleUIdata()
  25. {
  26. UIData = new SimpleUIdata();
  27. UIData.UITypeId = (int)UIType.Pop;
  28. UIData.UIDataType = (int)MType;
  29. }
  30. public virtual void Show()
  31. {
  32. /*
  33. if (UIData == null)
  34. {
  35. InitSimpleUIdata();
  36. }
  37. UICanshu = data;
  38. UIData.DataClassName = UICanshu.ToString();
  39. */
  40. this.Init();
  41. //ShowDataSend();
  42. }
  43. public virtual void Show(System.Object data)
  44. {
  45. if (UIData == null)
  46. {
  47. InitSimpleUIdata();
  48. }
  49. UICanshu = data;
  50. UIData.DataClassName = UICanshu.ToString();
  51. if (GamePlayerData.Instance.IsFangzhu())
  52. {
  53. ShowDataSend();
  54. }
  55. this.Init();
  56. this.InitView();
  57. }
  58. protected virtual void InitView()
  59. {
  60. }
  61. public bool IsShow()
  62. {
  63. return this.gameObject.activeSelf;
  64. }
  65. private void Init()
  66. {
  67. this.gameObject.SetActive(true);
  68. TweenController control = this.GetComponentInChildren<TweenController>();
  69. if (control != null)
  70. {
  71. control.Begin();
  72. }
  73. }
  74. public virtual void Hide()
  75. {
  76. if (!IsShow())
  77. {
  78. return;
  79. }
  80. this.gameObject.SetActive(false);
  81. HideDataSend();
  82. }
  83. //框体类型
  84. public virtual PopType MType { get { return PopType.Default; } }
  85. private void AddBackground()
  86. {
  87. var bgTex = new Texture2D(1, 1);
  88. bgTex.SetPixel(0, 0, backgroundColor);
  89. bgTex.Apply();
  90. m_background = new GameObject("PopupBackground");
  91. var image = m_background.AddComponent<Image>();
  92. var rect = new Rect(0, 0, bgTex.width, bgTex.height);
  93. var sprite = Sprite.Create(bgTex, rect, new Vector2(0.5f, 0.5f), 1);
  94. image.material.mainTexture = bgTex;
  95. image.sprite = sprite;
  96. var newColor = image.color;
  97. image.color = newColor;
  98. image.canvasRenderer.SetAlpha(0.0f);
  99. image.CrossFadeAlpha(1.0f, 0.4f, false);
  100. m_background.transform.localScale = new Vector3(1, 1, 1);
  101. m_background.GetComponent<RectTransform>().sizeDelta = new Vector2(3000, 3000);
  102. m_background.AddComponent<BoxCollider>().size = new Vector3(3000, 3000, 1);
  103. m_background.transform.SetParent(this.transform.parent, false);
  104. m_background.transform.SetSiblingIndex(transform.GetSiblingIndex());
  105. }
  106. }