private void AddPhysicsListener() { Action <LuaTable, Collision> luaOnCollisionEnter = m_LuaTable.Get <Action <LuaTable, Collision> >("OnCollisionEnter"); Action <LuaTable, Collision> luaOnCollisionExit = m_LuaTable.Get <Action <LuaTable, Collision> >("OnCollisionExit"); Action <LuaTable, Collision> luaOnCollisionStay = m_LuaTable.Get <Action <LuaTable, Collision> >("OnCollisionStay"); Action <LuaTable, Collider> luaOnTriggerEnter = m_LuaTable.Get <Action <LuaTable, Collider> >("OnTriggerEnter"); Action <LuaTable, Collider> luaOnTriggerExit = m_LuaTable.Get <Action <LuaTable, Collider> >("OnTriggerExit"); Action <LuaTable, Collider> luaOnTriggerStay = m_LuaTable.Get <Action <LuaTable, Collider> >("OnTriggerStay"); if (luaOnCollisionEnter != null || luaOnCollisionExit != null || luaOnCollisionStay != null || luaOnTriggerEnter != null || luaOnTriggerExit != null || luaOnTriggerStay != null) { PhysicsListener listener = PhysicsListener.Get(this); listener.onCollisionEnter = luaOnCollisionEnter; listener.onCollisionExit = luaOnCollisionExit; listener.onCollisionStay = luaOnCollisionStay; listener.onTriggerEnter = luaOnTriggerEnter; listener.onTriggerExit = luaOnTriggerExit; listener.onTriggerStay = luaOnTriggerStay; if (!m_BehaviourListenerSet.Contains(listener)) { m_BehaviourListenerSet.Add(listener); } } }
public static PhysicsListener Get(GameObject go, string listenerTag = null) { PhysicsListener[] listeners = go.GetComponents <PhysicsListener>(); PhysicsListener listener = FindListener(listeners, listenerTag); if (listener == null) { listener = go.AddComponent <PhysicsListener>(); listener.listenerTag = listenerTag; } return(listener); }