You've already forked taptap2024_GJ_chidouren
init
This commit is contained in:
67
Assets/Scripts/System/Utils/MultiGraphicControl.cs
Normal file
67
Assets/Scripts/System/Utils/MultiGraphicControl.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
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<ColorTarget> _targets;
|
||||
|
||||
private List<Color> _defaultColors;
|
||||
private bool _isInit;
|
||||
|
||||
private Color DefaultColor (int index)
|
||||
{
|
||||
if (!this._isInit)
|
||||
{
|
||||
this._defaultColors = new List<Color> (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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user