using System.Collections.Generic; using System.RandomPool; using Game.Data; using Sirenix.OdinInspector; using UnityEngine; namespace System.Utils { public class MultiGraphicControl : MonoBehaviour { [SerializeField, BoxGroup ("CustomTarget"), Title ("颜色控制目标")] public List _targets; private List _defaultColors; private bool _isInit; private Color DefaultColor (int index) { if (!this._isInit) { this._defaultColors = new List (this._targets.Count); foreach (var colorTarget in this._targets) { if (colorTarget._graphic == null) { this._defaultColors.Add (Color.white); } else { this._defaultColors.Add (colorTarget._graphic.color); } } this._isInit = true; } return this._defaultColors[index]; } public void SetColor (Color color) { if (this._targets?.Count > 0) { for (int i = 0; i < this._targets.Count; i++) { var target = this._targets[i]; var defColor = this.DefaultColor(i); if (target._graphic != null) { target._graphic.color = target._isCustomColor ? color * target._customColor : color * defColor; } } } } public void ResetDefaultColor () { for (int i = 0; i < this._targets.Count; i++) { this._targets[i]._graphic.color = this.DefaultColor(i); } } } }