123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using EPOOutline;
- using QFramework;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RayCastItem : MonoBehaviour
- {
- private Outlinable outLinable;
- /// <summary>
- /// 自身及父级列表
- /// </summary>
- private List<RayCastItem> parentList;
- /// <summary>
- /// 射线检测活跃状态
- /// </summary>
- 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<Outlinable>() == null
- ? this.gameObject.AddComponent<Outlinable>()
- : this.GetComponent<Outlinable>();
- outLinable.AddAllChildRenderersToRenderingList();
- outLinable.enabled = false;
- localLayer = this.gameObject.layer;
- }
- private void InitChildCollider()
- {
- if (childCollider == null)
- {
- childCollider = this.GetComponentsInChildren<Collider>();
- }
- }
- public void InitRayCastParents()
- {
- if (parentList == null)
- {
- CreatParentLists();
- }
- }
- public void CreatParentLists()
- {
- parentList = new List<RayCastItem>();
- parentList.AddRange(this.transform.GetComponentsInParent<RayCastItem>());
- }
- 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<Outlinable>())
- {
- //根据现况类型切换高亮预设
- OutLineManager.Instance.ResetOutLinableByType(item, outLineType);
- item.enabled = true;
- }
- }
- public void CloseHighlighter()
- {
- foreach (var item in this.GetComponentsInChildren<Outlinable>())
- {
- item.enabled = false;
- }
- }
- }
|