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 callBack, GameObject obj, List mrList, List 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 mats = new Dictionary(); static Renderer[] mrs; static Transform[] gos; public static void setAlpha(GameObject obj, float f, float time, Action callBack = null) { if (f == 0) { f = 0.00001f; } int callBackCt = 0; int callBackEndCt = 0; gos = obj.GetComponentsInChildren(); List mrList = new List(); List imList = new List(); mrs = obj.GetComponentsInChildren(); // 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(); 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(() => { callBackEndCt++; if (callBackEndCt >= callBackCt) { callBackCt = 9999; callBackEndCt = 0; callBackEnd(callBack, obj, mrList, imList); } }).OnComplete(() => { callBackEndCt++; if (callBackEndCt >= callBackCt) { callBackCt = 9999; callBackEndCt = 0; callBackEnd(callBack, obj, mrList, imList); } }); } Image im = gos[i].GetComponent(); 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(Ease.InCirc).OnComplete(() => { callBackEndCt++; if (callBackEndCt >= callBackCt) { callBackCt = 9999; callBackEndCt = 0; callBackEnd(callBack, obj, mrList, imList); } }).OnKill(() => { 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(Ease.InCirc).OnComplete(() => { callBackEndCt++; if (callBackEndCt >= callBackCt) { callBackCt = 9999; callBackEndCt = 0; callBackEnd(callBack, obj, mrList, imList); } }).OnKill(() => { 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(); 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(Ease.InCirc).OnComplete(() => { callBackEndCt++; if (callBackEndCt >= callBackCt) { callBackCt = 9999; callBackEndCt = 0; callBackEnd(callBack, obj, mrList, imList); } }).OnKill(() => { callBackEndCt++; if (callBackEndCt >= callBackCt) { callBackCt = 9999; callBackEndCt = 0; callBackEnd(callBack, obj, mrList, imList); } }); } } } obj.SetActive(true); } }