79 lines
2.2 KiB
C#
79 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using XED.Attributes;
|
|
|
|
namespace XED
|
|
{
|
|
public class RenderableTwinObject : TwinObject
|
|
{
|
|
public TwinPhysics physics = new TwinPhysics();
|
|
public event Action<TwinObject, TwinObject> onTwinConflictEvent;
|
|
public event Action<TwinObject, TwinObject> onTwinDeconflictEvent;
|
|
[PropertyVisible, Tooltip("ù ¹øÂ° info")]
|
|
public bool IsDisplayable;
|
|
[PropertyVisible, Tooltip("µÎ ¹øÂ° info")]
|
|
public bool IsInteractible;
|
|
public HashSet<RenderableTwinObject> crashObjects = new();
|
|
public BoxHighLighter boxHighLighter;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
base.AfterAwake();
|
|
physics.Init(this);
|
|
}
|
|
|
|
public virtual void SetDisplayable(bool value)
|
|
{
|
|
metaData.modeling.SetActive(!value);
|
|
}
|
|
|
|
public virtual void SetInteractible(bool value)
|
|
{
|
|
IsInteractible = !value;
|
|
physics.SetActive(!value);
|
|
}
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!other.TryGetComponent(out RenderableTwinObject contracter))
|
|
return;
|
|
crashObjects.Add(contracter);
|
|
Conflict(contracter);
|
|
}
|
|
|
|
public virtual void MaterialChange(Material mat)
|
|
{
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if (!other.TryGetComponent(out RenderableTwinObject twin))
|
|
return;
|
|
CrashObjectRemove(twin);
|
|
}
|
|
|
|
public void CrashBoxHighLightDeActive()
|
|
{
|
|
foreach (var contracter in crashObjects)
|
|
{
|
|
contracter.CrashObjectRemove(this);
|
|
}
|
|
}
|
|
public void CrashObjectRemove<T>(T crashObject) where T : RenderableTwinObject
|
|
{
|
|
crashObjects.Remove(crashObject);
|
|
Deconflict(crashObject);
|
|
}
|
|
public virtual void Conflict(TwinObject contract)
|
|
{
|
|
onTwinConflictEvent?.Invoke(this, contract);
|
|
}
|
|
|
|
public virtual void Deconflict(TwinObject contract)
|
|
{
|
|
onTwinDeconflictEvent?.Invoke(this, contract);
|
|
}
|
|
}
|
|
} |