zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/XNodeDemo/NewSkill/RunTime/SkillOption.cs

253 lines
8.7 KiB
C#

using MongoDB.Bson.Serialization.Attributes;
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using ET;
using System;
#if UNITY_EDITOR
using System.Linq;
using UnityEngine;
#endif
namespace Cal
{
#if UNITY
[Serializable]
public class DictionaryInt32Single : Dictionary<int, float>, ISerializationCallbackReceiver
{
[SerializeField] private List<int> keys = new List<int>();
[SerializeField] private List<float> values = new List<float>();
public void OnBeforeSerialize()
{
keys.Clear();
values.Clear();
foreach (KeyValuePair<int, float> pair in this)
{
keys.Add(pair.Key);
values.Add(pair.Value);
}
}
public void OnAfterDeserialize()
{
this.Clear();
if (keys.Count != values.Count)
throw new System.Exception("there are " + keys.Count + " keys and " + values.Count + " values after deserialization. Make sure that both key and value types are serializable.");
for (int i = 0; i < keys.Count; i++)
this.Add(keys[i], values[i]);
}
}
#endif
[GUIColor(0.8f, 0.8f, 1f)]
[BsonIgnoreExtraElements]
[HideReferenceObjectPicker]
[System.Serializable]
public class SkillParam
{
[LabelText("变化性数值")]
[DictionaryDrawerSettings(KeyLabel = "等级", ValueLabel = "数值")]
[ShowIf("skillSourcetype", SkillSourcetype.Changable)]
[BsonDictionaryOptions(Representation = MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
#if UNITY
[SerializeField]
public DictionaryInt32Single values;
#else
public Dictionary<int,float> values;
#endif
[HideInInspector]
public SkillSourcetype skillSourcetype;
#if UNITY
[BsonIgnore]
[LabelText("变化最大等级")]
[PropertyRange(0, 15), PropertyOrder(-1)]
[ShowInInspector]
[ShowIf("skillSourcetype", SkillSourcetype.Changable)]
private int maxLevel
{
get
{
if (values == null)
return 0;
if (values.Count == 0)
return 0;
return values.Last().Key;
}
set
{
var dic = new DictionaryInt32Single();
for (int i = 1; i <= value; i++)
{
if (values != null && values.TryGetValue(i, out var _value))
dic.Add(i, _value);
else
dic.Add(i, 0);
}
values = dic;
}
}
#endif
[LabelText("输入数值")]
[ShowIf("skillSourcetype", SkillSourcetype.Constage)]
public float value;
//#if SERVER
// public SkillDataTableArgs args;
//#endif
#if UNITY_EDITOR
//[LabelText("选择参数")]
//[ShowIf("skillSourcetype", SkillSourcetype.Changable)]
//public SkillDataTableArgs args
//{
// get => SkillDataTableArgs.Args0; set
// {
// if (skillSourcetype == SkillSourcetype.Constage)
// {
// values = null;
// }
// else if (skillSourcetype == SkillSourcetype.Changable)
// {
// if (dic.Count == 0)
// {
// GenerateDic();
// }
// if (!dic.TryGetValue(skillId_, out var _dic))
// {
// Log.Error($"@dic has not the key = {skillId_}");
// return;
// }
// values = new Dictionary<int, float>();
// foreach (var kv in _dic)
// {
// int level = kv.Key;
// if (!kv.Value.TryGetValue((int)value, out var floatValue))
// {
// //Log.Error($"@_dic has not the key = {skillId_} args = {value}");
// continue;
// }
// values.Add(level, floatValue);
// }
// }
// else
// {
// values = null;
// }
// }
//}
#region Excel
// private void GenerateDic()
// {
// NPOI.XSSF.UserModel.XSSFWorkbook workbook;
// using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
// {
// workbook = new XSSFWorkbook(file);
// }
// ISheet sheet = workbook.GetSheetAt(0);
// for (int i = 4; i < 500; i++)
// {
// for (int j = 10; j < 30; j++)
// {
// int id = int.Parse(GetCellString(sheet, i, 1));
// string str = GetCellString(sheet, i, j);
// if (str != "")
// {
// if (!dic.TryGetValue(id / 100, out var _dic))
// {
// dic[id / 100] = _dic = new Dictionary<int, Dictionary<int, float>>();
// }
// if (!_dic.TryGetValue(id % 100, out var __dic))
// {
// _dic[id % 100] = __dic = new Dictionary<int, float>();
// }
// __dic.Add(j - 10, float.Parse(str));
// }
// }
// }
// }
// private static string GetCellString(ISheet sheet, int i, int j)
// {
// IRow _irow = sheet.GetRow(i);
// if (_irow != null)
// {
// return GetCellString(_irow, j);
// }
// return "";
// }
// private static string GetCellString(IRow row, int i)
// {
// ICell _icell = row.GetCell(i);
// if (_icell != null)
// {
// return GetCellString(_icell); ;
// }
// return "";
// }
// private static string GetCellString(ICell cell)
// {
// if (cell != null)
// {
// if (cell.CellType == CellType.Numeric || (cell.CellType == CellType.Formula && cell.CachedFormulaResultType == CellType.Numeric))
// {
// return cell.NumericCellValue.ToString();
// }
// else if (cell.CellType == CellType.String || (cell.CellType == CellType.Formula && cell.CachedFormulaResultType == CellType.String))
// {
// return cell.StringCellValue.ToString();
// }
// else if (cell.CellType == CellType.Boolean || (cell.CellType == CellType.Formula && cell.CachedFormulaResultType == CellType.Boolean))
// {
// return cell.BooleanCellValue.ToString();
// }
// else
// {
// return cell.ToString();
// }
// }
// return "";
// }
#endregion
[Button("不需要数值")]
[ButtonGroup("param")]
void NoneParam()
{
skillSourcetype = SkillSourcetype.None;
values = null;
}
[Button("固定型数值")]
[ButtonGroup("param")]
void InputParam()
{
skillSourcetype = SkillSourcetype.Constage;
values = null;
}
[Button("变化型数值")]
[ButtonGroup("param")]
void DataTableParam()
{
skillSourcetype = SkillSourcetype.Changable;
}
#endif
}
[HideReferenceObjectPicker]
[Serializable]
public class ValueCalculate
{
[LabelText("伤害计算类型")]
public ValueCalculateType calculateType;
[LabelText("伤害系数(XX%)")]
[SerializeField]
public SkillParam param;
}
}