Skip to content

Commit

Permalink
Added Binder for Vector2
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Sep 26, 2017
1 parent cddb377 commit e40c3bd
Show file tree
Hide file tree
Showing 10 changed files with 504 additions and 1 deletion.
30 changes: 30 additions & 0 deletions HotFix_Project/TestValueType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,37 @@ public static void RunTest2()

public static void RunTest3()
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
//Debug.Log("测试Vector2的各种运算");
Vector2 a = new Vector2(1, 2);
Vector2 b = Vector2.one;

Debug.Log("a + b = " + (a + b));
Debug.Log("a - b = " + (a - b));
Debug.Log("a * 2 = " + (a * 2));
Debug.Log("2 * a = " + (2 * a));
Debug.Log("a / 2 = " + (a / 2));
Debug.Log("-a = " + (-a));
Debug.Log("a == b = " + (a == b));
Debug.Log("a != b = " + (a != b));
Debug.Log("(Vector3)a = " + ((Vector3)a));
Debug.Log("(Vector2)Vector3.one = " + ((Vector2)Vector3.one));
Debug.Log("a dot b = " + Vector2.Dot(a, b));
Debug.Log("a distance b = " + Vector2.Distance(a, b));
Debug.Log("a.magnitude = " + a.magnitude);
Debug.Log("a.normalized = " + a.normalized);
Debug.Log("a.sqrMagnitude = " + a.sqrMagnitude);

sw.Start();
float dot = 0;
for (int i = 0; i < 100000; i++)
{
a += Vector2.one;
dot += Vector2.Dot(a, Vector2.zero);
}
sw.Stop();

Debug.LogFormat("Value: a={0},dot={1}, time = {2}ms", a, dot, sw.ElapsedMilliseconds);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ IEnumerator LoadHotFixAssembly()
RunTest();
yield return new WaitForSeconds(0.5f);
RunTest2();
yield return new WaitForSeconds(0.5f);
RunTest3();
}

void InitializeILRuntime()
{
//这里做一些ILRuntime的注册,这里我们注册值类型Binder,注释和解注下面的代码来对比性能差别
appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
}

void RunTest()
Expand All @@ -87,4 +90,12 @@ void RunTest2()
//调用无参数静态方法,appdomain.Invoke("类名", "方法名", 对象引用, 参数列表);
appdomain.Invoke("HotFix_Project.TestValueType", "RunTest2", null, null);
}

void RunTest3()
{
Debug.Log("=======================================");
Debug.Log("Vector2测试");
//调用无参数静态方法,appdomain.Invoke("类名", "方法名", 对象引用, 参数列表);
appdomain.Invoke("HotFix_Project.TestValueType", "RunTest3", null, null);
}
}
Loading

0 comments on commit e40c3bd

Please sign in to comment.