-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af17539
commit 68b9754
Showing
10 changed files
with
112 additions
and
65 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using com.bbbirder.injection; | ||
using UnityEngine; | ||
using System; | ||
using UnityEngine.Assertions; | ||
using System.Reflection; | ||
using System.Collections.Generic; | ||
|
||
public class Demo : MonoBehaviour | ||
{ | ||
void Start() | ||
{ | ||
// FixHelper.InstallAll(); | ||
print("press SPACE to replace methods"); | ||
} | ||
|
||
void Update() | ||
{ | ||
Debug.Log(DemoModal.Salute()); | ||
Debug.Log(new DemoModal().ThisSalute()); | ||
Debug.Log(new DemoModal().Add(4, 1.2f)); | ||
if (Input.GetKeyDown(KeyCode.Space)) | ||
{ | ||
FixHelper.InstallAll(); | ||
} | ||
} | ||
|
||
#region Fix | ||
static Func<int> RawSalute; | ||
static int Salute() | ||
{ | ||
return 2; | ||
} | ||
|
||
static Func<DemoModal, int> RawThisSalute; | ||
static int ThisSalute(DemoModal demo) | ||
{ | ||
return 2; | ||
} | ||
|
||
static Func<DemoModal, int, float, float> RawAdd; | ||
static float Add(DemoModal demo, int i, float f) | ||
{ | ||
Debug.Log($"Add {i} + {f} is {i + f}"); | ||
return i + f; | ||
} | ||
|
||
static Action<object> RawLog; | ||
[HideInCallstack] | ||
static void Log(object msg) | ||
{ | ||
RawLog?.Invoke("msg:" + msg); | ||
} | ||
|
||
internal class MethodReplacer : IInjection | ||
{ | ||
static BindingFlags bindingFlags = 0 | ||
| BindingFlags.Public | ||
| BindingFlags.NonPublic | ||
| BindingFlags.Static | ||
; | ||
public IEnumerable<InjectionInfo> ProvideInjections() | ||
{ | ||
yield return InjectionInfo.Create<Func<int>>( | ||
DemoModal.Salute, | ||
Salute, | ||
f => RawSalute = f | ||
); | ||
yield return InjectionInfo.Create( | ||
typeof(DemoModal).GetMethod(nameof(DemoModal.ThisSalute)), | ||
typeof(Demo).GetMethod(nameof(Demo.ThisSalute), bindingFlags), | ||
f => RawThisSalute = (Func<DemoModal, int>)f | ||
); | ||
yield return InjectionInfo.Create( | ||
typeof(DemoModal).GetMethod(nameof(DemoModal.Add)), | ||
typeof(Demo).GetMethod(nameof(Demo.Add), bindingFlags), | ||
f => RawAdd = (Func<DemoModal, int, float, float>)f | ||
); | ||
yield return InjectionInfo.Create<Action<object>>( | ||
Debug.Log, | ||
Log, | ||
f => RawLog = f | ||
); | ||
} | ||
|
||
} | ||
#endregion | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters