浏览代码

create rigidbody action

/main
Laurent 5 年前
当前提交
7a954e26
共有 2 个文件被更改,包括 98 次插入0 次删除
  1. 87
      Runtime/LevelScripting/Actions/RigidbodyAction.cs
  2. 11
      Runtime/LevelScripting/Actions/RigidbodyAction.cs.meta

87
Runtime/LevelScripting/Actions/RigidbodyAction.cs


using NaughtyAttributes;
using UnityEngine;
namespace GameplayIngredients.Actions
{
public enum RigidbodyActionType { Force, Torque, ExplosionForce, Sleep };
public enum ActionSpace { Local, World };
[ExecuteAlways]
public class RigidbodyAction : ActionBase
{
public Rigidbody rb;
[OnValueChanged("OnParameterTypeChanged")]
public RigidbodyActionType actionType;
bool force = true;
bool explosion;
[ShowIf("force")]
public ActionSpace actionSpace;
[ShowIf("force")]
public ForceMode forceMode;
[ShowIf("force")]
public Vector3 direction;
[ShowIf("explosion")]
public float explosionForce;
[ShowIf("explosion")]
public Vector3 explositonPosition;
[ShowIf("explosion")]
public float explosionRadius;
public override void Execute(GameObject instigator = null)
{
if (rb == null)
return;
switch (actionType)
{
case RigidbodyActionType.Force:
if(actionSpace == ActionSpace.World)
{
rb.AddForce(direction, forceMode);
}
if(actionSpace == ActionSpace.Local)
{
rb.AddRelativeForce(direction, forceMode);
}
break;
case RigidbodyActionType.Torque:
if (actionSpace == ActionSpace.World)
{
rb.AddTorque(direction, forceMode);
}
if (actionSpace == ActionSpace.Local)
{
rb.AddRelativeTorque(direction, forceMode);
}
break;
case RigidbodyActionType.ExplosionForce:
rb.AddExplosionForce(explosionForce, explositonPosition, explosionRadius, 0, forceMode);
break;
case RigidbodyActionType.Sleep:
rb.Sleep();
break;
}
}
private void OnParameterTypeChanged()
{
force = false;
explosion = false;
switch (actionType)
{
case RigidbodyActionType.Force:
force = true;
break;
case RigidbodyActionType.Torque:
force = true;
break;
case RigidbodyActionType.ExplosionForce:
explosion = true;
break;
}
}
}
}

11
Runtime/LevelScripting/Actions/RigidbodyAction.cs.meta


fileFormatVersion: 2
guid: d3490d67f14565045b8de2af2380b379
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存