Пример #1
0
        /// <summary>
        /// Adds a torque to the object using the mode specified. Force and Impulse take the objects mass into account,
        /// Acceleration and VelocityChange ignore mass and move every object at the same speed.
        /// </summary>
        /// <param name="torque">The amount of torque to be applied.</param>
        /// <param name="mode">Describes how the force should be applied.</param>
        public void AddTorque(Vector3 torque, ForceMode mode = ForceMode.Force)
        {
            switch (mode)
            {
            // Normal torque.
            case ForceMode.Force:
                m_angularTorque += torque;
                break;

            // Mass-ignoring torque.
            case ForceMode.Acceleration:
                m_angularAcceleration += torque;
                break;

            // Torque over a second applied in an instant.
            case ForceMode.Impulse:
                m_angularTorque += torque / Time.fixedDeltaTime;
                break;

            // Mass-ignoring torque over a second applied in an instant.
            case ForceMode.VelocityChange:
                m_angularAcceleration += torque / Time.fixedDeltaTime;
                break;

            default:
                throw new System.NotImplementedException();
            }
        }
Пример #2
0
        /// <summary>
        /// Adds force at a given point in space, this is the desired way of moving objects and causes both a linear
        /// and angular reaction from the object.
        /// </summary>
        /// <param name="force">The amount of force to be applied.</param>
        /// <param name="point">The point in world co-ordinates of the force.</param>
        /// <param name="mode">How the force should be applied.</param>
        public void AddForceAtPoint(Vector3 force, Vector3 point, ForceMode mode = ForceMode.Force)
        {
            var torque = Vector3.Cross(force, (position + centreOfMass) - point);

            AddForce(force, mode);
            AddTorque(torque, mode);
        }
Пример #3
0
    static int AddForceAtPosition(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3)
            {
                UnityEngine.Rigidbody obj  = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                UnityEngine.Vector3   arg1 = ToLua.ToVector3(L, 3);
                obj.AddForceAtPosition(arg0, arg1);
                return(0);
            }
            else if (count == 4)
            {
                UnityEngine.Rigidbody obj  = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                UnityEngine.Vector3   arg1 = ToLua.ToVector3(L, 3);
                UnityEngine.ForceMode arg2 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 4, typeof(UnityEngine.ForceMode));
                obj.AddForceAtPosition(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Rigidbody.AddForceAtPosition"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #4
0
        /// <summary>
        /// Adds a force to the object using the mode specified. Force and Impulse take the objects mass into account,
        /// Acceleration and VelocityChange ignore mass and move every object at the same speed.
        /// </summary>
        /// <param name="force">The desired force to be applied.</param>
        /// <param name="mode">Describes how the force should be applied.</param>
        public void AddForce(Vector3 force, ForceMode mode = ForceMode.Force)
        {
            switch (mode)
            {
            // Normal force.
            case ForceMode.Force:
                m_linearForce += force;
                break;

            // Mass-ignoring force.
            case ForceMode.Acceleration:
                m_linearAcceleration += force;
                break;

            // Force over a second applied in an instant.
            case ForceMode.Impulse:
                m_linearForce += force / Time.fixedDeltaTime;
                break;

            // Mass-ignoring force over a second applied in an instant.
            case ForceMode.VelocityChange:
                m_linearAcceleration += force / Time.fixedDeltaTime;
                break;

            default:
                throw new System.NotImplementedException();
            }
        }
Пример #5
0
        public void PushUnityEngineForceMode(RealStatePtr L, UnityEngine.ForceMode val)
        {
            if (UnityEngineForceMode_TypeID == -1)
            {
                bool is_first;
                UnityEngineForceMode_TypeID = getTypeId(L, typeof(UnityEngine.ForceMode), out is_first);

                if (UnityEngineForceMode_EnumRef == -1)
                {
                    Utils.LoadCSTable(L, typeof(UnityEngine.ForceMode));
                    UnityEngineForceMode_EnumRef = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
                }
            }

            if (LuaAPI.xlua_tryget_cachedud(L, (int)val, UnityEngineForceMode_EnumRef) == 1)
            {
                return;
            }

            IntPtr buff = LuaAPI.xlua_pushstruct(L, 4, UnityEngineForceMode_TypeID);

            if (!CopyByValue.Pack(buff, 0, (int)val))
            {
                throw new Exception("pack fail fail for UnityEngine.ForceMode ,value=" + val);
            }

            LuaAPI.lua_getref(L, UnityEngineForceMode_EnumRef);
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.xlua_rawseti(L, -2, (int)val);
            LuaAPI.lua_pop(L, 1);
        }
Пример #6
0
    static int IntToEnum(IntPtr L)
    {
        int arg0 = (int)LuaDLL.lua_tonumber(L, 1);

        UnityEngine.ForceMode o = (UnityEngine.ForceMode)arg0;
        ToLua.Push(L, o);
        return(1);
    }
Пример #7
0
 public void AddRelativeForce(UnityEngine.Vector3 force, UnityEngine.ForceMode mode)
 {
     //Mock Data:
     if (m_functionCallCounts == null)
     {
         m_functionCallCounts = new Dictionary <string, int>();
     }
     if (!m_functionCallCounts.ContainsKey("Void AddRelativeForce(Vector3, ForceMode)"))
     {
         m_functionCallCounts.Add("Void AddRelativeForce(Vector3, ForceMode)", 0);
     }
     m_functionCallCounts["Void AddRelativeForce(Vector3, ForceMode)"]++;
 }
Пример #8
0
 public void AddForce(System.Single x, System.Single y, System.Single z, UnityEngine.ForceMode mode)
 {
     //Mock Data:
     if (m_functionCallCounts == null)
     {
         m_functionCallCounts = new Dictionary <string, int>();
     }
     if (!m_functionCallCounts.ContainsKey("Void AddForce(Single, Single, Single, ForceMode)"))
     {
         m_functionCallCounts.Add("Void AddForce(Single, Single, Single, ForceMode)", 0);
     }
     m_functionCallCounts["Void AddForce(Single, Single, Single, ForceMode)"]++;
 }
Пример #9
0
    static int AddRelativeTorque(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.Rigidbody obj  = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                obj.AddRelativeTorque(arg0);
                return(0);
            }
            else if (count == 3)
            {
                UnityEngine.Rigidbody obj  = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                UnityEngine.ForceMode arg1 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 3, typeof(UnityEngine.ForceMode));
                obj.AddRelativeTorque(arg0, arg1);
                return(0);
            }
            else if (count == 4)
            {
                UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
                obj.AddRelativeTorque(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 5)
            {
                UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
                UnityEngine.ForceMode arg3 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 5, typeof(UnityEngine.ForceMode));
                obj.AddRelativeTorque(arg0, arg1, arg2, arg3);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Rigidbody.AddRelativeTorque"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #10
0
        public void UpdateUnityEngineForceMode(RealStatePtr L, int index, UnityEngine.ForceMode val)
        {
            if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TUSERDATA)
            {
                if (LuaAPI.xlua_gettypeid(L, index) != UnityEngineForceMode_TypeID)
                {
                    throw new Exception("invalid userdata for UnityEngine.ForceMode");
                }

                IntPtr buff = LuaAPI.lua_touserdata(L, index);
                if (!CopyByValue.Pack(buff, 0, (int)val))
                {
                    throw new Exception("pack fail for UnityEngine.ForceMode ,value=" + val);
                }
            }

            else
            {
                throw new Exception("try to update a data with lua type:" + LuaAPI.lua_type(L, index));
            }
        }
