//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Friday, September 29, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using TableConfig; namespace Snxxz.UI { public class MonsterNameColor { static Dictionary> monsterNameColors = null; public static Color GetColor(E_MonsterType _monsterType, int _heroLevel, int _monsterLevel) { if (monsterNameColors == null) { monsterNameColors = new Dictionary>(); var allConfig = Config.Instance.GetAllValues(); foreach (var config in allConfig) { var monsterType = (E_MonsterType)config.MonsterType; List colors = null; if (!monsterNameColors.ContainsKey(monsterType)) { colors = new List(); monsterNameColors[monsterType] = colors; } else { colors = monsterNameColors[monsterType]; } colors.Add(config); } foreach (var key in monsterNameColors.Keys) { var colors = monsterNameColors[key]; colors.Sort( (MonsterNameColorConfig a, MonsterNameColorConfig b) => { return a.LevelDelta < b.LevelDelta ? -1 : 1; } ); } } int levelDelta = _monsterLevel - _heroLevel; List nameColors = null; if (monsterNameColors.TryGetValue(_monsterType, out nameColors)) { for (int i = 0; i < nameColors.Count; i++) { var config = nameColors[i]; if (levelDelta < config.LevelDelta || i == nameColors.Count - 1) { return new Color(config.Color.x, config.Color.y, config.Color.z, 1); } } return Color.white; } else { return Color.white; } } } }