mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
临时提交
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
namespace BehaviorTreeSlayer
|
||||
{
|
||||
|
||||
public class NoCreate : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class OutField : Attribute
|
||||
{
|
||||
public Type FieldType;
|
||||
|
||||
public OutField()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public OutField(Type fieldType)
|
||||
{
|
||||
FieldType = fieldType;
|
||||
}
|
||||
}
|
||||
public class ShowMe : Attribute
|
||||
{
|
||||
public string ShowMsg;
|
||||
|
||||
public ShowMe()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ShowMe(string showMsg)
|
||||
{
|
||||
ShowMsg = showMsg;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed213ded68349aa4bbc16893a3763ba3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace BehaviorTreeSlayer
|
||||
{
|
||||
public class SlayerUtils
|
||||
{
|
||||
static Dictionary<Type, Func<string, object>> dic = new Dictionary<Type, Func<string, object>>();
|
||||
public static Dictionary<Type, Func<string, object>> Dic => dic;
|
||||
public static void RegistCustomParser<T>(Func<string, object> func)
|
||||
{
|
||||
Type key = typeof(T);
|
||||
if (dic.ContainsKey(key))
|
||||
{
|
||||
dic[key] = func;
|
||||
}
|
||||
else
|
||||
{
|
||||
dic.Add(key, func);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74e1ebc0a31342545a0c4bdc5dc65344
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
78
JNFrame/Assets/BehaviorTreeSlayer/Scripts/Utils/XmlUtils.cs
Normal file
78
JNFrame/Assets/BehaviorTreeSlayer/Scripts/Utils/XmlUtils.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace BehaviorTreeSlayer
|
||||
{
|
||||
public class XmlUtils
|
||||
{
|
||||
public static T DeSerialize<T>(string path, string name)
|
||||
{
|
||||
FileStream fileStream = File.Open(path + "/" + name, FileMode.Open);
|
||||
XmlSerializer xml = new XmlSerializer(typeof(T));
|
||||
T list;
|
||||
try
|
||||
{
|
||||
list = (T)xml.Deserialize(fileStream);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
fileStream.Close();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public static T DeSerialize<T>(string text)
|
||||
{
|
||||
using (StringReader sr = new StringReader(text))
|
||||
{
|
||||
XmlSerializer xs = new XmlSerializer(typeof(T), Types);
|
||||
return (T)xs.Deserialize(sr);
|
||||
}
|
||||
}
|
||||
public static void XmlWriter<T>(T obj, string path)
|
||||
{
|
||||
using (FileStream fs = new FileStream(path, FileMode.Create))
|
||||
{
|
||||
XmlSerializer xml = new XmlSerializer(obj.GetType(), Types);
|
||||
xml.Serialize(fs, obj);
|
||||
}
|
||||
}
|
||||
static Type[] types;
|
||||
|
||||
public static Type[] Types
|
||||
{
|
||||
get
|
||||
{
|
||||
if (types == null)
|
||||
{
|
||||
types = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(a => a.GetTypes().Where(t => t.IsSubclassOf(typeof(TreeNode))))
|
||||
.ToArray();
|
||||
}
|
||||
return types;
|
||||
}
|
||||
}
|
||||
|
||||
public static string XmlSerialize<T>(T obj)
|
||||
{
|
||||
string s;
|
||||
|
||||
//派生类序列化
|
||||
XmlSerializer xml = new XmlSerializer(obj.GetType(), Types);
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
xml.Serialize(ms, obj);
|
||||
s = Encoding.UTF8.GetString(ms.ToArray());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93d2405f000836c41afde6b189b28771
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user