提交 06c30eb9 编写于 作者: T tanghai

简化脚本层UI创建,异常兼容ilruntime与非ilruntime

上级 87ef2a32
......@@ -118,7 +118,7 @@ namespace Model
BehaviorTreeConfig behaviorTreeConfig = treeGo.GetComponent<BehaviorTreeConfig>();
Node node = this.CreateTreeNode(behaviorTreeConfig.RootNodeProto);
tree = new BehaviorTree(scene, node);
if (Define.LoadResourceType == LoadResourceType.Async)
if (Define.IsAsync)
{
this.treeCache.Add(treeGo, tree);
}
......
......@@ -30,7 +30,7 @@ namespace Model
return resource as K;
}
if (Define.LoadResourceType == LoadResourceType.Async)
if (Define.IsAsync)
{
if (!this.bundleCaches.ContainsKey($"{bundleName}.unity3d".ToLower()))
{
......
namespace Model
{
public enum LoadResourceType
{
Async,
Sync
}
public static class Define
{
public const int FlyStartV = 7;
public const int GravityAcceleration = 36;
#if UNITY_EDITOR && !ASYNC
public static LoadResourceType LoadResourceType = LoadResourceType.Sync;
public static bool IsAsync = false;
#else
public static LoadResourceType LoadResourceType = LoadResourceType.Async;
public static bool IsAsync = true;
#endif
#if UNITY_EDITOR
......@@ -27,5 +19,11 @@
#else
public static bool IsDevelopmentBuild = false;
#endif
#if ILRuntime
public static bool IsILRuntime = true;
#else
public static bool IsILRuntime = false;
#endif
}
}
\ No newline at end of file
using System;
using Model;
namespace Hotfix
{
......@@ -6,7 +7,12 @@ namespace Hotfix
{
public static string ToStr(this Exception exception)
{
return (string)exception.Data["StackTrace"];
if (Define.IsILRuntime)
{
return (string) exception.Data["StackTrace"];
}
return exception.ToString();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ILRuntime.CLR.Method;
using Model;
using UnityEngine;
namespace Hotfix
{
#if ILRuntime
public class IILUIFactoryMethod : IUIFactory
{
private readonly object instance;
private readonly IMethod methodInfo;
private readonly object[] params3 = new object[3];
public IILUIFactoryMethod(Type type)
{
this.instance = Activator.CreateInstance(type);
this.methodInfo = DllHelper.GetType(type.FullName).GetMethod("Create", 3);
}
public UI Create(Scene scene, UIType type, GameObject parent)
{
this.params3[0] = scene;
this.params3[1] = type;
this.params3[2] = parent;
return (UI)Model.Init.Instance.AppDomain.Invoke(methodInfo, instance, params3);
}
}
#else
public class IMonoUIFactoryMethod : IUIFactory
{
private readonly object instance;
private readonly MethodInfo methodInfo;
private readonly object[] params3 = new object[3];
public IMonoUIFactoryMethod(Type type)
{
this.instance = Activator.CreateInstance(type);
this.methodInfo = type.GetMethod("Create");
}
public UI Create(Scene scene, UIType type, GameObject parent)
{
this.params3[0] = scene;
this.params3[1] = type;
this.params3[2] = parent;
return (UI)this.methodInfo.Invoke(this.instance, this.params3);
}
}
#endif
/// <summary>
/// 管理所有UI
/// </summary>
......@@ -107,13 +63,15 @@ namespace Hotfix
Log.Debug($"已经存在同类UI Factory: {attribute.Type}");
throw new Exception($"已经存在同类UI Factory: {attribute.Type}");
}
#if ILRuntime
IUIFactory iuiFactory = new IILUIFactoryMethod(type);
#else
IUIFactory iuiFactory = new IMonoUIFactoryMethod(type);
#endif
object o = Activator.CreateInstance(type);
IUIFactory factory = o as IUIFactory;
if (factory == null)
{
Log.Error($"{o.GetType().FullName} 没有继承 IUIFactory");
continue;
}
this.UiTypes.Add((UIType)attribute.Type, iuiFactory);
this.UiTypes.Add((UIType)attribute.Type, factory);
}
}
......

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2017
# Visual Studio 15
VisualStudioVersion = 15.0.26730.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Plugins", "Unity.Plugins.csproj", "{D1FDB199-0FB7-099D-3771-C6A942E4E326}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity", "Unity.csproj", "{CF118143-7E37-744F-BE45-3F55345FEC40}"
......@@ -35,4 +37,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0AB8BABF-C9E8-4CFB-B2C5-0A6CD8350FC4}
EndGlobalSection
EndGlobal
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册