Brak opisu
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.

ShapeProviderUtility.cs 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. #if UNITY_EDITOR
  6. using UnityEditor;
  7. #endif
  8. namespace UnityEngine.Rendering.Universal
  9. {
  10. internal class ShapeProviderUtility
  11. {
  12. static public void CallOnBeforeRender(ShadowShape2DProvider shapeProvider, Component component, ShadowMesh2D shadowMesh, Bounds bounds)
  13. {
  14. if (component != null)
  15. {
  16. if (shapeProvider != null && component.gameObject.activeInHierarchy)
  17. shapeProvider.OnBeforeRender(component, bounds, shadowMesh);
  18. }
  19. else if (shadowMesh != null && shadowMesh.mesh != null)
  20. {
  21. shadowMesh.mesh.Clear();
  22. }
  23. }
  24. static public void PersistantDataCreated(ShadowShape2DProvider shapeProvider, Component component, ShadowMesh2D shadowMesh)
  25. {
  26. if (component != null)
  27. {
  28. if (shapeProvider != null)
  29. shapeProvider.OnPersistantDataCreated(component, shadowMesh);
  30. }
  31. }
  32. #if UNITY_EDITOR
  33. static public void TryGetDefaultShadowShapeProviderSource(GameObject go, out Component outSource, out ShadowShape2DProvider outProvider)
  34. {
  35. outSource = null;
  36. outProvider = null;
  37. // Create some providers to check against.
  38. var providerTypes = TypeCache.GetTypesDerivedFrom<ShadowShape2DProvider>();
  39. var providers = new List<ShadowShape2DProvider>(providerTypes.Count);
  40. foreach (Type providerType in providerTypes)
  41. {
  42. if (providerType.IsAbstract)
  43. continue;
  44. providers.Add(Activator.CreateInstance(providerType) as ShadowShape2DProvider);
  45. }
  46. // Fetch the components to check.
  47. var components = go.GetComponents<Component>();
  48. var currentPriority = int.MinValue;
  49. foreach (var component in components)
  50. {
  51. // check each component to see if it is a valid provider
  52. foreach (var provider in providers)
  53. {
  54. if (provider.IsShapeSource(component))
  55. {
  56. var menuPriority = provider.Priority();
  57. if (menuPriority > currentPriority)
  58. {
  59. currentPriority = menuPriority;
  60. outSource = component;
  61. outProvider = provider;
  62. }
  63. }
  64. }
  65. }
  66. }
  67. #endif
  68. }
  69. }