246 lines
8.9 KiB
C#
246 lines
8.9 KiB
C#
using Thousandto.Cfg.Data;
|
|
using Thousandto.Core.Asset;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.Code.Logic
|
|
{
|
|
//ModelConfig的配置信息
|
|
public class FSkinModelConfig
|
|
{
|
|
//配置ID
|
|
public int CfgID { get; private set; }
|
|
//模型ID
|
|
public int ModelID { get; private set; }
|
|
//模型类型
|
|
public ModelTypeCode ModelType { get; private set; }
|
|
//是否是展示模型
|
|
public bool IsShow { get; private set; }
|
|
//模型效果ID
|
|
public int ModelEffectID { get; private set; }
|
|
//Shader的属性信息
|
|
public Dictionary<int, object> ShaderProperties { get; private set; }
|
|
//特效列表
|
|
public List<VFXCfgInfo> VfxList { get; private set; }
|
|
//特效类型
|
|
public ModelTypeCode VFXType { get; private set; }
|
|
//适用的状态
|
|
public FSkinStatusCode ApplyStatus { get; private set; }
|
|
//Outline的颜色
|
|
public Color OutLineColor { get; private set; }
|
|
//Outline的宽度
|
|
public float OutLineWidth { get; private set; }
|
|
|
|
|
|
//私有构造函数--外面不允许创建此类
|
|
private FSkinModelConfig(DeclareModelConfig cfg)
|
|
{
|
|
CfgID = cfg.Id;
|
|
ModelID = cfg.Model;
|
|
ModelTypeCode vfxType;
|
|
IsShow = cfg.IsShow > 0;
|
|
ModelType = GetModelType((RoleSkinModelType)cfg.Type,out vfxType);
|
|
VFXType = cfg.VfxType<=0? vfxType: (ModelTypeCode)cfg.VfxType;
|
|
//处理Shader相关
|
|
ModelEffectID = cfg.Shader;
|
|
if (ModelEffectID >= 0)
|
|
{
|
|
//通用的Shader属性
|
|
ShaderProperties = FSkinShaderRelation.GetEffectProperties(ModelEffectID, cfg.SharderParam1.Trim() + ";" + cfg.SharderParam2.Trim() + ";" + cfg.SharderParam3.Trim() + ";" + cfg.SharderParam4.Trim() + ";" + cfg.SharderParam5.Trim());
|
|
//描边的属性
|
|
var arr = cfg.OutLineParam.Split(FSkinShaderRelation.CN_PROPERTY_SPLIT_CHAR, StringSplitOptions.RemoveEmptyEntries);
|
|
if (arr.Length > 1)
|
|
{
|
|
OutLineColor = Color.black;
|
|
OutLineWidth = 0.005f;
|
|
|
|
Color c = Color.black;
|
|
if (FSkinShaderRelation.TryParseColorText(arr[0], ref c))
|
|
{
|
|
OutLineColor = c;
|
|
}
|
|
|
|
float f = 0;
|
|
if (FSkinShaderRelation.TryParseFloatText(arr[1], ref f))
|
|
{
|
|
OutLineWidth = f;
|
|
}
|
|
|
|
//模型效果ID
|
|
if (ModelEffectID > 0)
|
|
{
|
|
//ShaderProperties[ShaderPropertyNameDefine.CN_SPN_OUTLINECOLOR] = OutLineColor;
|
|
// ShaderProperties[ShaderPropertyNameDefine.CN_SPN_OUTLINE] = OutLineWidth;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//设置适用的状态
|
|
if (cfg.ApplyStatus <= 0)
|
|
ApplyStatus = FSkinStatusCode.Normal;
|
|
else
|
|
ApplyStatus = (FSkinStatusCode)cfg.ApplyStatus;
|
|
|
|
//提取关联的特效
|
|
VfxList = new List<VFXCfgInfo>();
|
|
VFXCfgInfo vfxinfo;
|
|
if (TryParseVfx(cfg.Vfx1, out vfxinfo)) VfxList.Add(vfxinfo);
|
|
if (TryParseVfx(cfg.Vfx2, out vfxinfo)) VfxList.Add(vfxinfo);
|
|
if (TryParseVfx(cfg.Vfx3, out vfxinfo)) VfxList.Add(vfxinfo);
|
|
if (TryParseVfx(cfg.Vfx4, out vfxinfo)) VfxList.Add(vfxinfo);
|
|
if (TryParseVfx(cfg.Vfx5, out vfxinfo)) VfxList.Add(vfxinfo);
|
|
|
|
}
|
|
|
|
//获取Shader名字
|
|
public string GetShaderName(FSkinTypeCode skinType)
|
|
{
|
|
if (ModelEffectID >= 0)
|
|
{
|
|
return FSkinShaderRelation.GetModelShader(skinType, ModelType, ModelEffectID);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
//获取模型路径
|
|
public string GetModelPath(ref List<string> vfxPathList)
|
|
{
|
|
for (int i = 0; i < VfxList.Count; i++)
|
|
{
|
|
vfxPathList.Add(VfxList[i].GetVFXPath());
|
|
}
|
|
return AssetUtils.GetModelAssetPath(ModelType, ModelID, IsShow);
|
|
}
|
|
|
|
//分析特效
|
|
private bool TryParseVfx(string vfxStr,out VFXCfgInfo vfx)
|
|
{
|
|
vfx = new VFXCfgInfo();
|
|
if (string.IsNullOrEmpty(vfxStr)) return false;
|
|
var arr = vfxStr.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
|
|
if (arr.Length > 1)
|
|
{
|
|
int slotID;
|
|
if (int.TryParse(arr[0], out slotID))
|
|
{
|
|
int vfxID;
|
|
if (int.TryParse(arr[1], out vfxID))
|
|
{
|
|
var slotName = SlotUtils.GetSlotName((Slot)slotID);
|
|
vfx.VfxID = vfxID;
|
|
vfx.SlotName = slotName;
|
|
vfx.VfxType = VFXType;
|
|
return true;
|
|
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
//从表格中获取模型类型
|
|
private ModelTypeCode GetModelType(RoleSkinModelType type,out ModelTypeCode vfx)
|
|
{
|
|
switch (type)
|
|
{
|
|
case RoleSkinModelType.PlayerBody://角色身体
|
|
vfx = ModelTypeCode.BodyVFX;
|
|
return ModelTypeCode.Player;
|
|
case RoleSkinModelType.PlayerWeapon://武器
|
|
vfx = ModelTypeCode.WeaponVFX;
|
|
return ModelTypeCode.Weapon;
|
|
case RoleSkinModelType.GodWeapon://神兵武器
|
|
vfx = ModelTypeCode.WeaponVFX;
|
|
return ModelTypeCode.GodWeapon;
|
|
case RoleSkinModelType.PlayerWing: //翅膀
|
|
vfx = ModelTypeCode.WingVFX;
|
|
return ModelTypeCode.Wing;
|
|
case RoleSkinModelType.PlayerMount://角色坐骑
|
|
vfx = ModelTypeCode.MountVFX;
|
|
return ModelTypeCode.Mount;
|
|
case RoleSkinModelType.MonsterBody://怪物,npc主体
|
|
vfx = ModelTypeCode.MonsterVFX;
|
|
return ModelTypeCode.Monster;
|
|
case RoleSkinModelType.CollectionBody://采集物主体
|
|
vfx = ModelTypeCode.CollectionVFX;
|
|
return ModelTypeCode.Object;
|
|
case RoleSkinModelType.PlayerStrengthenVfx://角色强化特效
|
|
vfx = ModelTypeCode.BodyVFX;
|
|
return ModelTypeCode.StrengthenVfx;
|
|
case RoleSkinModelType.DrapItem: //用于展示的武器
|
|
vfx = ModelTypeCode.OtherVFX;
|
|
return ModelTypeCode.Object;
|
|
case RoleSkinModelType.GodWeaponVfx:
|
|
vfx = ModelTypeCode.WeaponVFX;
|
|
return ModelTypeCode.WeaponVFX;
|
|
case RoleSkinModelType.UISceneModel:
|
|
vfx = ModelTypeCode.OtherVFX;
|
|
return ModelTypeCode.UISceneModel;
|
|
default:
|
|
vfx = ModelTypeCode.OtherVFX;
|
|
return ModelTypeCode.Object;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#region//静态方法 -- 读取解析后的ModelConfig
|
|
//存储解析后的ModelConfig
|
|
private static Dictionary<int, FSkinModelConfig> _cacheData = new Dictionary<int, FSkinModelConfig>();
|
|
public static Dictionary<int, FSkinModelConfig> CacheData
|
|
{
|
|
get
|
|
{
|
|
return _cacheData;
|
|
}
|
|
}
|
|
//根据配置ID获取配置数据
|
|
public static FSkinModelConfig GetConfigData(int id)
|
|
{
|
|
if (id > 0)
|
|
{
|
|
FSkinModelConfig cfg = null;
|
|
if (_cacheData.TryGetValue(id, out cfg))
|
|
{
|
|
return cfg;
|
|
}
|
|
else
|
|
{
|
|
var modelcfg = DeclareModelConfig.Get(id);
|
|
if (modelcfg != null)
|
|
{
|
|
cfg = new Logic.FSkinModelConfig(modelcfg);
|
|
_cacheData[id] = cfg;
|
|
return cfg;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
#endregion
|
|
|
|
#region//特效处理
|
|
//特效的信息
|
|
public struct VFXCfgInfo
|
|
{
|
|
//插槽名字
|
|
public string SlotName;
|
|
//特效类型
|
|
public ModelTypeCode VfxType;
|
|
//特效ID
|
|
public int VfxID;
|
|
|
|
public string GetVFXPath()
|
|
{
|
|
return AssetUtils.GetModelAssetPath(VfxType, VfxID);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|