In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
1. Principle
It is usually said in the Lua framework to open a web interface to C #, or to register functions in the Slua framework.
two。 Action
Call the method in C# in Lua, which is commonly used in hot updates, whether it's slua or lua. Here, I'll take slua as an example.
3. Practical application example: how to print Log in Slua
Principle: in fact, slua achieves printing by calling the Debug.Log method in C#, not the printing method in lua.
Steps:
First of all, since Lua calls the method in C #, here is a custom method to write a print log.
12345678910111213141516171819202122232425262728public class CDebug {/ lua print Log / title / content public static void Log (string title,string contents) {int level = 3; / / the code here does not need to explain, if there is a need for color, you can modify it slightly. Switch (level) {case 1: Debug.Log (contents); break; case 2: Debug.LogWarning (title+ ":" + contents); break; case 3: Debug.LogError (title+ ":" + contents); break; default: Debug.Log (contents); break;}} I:
Notice the red mark in the picture. In general, in every lua framework, there will be such a registration function, with this registration function added. Only then, there will be the next step. Execute.
II:
Click Slua- > Custom- > Make
After that, it is found that after compilation, there is one more:
III:
Note: after that, we can see that there is one more script, using svn version control, to compare the files, but there are actually other changes.
You will find that the code in the BindCustom file becomes
12345678910111213public class BindCustom {public static Action [] GetBindList () {Action [] list= {Lua_CDebug.reg, / / this is automatically generated, multiple additional / / because we saw previously in the OnAddCustomClass method in the CustomExport script / / many methods are annotated, so we need to manually add the previously generated files, specifically see / / SVN version control to compare BundCustom scripts, need to manually add the previously generated code / /. / / additional: this is not a BUG, because people think that all the code that needs to call C # in Lua is attached, / / so, it is not necessary, if our project needs to go online, we also need to restore the Log method, because it will be packaged into / / apk package.
Such a function to call the method in C# is done, and others like this can be copied from this example.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.