├── .npmignore
├── LICENSE.md.meta
├── README.md.meta
├── package.json.meta
├── Editor
├── template.txt.meta
├── com.bbbirder.injection.Editor.asmdef.meta
├── InjectHelper.cs.meta
├── InjectionSettings.cs.meta
├── TemplateGenerator.cs.meta
├── UnityInjectUtils.cs.meta
├── InjectionSettingsWindow.cs.meta
├── InjectionSourceUI.uxml.meta
├── InjectionWindowUI.uxml.meta
├── InjectionSourceUI.uxml
├── com.bbbirder.injection.Editor.asmdef
├── TemplateGenerator.cs
├── template.txt
├── InjectionSettingsWindow.cs
├── InjectionWindowUI.uxml
├── InjectionSettings.cs
├── UnityInjectUtils.cs
└── InjectHelper.cs
├── Documentation
├── usage-di.md.meta
├── usage-decorator.md.meta
├── usage-proxy.md.meta
├── usage-proxy.md
├── usage-di.md
└── usage-decorator.md
├── Editor.meta
├── Runtime.meta
├── Samples~
└── MethodFix
│ ├── Demo.unity.meta
│ ├── com.bbbirder.injection.sample.asmdef.meta
│ ├── Demo.cs.meta
│ ├── DemoModal.cs.meta
│ ├── DemoModal.cs
│ ├── com.bbbirder.injection.sample.asmdef
│ ├── Demo.cs
│ └── Demo.unity
├── Documentation.meta
├── Runtime
├── ClassicalUsages.meta
├── com.bbbirder.injection.asmdef.meta
├── Constants.cs.meta
├── FixHelper.cs.meta
├── IInjection.cs.meta
├── InjectionInfo.cs.meta
├── InjectionAttribute.cs.meta
├── ClassicalUsages
│ ├── ProxyData.cs.meta
│ ├── Decorator-AutoGen.cs.meta
│ ├── OrderDIAttribute.cs.meta
│ ├── ServiceContainer.cs.meta
│ ├── SimpleDIAttribute.cs.meta
│ ├── DecoratorAttribute.cs.meta
│ ├── OrderDIAttribute.cs
│ ├── ProxyData.cs
│ ├── DecoratorAttribute.cs
│ ├── SimpleDIAttribute.cs
│ ├── ServiceContainer.cs
│ └── Decorator-AutoGen.cs
├── IInjection.cs
├── com.bbbirder.injection.asmdef
├── InjectionAttribute.cs
├── Constants.cs
├── InjectionInfo.cs
└── FixHelper.cs
├── .github
└── workflows
│ └── ci.yml
├── package.json
├── LICENSE.md
└── README.md
/.npmignore:
--------------------------------------------------------------------------------
1 | VSProj~
2 | .github
3 | README.md
4 | Documentation
--------------------------------------------------------------------------------
/LICENSE.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 14356c2e544ffe34ea1d907ab3d2f8f6
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/README.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f2186d4edaa19b443b2fa1c9ba785a9b
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: add7790670f7d624eb9d946e01ab2660
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Editor/template.txt.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ce98390825738344eb1925c70711d599
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Documentation/usage-di.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 79041f1af82164946a2b7f5b38217fe6
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c6af47a612abaff4b9e26e5ee7591997
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Runtime.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 06e9479868352fa4a920ffa6f6413183
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Samples~/MethodFix/Demo.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4c686b13ed31b5a49ba86a2c27364f68
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Documentation.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2c0b8c26a3dbaeb4f8e7aa80a36d3c00
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Documentation/usage-decorator.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 55127db03c3f63148ab97390eb9998e5
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Documentation/usage-proxy.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4d9d250f654dacd4ea3e3e638a00db62
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Runtime/ClassicalUsages.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9f8f02389c389b74e85afc1c067f21ae
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Runtime/com.bbbirder.injection.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 521f16345e07cc2439d976f3bbd67b45
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Editor/com.bbbirder.injection.Editor.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2567c54de59cd2a49b392206a1c6d31f
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Samples~/MethodFix/com.bbbirder.injection.sample.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 71e2e836302736d418b5e089b90d66f3
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Editor/InjectHelper.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ba6634917bee7ec408331b633d6656aa
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/Constants.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2c911f63e0861b649a0bd65cd67aa033
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/FixHelper.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ddf99b70e8ecfcd49826915759fa655c
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/IInjection.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3a1865fcca4e0f14ea2bee5b0a8fe8cb
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/InjectionInfo.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 36ae91194cb419b4f94e17c03fb1e6f7
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/InjectionSettings.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9273ff3f41d65c14e99236f70f1f06c7
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/TemplateGenerator.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9a998018f8e3b7a44b5616beab7d6cce
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/UnityInjectUtils.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b77aff1dc6991c343acc25a060739421
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/InjectionAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e4f8561d305c6df4dba609aeeadd988b
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Samples~/MethodFix/Demo.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2c807aa2ed3eacf498e4b8cf0fed1c04
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/InjectionSettingsWindow.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f53701e1414a09b43bf31a057c7e4cbb
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Samples~/MethodFix/DemoModal.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b82c4d7e8a309394b8a9aecb79e26a59
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/ClassicalUsages/ProxyData.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 798b8a97a9e084846b9466e6c2fc3aeb
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/ClassicalUsages/Decorator-AutoGen.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1e1bbfdbc88d96d45bedbfabff63e955
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/ClassicalUsages/OrderDIAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dd7556feaa4bbc14da18242731861339
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/ClassicalUsages/ServiceContainer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6a7627286c3518f479366b70cdab0f90
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/ClassicalUsages/SimpleDIAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9eccd17b69df0684891b0a878431acbb
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: Create Tag
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 |
8 | jobs:
9 | build:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v2
13 | - uses: Klemensas/action-autotag@stable
14 | with:
15 | GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
16 |
--------------------------------------------------------------------------------
/Runtime/ClassicalUsages/DecoratorAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 506cafa565bcfb3448e55f06d22a55a9
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/InjectionSourceUI.uxml.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e0689cb498ad5f8459d2bee8fd022488
3 | ScriptedImporter:
4 | internalIDToNameTable: []
5 | externalObjects: {}
6 | serializedVersion: 2
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 | script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
11 |
--------------------------------------------------------------------------------
/Editor/InjectionWindowUI.uxml.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 64949e9c31ce0a04b8aa1a3d01d72ab1
3 | ScriptedImporter:
4 | internalIDToNameTable: []
5 | externalObjects: {}
6 | serializedVersion: 2
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 | script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
11 |
--------------------------------------------------------------------------------
/Samples~/MethodFix/DemoModal.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 | using UnityEngine;
4 | using System;
5 |
6 | public class DemoModal{
7 | public static int Salute(){
8 | return 1;
9 | }
10 | public int ThisSalute(){
11 | return 1;
12 | }
13 | public float Add(int i, float f){
14 | return i*f;
15 | }
16 | }
--------------------------------------------------------------------------------
/Runtime/IInjection.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace com.bbbirder.injection
4 | {
5 | public interface IInjection : IDirectRetrieve
6 | {
7 | ///
8 | /// set this property to populate injections
9 | ///
10 | ///
11 | public IEnumerable ProvideInjections();
12 | }
13 | }
--------------------------------------------------------------------------------
/Editor/InjectionSourceUI.uxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Runtime/com.bbbirder.injection.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.bbbirder.injection",
3 | "rootNamespace": "",
4 | "references": [
5 | "GUID:b66755024ec682a4aa0f53d87f0616ea"
6 | ],
7 | "includePlatforms": [],
8 | "excludePlatforms": [],
9 | "allowUnsafeCode": false,
10 | "overrideReferences": false,
11 | "precompiledReferences": [],
12 | "autoReferenced": true,
13 | "defineConstraints": [],
14 | "versionDefines": [],
15 | "noEngineReferences": false
16 | }
--------------------------------------------------------------------------------
/Runtime/InjectionAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Reflection;
5 | using UnityEngine.Assertions;
6 |
7 | namespace com.bbbirder.injection
8 | {
9 | public abstract class InjectionAttribute : DirectRetrieveAttribute
10 | {
11 | ///
12 | /// set this property to populate injections
13 | ///
14 | ///
15 | public abstract IEnumerable ProvideInjections();
16 | }
17 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.bbbirder.injection",
3 | "displayName": "Unity Injection",
4 | "description": "Unity注入模块,可以运行时改变被注入函数实现。",
5 | "version": "1.3.32",
6 | "hideInEditor": false,
7 | "author": "bbbirder <502100554@qq.com>",
8 | "dependencies": {
9 | "com.bbbirder.directattribute": "2.0.0",
10 | "com.unity.nuget.mono-cecil": "1.10.2"
11 | },
12 | "samples": [
13 | {
14 | "displayName": "Method Fix",
15 | "path": "Samples~/MethodFix"
16 | }
17 | ],
18 | "gitHead": "18b3c53f1dec43ebd854d02b30959cf96962da13"
19 | }
20 |
--------------------------------------------------------------------------------
/Samples~/MethodFix/com.bbbirder.injection.sample.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.bbbirder.injection.sample",
3 | "rootNamespace": "",
4 | "references": [
5 | "GUID:b66755024ec682a4aa0f53d87f0616ea",
6 | "GUID:521f16345e07cc2439d976f3bbd67b45"
7 | ],
8 | "includePlatforms": [],
9 | "excludePlatforms": [],
10 | "allowUnsafeCode": false,
11 | "overrideReferences": false,
12 | "precompiledReferences": [],
13 | "autoReferenced": true,
14 | "defineConstraints": [],
15 | "versionDefines": [],
16 | "noEngineReferences": false
17 | }
--------------------------------------------------------------------------------
/Editor/com.bbbirder.injection.Editor.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.bbbirder.injection.Editor",
3 | "rootNamespace": "",
4 | "references": [
5 | "com.bbbirder.injection",
6 | "com.bbbirder.directattribute"
7 | ],
8 | "includePlatforms": [
9 | "Editor"
10 | ],
11 | "excludePlatforms": [],
12 | "allowUnsafeCode": false,
13 | "overrideReferences": true,
14 | "precompiledReferences": [
15 | "Mono.Cecil.dll"
16 | ],
17 | "autoReferenced": true,
18 | "defineConstraints": [],
19 | "versionDefines": [],
20 | "noEngineReferences": false
21 | }
--------------------------------------------------------------------------------
/Runtime/ClassicalUsages/OrderDIAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace com.bbbirder.injection
4 | {
5 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)]
6 | public class OrderDIAttribute : Attribute
7 | {
8 | internal int order;
9 | ///
10 | /// The default assign order of this type
11 | ///
12 | /// pick from litter
13 | public OrderDIAttribute(int order)
14 | {
15 | this.order = order;
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/Documentation/usage-proxy.md:
--------------------------------------------------------------------------------
1 | # 数据代理
2 |
3 | 下面的代码演示实现一个数据代理:
4 |
5 | ```csharp
6 | public class Pat : ProxyData // 需要继承ProxyData
7 | {
8 | public string name { get; set; }
9 | public int age { get; set; }
10 | }
11 |
12 | var pet = new Pet();
13 | pet.OnSetProperty(key=>{
14 | print($"set {key}");
15 | });
16 | pet.OnGetProperty(key=>{
17 | print($"get {key}");
18 | });
19 |
20 | pet.age += 1;
21 |
22 | /*
23 | output:
24 | get age
25 | set age
26 | */
27 |
28 | ```
29 |
30 | 有时你需要判断代理类是否被正确注入:
31 |
32 | ```csharp
33 | print(pet.IsFixed()); // false
34 | FixHelper.InstallAll();
35 | print(pet.IsFixed()); // true
36 | ```
37 |
--------------------------------------------------------------------------------
/Editor/TemplateGenerator.cs:
--------------------------------------------------------------------------------
1 | // using UnityEngine;
2 | // using UnityEditor;
3 | // using System.Runtime.CompilerServices;
4 | // using System.IO;
5 |
6 | // class TemplateGenerator{
7 | // [InitializeOnLoadMethod]
8 | // static void Generate(){
9 | // var input = File.ReadAllText(GetFilePath());
10 | // var output = Scriban.Template.Parse(input).Render();
11 | // File.WriteAllText(GetOutputPath(),output);
12 | // Debug.Log(output);
13 | // }
14 | // static string GetFilePath([CallerFilePath]string path=null)
15 | // =>Path.Join(path,"../template.txt");
16 | // static string GetOutputPath([CallerFilePath]string path=null)
17 | // =>Path.Join(path,"../../Runtime/Decorator-AutoGen.cs");
18 | // }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 labbbirder
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/Runtime/Constants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Security.Cryptography;
5 | using System.Text;
6 |
7 | namespace com.bbbirder.injection
8 | {
9 | public static class Constants
10 | {
11 | public const string INJECTED_MARK_NAMESPACE = "com.bbbirder";
12 | public const string INJECTED_MARK_NAME = "InjectedMarkAttribute";
13 |
14 | public static string GetInjectedFieldName(string methodName, string methodSignature)
15 | => strBuilder.Clear().Append("_injection_field+").Append(methodName).Append(MD5Hash(methodSignature)).ToString();
16 |
17 | public static string GetOriginMethodName(string methodName, string methodSignature)
18 | => strBuilder.Clear().Append("_injection_origin+").Append(methodName).Append(MD5Hash(methodSignature)).ToString();
19 |
20 | static string MD5Hash(string rawContent)
21 | {
22 | var md5 = MD5.Create();
23 | var buffer = md5.ComputeHash(Encoding.UTF8.GetBytes(rawContent));
24 | return string.Concat(buffer.Select(b => b.ToString("X")));
25 | }
26 |
27 | static StringBuilder strBuilder = new();
28 | }
29 | }
--------------------------------------------------------------------------------
/Editor/template.txt:
--------------------------------------------------------------------------------
1 | // Dont Modify It: This is an Auto-Generated File
2 | using System;
3 | using System.Reflection;
4 |
5 | {{
6 | func get_pt
7 | $cnt = $0
8 | $format = $1
9 | $spliter = $2
10 | $result = ''
11 | for $i in (1..$cnt)
12 | $result += string.replace($format,'i',$i)
13 | if $i!=$cnt
14 | $result += $spliter
15 | end
16 | end
17 | ret $result
18 | end
19 | }}
20 | namespace com.bbbirder.unity {
21 | partial class DecoratorAttribute{
22 | {{~ for cnt in 1..12 ~}}
23 | {{~pt_gl = get_pt cnt 'Ti' ','~}}
24 | {{~pt_vl = get_pt cnt 'ti' ','~}}
25 | {{~pt_dl = get_pt cnt 'Ti _ti' ','~}}
26 | Func<{{pt_gl}},R> UniversalFunc<{{pt_gl}},R>(MethodInfo mi){
27 | {{~ for i in 1..cnt ~}}
28 | T{{i}} t{{i}} = default;
29 | {{~ end ~}}
30 | var invocation = new InvocationInfo(){
31 | invoker = ()=>((Func<{{pt_gl}},R>)originFunc).Invoke({{pt_vl}}),
32 | Method = mi,
33 | argumentGetter = ()=>new object[]{ {{pt_vl}} }
34 | };
35 | return ({{pt_dl}})=>{
36 | {{~ for i in 1..cnt ~}}
37 | t{{i}} = _t{{i}};
38 | {{~ end ~}}
39 | return Decorate(invocation);
40 | };
41 | }
42 | Action<{{pt_gl}}> UniversalAction<{{pt_gl}}>(MethodInfo mi){
43 | {{~ for i in 1..cnt ~}}
44 | T{{i}} t{{i}} = default;
45 | {{~ end ~}}
46 | var invocation = new InvocationInfo