//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, September 29, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
|
|
namespace vnxbqy.UI
|
{
|
|
public class MonsterNameColor
|
{
|
|
static Dictionary<E_MonsterType, List<MonsterNameColorConfig>> monsterNameColors = null;
|
|
public static Color GetColor(E_MonsterType _monsterType, int _heroLevel, int _monsterLevel)
|
{
|
if (monsterNameColors == null)
|
{
|
monsterNameColors = new Dictionary<E_MonsterType, List<MonsterNameColorConfig>>();
|
var allConfig = MonsterNameColorConfig.GetValues();
|
foreach (var config in allConfig)
|
{
|
var monsterType = (E_MonsterType)config.MonsterType;
|
List<MonsterNameColorConfig> colors = null;
|
if (!monsterNameColors.ContainsKey(monsterType))
|
{
|
colors = new List<MonsterNameColorConfig>();
|
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<MonsterNameColorConfig> 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;
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|