但是,探索遊戲您探索級別的地方,但是世界上的對像是不完整的,必須使用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
}