using UnityEngine;
using System.Collections;
using LuaInterface;
public class TestGameObject: MonoBehaviour
{
private string script =
@"
local Color = UnityEngine.Color
local GameObject = UnityEngine.GameObject
local ParticleSystem = UnityEngine.ParticleSystem
function OnComplete()
print('OnComplete CallBack')
end
local go = GameObject('go') --lua中创建名字为go的物体
go:AddComponent(typeof(ParticleSystem)) --在lua中给游戏物体添加ParticleSystem类型组件
local node = go.transform
node.position = Vector3.one
print('gameObject is: '..tostring(go))
--go.transform:DOPath({Vector3.zero, Vector3.one * 10}, 1, DG.Tweening.PathType.Linear, DG.Tweening.PathMode.Full3D, 10, nil)
--go.transform:DORotate(Vector3(0,0,360), 2, DG.Tweening.RotateMode.FastBeyond360):OnComplete(OnComplete)
GameObject.Destroy(go, 2) --延时销毁的指定的游戏物体 2是延迟时间
go.name = '123'
--print('delay destroy gameobject is: '..go.name)
";
LuaState lua = null;
void Start()
{
#if UNITY_5 || UNITY_2017 || UNITY_2018
Application.logMessageReceived += ShowTips;
#else
Application.RegisterLogCallback(ShowTips);
#endif
new LuaResLoader();
lua = new LuaState();
lua.LogGC = true;
lua.Start();
LuaBinder.Bind(lua);
lua.DoString(script, "TestGameObject.cs");
}
void Update()
{
lua.CheckTop();
lua.Collect();
}
string tips = "";
void ShowTips(string msg, string stackTrace, LogType type)
{
tips += msg;
tips += "\r\n";
}
void OnApplicationQuit()
{
lua.Dispose();
lua = null;
#if UNITY_5 || UNITY_2017 || UNITY_2018
Application.logMessageReceived -= ShowTips;
#else
Application.RegisterLogCallback(null);
#endif
}
void OnGUI()
{
GUI.Label(new Rect(Screen.width / 2 - 300, Screen.height / 2 - 300, 600, 600), tips);
}
}