存档功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -74,10 +75,50 @@ namespace AibisDream.Utility
|
||||
public static Vector3 GetMouseWorldPos(Vector3 mousePoint, Transform transform)
|
||||
{
|
||||
if (!_mainCam) _mainCam = Camera.main;
|
||||
|
||||
|
||||
mousePoint.z = _mainCam.WorldToScreenPoint(transform.position).z;
|
||||
return _mainCam.ScreenToWorldPoint(mousePoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 属性复制
|
||||
/// </summary>
|
||||
/// <param name="source">属性源</param>
|
||||
/// <param name="target">属性目标</param>
|
||||
public static void CopyProperties(object source, object target)
|
||||
{
|
||||
var sourceProperties = source.GetType().GetProperties();
|
||||
var targetProperties = target.GetType().GetProperties();
|
||||
|
||||
foreach (var sourceProperty in sourceProperties)
|
||||
{
|
||||
var targetProperty = targetProperties.FirstOrDefault(p =>
|
||||
p.Name == sourceProperty.Name && p.PropertyType == sourceProperty.PropertyType);
|
||||
if (targetProperty != null && targetProperty.CanWrite)
|
||||
{
|
||||
targetProperty.SetValue(target, sourceProperty.GetValue(source));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 链式扩展
|
||||
|
||||
public static T As<T>(this object selfObj) where T : class
|
||||
{
|
||||
return selfObj as T;
|
||||
}
|
||||
|
||||
public static T Self<T>(this T self, Action<T> onDo)
|
||||
{
|
||||
onDo?.Invoke(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
public static T Self<T>(this T self, Func<T, T> onDo)
|
||||
{
|
||||
return onDo.Invoke(self);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,12 @@ namespace AibisDream.Utility
|
||||
return jObject.Properties().Select(jProp => jProp.Name).ToArray();
|
||||
}
|
||||
|
||||
public static JObject ReadJObject(string path)
|
||||
{
|
||||
string json = File.ReadAllText(path);
|
||||
return JObject.Parse(json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存Bean
|
||||
/// </summary>
|
||||
@@ -81,6 +87,12 @@ namespace AibisDream.Utility
|
||||
File.WriteAllText(path, json);
|
||||
}
|
||||
|
||||
public static void SaveJObject(JObject jObject, string path)
|
||||
{
|
||||
string json = jObject.ToString();
|
||||
File.WriteAllText(path, json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存类
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user