123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using DG.Tweening;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- public class GameEffect : MonoBehaviour
- {
- public void Update()
- {
- }
- public static void callBackEnd(Action<GameObject> callBack, GameObject obj, List<MeshRenderer> mrList, List<Image> imList)
- {
- if (callBack != null)
- {
- callBack.Invoke(obj);
- }
- for (int i = 0; i < imList.Count; i++)
- {
- string mName = imList[i].materialForRendering.name.Split('(')[0];
- string lenCt = mName.Substring(mName.Length - 1);
- if (lenCt == " ")
- {
- mName = mName.Substring(0, mName.Length - 1);
- }
- if (mats.ContainsKey(mName))
- {
- imList[i].material = mats[mName];
- }
- else
- {
- }
- }
- for (int i = 0; i < mrList.Count; i++)
- {
- string mName = mrList[i].sharedMaterial.name.Split('(')[0];
- string lenCt = mName.Substring(mName.Length - 1);
- if (lenCt == " ")
- {
- mName = mName.Substring(0, mName.Length - 1);
- }
- if (mats.ContainsKey(mName))
- {
- mrList[i].material = mats[mName];
- }
- else
- {
- }
- }
- }
- static Dictionary<string, Material> mats = new Dictionary<string, Material>();
- static Renderer[] mrs;
- static Transform[] gos;
- public static void setAlpha(GameObject obj, float f, float time, Action<GameObject> callBack = null)
- {
- if (f == 0)
- {
- f = 0.00001f;
- }
- int callBackCt = 0;
- int callBackEndCt = 0;
- gos = obj.GetComponentsInChildren<Transform>();
- List<MeshRenderer> mrList = new List<MeshRenderer>();
- List<Image> imList = new List<Image>();
- mrs = obj.GetComponentsInChildren<Renderer>();
- // return;
- for (int i = 0; i < gos.Length; i++)
- {
- if (!gos[i].name.Contains("UIRoot") && !gos[i].name.Contains("XRScrollRect") && !gos[i].name.Contains("Viewport")
- && !gos[i].name.Contains("BoxIcon3D") && !gos[i].name.Contains("MenuGroup") && !gos[i].name.Contains("Shortcutkey"))
- {
- MeshRenderer mr = gos[i].GetComponent<MeshRenderer>();
- if (mr != null && mr.sharedMaterial)
- {
- if (!mr.material.HasProperty("_Color"))
- {
- continue;
- }
- string mName = mr.sharedMaterial.name.Split('(')[0];
- string lenCt = mName.Substring(mName.Length - 1);
- if (!mats.ContainsKey(mName) && lenCt != " ")
- {
- mats.Add(mName, mr.sharedMaterial);
- }
- mrList.Add(mr);
- if ((mr.material.color.a <= 0))
- {
- continue;
- }
- if (f > 0.1f)
- {
- mr.material.color = new Color(mr.material.color.r, mr.material.color.g, mr.material.color.b, 0.001f);
- }
- callBackCt++;
- mr.DOKill();
- mr.material.DOFade(f, time).OnKill<Tween>(() =>
- {
- callBackEndCt++;
- if (callBackEndCt >= callBackCt)
- {
- callBackCt = 9999;
- callBackEndCt = 0;
- callBackEnd(callBack, obj, mrList, imList);
- }
- }).OnComplete<Tween>(() =>
- {
- callBackEndCt++;
- if (callBackEndCt >= callBackCt)
- {
- callBackCt = 9999;
- callBackEndCt = 0;
- callBackEnd(callBack, obj, mrList, imList);
- }
- });
- }
- Image im = gos[i].GetComponent<Image>();
- if (im != null)
- {
- if ((im.color.a <= 0))
- {
- continue;
- }
- if (f > 0.1f)
- im.color = new Color(im.color.r, im.color.g, im.color.b, 0.001f);
- callBackCt++;
- im.DOKill();
- im.DOFade(f, time).SetEase<Tween>(Ease.InCirc).OnComplete<Tween>(() =>
- {
- callBackEndCt++;
- if (callBackEndCt >= callBackCt)
- {
- callBackCt = 9999;
- callBackEndCt = 0;
- callBackEnd(callBack, obj, mrList, imList);
- }
- }).OnKill<Tween>(() =>
- {
- callBackEndCt++;
- if (callBackEndCt >= callBackCt)
- {
- callBackCt = 9999;
- callBackEndCt = 0;
- callBackEnd(callBack, obj, mrList, imList);
- }
- });
- if (!im.material.ToString().Contains("Default UI Material"))
- {
- string mName = im.materialForRendering.name.Split('(')[0];
- string lenCt = mName.Substring(mName.Length - 1);
- if (!mats.ContainsKey(mName) && lenCt != " ")
- {
- mats.Add(mName, im.materialForRendering);
- }
- imList.Add(im);
- if (f > 0.1f)
- {
- // im.material.color = new Color(im.material.color.r, im.material.color.g, im.material.color.b, 0.001f);
- }
- callBackCt++;
- im.material.DOFade(f, time).SetEase<Tween>(Ease.InCirc).OnComplete<Tween>(() =>
- {
- callBackEndCt++;
- if (callBackEndCt >= callBackCt)
- {
- callBackCt = 9999;
- callBackEndCt = 0;
- callBackEnd(callBack, obj, mrList, imList);
- }
- }).OnKill<Tween>(() =>
- {
- callBackEndCt++;
- if (callBackEndCt >= callBackCt)
- {
- callBackCt = 9999;
- callBackEndCt = 0;
- callBackEnd(callBack, obj, mrList, imList);
- }
- if (f < 1)
- {
- Color c = im.material.color;
- im.material.color = new Color(c.r, c.g, c.b, 1);
- }
- });
- }
- }
- SpriteRenderer sr = gos[i].GetComponent<SpriteRenderer>();
- if (sr != null)
- {
- if ((sr.color.a <= 0))
- {
- continue;
- }
- if (f > 0.1f)
- sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, 0.001f);
- callBackCt++;
- sr.DOKill();
- sr.DOFade(f, time).SetEase<Tween>(Ease.InCirc).OnComplete<Tween>(() =>
- {
- callBackEndCt++;
- if (callBackEndCt >= callBackCt)
- {
- callBackCt = 9999;
- callBackEndCt = 0;
- callBackEnd(callBack, obj, mrList, imList);
- }
- }).OnKill<Tween>(() =>
- {
- callBackEndCt++;
- if (callBackEndCt >= callBackCt)
- {
- callBackCt = 9999;
- callBackEndCt = 0;
- callBackEnd(callBack, obj, mrList, imList);
- }
- });
- }
- }
- }
- obj.SetActive(true);
- }
- }
|