123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class SceneBubbleWindow : MonoBehaviour
- {
- public string[] text;
- public bool isAuto = false;
- GameObject bg;
- GameObject frame;
- Text content;
- float liveTime = 3.0f;
- float curTime = 0;
- bool isEnable = false;
- YLBattle.SpawnPoint.BubbleType bubbleType = YLBattle.SpawnPoint.BubbleType.Area;
- int nowIndex = 0;
- bool isShow = false;
- private void Awake()
- {
- return;
- if(text == null)
- {
- text = new string[1];
- }
- if(text.Length == 0)
- {
- return;
- }
- ResourceHelper.Instance.LoadAssetBundle("SceneBubbleWindow", ab =>
- {
- if (ab != null)
- {
- GameObject bubble = (GameObject)Instantiate(ab.LoadAsset("SceneBubbleWindow"));
- bubble.transform.SetParent(this.transform);
- bubble.transform.localPosition = Vector3.zero;
- bubble.transform.SetLocalPositionY(2.0f);
- TransformRotation rtCmpt = bubble.AddComponent<TransformRotation>();
- bg = bubble.transform.Find("Canvas/Text/bg").gameObject;
- frame = bubble.transform.Find("frame").gameObject;
- content = bubble.transform.Find("Canvas/Text").GetComponent<Text>();
- content.text = text[nowIndex];
- curTime = 0;
- Hide();
- }
- });
-
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if(!isEnable)
- {
- return;
- }
- curTime += Time.deltaTime;
- if(curTime > liveTime)
- {
- //GameObject.Destroy(this.gameObject);
- if(isShow)
- {
- Hide();
- }
- else
- {
- Show();
- }
- curTime = 0;
- }
- }
- public void SetContent(string str)
- {
- if(text == null)
- {
- text = new string[1];
-
- }
- text[0] = str;
- }
- public void SetEnableType(YLBattle.SpawnPoint.BubbleType bt)
- {
- bubbleType = bt;
- if(bubbleType == YLBattle.SpawnPoint.BubbleType.Create)
- {
- isEnable = false;
- }
- }
- public void Show()
- {
- this.isEnable = true;
- if(bg == null)
- {
- return;
- }
- this.bg.SetActive(true);
- this.frame.SetActive(true);
- this.content.gameObject.SetActive(true);
- this.content.text = text[nowIndex];
- ++nowIndex;
- if(nowIndex >= text.Length)
- {
- nowIndex = 0;
- }
- this.isShow = true;
- }
- public void Hide()
- {
- if (bg == null)
- {
- return;
- }
- this.bg.SetActive(false);
- this.frame.SetActive(false);
- this.content.gameObject.SetActive(false);
- this.isShow = false;
- }
- public void OnTriggerEnter(Collider other)
- {
- if(isAuto && other.gameObject.layer == LayerMask.NameToLayer("Player"))
- {
- SetContent(this.text[nowIndex]);
- Show();
- }
- }
- }
|