using Thousandto.Code.Logic; using Thousandto.Core.Asset; using Thousandto.Editor.Excel; using System.Collections.Generic; using UnityEngine; namespace Thousandto.Editor.ModelEditor { //模型编辑器数据 public class ModelData { public int CfgID { get; set; } public string Name { get; set; } public RoleSkinModelType ModeType { get; set; } public int ModelID { get; set; } public bool IsShow { get; set; } public int ApplyStatus { get; set; } public FModelEffectCode Shader { get; set; } public Color OutLineColor { get; set; } public float OutLineSize { get; set; } public string ShaderParam1 { get; set; } public string ShaderParam2 { get; set; } public string ShaderParam3 { get; set; } public string ShaderParam4 { get; set; } public string ShaderParam5 { get; set; } public List VfxList { get; set; } public string MainTexture { get; set; } public string MaskTexture { get; set; } public ModelTypeCode ModelTypeCode { get; set; } public ModelTypeCode VfxModelTypeCode { get; set; } public ModelShaderInfoBase ShaderParam { get; set; } private string _excelID = string.Empty; private ExcelInfo _excelInfo = null; public ModelData(string id, ExcelInfo excelInfo) { _excelID = id; _excelInfo = excelInfo; CfgID = excelInfo.GetIntValue(id, ModelEditorDefine.Key_Id); Name = excelInfo.GetStringValue(id, ModelEditorDefine.Key_Name); ModeType = (RoleSkinModelType)excelInfo.GetIntValue(id, ModelEditorDefine.Key_Type); ModelTypeCode = ModelDataManager.GetModelType(ModeType); ModelID = excelInfo.GetIntValue(id, ModelEditorDefine.Key_Model); IsShow = excelInfo.GetIntValue(id, ModelEditorDefine.Key_IsShow) != 0; ApplyStatus = excelInfo.GetIntValue(id, ModelEditorDefine.Key_ApplyStatus); Shader = (FModelEffectCode)excelInfo.GetIntValue(id, ModelEditorDefine.Key_Shader); OutLineColor = Color.black; OutLineSize = 0.005f; var outLineParam = excelInfo.GetStringValue(id, ModelEditorDefine.Key_OutLine); var olParams = outLineParam.Split(';'); if (olParams != null && olParams.Length >= 2) { var colorParams = olParams[0].Split('_'); if (colorParams != null && colorParams.Length >= 3) { byte r, g, b; if (byte.TryParse(colorParams[0], out r) && byte.TryParse(colorParams[1], out g) && byte.TryParse(colorParams[2], out b)) { OutLineColor = new Color32(r, g, b, 255); } } float olSize = 0f; if (float.TryParse(olParams[1], out olSize)) { OutLineSize = olSize; } } ShaderParam1 = excelInfo.GetStringValue(id, ModelEditorDefine.Key_ShaderParam1); ShaderParam2 = excelInfo.GetStringValue(id, ModelEditorDefine.Key_ShaderParam2); ShaderParam3 = excelInfo.GetStringValue(id, ModelEditorDefine.Key_ShaderParam3); ShaderParam4 = excelInfo.GetStringValue(id, ModelEditorDefine.Key_ShaderParam4); ShaderParam5 = excelInfo.GetStringValue(id, ModelEditorDefine.Key_ShaderParam5); VfxModelTypeCode = ModelDataManager.GetVfxModelType(ModeType); VfxList = new List(); var vfxParam = excelInfo.GetStringValue(id, ModelEditorDefine.Key_Vfx1); var vfx = ParseVfx(VfxModelTypeCode, vfxParam); if (vfx != null) { VfxList.Add(vfx); } vfxParam = excelInfo.GetStringValue(id, ModelEditorDefine.Key_Vfx2); vfx = ParseVfx(VfxModelTypeCode, vfxParam); if (vfx != null) { VfxList.Add(vfx); } vfxParam = excelInfo.GetStringValue(id, ModelEditorDefine.Key_Vfx3); vfx = ParseVfx(VfxModelTypeCode, vfxParam); if (vfx != null) { VfxList.Add(vfx); } vfxParam = excelInfo.GetStringValue(id, ModelEditorDefine.Key_Vfx4); vfx = ParseVfx(VfxModelTypeCode, vfxParam); if (vfx != null) { VfxList.Add(vfx); } vfxParam = excelInfo.GetStringValue(id, ModelEditorDefine.Key_Vfx5); vfx = ParseVfx(VfxModelTypeCode, vfxParam); if (vfx != null) { VfxList.Add(vfx); } MainTexture = excelInfo.GetStringValue(id, ModelEditorDefine.Key_MainTexture); MaskTexture = excelInfo.GetStringValue(id, ModelEditorDefine.Key_MaskTexture); SetUPShaderParam(); } public void SaveToExcel() { _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Id, CfgID); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Name, Name); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Type, (int)ModeType); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Model, (int)ModelID); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_IsShow, IsShow ? 1 : 0); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_ApplyStatus, ApplyStatus); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Shader, (int)Shader); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_OutLine, string.Format("{0}_{1}_{2};{3}", (int)(OutLineColor.r * 255), (int)(OutLineColor.g * 255), (int)(OutLineColor.b * 255), OutLineSize)); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_ShaderParam1, ShaderParam != null ? ShaderParam.ToString() : ""); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_ShaderParam2, ""); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_ShaderParam3, ""); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_ShaderParam4, ""); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_ShaderParam5, ""); if(VfxList.Count > 0) { _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Vfx1, string.Format("{0}_{1}", VfxList[0].VfxSlot, VfxList[0].VfxID)); } if (VfxList.Count > 1) { _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Vfx2, string.Format("{0}_{1}", VfxList[1].VfxSlot, VfxList[1].VfxID)); } if (VfxList.Count > 2) { _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Vfx3, string.Format("{0}_{1}", VfxList[2].VfxSlot, VfxList[2].VfxID)); } if (VfxList.Count > 3) { _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Vfx4, string.Format("{0}_{1}", VfxList[3].VfxSlot, VfxList[3].VfxID)); } if (VfxList.Count > 4) { _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_Vfx5, string.Format("{0}_{1}", VfxList[4].VfxSlot, VfxList[4].VfxID)); } _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_MainTexture, MainTexture); _excelInfo.SetValue(_excelID, ModelEditorDefine.Key_MaskTexture, MaskTexture); } private ModelVFXInfo ParseVfx(ModelTypeCode vfxModelType, string vfxParam) { var vfxParams = vfxParam.Split('_'); if (vfxParams.Length >= 2) { int slot = 0; int vfxID = 0; if (int.TryParse(vfxParams[0], out slot) && int.TryParse(vfxParams[1], out vfxID)) { ModelVFXInfo vfx = new ModelData.ModelVFXInfo(); vfx.VfxID = vfxID; vfx.VfxSlot = slot; vfx.VfxModeType = vfxModelType; return vfx; } } return null; } public void SetUPShaderParam() { switch (Shader) { case FModelEffectCode.None: ShaderParam = new NormalShaderInfo(); break; case FModelEffectCode.Flow: ShaderParam = new FlowShaderInfo(); break; case FModelEffectCode.Rim: ShaderParam = new RimShaderInfo(); break; case FModelEffectCode.Dissolving: ShaderParam = new DissolvingShaderInfo(); break; case FModelEffectCode.Transparent: ShaderParam = new TransparentShaderInfo(); break; case FModelEffectCode.Cube: ShaderParam = new GlassShaderInfo(); break; case FModelEffectCode.Flux: ShaderParam = new NewFlowShaderInfo(); break; default: ShaderParam = null; break; } if(ShaderParam != null) { var paramText = ShaderParam1.Trim() + ";" + ShaderParam2.Trim() + ";" + ShaderParam3.Trim() + ";" + ShaderParam4.Trim() + ";" + ShaderParam5.Trim(); ShaderParam.Parse(paramText); } } public class ModelVFXInfo { public int VfxID { get; set; } public int VfxSlot { get; set; } public ModelTypeCode VfxModeType { get; set; } } } }