mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交GAS 打算做一个帧同步的GAS
This commit is contained in:
22
JEX_GAS/Assets/GAS/Runtime/Utils/AttributeValidator.cs
Normal file
22
JEX_GAS/Assets/GAS/Runtime/Utils/AttributeValidator.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace GAS.Runtime
|
||||
{
|
||||
public static class AttributeValidator
|
||||
{
|
||||
/// <summary>
|
||||
/// 校验属性名称是否有效.
|
||||
/// <example>
|
||||
/// 使用示例:
|
||||
/// <code>
|
||||
/// [ValidateInput("@AttributeValidator.IsValidAttributeName($value)", "属性名无效")]
|
||||
/// public string AttributeName;
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
public static bool IsValidAttributeName(string attributeName)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(attributeName) && ReflectionHelper.AttributeNames.Any(x => x == attributeName);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8ed453ad03c42ab888ae6e1aa021020
|
||||
timeCreated: 1723708236
|
220
JEX_GAS/Assets/GAS/Runtime/Utils/ReflectionHelper.cs
Normal file
220
JEX_GAS/Assets/GAS/Runtime/Utils/ReflectionHelper.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using GAS.General;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GAS.Runtime
|
||||
{
|
||||
public static class ReflectionHelper
|
||||
{
|
||||
#region AttributeSetNames
|
||||
|
||||
private static string[] _attributeSetNames;
|
||||
|
||||
public static IEnumerable<string> AttributeSetNames
|
||||
{
|
||||
get
|
||||
{
|
||||
_attributeSetNames ??= LoadAttributeSetNames();
|
||||
return _attributeSetNames;
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] LoadAttributeSetNames()
|
||||
{
|
||||
var libType = TypeUtil.FindTypeInAllAssemblies("GAS.Runtime.GAttrSetLib");
|
||||
if (libType == null)
|
||||
{
|
||||
Debug.LogError("[EX] Type 'GAttrSetLib' not found. Please generate the GAttrSetLib CODE first!");
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
const string fieldName = "AttrSetTypeDict";
|
||||
var field = libType.GetField(fieldName, BindingFlags.Public | BindingFlags.Static);
|
||||
if (field == null)
|
||||
{
|
||||
Debug.LogError($"[EX] Field \"{fieldName}\" not found in GAttrSetLib!");
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
var value = field.GetValue(null);
|
||||
if (value is not Dictionary<string, Type> dict)
|
||||
{
|
||||
Debug.LogError($"[EX] Field \"{fieldName}\" is not a Dictionary<string, Type> in GAttrSetLib!");
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
return dict.Keys.ToArray();
|
||||
}
|
||||
|
||||
#endregion AttributeSetNames
|
||||
|
||||
#region AttributeNames
|
||||
|
||||
private static string[] _attributeNames;
|
||||
|
||||
public static IEnumerable<string> AttributeNames
|
||||
{
|
||||
get
|
||||
{
|
||||
_attributeNames ??= LoadAttributeNames();
|
||||
return _attributeNames;
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] LoadAttributeNames()
|
||||
{
|
||||
var libType = TypeUtil.FindTypeInAllAssemblies("GAS.Runtime.GAttrSetLib");
|
||||
if (libType == null)
|
||||
{
|
||||
Debug.LogError("[EX] Type 'GAttrSetLib' not found. Please generate the GAttrSetLib CODE first!");
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
const string fieldName = "AttributeFullNames";
|
||||
var field = libType.GetField(fieldName, BindingFlags.Public | BindingFlags.Static);
|
||||
if (field == null)
|
||||
{
|
||||
Debug.LogError($"[EX] Field \"{fieldName}\" not found in GAttrSetLib!");
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
var value = field.GetValue(null);
|
||||
if (value is not List<string> list)
|
||||
{
|
||||
Debug.LogError($"[EX] Field \"{fieldName}\" is not a List<string> in GAttrSetLib!");
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
#endregion AttributeNames
|
||||
|
||||
#region Attributes
|
||||
|
||||
private static Dictionary<string, AttributeSet> _attributeSetDict;
|
||||
private static Dictionary<string, AttributeBase> _attributeDict;
|
||||
private static AttributeBase[] _attributes;
|
||||
|
||||
public static IEnumerable<AttributeBase> Attributes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_attributes == null)
|
||||
{
|
||||
LoadAttributes();
|
||||
}
|
||||
|
||||
return _attributes;
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadAttributes()
|
||||
{
|
||||
_attributes = AttributeNames.Select(x =>
|
||||
{
|
||||
var strings = x.Split('.');
|
||||
return LoadAttribute(strings[0], strings[1]);
|
||||
}).Where(x => x != null).ToArray();
|
||||
}
|
||||
|
||||
|
||||
public static AttributeBase GetAttribute(string attributeFullName)
|
||||
{
|
||||
if (_attributes == null)
|
||||
{
|
||||
LoadAttributes();
|
||||
}
|
||||
|
||||
_attributeDict.TryGetValue(attributeFullName, out var attr);
|
||||
return attr;
|
||||
}
|
||||
|
||||
public static AttributeBase GetAttribute(string attrSetName, string attrName)
|
||||
{
|
||||
return GetAttribute(attrSetName + "." + attrName);
|
||||
}
|
||||
|
||||
private static AttributeBase LoadAttribute(string attrSetName, string attrName)
|
||||
{
|
||||
_attributeSetDict ??= new();
|
||||
_attributeDict ??= new();
|
||||
if (!_attributeSetDict.TryGetValue(attrSetName, out var attrSet))
|
||||
{
|
||||
var fullName = $"GAS.Runtime.{attrSetName}";
|
||||
var type = TypeUtil.FindTypeInAllAssemblies(fullName);
|
||||
if (type == null)
|
||||
{
|
||||
Debug.LogError($"[EX] attr set Type '{fullName}' not found. Please generate the GAttrSetLib CODE first!");
|
||||
return null;
|
||||
}
|
||||
|
||||
attrSet = Activator.CreateInstance(type) as AttributeSet;
|
||||
_attributeSetDict[attrSetName] = attrSet;
|
||||
}
|
||||
|
||||
if (attrSet == null)
|
||||
{
|
||||
Debug.LogError($"[EX] attr set '{attrSetName}' is null. Please generate the GAttrSetLib CODE first!");
|
||||
return null;
|
||||
}
|
||||
|
||||
var attr = attrSet[attrName];
|
||||
if (attr == null)
|
||||
{
|
||||
Debug.LogError($"[EX] attr '{attrSetName}.{attrName}' is null. Please generate the GAttrSetLib CODE first!");
|
||||
return null;
|
||||
}
|
||||
|
||||
_attributeDict[attr.Name] = attr;
|
||||
return attr;
|
||||
}
|
||||
|
||||
#endregion Attributes
|
||||
|
||||
#region GameplayTags
|
||||
|
||||
private static GameplayTag[] _gameplayTags;
|
||||
|
||||
public static IEnumerable<GameplayTag> GameplayTags
|
||||
{
|
||||
get
|
||||
{
|
||||
_gameplayTags ??= LoadTags();
|
||||
return _gameplayTags;
|
||||
}
|
||||
}
|
||||
|
||||
private static GameplayTag[] LoadTags()
|
||||
{
|
||||
var tagLibType = TypeUtil.FindTypeInAllAssemblies("GAS.Runtime.GTagLib");
|
||||
if (tagLibType == null)
|
||||
{
|
||||
Debug.LogError("[EX] Type 'GTagLib' not found. Please generate the TAGS CODE first!");
|
||||
return Array.Empty<GameplayTag>();
|
||||
}
|
||||
|
||||
const string fieldName = "TagMap";
|
||||
var field = tagLibType.GetField("TagMap", BindingFlags.Public | BindingFlags.Static);
|
||||
if (field == null)
|
||||
{
|
||||
Debug.LogError($"[EX] Field \"{fieldName}\" not found in GTagLib!");
|
||||
return Array.Empty<GameplayTag>();
|
||||
}
|
||||
|
||||
var value = field.GetValue(null);
|
||||
if (value is not Dictionary<string, GameplayTag> tagMap)
|
||||
{
|
||||
Debug.LogError($"[EX] Field \"{fieldName}\" is not a Dictionary<string, GameplayTag> in GTagLib!");
|
||||
return Array.Empty<GameplayTag>();
|
||||
}
|
||||
|
||||
return tagMap.Values.ToArray();
|
||||
}
|
||||
|
||||
#endregion GameplayTags
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 466100b4f1cc4a8898633bbf9e9085a1
|
||||
timeCreated: 1716454050
|
10
JEX_GAS/Assets/GAS/Runtime/Utils/TagHelper.cs
Normal file
10
JEX_GAS/Assets/GAS/Runtime/Utils/TagHelper.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace GAS.Runtime
|
||||
{
|
||||
public static class TagHelper
|
||||
{
|
||||
public static GameplayTag[] Sort(IEnumerable<GameplayTag> tags) => tags.OrderBy(tag => tag.Name).ToArray();
|
||||
}
|
||||
}
|
3
JEX_GAS/Assets/GAS/Runtime/Utils/TagHelper.cs.meta
Normal file
3
JEX_GAS/Assets/GAS/Runtime/Utils/TagHelper.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a08771ffd5734515aebaac52e31b2998
|
||||
timeCreated: 1724145317
|
58
JEX_GAS/Assets/GAS/Runtime/Utils/ValueDropdownHelper.cs
Normal file
58
JEX_GAS/Assets/GAS/Runtime/Utils/ValueDropdownHelper.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Sirenix.OdinInspector;
|
||||
|
||||
namespace GAS.Runtime
|
||||
{
|
||||
public static class ValueDropdownHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 显示一个下列列表, 包含所有的属性集名称.
|
||||
/// <example>
|
||||
/// 使用示例:
|
||||
/// <code>
|
||||
/// [ValueDropdown("@ValueDropdownHelper.AttributeSetChoices", IsUniqueList = true)]
|
||||
/// public string AttributeSet;
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
public static IEnumerable<string> AttributeSetChoices => ReflectionHelper.AttributeSetNames;
|
||||
|
||||
/// <summary>
|
||||
/// 显示一个下拉列表,包含所有的属性名称.
|
||||
/// <example>
|
||||
/// 使用示例:
|
||||
/// <code>
|
||||
/// [ValueDropdown("@ValueDropdownHelper.AttributeChoices", IsUniqueList = true)]
|
||||
/// public string Attribute;
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
public static IEnumerable<string> AttributeChoices => ReflectionHelper.AttributeNames;
|
||||
|
||||
private static ValueDropdownItem[] _gameplayTagChoices;
|
||||
|
||||
/// <summary>
|
||||
/// 显示一个下拉列表,包含所有的GameplayTag.
|
||||
/// <example>
|
||||
/// 使用示例:
|
||||
/// <code>
|
||||
/// [ValueDropdown("@ValueDropdownHelper.GameplayTagChoices", IsUniqueList = true, HideChildProperties = true)]
|
||||
/// public GameplayTag[] Tags;
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
public static IEnumerable<ValueDropdownItem> GameplayTagChoices
|
||||
{
|
||||
get
|
||||
{
|
||||
_gameplayTagChoices ??= ReflectionHelper.GameplayTags
|
||||
.Select(gameplayTag => new ValueDropdownItem(gameplayTag.Name, gameplayTag))
|
||||
.ToArray();
|
||||
return _gameplayTagChoices;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1123ed56f57e41218ce90ca53e5f7058
|
||||
timeCreated: 1716465180
|
Reference in New Issue
Block a user