暫無描述
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.

SceneRenderPipeline.cs 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #if UNITY_EDITOR
  2. using UnityEditor;
  3. #endif
  4. using System;
  5. using UnityEngine.Analytics;
  6. namespace UnityEngine.Rendering
  7. {
  8. /// <summary>
  9. /// Setup a specific render pipeline on scene loading.
  10. /// This need to be used with caution as it will change project configuration.
  11. /// </summary>
  12. #if UNITY_EDITOR
  13. [ExecuteAlways]
  14. #endif
  15. public class SceneRenderPipeline : MonoBehaviour
  16. {
  17. #if UNITY_EDITOR
  18. [SerializeField] bool firstTimeCreated = true;
  19. /// <summary>
  20. /// Scriptable Render Pipeline Asset to setup on scene load.
  21. /// </summary>
  22. public RenderPipelineAsset renderPipelineAsset;
  23. void Awake()
  24. {
  25. if (firstTimeCreated)
  26. {
  27. renderPipelineAsset = GraphicsSettings.defaultRenderPipeline;
  28. firstTimeCreated = false;
  29. }
  30. //Send analytics each time to find usage in content dl on the asset store too
  31. SceneRenderPipelineAnalytic.SendAnalytic(this);
  32. }
  33. void OnEnable()
  34. {
  35. GraphicsSettings.defaultRenderPipeline = renderPipelineAsset;
  36. }
  37. [AnalyticInfo(eventName: "sceneRenderPipelineAssignment", vendorKey: "unity.srp", maxEventsPerHour: 10, maxNumberOfElements: 1000)]
  38. class SceneRenderPipelineAnalytic : IAnalytic
  39. {
  40. public SceneRenderPipelineAnalytic(string guid)
  41. {
  42. m_Data = new Data
  43. {
  44. scene_guid = guid
  45. };
  46. }
  47. [System.Diagnostics.DebuggerDisplay("{scene_guid}")]
  48. [Serializable]
  49. internal struct Data : IAnalytic.IData
  50. {
  51. // Naming convention for analytics data
  52. public string scene_guid;
  53. };
  54. public bool TryGatherData(out IAnalytic.IData data, out Exception error)
  55. {
  56. data = m_Data;
  57. error = null;
  58. return true;
  59. }
  60. static public void SendAnalytic(SceneRenderPipeline sender)
  61. {
  62. SceneRenderPipelineAnalytic analytic = new SceneRenderPipelineAnalytic(sender.gameObject.scene.GetGUID());
  63. EditorAnalytics.SendAnalytic(analytic);
  64. }
  65. Data m_Data;
  66. }
  67. #endif
  68. }
  69. }