Пример #11
0
        public void Get(RealStatePtr L, int index, out UnityEngine.ForceMode val)
        {
            LuaTypes type = LuaAPI.lua_type(L, index);

            if (type == LuaTypes.LUA_TUSERDATA)
            {
                if (LuaAPI.xlua_gettypeid(L, index) != UnityEngineForceMode_TypeID)
                {
                    throw new Exception("invalid userdata for UnityEngine.ForceMode");
                }

                IntPtr buff = LuaAPI.lua_touserdata(L, index);
                int    e;
                if (!CopyByValue.UnPack(buff, 0, out e))
                {
                    throw new Exception("unpack fail for UnityEngine.ForceMode");
                }
                val = (UnityEngine.ForceMode)e;
            }
            else
            {
                val = (UnityEngine.ForceMode)objectCasters.GetCaster(typeof(UnityEngine.ForceMode))(L, index, null);
            }
        }
Пример #12
0
 static void Push(IntPtr L, UnityEngine.ForceMode arg)
 {
     ToLua.Push(L, arg);
 }
Пример #13
0
 public void AddExplosionForce(System.Single explosionForce, UnityEngine.Vector3 explosionPosition, System.Single explosionRadius, System.Single upwardsModifier, UnityEngine.ForceMode mode)
 {
     //Mock Data:
     if (m_functionCallCounts == null)
     {
         m_functionCallCounts = new Dictionary <string, int>();
     }
     if (!m_functionCallCounts.ContainsKey("Void AddExplosionForce(Single, Vector3, Single, Single, ForceMode)"))
     {
         m_functionCallCounts.Add("Void AddExplosionForce(Single, Vector3, Single, Single, ForceMode)", 0);
     }
     m_functionCallCounts["Void AddExplosionForce(Single, Vector3, Single, Single, ForceMode)"]++;
 }