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