123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class PopBase : UIBase
- {
- private Color backgroundColor = new Color(10.0f / 255.0f, 10.0f / 255.0f, 10.0f / 255.0f, 0.6f);
- private GameObject m_background;//背景遮罩板子
- private RectTransform rect_transform = null;
- private CanvasGroup canvas_group = null;
- protected override void Awake()
- {
- base.Awake();
- rect_transform = GetComponent<RectTransform>();
- canvas_group = GetComponent<CanvasGroup>();
- }
- protected override void Start () {
- base.Start();
- }
- protected override void OnDestroy()
- {
- base.OnDestroy();
- }
- public override void InitSimpleUIdata()
- {
- UIData = new SimpleUIdata();
- UIData.UITypeId = (int)UIType.Pop;
- UIData.UIDataType = (int)MType;
- }
- public virtual void Show()
- {
- /*
- if (UIData == null)
- {
- InitSimpleUIdata();
- }
- UICanshu = data;
- UIData.DataClassName = UICanshu.ToString();
- */
- this.Init();
- //ShowDataSend();
- }
- public virtual void Show(System.Object data)
- {
- if (UIData == null)
- {
- InitSimpleUIdata();
- }
- UICanshu = data;
- UIData.DataClassName = UICanshu.ToString();
- if (GamePlayerData.Instance.IsFangzhu())
- {
- ShowDataSend();
- }
- this.Init();
- this.InitView();
- }
- protected virtual void InitView()
- {
- }
- public bool IsShow()
- {
- return this.gameObject.activeSelf;
- }
- private void Init()
- {
- this.gameObject.SetActive(true);
- TweenController control = this.GetComponentInChildren<TweenController>();
- if (control != null)
- {
- control.Begin();
- }
- }
- public virtual void Hide()
- {
- if (!IsShow())
- {
- return;
- }
- this.gameObject.SetActive(false);
- HideDataSend();
- }
- //框体类型
- public virtual PopType MType { get { return PopType.Default; } }
- private void AddBackground()
- {
- var bgTex = new Texture2D(1, 1);
- bgTex.SetPixel(0, 0, backgroundColor);
- bgTex.Apply();
- m_background = new GameObject("PopupBackground");
- var image = m_background.AddComponent<Image>();
- var rect = new Rect(0, 0, bgTex.width, bgTex.height);
- var sprite = Sprite.Create(bgTex, rect, new Vector2(0.5f, 0.5f), 1);
- image.material.mainTexture = bgTex;
- image.sprite = sprite;
- var newColor = image.color;
- image.color = newColor;
- image.canvasRenderer.SetAlpha(0.0f);
- image.CrossFadeAlpha(1.0f, 0.4f, false);
- m_background.transform.localScale = new Vector3(1, 1, 1);
- m_background.GetComponent<RectTransform>().sizeDelta = new Vector2(3000, 3000);
- m_background.AddComponent<BoxCollider>().size = new Vector3(3000, 3000, 1);
- m_background.transform.SetParent(this.transform.parent, false);
- m_background.transform.SetSiblingIndex(transform.GetSiblingIndex());
- }
- }
|