55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using WI.Util;
|
|
|
|
namespace XED
|
|
{
|
|
[Serializable]
|
|
public class TwinPhysics
|
|
{
|
|
TwinObject owner;
|
|
private Rigidbody rg;
|
|
public Collider areabox;
|
|
private Vector3[] Vertices;
|
|
internal bool activeSelf
|
|
{
|
|
get
|
|
{
|
|
if (areabox == null)
|
|
return true;
|
|
return areabox.enabled;
|
|
}
|
|
}
|
|
|
|
public Vector3Int Size { get; private set; }
|
|
public void Init(TwinObject owner)
|
|
{
|
|
this.owner = owner;
|
|
GenerateDefalutPhysics();
|
|
}
|
|
|
|
void GenerateDefalutPhysics()
|
|
{
|
|
areabox = owner.GetComponentInChildren<BoxCollider>();
|
|
if (areabox == null)
|
|
return;
|
|
areabox.isTrigger = true;
|
|
rg = owner.transform.GetOrAddComponent<Rigidbody>();
|
|
rg.isKinematic = true;
|
|
rg.useGravity = false;
|
|
Vertices = new Vector3[4];
|
|
|
|
Vertices[0] = areabox.bounds.center + new Vector3(-areabox.bounds.size.x, -areabox.bounds.size.y, -areabox.bounds.size.z) * 0.5f;
|
|
Vertices[1] = areabox.bounds.center + new Vector3(areabox.bounds.size.x, -areabox.bounds.size.y, -areabox.bounds.size.z) * 0.5f;
|
|
Vertices[2] = areabox.bounds.center + new Vector3(areabox.bounds.size.x, -areabox.bounds.size.y, areabox.bounds.size.z) * 0.5f;
|
|
Vertices[3] = areabox.bounds.center + new Vector3(-areabox.bounds.size.x, -areabox.bounds.size.y, areabox.bounds.size.z) * 0.5f;
|
|
|
|
Size = new Vector3Int((int)Mathf.Abs((Vertices[0] - Vertices[1]).x), (int)Mathf.Abs((Vertices[0] - Vertices[3]).y), 1);
|
|
}
|
|
|
|
public void SetActive(bool value)
|
|
{
|
|
areabox.enabled = value;
|
|
}
|
|
}
|
|
} |