但是,探索游戏您探索级别的地方,但是世界上的对象是不完整的,必须使用LUA脚本脚本来解决难题和进步。
该游戏使用以下库:
注意:API在开发过程中可能会发生变化!
在脚本/ Lua.Modules中,使用此模板创建一个模块文件:
using UnityEngine ;
namespace Lua . Modules
{
public class ModuleName : MonoBehaviour
{
}
}要创建一个示例方法,您必须提供返回类型(可选的带有参数),例如静态和公共):
注意:如果您使用参数,则有一种绕过返回类型的方法(请参阅Lua.Modules.Miscellaneous和Print ,但不建议这样做)
// Example method
public static int ExampleMethod ( string message )
{
UnityEngine . Debug . Log ( message ) ;
return 0 ; // 0 - Success
}要暴露该方法,以便可以在LUA中使用,还有两个步骤。在Lua.LuaManager内部,有一个名为“暴露”的地区。在其中,创建一个Func或Action ,并引用模块中的功能
// Miscellaneous
script . Globals [ "ExampleMethod" ] = ( Func < string , int > ) ModuleName . ExampleMethod ;最后,需要在Lua.LuaControllable内部的方法中添加一个切换。如果该方法需要使用Utils.ReturnLuaObject或LuaControllable.CheckOperationLegality 。为此,请进入Lua.LuaControllable内部,然后在区域内“启用允许在对象上允许的功能”的区域。然后创建一个用创建函数的确切名称(需要您的函数在所有曝光方法中命名的函数)的确切名称(私有名称),例如
[ SerializeField ] private bool ExampleMethod = false ;要使用方法LuaControllable.CheckOperationLegality ,您还必须使用Utils.ReturnLuaObject作为luacontrollable.CheckeCoperationLegality.CheckoPerationLegality需要参考该游戏对象及其Luacontroller。
首先,创建的方法需要一个字符串参数(第一个参数是标准),例如: public static int SetPositionRelative(string controllerName, float x, float y)
次要,可以使用“ utils.returnluaobject”获得对想要的游戏对象的引用(要求所有游戏对象在其Lua.LuaControllable serialization Field中设置一个唯一的名称)
最后,可以使用LuaControllable.CheckOperationLegality检查该对象上是否允许命令。该方法应使用Value System.Reflection.MethodBase.GetCurrentMethod().Name 。
所有这些的示例来自一个基本模块之一:
// String name used in Lua
public static int SetPositionRelative ( string controllerName , float x , float y )
{
// Get a reference to the controller
var controller = Utils . ReturnLuaObject ( controllerName ) ;
// Check the controller is not null
// System.Reflection.MethodBase.GetCurrentMethod().Name is required to be passed
if ( controller . controller != null )
{
// Check the operation is allowed
switch ( controller . controller . CheckOperationLegality ( System . Reflection . MethodBase . GetCurrentMethod ( ) . Name ) )
{
case false :
return 2 ; // 2 - Illegal operation
case null :
return 3 ; // 3 - Unknown operation
}
// Any code here
return 0 ; // 0 - Command success
}
return 1 ; // 1 - Command failed
}