hch
5 小时以前 cba555476b1f1b856b9211451e739d8cdce0eeba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
[CreateAssetMenu(menuName = "Config/EnableButtonConfig")]
public class EnableButtonConfig : ScriptableObject
{
    [SerializeField] EnableButtonType type;
    [SerializeField] EnableButtonStyle enableButton;
    [SerializeField] EnableButtonStyle unEnableButton;
 
    public static Dictionary<EnableButtonType, EnableButtonConfig> dict = new Dictionary<EnableButtonType, EnableButtonConfig>();
 
    public static void SetEnable(Button _btn, Text _text, bool _enable, EnableButtonType _type)
    {
        var _cfg = GetEnableButtonCfg(_type);
        var _btnStyle = _enable ? _cfg.enableButton : _cfg.unEnableButton;
        _btn.interactable = _enable;
        var _colors = _btn.colors;
        _colors.disabledColor = Color.white;
        _btn.colors = _colors;
        _btn.image.SetSprite(_btnStyle.iconKey);
        _text.fontSize = _btnStyle.fontSize;
        _text.color = _btnStyle.fontColor;
    }
 
    public static EnableButtonConfig GetEnableButtonCfg(EnableButtonType _type)
    {
        if (dict.ContainsKey(_type))
        {
            return dict[_type];
        }
        var _cfg= BuiltInLoader.LoadScriptableObject<EnableButtonConfig>(StringUtility.Contact("EnableButton_", _type));
        dict.Add(_type, _cfg);
        return _cfg;
    }
 
    [Serializable]
    public struct EnableButtonStyle
    {
        public string iconKey;
        public Color fontColor;
        public int fontSize;
    }
 
    public enum EnableButtonType
    {
        Default,
    }
}