123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- [SerializeField]
- public enum UILayer{
- none = -1,
- lower = 0,
- mid = 1,
- up = 2
- }
- public class UIComponent : MonoBehaviour {
- [SerializeField]
- public UILayer uiLayer = UILayer.none;
- public bool isFull = false;
- public bool ignoreRayCast = false;
- public float zAdd = 0;
- public int requestOrder = 0;
- public Animator startAnimator;
- public Animation startAnimation;
- public SystemDelegate.VoidDelegate focusDel;
- public SystemDelegate.VoidDelegate postAnimDel;
- public bool mIsInit = false;
- public bool isPreLoad = false;
- public bool isFinishAnim = false;
- public float z{
- get{
- if (gameObject.GetComponent<RectTransform>()!=null ){
- return gameObject.GetComponent<RectTransform>().localPosition.z;
- }
- return transform.localPosition.z;
- }
- set{
- // if (gameObject.GetComponent<RectTransform>()!=null ){
- // RectTransform rectTrans = gameObject.GetComponent<RectTransform>();
- // Vector3 pos = rectTrans.localPosition;
- // pos.z = value;
- // rectTrans.localPosition = pos;
- // return;
- // }
- Vector3 posTrans = transform.localPosition;
- posTrans.z = value;
- transform.localPosition = posTrans;
- }
-
- }
- public int curOrder{
- get{
- Canvas canvas = gameObject.GetComponent<Canvas>();
- if (canvas!=null){
- return canvas.sortingOrder;
- }
- return 0;
- }
- set{
- Canvas canvas = gameObject.GetComponent<Canvas>();
- if (canvas==null ){
- canvas = gameObject.AddComponent<Canvas>();
- if(!ignoreRayCast)
- Tools.GetOrCreateComponent<GraphicRaycaster>(gameObject);
- }
- canvas.overrideSorting = true;
- canvas.sortingOrder = value;
- Canvas[] canvases = gameObject.GetComponentsInChildren<Canvas>(true );
- foreach(Canvas preCanvas in canvases ){
- if (preCanvas.gameObject == gameObject){
- continue;
- }
- preCanvas.sortingOrder += canvas.sortingOrder;
- //Debug.LogWarning(preCanvas.sortingOrder + "add once in canvas order " + preCanvas.gameObject.name );
- }
- }
- }
- public void FindButton()
- {
- Button[] childs = gameObject.GetComponentsInChildren<Button>(true);
- foreach (Button child in childs)
- {
- AddaudioSource(child);
- }
- }
- public void AddaudioSource(Button btn)
- {
- ButtonAudio btnAudio = btn.gameObject.GetComponent<ButtonAudio>();
- if (btnAudio == null)
- btnAudio = btn.gameObject.AddComponent<ButtonAudio>();
- }
- public void SetInit( ){
- mIsInit = true;
- }
- public void OnResume(){
- if (focusDel!=null ){
- focusDel();
- }
- }
- public void OnDestroy()
- {
- if (isPreLoad){
- return;
- }
- UIManager.GetInstance().DestroyUI(this );
- }
- // Use this for initialization
- void Start() {
- if (!mIsInit ){
- UIManager.GetInstance().AddUI(this );
- }
- StartCoroutine(DelayStartAnim() );
- FindButton();
- }
- public void CloseAnim(){
- if (startAnimation != null ){
- DestroyImmediate(startAnimation);
- startAnimation = null;
- }
- if (startAnimator != null ){
- DestroyImmediate(startAnimator);
- startAnimator = null;
- }
- }
- IEnumerator DelayStartAnim(){
- float time = Time.time;
- while(startAnimation!=null&&startAnimation.isPlaying ){
- yield return 1;
- }
- while(startAnimator!=null&&Tools.IsAnimatorPlay(startAnimator )){
- yield return 1;
- }
- yield return 1;
- isFinishAnim = true;
- //Debug.LogWarning("call post anim " + (Time.time - time ));
- if (postAnimDel!=null ){
- postAnimDel();
- }
- }
-
- // Update is called once per frame
- void Update() {
-
- }
- }
|