xlua怎么樣hotfix C#中的重寫方法???


問題的來源之這樣的:

線上項目遇到一個問題,就是子類 override 了父類的一個 virtual 方法,並且調用到了父類里面的 virtual 方法。現在子類  override 的方法里有一些錯誤邏輯,希望通過 xlua 去修復。類似如下的代碼:

 1 using System;
 2 using UnityEngine;
 3 
 4 namespace LGSTEST
 5 {
 6     public class LgsParent : MonoBehaviour
 7     {
 8         public virtual void ShowName()
 9         {
10             Debug.Log("parent function!");
11         }
12     }
13 
14     public class Lgs : LgsParent
15     {
16         void Update()
17         {
18             if (Input.GetMouseButtonDown(0))
19             {
20                 ShowName();
21             }
22         }
23 
24         public override void ShowName()
25         {
26             base.ShowName();
27 
28             Debug.Log("child function!");
29 
30             #region 錯誤的邏輯
31 
32             #endregion
33         }
34     }
35 }

xlua代碼:

1 xlua.hotfix(CS.LGSTEST.Lgs, "ShowName", function(self)
2 
3     base(self):ShowName();
4 
5     --[[
6         修復后的邏輯放到這里
7     --]]
8 
9 end)

也就是說 C# 第 26 行的寫法,對應 xlua 中的第 3 行寫法


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM