迁移数据表到 Luban,移除 JsonNet、EnumUtility
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using GameFramework;
|
||||
using System;
|
||||
using GameFramework;
|
||||
|
||||
namespace SepCore.CustomUtility
|
||||
{
|
||||
@@ -39,9 +40,19 @@ namespace SepCore.CustomUtility
|
||||
return Utility.Text.Format("Assets/GameMain/Sounds/{0}.wav", assetName);
|
||||
}
|
||||
|
||||
public static string GetEntityAsset(string assetName)
|
||||
public static string GetEntityAsset(string assetPath)
|
||||
{
|
||||
return Utility.Text.Format("Assets/GameMain/Entities/{0}.prefab", assetName);
|
||||
if (string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (assetPath.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Utility.Text.Format("Assets/GameMain/Entities/{0}", assetPath);
|
||||
}
|
||||
|
||||
return Utility.Text.Format("Assets/GameMain/Entities/{0}.prefab", assetPath);
|
||||
}
|
||||
|
||||
public static string GetUIFormAsset(string assetName)
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.CustomUtility
|
||||
{
|
||||
public static class EnumUtility<T> where T : struct, System.Enum
|
||||
{
|
||||
private static readonly Dictionary<string, T> _enumCache = new();
|
||||
|
||||
public static T Get(string value)
|
||||
{
|
||||
if (!_enumCache.TryGetValue(value, out T result))
|
||||
{
|
||||
if (System.Enum.TryParse(value, true, out result))
|
||||
{
|
||||
_enumCache[value] = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"Enum 解析失败:类型:{typeof(T).Name} 不包含值 {value}");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a39ac998e79e504fa643b459880ee9e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SepCore.CustomUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// Newtonsoft.Json 函数集辅助器。
|
||||
/// </summary>
|
||||
public class JsonNetUtility : GameFramework.Utility.Json.IJsonHelper
|
||||
{
|
||||
public string ToJson(object obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj);
|
||||
}
|
||||
|
||||
public T ToObject<T>(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
|
||||
public object ToObject(Type objectType, string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(json, objectType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2eb0a4b148e1c24ebc91cb3a2ef3180
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,89 +0,0 @@
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using GameFramework.DataTable;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.CustomUtility
|
||||
{
|
||||
public static class RarityUtility
|
||||
{
|
||||
public static ItemRarity SelectRarityForLevel(IDataTable<DRLevelRarity> table, int level)
|
||||
{
|
||||
DRLevelRarity row = GetLevelRarityRow(table, level);
|
||||
if (row == null)
|
||||
{
|
||||
return ItemRarity.White;
|
||||
}
|
||||
|
||||
int white = Mathf.Max(0, row.WhiteWeight);
|
||||
int green = Mathf.Max(0, row.GreenWeight);
|
||||
int blue = Mathf.Max(0, row.BlueWeight);
|
||||
int purple = Mathf.Max(0, row.PurpleWeight);
|
||||
int red = Mathf.Max(0, row.RedWeight);
|
||||
|
||||
int total = white + green + blue + purple + red;
|
||||
if (total <= 0)
|
||||
{
|
||||
return ItemRarity.White;
|
||||
}
|
||||
|
||||
int roll = Random.Range(1, total + 1);
|
||||
if (roll <= white) return ItemRarity.White;
|
||||
roll -= white;
|
||||
if (roll <= green) return ItemRarity.Green;
|
||||
roll -= green;
|
||||
if (roll <= blue) return ItemRarity.Blue;
|
||||
roll -= blue;
|
||||
if (roll <= purple) return ItemRarity.Purple;
|
||||
return ItemRarity.Red;
|
||||
}
|
||||
|
||||
private static DRLevelRarity GetLevelRarityRow(IDataTable<DRLevelRarity> table, int level)
|
||||
{
|
||||
if (table == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
DRLevelRarity[] rows = table.GetAllDataRows();
|
||||
if (rows == null || rows.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int safeLevel = Mathf.Max(1, level);
|
||||
DRLevelRarity below = null;
|
||||
DRLevelRarity above = null;
|
||||
|
||||
foreach (DRLevelRarity row in rows)
|
||||
{
|
||||
if (row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (safeLevel >= row.LevelMin && safeLevel <= row.LevelMax)
|
||||
{
|
||||
return row;
|
||||
}
|
||||
|
||||
if (safeLevel < row.LevelMin)
|
||||
{
|
||||
if (above == null || row.LevelMin < above.LevelMin)
|
||||
{
|
||||
above = row;
|
||||
}
|
||||
}
|
||||
else if (safeLevel > row.LevelMax)
|
||||
{
|
||||
if (below == null || row.LevelMax > below.LevelMax)
|
||||
{
|
||||
below = row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return above ?? below;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9186261c82d4f0b8270048f08158b0f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user