using EPOOutline;
using QFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayCastItem : MonoBehaviour
{
private Outlinable outLinable;
///
/// 自身及父级列表
///
private List parentList;
///
/// 射线检测活跃状态
///
private bool activeState = false;
public bool ActiveState
{
get
{
return activeState;
}
set
{
if (activeState != value)
{
activeState = value;
InitChildCollider();
foreach (var item in childCollider)
{
item.gameObject.layer = activeState ? CameraRayCastManager.RayCastActivelayer : localLayer;
}
}
}
}
public bool HighlighterConstant
{
get
{
if (outLinable == null)
return false;
else
return outLinable.isActiveAndEnabled;
}
}
private int localLayer;
private Collider[] childCollider;
private void Awake()
{
outLinable = this.GetComponent() == null
? this.gameObject.AddComponent()
: this.GetComponent();
outLinable.AddAllChildRenderersToRenderingList();
outLinable.enabled = false;
localLayer = this.gameObject.layer;
}
private void InitChildCollider()
{
if (childCollider == null)
{
childCollider = this.GetComponentsInChildren();
}
}
public void InitRayCastParents()
{
if (parentList == null)
{
CreatParentLists();
}
}
public void CreatParentLists()
{
parentList = new List();
parentList.AddRange(this.transform.GetComponentsInParent());
}
public bool Contains(RayCastItem item)
{
if (parentList == null)
{
return this == item;
}
return parentList.Contains(item);
}
public void OpenHighlighter(OutLineType outLineType)
{
foreach (var item in this.GetComponentsInChildren())
{
//根据现况类型切换高亮预设
OutLineManager.Instance.ResetOutLinableByType(item, outLineType);
item.enabled = true;
}
}
public void CloseHighlighter()
{
foreach (var item in this.GetComponentsInChildren())
{
item.enabled = false;
}
}
}