Added Feel plugin
This commit is contained in:
105
Assets/External/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyCenterOfMass.cs
vendored
Normal file
105
Assets/External/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyCenterOfMass.cs
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Add this class to a Rigidbody or Rigidbody2D to be able to edit its center of mass from the inspector directly
|
||||
/// </summary>
|
||||
public class MMRigidbodyCenterOfMass : MonoBehaviour
|
||||
{
|
||||
/// the possible modes this class can start on
|
||||
public enum AutomaticSetModes { Awake, Start, ScriptOnly }
|
||||
|
||||
[Header("CenterOfMass")]
|
||||
/// the offset to apply to the center of mass
|
||||
public Vector3 CenterOfMassOffset;
|
||||
|
||||
[Header("Automation")]
|
||||
/// whether to set the center of mass on awake, start, or via script only
|
||||
public AutomaticSetModes AutomaticSetMode = AutomaticSetModes.Awake;
|
||||
/// whether or not this component should auto destroy after a set
|
||||
public bool AutoDestroyComponentAfterSet = true;
|
||||
|
||||
[Header("Test")]
|
||||
/// the size of the gizmo point to display at the center of mass
|
||||
public float GizmoPointSize = 0.05f;
|
||||
/// a button to test the set method
|
||||
[MMInspectorButton("SetCenterOfMass")]
|
||||
public bool SetCenterOfMassButton;
|
||||
|
||||
protected Vector3 _gizmoCenter;
|
||||
protected Rigidbody _rigidbody;
|
||||
#if MM_PHYSICS2D
|
||||
protected Rigidbody2D _rigidbody2D;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// On Awake we grab our components and set our center of mass if needed
|
||||
/// </summary>
|
||||
protected virtual void Awake()
|
||||
{
|
||||
Initialization();
|
||||
|
||||
if (AutomaticSetMode == AutomaticSetModes.Awake)
|
||||
{
|
||||
SetCenterOfMass();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Start we set our center of mass if needed
|
||||
/// </summary>
|
||||
protected virtual void Start()
|
||||
{
|
||||
if (AutomaticSetMode == AutomaticSetModes.Start)
|
||||
{
|
||||
SetCenterOfMass();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs the rigidbody or rigidbody2D components
|
||||
/// </summary>
|
||||
protected virtual void Initialization()
|
||||
{
|
||||
_rigidbody = this.gameObject.MMGetComponentNoAlloc<Rigidbody>();
|
||||
#if MM_PHYSICS2D
|
||||
_rigidbody2D = this.gameObject.MMGetComponentNoAlloc<Rigidbody2D>();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the center of mass on the rigidbody or rigidbody2D
|
||||
/// </summary>
|
||||
public virtual void SetCenterOfMass()
|
||||
{
|
||||
if (_rigidbody != null)
|
||||
{
|
||||
_rigidbody.centerOfMass = CenterOfMassOffset;
|
||||
}
|
||||
|
||||
#if MM_PHYSICS2D
|
||||
if (_rigidbody2D != null)
|
||||
{
|
||||
_rigidbody2D.centerOfMass = CenterOfMassOffset;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (AutoDestroyComponentAfterSet)
|
||||
{
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On DrawGizmosSelected, we draw a yellow point at the position of our center of mass
|
||||
/// </summary>
|
||||
protected virtual void OnDrawGizmosSelected()
|
||||
{
|
||||
_gizmoCenter = this.transform.TransformPoint(CenterOfMassOffset);
|
||||
MMDebug.DrawGizmoPoint(_gizmoCenter, GizmoPointSize, Color.yellow);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyCenterOfMass.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyCenterOfMass.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efda6721f0081284c9800ba75977ba30
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyCenterOfMass.cs
|
||||
uploadId: 830868
|
||||
318
Assets/External/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyInterface.cs
vendored
Normal file
318
Assets/External/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyInterface.cs
vendored
Normal file
@@ -0,0 +1,318 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// This class acts as an interface to allow the demo levels to work whether the environment (colliders, rigidbodies) are set as 2D or 3D.
|
||||
/// If you already know for sure that you're going for a 2D or 3D game, I suggest you replace the use of this class with the appropriate classes.
|
||||
/// </summary>
|
||||
[AddComponentMenu("More Mountains/Tools/Rigidbody Interface/MM Rigidbody Interface")]
|
||||
public class MMRigidbodyInterface : MonoBehaviour
|
||||
{
|
||||
#if MM_PHYSICS2D
|
||||
/// <summary>
|
||||
/// Returns the rigidbody's position
|
||||
/// </summary>
|
||||
/// <value>The position.</value>
|
||||
public Vector3 position
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_rigidbody2D != null)
|
||||
{
|
||||
return _rigidbody2D.position;
|
||||
}
|
||||
if (_rigidbody != null)
|
||||
{
|
||||
return _rigidbody.position;
|
||||
}
|
||||
return Vector3.zero;
|
||||
}
|
||||
set { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only use if you absolutely need to target the rigidbody2D specifically
|
||||
/// </summary>
|
||||
/// <value>The internal rigid body2 d.</value>
|
||||
public Rigidbody2D InternalRigidBody2D
|
||||
{
|
||||
get {
|
||||
return _rigidbody2D;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only use if you absolutely need to target the rigidbody2D specifically
|
||||
/// </summary>
|
||||
/// <value>The internal rigid body.</value>
|
||||
public Rigidbody InternalRigidBody
|
||||
{
|
||||
get {
|
||||
return _rigidbody;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the velocity of the rigidbody associated to the interface.
|
||||
/// </summary>
|
||||
/// <value>The velocity.</value>
|
||||
public Vector3 Velocity
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mode == "2D")
|
||||
{
|
||||
return(_rigidbody2D.linearVelocity);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_mode == "3D")
|
||||
{
|
||||
return(_rigidbody.linearVelocity);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(0,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_mode == "2D") {
|
||||
_rigidbody2D.linearVelocity = value;
|
||||
}
|
||||
if (_mode == "3D") {
|
||||
_rigidbody.linearVelocity = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collider bounds.
|
||||
/// </summary>
|
||||
/// <value>The collider bounds.</value>
|
||||
public Bounds ColliderBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_rigidbody2D != null)
|
||||
{
|
||||
return _collider2D.bounds;
|
||||
}
|
||||
if (_rigidbody != null)
|
||||
{
|
||||
return _collider.bounds;
|
||||
}
|
||||
return new Bounds();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this <see cref="MoreMountains.Tools.RigidbodyInterface"/> is kinematic.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if is kinematic; otherwise, <c>false</c>.</value>
|
||||
public bool isKinematic
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mode == "2D")
|
||||
{
|
||||
return(_rigidbody2D.bodyType == RigidbodyType2D.Kinematic);
|
||||
}
|
||||
if (_mode == "3D")
|
||||
{
|
||||
return(_rigidbody.isKinematic);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected string _mode;
|
||||
protected Rigidbody2D _rigidbody2D;
|
||||
protected Rigidbody _rigidbody;
|
||||
protected Collider2D _collider2D;
|
||||
protected Collider _collider;
|
||||
protected Bounds _colliderBounds;
|
||||
|
||||
/// <summary>
|
||||
/// Initialization
|
||||
/// </summary>
|
||||
protected virtual void Awake ()
|
||||
{
|
||||
// we check for rigidbodies, and depending on their presence determine if the interface will work with 2D or 3D rigidbodies and colliders.
|
||||
_rigidbody2D=GetComponent<Rigidbody2D>();
|
||||
_rigidbody=GetComponent<Rigidbody>();
|
||||
|
||||
if (_rigidbody2D != null)
|
||||
{
|
||||
_mode="2D";
|
||||
_collider2D = GetComponent<Collider2D> ();
|
||||
}
|
||||
if (_rigidbody != null)
|
||||
{
|
||||
_mode="3D";
|
||||
_collider = GetComponent<Collider> ();
|
||||
}
|
||||
if (_rigidbody==null && _rigidbody2D==null)
|
||||
{
|
||||
Debug.LogWarning("A RigidBodyInterface has been added to "+gameObject+" but there's no Rigidbody or Rigidbody2D on it.", gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified force to the rigidbody associated to the interface..
|
||||
/// </summary>
|
||||
/// <param name="force">Force.</param>
|
||||
public virtual void AddForce(Vector3 force)
|
||||
{
|
||||
if (_mode == "2D")
|
||||
{
|
||||
_rigidbody2D.AddForce(force,ForceMode2D.Impulse);
|
||||
}
|
||||
if (_mode == "3D")
|
||||
{
|
||||
_rigidbody.AddForce(force);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified relative force to the rigidbody associated to the interface..
|
||||
/// </summary>
|
||||
/// <param name="force">Force.</param>
|
||||
public virtual void AddRelativeForce(Vector3 force)
|
||||
{
|
||||
if (_mode == "2D")
|
||||
{
|
||||
_rigidbody2D.AddRelativeForce(force,ForceMode2D.Impulse);
|
||||
}
|
||||
if (_mode == "3D")
|
||||
{
|
||||
_rigidbody.AddRelativeForce(force);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Move the rigidbody to the position vector specified
|
||||
/// </summary>
|
||||
/// <param name="newPosition"></param>
|
||||
public virtual void MovePosition(Vector3 newPosition)
|
||||
{
|
||||
if (_mode == "2D")
|
||||
{
|
||||
_rigidbody2D.MovePosition(newPosition);
|
||||
}
|
||||
if (_mode == "3D")
|
||||
{
|
||||
_rigidbody.MovePosition(newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the angular velocity.
|
||||
/// </summary>
|
||||
public virtual void ResetAngularVelocity()
|
||||
{
|
||||
if (_mode == "2D")
|
||||
{
|
||||
_rigidbody2D.angularVelocity = 0;
|
||||
}
|
||||
if (_mode == "3D")
|
||||
{
|
||||
_rigidbody.angularVelocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the rotation.
|
||||
/// </summary>
|
||||
public virtual void ResetRotation()
|
||||
{
|
||||
if (_mode == "2D")
|
||||
{
|
||||
_rigidbody2D.rotation = 0;
|
||||
}
|
||||
if (_mode == "3D")
|
||||
{
|
||||
_rigidbody.rotation = Quaternion.identity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the rigidbody associated to the interface is kinematic
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if this instance is kinematic the specified status; otherwise, <c>false</c>.</returns>
|
||||
/// <param name="status">If set to <c>true</c> status.</param>
|
||||
public virtual void IsKinematic(bool status)
|
||||
{
|
||||
if (_mode == "2D")
|
||||
{
|
||||
_rigidbody2D.bodyType = status ? RigidbodyType2D.Kinematic : RigidbodyType2D.Dynamic;
|
||||
}
|
||||
if (_mode == "3D")
|
||||
{
|
||||
_rigidbody.isKinematic = status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Enables the box collider associated to the interface.
|
||||
/// </summary>
|
||||
/// <param name="status">If set to <c>true</c> status.</param>
|
||||
public virtual void EnableBoxCollider(bool status)
|
||||
{
|
||||
if (_mode == "2D")
|
||||
{
|
||||
GetComponent<Collider2D>().enabled=status;
|
||||
}
|
||||
if (_mode == "3D")
|
||||
{
|
||||
GetComponent<Collider>().enabled=status;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to check if you're dealing with a 3D object
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is3 d; otherwise, <c>false</c>.</value>
|
||||
public bool Is3D
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mode=="3D")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to check if you're dealing with a 2D object
|
||||
/// </summary>
|
||||
/// <value>The position.</value>
|
||||
public bool Is2D
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mode=="2D")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
20
Assets/External/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyInterface.cs.meta
vendored
Normal file
20
Assets/External/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyInterface.cs.meta
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1eac7cbe197dc794dbaed99e0565d2de
|
||||
timeCreated: 1523900507
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Accessories/MMPhysics/MMRigidbodyInterface.cs
|
||||
uploadId: 830868
|
||||
Reference in New Issue
Block a user