55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Pool;
|
|
using XED.Interfaces;
|
|
using static XED.Wall;
|
|
|
|
namespace XED
|
|
{
|
|
public class BoxHighLighter : MonoBehaviour, IPooledObject
|
|
{
|
|
private Material material;
|
|
private MeshRenderer meshRenderer;
|
|
|
|
public IObjectPool<Component> Pool { get; set; }
|
|
|
|
void OnDisable()
|
|
{
|
|
Pool.Release(this);
|
|
}
|
|
//TODO::
|
|
public override void AfterAwake()
|
|
{
|
|
material = Resources.Load<Material>("Materials/Mat_BoxHighLight");
|
|
meshRenderer = GetComponent<MeshRenderer>();
|
|
meshRenderer.material = material;
|
|
}
|
|
|
|
private void WallBoxSize(Wall wall)
|
|
{
|
|
var ySize = wall.meshfilter.mesh.bounds.size.y;
|
|
|
|
var start = wall.n_GonPoints[(int)VertexPoint.LeftCenter];
|
|
var end = wall.n_GonPoints[(int)VertexPoint.RightCenter];
|
|
var zSize = Vector3.Distance(start, end);
|
|
//zfighting¶§¹®¿¡ 0.01¾¿ ´õÇØÁÜ
|
|
transform.localPosition = Vector3.up * (ySize * 0.5f);
|
|
transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
|
|
transform.localScale = new Vector3(0.11f, ySize + 0.01f, zSize + 0.01f);
|
|
}
|
|
|
|
public void TwinObjectBoxSize(TwinObject twinObject)
|
|
{
|
|
if(twinObject is Wall)
|
|
{
|
|
WallBoxSize((Wall)twinObject);
|
|
return;
|
|
}
|
|
|
|
var collider = twinObject.GetComponent<BoxCollider>();
|
|
transform.localScale = collider.size;
|
|
transform.localPosition = Vector3.zero;
|
|
transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
|
|
}
|
|
}
|
|
}
|