This commit is contained in:
parent
ceea55b67a
commit
4a2ab82e20
|
@ -359,7 +359,7 @@ namespace BITKit.Net
|
||||||
{
|
{
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
return (T)value;
|
return value.As<T>();
|
||||||
}
|
}
|
||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,6 +234,10 @@ namespace BITKit.Net
|
||||||
var isAwaitable = methodInfo.ReturnType.GetMethod(nameof(Task.GetAwaiter)) != null;
|
var isAwaitable = methodInfo.ReturnType.GetMethod(nameof(Task.GetAwaiter)) != null;
|
||||||
var handle = _rpcHandles[path];
|
var handle = _rpcHandles[path];
|
||||||
object value = null;
|
object value = null;
|
||||||
|
if (methodInfo.GetParameters().Length is 0)
|
||||||
|
{
|
||||||
|
pars = new object[]{};
|
||||||
|
}
|
||||||
if (isAwaitable)
|
if (isAwaitable)
|
||||||
{
|
{
|
||||||
dynamic result = methodInfo.Invoke(handle, pars)!;
|
dynamic result = methodInfo.Invoke(handle, pars)!;
|
||||||
|
@ -250,8 +254,7 @@ namespace BITKit.Net
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
returnWriter.Write(false);
|
throw new Exception("未找到对应的Rpc方法");
|
||||||
returnWriter.Write("未找到对应的Rpc方法");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -261,23 +264,13 @@ namespace BITKit.Net
|
||||||
.As<object[]>()[0];
|
.As<object[]>()[0];
|
||||||
if (_rpc.TryGetValue(commandObj.GetType()!.FullName!, out var func))
|
if (_rpc.TryGetValue(commandObj.GetType()!.FullName!, out var func))
|
||||||
{
|
{
|
||||||
try
|
var value = await func.As<Func<object, UniTask<object>>>().Invoke(commandObj);
|
||||||
{
|
returnWriter.Write(true);
|
||||||
var value = await func.As<Func<object, UniTask<object>>>().Invoke(commandObj);
|
BITBinary.Write(returnWriter, value);
|
||||||
returnWriter.Write(true);
|
|
||||||
BITBinary.Write(returnWriter, value);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
//BIT4Log.LogException(e);
|
|
||||||
returnWriter.Write(false);
|
|
||||||
returnWriter.Write(e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
returnWriter.Write(false);
|
throw new Exception("未找到对应的Rpc方法");
|
||||||
returnWriter.Write("未找到对应的command方法");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -287,6 +280,11 @@ namespace BITKit.Net
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
returnWriter.Write(false);
|
||||||
|
returnWriter.Write(e.Message);
|
||||||
|
|
||||||
|
var _bytes = returnMS.ToArray();
|
||||||
|
server.Send(Id, _bytes, KcpChannel.Reliable);
|
||||||
BIT4Log.LogException(e);
|
BIT4Log.LogException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace BITKit
|
namespace BITKit
|
||||||
{
|
{
|
||||||
public static class MathO
|
public static class MathO
|
||||||
{
|
{
|
||||||
public static T As<T>(this object self) where T : class
|
public static T As<T>(this object self)
|
||||||
{
|
{
|
||||||
// {
|
// {
|
||||||
// if (typeof(T) == typeof(object[]))
|
// if (typeof(T) == typeof(object[]))
|
||||||
|
@ -20,7 +22,28 @@ namespace BITKit
|
||||||
// return o[0] as T;
|
// return o[0] as T;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
return self as T;
|
try
|
||||||
|
{
|
||||||
|
return (T)self;
|
||||||
|
}
|
||||||
|
catch (InvalidCastException)
|
||||||
|
{
|
||||||
|
if(self.GetType().IsArray && typeof(T).IsArray && self is IEnumerable enumerable)
|
||||||
|
{
|
||||||
|
var newArray = Array.CreateInstance(typeof(T).GetElementType()!, enumerable.Cast<object>().Count());
|
||||||
|
var i = 0;
|
||||||
|
foreach (var x in enumerable)
|
||||||
|
{
|
||||||
|
newArray.SetValue(x, i++);
|
||||||
|
}
|
||||||
|
if (newArray is T newValue)
|
||||||
|
{
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,10 +16,11 @@ namespace BITKit.GameEditor
|
||||||
{
|
{
|
||||||
protected virtual string AssetsPath => $"Assets/Artists/";
|
protected virtual string AssetsPath => $"Assets/Artists/";
|
||||||
protected virtual string ExportPathKey => $"{typeof(T).Name}.ExportPath";
|
protected virtual string ExportPathKey => $"{typeof(T).Name}.ExportPath";
|
||||||
|
protected virtual string ExportNameKey=> $"{typeof(T).Name}.ExportName";
|
||||||
protected readonly List<T> List=new();
|
protected readonly List<T> List=new();
|
||||||
|
|
||||||
private ListView _listView;
|
protected ListView listView { get; private set; }
|
||||||
protected VisualElement _container { get; private set; }
|
protected VisualElement container { get; private set; }
|
||||||
private Button _createButton;
|
private Button _createButton;
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
|
@ -44,7 +45,7 @@ namespace BITKit.GameEditor
|
||||||
refreshButton.clicked += () =>
|
refreshButton.clicked += () =>
|
||||||
{
|
{
|
||||||
RebuildList();
|
RebuildList();
|
||||||
_listView.Rebuild();
|
listView.Rebuild();
|
||||||
};
|
};
|
||||||
var container = leftSlider.Create<VisualElement>();
|
var container = leftSlider.Create<VisualElement>();
|
||||||
|
|
||||||
|
@ -74,27 +75,27 @@ namespace BITKit.GameEditor
|
||||||
listViewContainer.Create<Label>().text = $"获取到:{List.Count}个配置";
|
listViewContainer.Create<Label>().text = $"获取到:{List.Count}个配置";
|
||||||
listViewContainer.AddToClassList("pa-8");
|
listViewContainer.AddToClassList("pa-8");
|
||||||
|
|
||||||
_listView = leftSlider.Create<ListView>();
|
listView = leftSlider.Create<ListView>();
|
||||||
_listView.makeItem = MakeItem;
|
listView.makeItem = MakeItem;
|
||||||
_listView.bindItem = BindItem;
|
listView.bindItem = BindItem;
|
||||||
_listView.itemsChosen += ItemsChosen;
|
listView.itemsChosen += ItemsChosen;
|
||||||
_listView.style.minWidth = 128;
|
listView.style.minWidth = 128;
|
||||||
_listView.style.flexGrow = 1;
|
listView.style.flexGrow = 1;
|
||||||
|
|
||||||
_listView.itemsSource = List;
|
listView.itemsSource = List;
|
||||||
|
|
||||||
var scroll = rootVisualElement.Create<ScrollView>();
|
var scroll = rootVisualElement.Create<ScrollView>();
|
||||||
scroll.name = "Scroll";
|
scroll.name = "Scroll";
|
||||||
scroll.style.flexGrow = 1;
|
scroll.style.flexGrow = 1;
|
||||||
|
|
||||||
_container = scroll.Create<GroupBox>();
|
this.container = scroll.Create<GroupBox>();
|
||||||
|
|
||||||
var pingButton = toolbarContainer.Create<Button>();
|
var pingButton = toolbarContainer.Create<Button>();
|
||||||
pingButton.text = "Ping";
|
pingButton.text = "Ping";
|
||||||
pingButton.clicked += () =>
|
pingButton.clicked += () =>
|
||||||
{
|
{
|
||||||
if (_listView.selectedIndex < 0) return;
|
if (listView.selectedIndex < 0) return;
|
||||||
var item = List[_listView.selectedIndex];
|
var item = List[listView.selectedIndex];
|
||||||
EditorGUIUtility.PingObject(item);
|
EditorGUIUtility.PingObject(item);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -133,8 +134,8 @@ namespace BITKit.GameEditor
|
||||||
{
|
{
|
||||||
var selected = obj.FirstOrDefault() as Object;
|
var selected = obj.FirstOrDefault() as Object;
|
||||||
var serializedObject = new SerializedObject(selected);
|
var serializedObject = new SerializedObject(selected);
|
||||||
BITInspectorExtensions.FillDefaultInspector(_container,serializedObject, true);
|
BITInspectorExtensions.FillDefaultInspector(container,serializedObject, true);
|
||||||
_container.Bind(serializedObject);
|
container.Bind(serializedObject);
|
||||||
}
|
}
|
||||||
protected virtual VisualElement MakeItem()
|
protected virtual VisualElement MakeItem()
|
||||||
{
|
{
|
||||||
|
@ -219,7 +220,7 @@ namespace BITKit.GameEditor
|
||||||
|
|
||||||
List.Add(item);
|
List.Add(item);
|
||||||
|
|
||||||
_listView.Rebuild();
|
listView.Rebuild();
|
||||||
|
|
||||||
ItemsChosen(new[] {item});
|
ItemsChosen(new[] {item});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue