RunTime AssetBundle Analyze

RunTime AssetBundle Analyze
This commit is contained in:
ALEXTANG
2022-05-25 19:33:41 +08:00
parent 9534994b6c
commit 8084f0add1
12 changed files with 1391 additions and 0 deletions

View File

@@ -12,6 +12,11 @@ namespace TEngine
{
base.Awake();
#if ENABLE_GM || UNITY_EDITOR || _DEVELOPMENT_BUILD_
GMPage.CollectExecCommands();
GMPage.Active();
#endif
TLogger.LogInfo($"DevicePerformanceLevel 设备性能评级:{DevicePerformanceUtil.GetDevicePerformanceLevel()}");
InitLibImp();

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e5581e1dc10604545879c83fa6e55946
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
#if ENABLE_GM || UNITY_EDITOR || _DEVELOPMENT_BUILD_
using System.Collections.Generic;
using UnityEngine;
namespace TEngine
{
public class AbOnRunning : MonoBehaviour
{
private static bool hasInit = false;
private static string filterName = "";
private static int _count = 0;
private static Vector2 _vec2ScollPos = new Vector2();
private static Dictionary<string, AssetBundleData> _bundleDatasValue;
static void DoInit()
{
if (hasInit)
{
return;
}
_bundleDatasValue = new Dictionary<string, AssetBundleData>();
hasInit = true;
}
private static void ToogleScrollView1()
{
GUILayout.BeginVertical("box");
GUILayout.BeginHorizontal("box");
GUILayout.Label("AB名:", GUILayout.MaxWidth(100));
filterName = GUILayout.TextField(filterName);
filterName = filterName.ToLower();
GUILayout.EndHorizontal();
GUIStyle curStyle = new GUIStyle("box");
curStyle.alignment = TextAnchor.MiddleLeft;
curStyle.fontSize = Screen.width / 40;
GUILayout.Label($"引用数-被引用数-AbName-当前激活数 = {_count}", curStyle);
_count = 0;
_vec2ScollPos = GUILayout.BeginScrollView(_vec2ScollPos);
foreach (var pair in _bundleDatasValue)
{
if (pair.Value.RefCount == 0 && pair.Value.DepCount == 0)
{
continue;
}
if (!string.IsNullOrEmpty(filterName) && !pair.Value.Name.Contains(filterName))
continue;
_count++;
GUILayout.Label($"{pair.Value.RefCount} {pair.Value.DepCount} {pair.Value.Name}");
}
GUILayout.EndScrollView();
GUILayout.EndVertical();
}
[CommonGMCommand("AB信息预览", "", mIsDrawer = true)]
public static void GM_ABRuntime()
{
DoInit();
ToogleScrollView1();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7bb74d5789153374b94ad84f20b18685
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
using System;
namespace TEngine
{
public class CommonGMCommandAttribute : Attribute
{
public string mThread;
public string mPage;
public string mName;
public string mButtonName;
public bool mIsDrawer;
public Action mCustomDrawCallback;
public bool mIsEditorOnly = false;
public CommonGMCommandAttribute(string page, string name, bool isEditorOnly = false)
{
mThread = "";
mPage = page;
mName = name;
mButtonName = "Execute";
mCustomDrawCallback = null;
}
public CommonGMCommandAttribute(string page, string name, string buttonName, bool isEditorOnly = false)
{
mThread = "";
mPage = page;
mName = name;
mButtonName = buttonName;
mCustomDrawCallback = null;
}
public CommonGMCommandAttribute(string page, string name, string buttonName, string thread, bool isEditorOnly = false)
{
mThread = thread;
mPage = page;
mName = name;
mButtonName = buttonName;
mCustomDrawCallback = null;
}
public CommonGMCommandAttribute(string page, string name, string buttonName, string thread, Action customDrawCallback, bool isEditorOnly = false)
{
mThread = thread;
mPage = page;
mName = name;
mButtonName = buttonName;
mCustomDrawCallback = customDrawCallback;
}
public CommonGMCommandAttribute(string page, string name, Action customDrawCallback, bool isEditorOnly = false)
{
mThread = "";
mPage = page;
mName = name;
mButtonName = "Execute";
mCustomDrawCallback = customDrawCallback;
}
public CommonGMCommandAttribute(string page, string name, string thread, Action customDrawCallback, bool isEditorOnly = false)
{
mThread = thread;
mPage = page;
mName = name;
mButtonName = "Execute";
mCustomDrawCallback = customDrawCallback;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7d214df1549a49a2872e384af675a8e6
timeCreated: 1635737023

View File

@@ -0,0 +1,607 @@
#if ENABLE_GM || UNITY_EDITOR || _DEVELOPMENT_BUILD_
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace TEngine
{
public static class GMDrawer
{
public static int LABEL_WIDTH = 150;
public static List<GMCommandDrawer> listExecCommandDrawer = new List<GMCommandDrawer>();
public static Rect SelectWindowRect()
{
return new Rect(0, 0, Screen.width, Screen.height);
}
public static void InitStyle()
{
EnumParameterDrawer.Style.InitStyle();
}
public static GMCommandDrawer GetExecCommandDrawer(Type type, MethodInfo methodInfo, CommonGMCommandAttribute attribute)
{
GMCommandDrawer newGmCommandDrawer= new GMCommandDrawer(attribute.mThread, attribute.mPage, attribute.mName, attribute.mButtonName, type, methodInfo, attribute.mCustomDrawCallback);
listExecCommandDrawer.Add(newGmCommandDrawer);
return newGmCommandDrawer;
}
public class GMCommandDrawer
{
public string mThread;
public string mPage;
public string mName;
private bool mHasDone = false;
private object mExecReult = null;
private string mButtonName;
private Type mType;
private MethodInfo mMethodInfo;
private Action mCustomDrawCallback;
private List<ParameterDrawer> mDrawers = new List<ParameterDrawer>();
public GMCommandDrawer(string thread, string page, string name, string buttonName, Type type, MethodInfo method, Action customDrawCallback)
{
mThread = thread;
mPage = page;
mName = name;
mButtonName = buttonName;
mType = type;
mMethodInfo = method;
mCustomDrawCallback = customDrawCallback;
mExecReult = null;
if (mMethodInfo != null)
{
ParameterInfo[] parameters = mMethodInfo.GetParameters();
for (int i = 0; i < parameters.Length; i++)
{
ParameterInfo param = parameters[i];
if (null == param)
{
continue;
}
ParameterDrawer drawer = GetDrawer(param.ParameterType, param.Name);
if (param.HasDefaultValue)
{
drawer.SetValue(param.DefaultValue);
}
if (drawer != null)
{
mDrawers.Add(drawer);
}
}
}
}
public void OnGUI()
{
if (mCustomDrawCallback != null)
{
mCustomDrawCallback();
return;
}
DrawDefault();
}
public void Reset()
{
mHasDone = false;
mExecReult = null;
}
private void DrawDefault()
{
GUILayout.BeginVertical("box");
string name = string.Format("<color=#FFFF00FF>{0}</color>", mName);
GUILayout.Label(name);
for (int i = 0; i < mDrawers.Count; i++)
{
mDrawers[i].OnGUI(new Rect(200,200,500,50));
}
if (mHasDone)
{
if (mExecReult != null)
{
GUILayout.Label(" done result : " + mExecReult.ToString());
}
else
{
GUILayout.Label("done!");
}
}
if (GUILayout.Button(mButtonName ))
{
if (mMethodInfo != null)
{
List<object> ps = new List<object>();
for (int i = 0; i < mDrawers.Count; i++)
{
ps.Add(mDrawers[i].GetValue());
}
if (mThread == "MainThread")
{
mExecReult = mMethodInfo.Invoke(null, ps.ToArray());
}
else if (mThread == "LogicThread")
{
TLogger.LogError("LogicThread GM not supported by now");
}
else if (mThread == "NetThread")
{
TLogger.LogError("NetThread GM not supported by now");
}
}
mHasDone = true;
}
GUILayout.EndVertical();
}
}
public class ParameterDrawer
{
public string mName;
public ParameterDrawer(string name)
{
mName = name;
}
public virtual void OnGUI(Rect InBoundRect) { throw new NotImplementedException(); }
public virtual object GetValue() { throw new NotImplementedException(); }
public virtual void SetValue(object objValue) { }
}
public class IntParameterDrawer : ParameterDrawer
{
public int mObj;
public IntParameterDrawer(string name) : base(name)
{
}
public override void OnGUI(Rect InBoundRect)
{
int ret = mObj;
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
if (int.TryParse(GUILayout.TextField(ret.ToString()), out ret))
{
mObj = ret;
}
GUILayout.EndHorizontal();
}
public override object GetValue()
{
return mObj;
}
public override void SetValue(object objValue)
{
mObj = (int)objValue;
}
}
public class FloatParameterDrawer : ParameterDrawer
{
private float mObj = 0.0f;
public FloatParameterDrawer(string name) : base(name)
{
}
public override void OnGUI(Rect InBoundRect)
{
float ret = mObj;
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
if (float.TryParse(GUILayout.TextField(ret.ToString("#0.000")), out ret))
{
mObj = ret;
}
GUILayout.EndHorizontal();
}
public override object GetValue()
{
return mObj;
}
public override void SetValue(object objValue)
{
mObj = (float)objValue;
}
}
public class DoubleParameterDrawer : ParameterDrawer
{
private double mObj = 0.0;
public DoubleParameterDrawer(string name) : base(name)
{
}
public override void OnGUI(Rect InBoundRect)
{
double ret = mObj;
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
if (double.TryParse(GUILayout.TextField(ret.ToString("#0.000")), out ret))
{
mObj = ret;
}
GUILayout.EndHorizontal();
}
public override object GetValue()
{
return mObj;
}
public override void SetValue(object objValue)
{
mObj = (double)objValue;
}
}
public class LongParameterDrawer : ParameterDrawer
{
private long mObj;
public LongParameterDrawer(string name) : base(name)
{
}
public override void OnGUI(Rect InBoundRect)
{
long ret = mObj;
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
if (long.TryParse(GUILayout.TextField(ret.ToString()), out ret))
{
mObj = ret;
}
GUILayout.EndHorizontal();
}
public override object GetValue()
{
return mObj;
}
public override void SetValue(object objValue)
{
mObj = (long)objValue;
}
}
public class BooleanParameterDrawer : ParameterDrawer
{
private bool mObj;
public BooleanParameterDrawer(string name) : base(name)
{
}
public override void OnGUI(Rect InBoundRect)
{
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
mObj = GUILayout.Toggle(mObj, "",GUILayout.ExpandWidth(true));
GUILayout.EndHorizontal();
}
public override object GetValue()
{
return mObj;
}
public override void SetValue(object objValue)
{
mObj = (bool)objValue;
}
}
public class StringParameterDrawer : ParameterDrawer
{
private string mObj = "";
public StringParameterDrawer(string name) : base(name)
{
}
public override void OnGUI(Rect InBoundRect)
{
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
mObj = GUILayout.TextField(mObj);
GUILayout.EndHorizontal();
}
public override object GetValue()
{
return mObj;
}
public override void SetValue(object objValue)
{
mObj = objValue as string;
}
}
public class EnumParameterDrawer : ParameterDrawer
{
public static class Style
{
public static float ItemHeight;
public static GUIStyle Normal;
public static GUIStyle Selected;
public static void InitStyle()
{
Normal = new GUIStyle();
Normal.normal.textColor = Color.white;
Texture2D texInit = new Texture2D(1, 1);
texInit.Apply();
texInit.SetPixel(0, 0, Color.white);
Texture2D backgroundInit = new Texture2D(1, 1);
backgroundInit.SetPixel(0, 0, new Color(0,0,0,0.5f));
backgroundInit.Apply();
Texture2D activeBgInit = new Texture2D(1, 1);
activeBgInit.SetPixel(0, 0, new Color(0, 0,1.0f));
activeBgInit.Apply();
Normal.active.background = activeBgInit;
Normal.hover.background = backgroundInit;
Normal.onHover.background = backgroundInit;
Normal.hover.textColor = Color.black;
Normal.onHover.textColor = Color.black;
Normal.padding = new RectOffset(4, 4, 4, 4);
Normal.fontSize = 30;
Selected = new GUIStyle();
Selected.normal.textColor = Color.red;
Selected.hover.background = texInit;
Selected.onHover.background = texInit;
Selected.hover.textColor = Color.red;
Selected.onHover.textColor = Color.red;
Selected.padding = new RectOffset(4, 4, 4, 4);
Selected.fontSize = 30;
ItemHeight = 30;
}
}
private int mObj;
private Type mType;
private string[] mItems;
private int mSelectedIndex;
private Rect mListBoxRect;
private bool mVisible;
public delegate void SelectionEventHandler(int InIndex);
private event SelectionEventHandler OnSelectedEvent;
private event SelectionEventHandler OnSelectedChangedEvent;
public EnumParameterDrawer(string name, Type type, SelectionEventHandler onSelected = null, SelectionEventHandler onChanged = null)
: base(name)
{
mType = type;
mItems = Enum.GetNames(type);
mVisible = false;
mSelectedIndex = 0;
OnSelectedEvent = onSelected;
OnSelectedChangedEvent = onChanged;
if (mItems != null && mItems.Length > 0)
{
mObj = (int)Enum.Parse(type, mItems[0]);
}
}
public override void OnGUI(Rect InBoundRect)
{
if (mItems == null || mItems.Length == 0)
{
return;
}
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
string selectedString = mItems[mSelectedIndex];
if (GUILayout.Button(selectedString))
{
mVisible = !mVisible;
}
InBoundRect = GUILayoutUtility.GetLastRect();
GUILayout.EndHorizontal();
if (mVisible && mItems != null)
{
mListBoxRect = new Rect(InBoundRect);
mListBoxRect.y = mListBoxRect.y + mListBoxRect.height;
mListBoxRect.height = mItems.Length * Style.ItemHeight;
GUI.Box(mListBoxRect, "");
for (int i = 0; i < mItems.Length; i++)
{
Rect ListButtonRect = new Rect(mListBoxRect);
ListButtonRect.y = ListButtonRect.y + Style.ItemHeight * i;
ListButtonRect.height = Style.ItemHeight;
GUIStyle StyleSelection = mSelectedIndex == i ? Style.Selected : Style.Normal;
if (GUI.Button(ListButtonRect,new GUIContent(mItems[i], mItems[i]),StyleSelection))
{
if (OnSelectedEvent != null)
{
OnSelectedEvent(i);
}
if (mSelectedIndex != i)
{
mSelectedIndex = i;
mObj = (int)Enum.Parse(mType, mItems[i]);
if (OnSelectedChangedEvent != null)
{
OnSelectedChangedEvent(i);
}
}
mVisible = false;
}
}
}
}
public override object GetValue()
{
return mObj;
}
public override void SetValue(object objValue)
{
mObj = (int)objValue;
}
}
public class UnityVector3ParameterDrawer : ParameterDrawer
{
protected UnityEngine.Vector3 mObj = UnityEngine.Vector3.zero;
public UnityVector3ParameterDrawer(string name) : base(name)
{
}
public override void OnGUI(Rect InBoundRect)
{
Vector3 ret = mObj;
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
if (float.TryParse(GUILayout.TextField(ret.x.ToString("#0.000")), out ret.x))
{
mObj.x = ret.x;
}
if (float.TryParse(GUILayout.TextField(ret.y.ToString("#0.000")), out ret.y))
{
mObj.y = ret.y;
}
if (float.TryParse(GUILayout.TextField(ret.z.ToString("#0.000")), out ret.z))
{
mObj.z = ret.z;
}
GUILayout.EndHorizontal();
}
public override object GetValue()
{
return mObj;
}
public override void SetValue(object objValue)
{
mObj = (Vector3)objValue;
}
}
public class UnityVector2ParameterDrawer : ParameterDrawer
{
protected UnityEngine.Vector2 mObj = UnityEngine.Vector2.zero;
public UnityVector2ParameterDrawer(string name) : base(name)
{
}
public override void OnGUI(Rect InBoundRect)
{
Vector2 ret = mObj;
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
if (float.TryParse(GUILayout.TextField(ret.x.ToString("#0.000")), out ret.x))
{
mObj.x = ret.x;
}
if (float.TryParse(GUILayout.TextField(ret.y.ToString("#0.000")), out ret.y))
{
mObj.y = ret.y;
}
GUILayout.EndHorizontal();
}
public override object GetValue()
{
return mObj;
}
public override void SetValue(object objValue)
{
mObj = (Vector2)objValue;
}
}
public class UnityQuaternionParameterDrawer : ParameterDrawer
{
protected UnityEngine.Vector3 mObj = UnityEngine.Vector3.zero;
public UnityQuaternionParameterDrawer(string name) : base(name)
{
}
public override void OnGUI(Rect InBoundRect)
{
Vector3 ret = mObj;
GUILayout.BeginHorizontal();
GUILayout.Label(mName, GUILayout.Width(LABEL_WIDTH), GUILayout.ExpandWidth(false));
if (float.TryParse(GUILayout.TextField(ret.x.ToString("#0.000")), out ret.x))
{
mObj.x = ret.x;
}
if (float.TryParse(GUILayout.TextField(ret.y.ToString("#0.000")), out ret.y))
{
mObj.y = ret.y;
}
if (float.TryParse(GUILayout.TextField(ret.z.ToString("#0.000")), out ret.z))
{
mObj.z = ret.z;
}
GUILayout.EndHorizontal();
}
public override object GetValue()
{
return UnityEngine.Quaternion.Euler(mObj);
}
public override void SetValue(object objValue)
{
mObj = (Vector3)objValue;
}
}
public static ParameterDrawer GetDrawer(Type type, string name)
{
if (type == typeof(int))
{
return new IntParameterDrawer(name);
}
if (type == typeof(float))
{
return new FloatParameterDrawer(name);
}
if (type == typeof(double))
{
return new DoubleParameterDrawer(name);
}
if (type == typeof(long))
{
return new LongParameterDrawer(name);
}
if (type == typeof(string))
{
return new StringParameterDrawer(name);
}
if (type == typeof(bool))
{
return new BooleanParameterDrawer(name);
}
if (type == typeof(UnityEngine.Vector2))
{
return new UnityVector2ParameterDrawer(name);
}
if (type == typeof(UnityEngine.Vector3))
{
return new UnityVector3ParameterDrawer(name);
}
if (type == typeof(UnityEngine.Quaternion))
{
return new UnityQuaternionParameterDrawer(name);
}
if (type.IsEnum)
{
return new EnumParameterDrawer(name, type);
}
return null;
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 85e2cfb9760645bcbd9df2d47e3c219e
timeCreated: 1635745742

View File

@@ -0,0 +1,263 @@
#if ENABLE_GM || UNITY_EDITOR || _DEVELOPMENT_BUILD_
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
namespace TEngine
{
public class GMPage : UnitySingleton<GMPage>
{
private static List<string> mGMCommandPages = new List<string>();
private static List<GMDrawer.GMCommandDrawer> mGMCommands = new List<GMDrawer.GMCommandDrawer>();
private string mCurPage;
private bool mOpened = false;
protected override void OnLoad()
{
}
private EventSystem mDisabledEventSystem;
private int mTouchCount = 0;
private void Update()
{
int touchcount = Input.touchCount;
if (Input.GetKeyDown(KeyCode.BackQuote) || (touchcount == 4 && mTouchCount != touchcount))
{
if (IsEditor())
{
if (mOpened)
{
CLosePage();
}
else
{
OpenPage();
}
}
else
{
OpenPage();
}
}
mTouchCount = touchcount;
}
private void OpenPage()
{
GMDrawer.InitStyle();
mWindowRect = GMDrawer.SelectWindowRect();
mOpened = true;
mDisabledEventSystem = EventSystem.current;
EventSystem.current.enabled = false;
}
private void CLosePage()
{
mOpened = false;
mDisabledEventSystem.enabled = true;
}
public static bool IsTypeWithAttributeType(Type inAttributeType, Type inCurType)
{
try
{
if ((inCurType.Attributes & (TypeAttributes.Interface | TypeAttributes.HasSecurity)) != 0)
{
return false;
}
if (inCurType.IsEnum || inCurType.IsPrimitive || inCurType.IsGenericType)
{
return false;
}
MethodInfo[] methods = inCurType.GetMethods(BindingFlags.Public | BindingFlags.Static);
for (int j = 0; j < methods.Length; j++)
{
MethodInfo method = methods[j];
Attribute attr = method.GetCustomAttribute(inAttributeType);
if (attr == null)
{
continue;
}
if (attr is CommonGMCommandAttribute execCommandAttribute)
{
if (execCommandAttribute.mIsEditorOnly && IsEditor())
{
continue;
}
}
return true;
}
}
catch (Exception e)
{
TLogger.LogError(e.ToString());
}
return false;
}
public static bool IsEditor()
{
bool isEditor = false;
#if UNITY_EDITOR
isEditor = true;
#endif
return isEditor;
}
public static void CollectExecCommands()
{
Type[] types = null;
TypeUtility.GetTypesImpl(typeof(CommonGMCommandAttribute),
"", true, IsTypeWithAttributeType, out types);
if (types == null)
{
return;
}
for (int i = 0; i < types.Length; i++)
{
Type type = types[i];
MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static);
for (int j = 0; j < methods.Length; j++)
{
MethodInfo method = methods[j];
CommonGMCommandAttribute attr = method.GetCustomAttribute<CommonGMCommandAttribute>();
if (attr == null)
{
continue;
}
if (attr.mIsEditorOnly && IsEditor())
{
continue;
}
if (string.IsNullOrEmpty(attr.mThread))
{
attr.mThread = "MainThread";
}
attr.mThread = string.Intern(attr.mThread);
attr.mPage = string.Intern(attr.mPage);
attr.mName = string.Intern(attr.mName);
attr.mButtonName = string.Intern(attr.mButtonName);
if (attr.mIsDrawer)
{
attr.mCustomDrawCallback = () => method.Invoke(null, null);
}
if (!mGMCommandPages.Contains(attr.mPage))
{
mGMCommandPages.Add(attr.mPage);
}
GMDrawer.GMCommandDrawer drawer = GMDrawer.GetExecCommandDrawer(type, method, attr);
mGMCommands.Add(drawer);
}
}
}
static int InternalID = 0x00dbdbdb;
private Vector2 mGUIScroll;
public Rect mWindowRect;
private void OnGUI()
{
if (!mOpened)
{
return;
}
int CONST_SIZE = 32;
GUI.skin.verticalScrollbar.fixedWidth = Screen.width * 0.001f * CONST_SIZE;
GUI.skin.verticalScrollbarThumb.fixedWidth = Screen.width * 0.001f * CONST_SIZE;
GUI.skin.label.fontSize = CONST_SIZE;
GUI.skin.textField.fontSize = CONST_SIZE;
GUI.skin.button.fontSize = CONST_SIZE;
GUI.skin.toggle.fontSize = 64;
GUI.skin.toggle.fixedHeight = 50;
GUI.skin.toggle.fixedWidth = 50;
GUI.skin.textArea.fontSize = CONST_SIZE;
GUI.skin.textArea.richText = true;
GUILayout.Window(InternalID, mWindowRect, DrawExeCommandWindow, "GM Command");
}
void DrawExeCommandWindow(int InWindowID)
{
GUILayout.BeginVertical();
string pageName = "Current Page: " + mCurPage;
GUILayout.Label(pageName, GUILayout.ExpandWidth(true));
GUILayout.EndVertical();
mGUIScroll = GUILayout.BeginScrollView(mGUIScroll);
GUILayout.BeginHorizontal();
GUILayout.BeginVertical("box", GUILayout.Width(mWindowRect.width * 0.1f), GUILayout.ExpandHeight(true));
if (GUILayout.Button("关闭"))
{
CLosePage();
}
for (int i = mGMCommandPages.Count - 1; i >= 0; i--)
{
string str = mGMCommandPages[i];
if (GUILayout.Button(str))
{
mCurPage = str;
}
}
GUILayout.EndVertical();
GUILayout.BeginVertical();
for (int i = 0; i < mGMCommands.Count; i++)
{
GMDrawer.GMCommandDrawer command = mGMCommands[i];
if (command.mPage == mCurPage)
{
command.OnGUI();
}
else
{
command.Reset();
}
GUILayout.Space(1.0f);
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.EndScrollView();
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3d7f8f61649e4eed89f8d48cdb7f5cb4
timeCreated: 1635745668

View File

@@ -0,0 +1,332 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace TEngine
{
public class TypeUtility
{
public static Type GetType(string typeName)
{
return GetType("", typeName, false);
}
public static Type GetTypeInEditor(string typeName)
{
return GetType("", typeName, true);
}
public static Type GetNestedType(Type inDelareType, string inStrTypeName)
{
Type type = inDelareType.GetNestedType(inStrTypeName,
BindingFlags.Public | BindingFlags.NonPublic);
if (type == null)
{
TLogger.LogError("GetNestedType failed: {0}.{1}", inDelareType, inStrTypeName);
}
return type;
}
private static Dictionary<string, Dictionary<string, Type>> _s_type_with_name_cache = null;
public static Type GetType(string inStrAssemblyName, string inStrTypeName, bool inIsEditor)
{
if (string.IsNullOrEmpty(inStrTypeName))
{
TLogger.LogError("GetType:typeName is null");
return null;
}
Type type = null;
if (_s_type_with_name_cache == null)
{
_s_type_with_name_cache = new Dictionary<string, Dictionary<string, Type>>();
}
if (_s_type_with_name_cache.ContainsKey(inStrAssemblyName) != true)
{
_s_type_with_name_cache.Add(inStrAssemblyName, new Dictionary<string, Type>());
}
else
{
if (_s_type_with_name_cache[inStrAssemblyName].ContainsKey(inStrTypeName))
{
type = _s_type_with_name_cache[inStrAssemblyName][inStrTypeName];
return type;
}
}
type = Type.GetType(inStrTypeName);
if (null != type)
{
_s_type_with_name_cache[inStrAssemblyName][inStrTypeName] = type;
return type;
}
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
if (!string.IsNullOrEmpty(inStrAssemblyName) && a.GetName().Name != inStrAssemblyName)
continue;
type = a.GetType(inStrTypeName);
if (type != null)
{
_s_type_with_name_cache[inStrAssemblyName][inStrTypeName] = type;
return type;
}
}
return null;
}
public static void ClearTypeCache()
{
if (_s_type_with_name_cache != null)
{
foreach (var kv in _s_type_with_name_cache)
{
if (kv.Value != null)
{
kv.Value.Clear();
}
}
_s_type_with_name_cache.Clear();
_s_type_with_name_cache = null;
}
}
public class TypeComparer : IComparer<Type>
{
public int Compare(Type x, Type y)
{
if (object.ReferenceEquals(x, y))
return 0;
else if (x == null)
return -1;
else if (y == null)
return 1;
else
{
return string.Compare(x.FullName, y.FullName);
}
}
}
private static Dictionary<Type, Type[]> msDerivedTypes = new Dictionary<Type, Type[]>();
public static bool InitStaticTypes(Type inBaseType, Type[] inTypes)
{
if (inTypes.Length == 0)
return true;
if (!msDerivedTypes.TryGetValue(inBaseType, out Type[] existingTypes))
{
existingTypes = inTypes;
msDerivedTypes[inBaseType] = inTypes;
}
else
{
int numRedefinedTypes = 0;
List<Type> tempTypes = new List<Type>(inTypes.Length + existingTypes.Length);
tempTypes.AddRange(existingTypes);
#if UNITY_EDITOR
TypeComparer comparer = new TypeUtility.TypeComparer();
for (int i = 0; i < inTypes.Length; ++i)
{
Type curType = inTypes[i];
int idx = Array.BinarySearch<Type>(existingTypes, 0, existingTypes.Length, curType, comparer);
if (idx < 0)
tempTypes.Add(curType);
else
numRedefinedTypes++;
}
if (numRedefinedTypes > 0)
{
TLogger.LogError("{0} Redefined type in static type list.", numRedefinedTypes);
}
existingTypes = tempTypes.ToArray();
Array.Sort(existingTypes, comparer);
#else
tempTypes.AddRange(inTypes);
existingTypes = tempTypes.ToArray();
#endif
msDerivedTypes[inBaseType] = existingTypes;
}
return true;
}
[ThreadStatic]
private static Dictionary<Type, Type[]> msDerivedTypesCurThread;
public static void GetDerivedTypes(Type inType, string inStrAssembly, out Type[] outTypes)
{
GetTypesImpl(inType, inStrAssembly, true, IsDerivedClass, out outTypes);
}
public static void GetTypesImpInterfaceNonGenericNonAbstract(Type inInterface, string inStrAssembly, out Type[] outTypes)
{
GetTypesImpl(inInterface, inStrAssembly, true, IsImplInterfaceNonGeneric, out outTypes);
}
public static bool IsImplInterfaceNonGeneric(Type inInterface, Type inType)
{
return !inType.IsAbstract && !inType.IsGenericType && inType.GetInterface(inInterface.Name) != null;
}
public static bool IsSubclassOf(Type src, Type dst)
{
return src.IsSubclassOf(dst);
}
public static bool Equals(Type src, Type dst)
{
return src.Equals(dst);
}
public static bool IsDerivedClass(Type inBaseType, Type inType)
{
return (inBaseType == inType) || (!inType.IsAbstract && inType.IsSubclassOf(inBaseType));
}
public static void GetTypesImpl(Type inParamType, string inStrAssembly, bool inIsUseCache,
Func<Type, Type, bool> inCriteria, out Type[] outTypes)
{
Type[] existingTypes = null;
if (inIsUseCache && msDerivedTypes.TryGetValue(inParamType, out existingTypes) && existingTypes != null)
{
#if !UNITY_EDITOR
outTypes = existingTypes;
return;
#endif
}
if (inIsUseCache)
{
if (msDerivedTypesCurThread == null)
msDerivedTypesCurThread = new Dictionary<Type, Type[]>();
else
{
if (msDerivedTypesCurThread.TryGetValue(inParamType, out Type[] threadExistingTypes)
&& existingTypes != null)
{
outTypes = existingTypes;
return;
}
}
}
if (existingTypes == null)
{
TLogger.LogWarning("TypeUtility: Getting {0} Derived Type by iterating assembly.", inParamType);
}
else
{
TLogger.LogInfo("TypeUtility: Checking {0} Derived Type with assembly iterating.", inParamType);
}
List<Type> derivedTypeList = new List<Type>();
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int k = 0; k < assemblies.Length; ++k)
{
Assembly tAssemble = assemblies[k];
if (!string.IsNullOrEmpty(inStrAssembly)
&& !tAssemble.GetName().Name.Equals(inStrAssembly))
{
continue;
}
Type[] allTypes = null;
try
{
allTypes = tAssemble.GetTypes();
}
catch (Exception e)
{
TLogger.LogError("GetDerivedTypes: {0} , GetTypes error -> {1}", e.ToString(), tAssemble);
}
if (allTypes == null)
continue;
for (int i = 0; i < allTypes.Length; ++i)
{
Type type = allTypes[i];
try
{
if (inCriteria(inParamType, type))
{
derivedTypeList.Add(type);
}
}
catch (Exception e)
{
TLogger.LogError("GetDerivedTypes with exception {0}, Type error -> {1} ", e.ToString(), type);
}
}
}
#if UNITY_EDITOR
if (existingTypes != null)
{
TypeUtility.TypeComparer comparer = new TypeComparer();
derivedTypeList.Sort(comparer);
StringBuilder sb = new StringBuilder();
int numDiff = 0;
int numTypes;
numTypes = derivedTypeList.Count;
int i = 0;
for (; i < numTypes; ++i)
{
Type t = derivedTypeList[i];
int idx = Array.BinarySearch(existingTypes, t, comparer);
if (idx < 0)
{
if (t.Assembly.GetName().Name != "PMEditor")
{
sb.AppendFormat("{0}\n", t.Name);
numDiff++;
}
}
}
if (numDiff != 0)
{
TLogger.LogWarning("GetDerivedTypes {0} consistency check failed with differences,\n runtime = {1}, static list = {2}, re-export code! Diff: {3}",
inParamType, derivedTypeList.Count, existingTypes.Length, sb.ToString());
}
}
else
{
TLogger.LogWarning("GetDerivedTypes type \"{0}\" was not defined in generated code.", inParamType);
}
#endif
outTypes = derivedTypeList.ToArray();
if (inIsUseCache)
{
msDerivedTypesCurThread[inParamType] = outTypes;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 47c4d87ce2ebe82469c001812ba48857
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: