/// <summary>还原原色</summary> public void RevertColor(GameObject tar) { if (tar == null) { return; } if (!_ColorDic.ContainsKey(tar)) { //Debug.Log("在还原 [" + tar.name + "] 颜色之前未记录!"); return; } SongeUtil.forAllChildren(tar, go => { Renderer r = go.GetComponent <Renderer>(); if (r != null) { foreach (var mat in r.materials) { if (mat != null) { if (_ColorDic[tar].ContainsKey(mat)) { mat.SetColor("_Color", _ColorDic[tar][mat]); if (mat.HasProperty("_Emission")) { mat.SetColor("_Emission", _EmissionDic[tar][mat]); } } } } } }, true); }
public static Bounds?GetBounds(GameObject go) { Bounds?bounds = null; //bounds. Bounds ab; SongeUtil.forAllChildren(go, tar => { if (tar.GetComponent <Renderer>() != null) { Bounds b = tar.GetComponent <Renderer>().bounds; if (bounds == null) { bounds = b; } else { ab = bounds.Value;//对bounds.Value的改变不能作用到bounds上 需要中间变量 ab.Encapsulate(b); bounds = ab; } } }); return(bounds); }
/// <summary>改变颜色</summary> public void ChangeColor(GameObject tar, UnityEngine.Color color) { if (tar == null) { return; } bool hasRecord = _ColorDic.ContainsKey(tar); if (!hasRecord) { _ColorDic.Add(tar, new Dictionary <Material, UnityEngine.Color>()); _EmissionDic.Add(tar, new Dictionary <Material, UnityEngine.Color>()); } SongeUtil.forAllChildren(tar, go => { Renderer r = go.GetComponent <Renderer>(); if (r != null) { foreach (var mat in r.materials) { if (mat != null) { if (!hasRecord) { _ColorDic[tar].Add(mat, mat.GetColor("_Color")); if (mat.HasProperty("_Emission")) { _EmissionDic[tar].Add(mat, mat.GetColor("_Emission")); } } mat.SetColor("_Color", color); if (mat.HasProperty("_Emission")) { mat.SetColor("_Emission", color); } } } } }, true); }