2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.9 KiB

5 years ago
  1. //========= Copyright 2016-2020, HTC Corporation. All rights reserved. ===========
  2. using HTC.UnityPlugin.Utility;
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. namespace HTC.UnityPlugin.Pointer3D
  8. {
  9. [DisallowMultipleComponent]
  10. public abstract class BaseMultiMethodRaycaster : BaseRaycaster
  11. {
  12. protected readonly IndexedSet<IRaycastMethod> methods = new IndexedSet<IRaycastMethod>();
  13. #if UNITY_EDITOR
  14. protected override void Reset()
  15. {
  16. base.Reset();
  17. if (GetComponent<PhysicsRaycastMethod>() == null) { gameObject.AddComponent<PhysicsRaycastMethod>(); }
  18. if (GetComponent<CanvasRaycastMethod>() == null) { gameObject.AddComponent<CanvasRaycastMethod>(); }
  19. }
  20. #endif
  21. public void AddRaycastMethod(IRaycastMethod obj)
  22. {
  23. methods.AddUnique(obj);
  24. }
  25. public void RemoveRaycastMethod(IRaycastMethod obj)
  26. {
  27. methods.Remove(obj);
  28. }
  29. protected void ForeachRaycastMethods(Ray ray, float distance, List<RaycastResult> resultAppendList)
  30. {
  31. var results = ListPool<RaycastResult>.Get();
  32. for (int i = methods.Count - 1; i >= 0; --i)
  33. {
  34. var method = methods[i];
  35. if (!method.enabled) { continue; }
  36. method.Raycast(ray, distance, results);
  37. }
  38. var comparer = GetRaycasterResultComparer();
  39. if (comparer != null)
  40. {
  41. results.Sort(comparer);
  42. }
  43. for (int i = 0, imax = results.Count; i < imax; ++i)
  44. {
  45. resultAppendList.Add(results[i]);
  46. }
  47. ListPool<RaycastResult>.Release(results);
  48. }
  49. protected virtual Comparison<RaycastResult> GetRaycasterResultComparer()
  50. {
  51. return Pointer3DInputModule.defaultRaycastComparer;
  52. }
  53. }
  54. }