You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.4 KiB
C#
77 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Autohand {
|
|
public struct SaveRigidbodyData {
|
|
GameObject origin;
|
|
float mass;
|
|
float angularDrag;
|
|
float drag;
|
|
bool useGravity;
|
|
bool isKinematic;
|
|
RigidbodyInterpolation interpolation;
|
|
CollisionDetectionMode collisionDetectionMode;
|
|
RigidbodyConstraints constraints;
|
|
|
|
public SaveRigidbodyData(Rigidbody from, bool removeBody = true) {
|
|
origin = from.gameObject;
|
|
mass = from.mass;
|
|
drag = from.drag;
|
|
angularDrag = from.angularDrag;
|
|
useGravity = from.useGravity;
|
|
isKinematic = from.isKinematic;
|
|
interpolation = from.interpolation;
|
|
collisionDetectionMode = from.collisionDetectionMode;
|
|
constraints = from.constraints;
|
|
if(removeBody)
|
|
GameObject.Destroy(from);
|
|
}
|
|
public SaveRigidbodyData(SaveRigidbodyData from) {
|
|
origin = from.origin;
|
|
mass = from.mass;
|
|
drag = from.drag;
|
|
angularDrag = from.angularDrag;
|
|
useGravity = from.useGravity;
|
|
isKinematic = from.isKinematic;
|
|
interpolation = from.interpolation;
|
|
collisionDetectionMode = from.collisionDetectionMode;
|
|
constraints = from.constraints;
|
|
}
|
|
|
|
public Transform GetOrigin() {
|
|
return origin.transform;
|
|
}
|
|
|
|
public bool IsSet() {
|
|
return origin != null;
|
|
}
|
|
|
|
public Rigidbody ReloadRigidbody() {
|
|
if(origin != null) {
|
|
if(origin.CanGetComponent<Rigidbody>(out var currBody))
|
|
return currBody;
|
|
var from = origin.AddComponent<Rigidbody>();
|
|
if(from != null) {
|
|
from.mass = mass;
|
|
from.drag = drag;
|
|
from.angularDrag = angularDrag;
|
|
from.useGravity = useGravity;
|
|
from.isKinematic = isKinematic;
|
|
from.interpolation = interpolation;
|
|
from.collisionDetectionMode = collisionDetectionMode;
|
|
from.constraints = constraints;
|
|
origin = null;
|
|
return from;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
public static class GrabbableExtensions {
|
|
|
|
|
|
}
|
|
} |