DynamicBackgroundControler.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using UnityEngine;
  2. using System.Collections;
  3. /// <summary>
  4. /// 动态UI背景图管理器
  5. /// </summary>
  6. public class DynamicBackgroundControler : MonoBehaviour
  7. {
  8. /// <summary>
  9. /// 单键
  10. /// </summary>
  11. private static DynamicBackgroundControler pInit = null;
  12. /// <summary>
  13. /// 背景图
  14. /// </summary>
  15. private GameObject mBgPlane;
  16. /// <summary>
  17. /// 获取管理者
  18. /// </summary>
  19. /// <returns>单键实例</returns>
  20. public static DynamicBackgroundControler Instance()
  21. {
  22. return pInit;
  23. }
  24. /// <summary>
  25. /// 初始化
  26. /// </summary>
  27. private void Awake()
  28. {
  29. pInit = this;
  30. //// 切换关卡时不删除
  31. DontDestroyOnLoad(this);
  32. }
  33. /// <summary>
  34. /// 相机映射图片
  35. /// </summary>
  36. private RenderTexture renderTexture;
  37. /// <summary>
  38. /// 开始
  39. /// </summary>
  40. private void Start()
  41. {
  42. //renderTexure赋值
  43. GameObject _mCamera = this.transform.Find("Camera").gameObject;
  44. if (_mCamera.GetComponent<AudioListener>() != null)
  45. {
  46. Destroy(_mCamera.GetComponent<AudioListener>());
  47. }
  48. renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
  49. _mCamera.GetComponent<Camera>().targetTexture = renderTexture;
  50. mBgPlane = this.transform.Find("BGmian/Plane").gameObject;
  51. }
  52. /// <summary>
  53. /// 相机动态render图片
  54. /// </summary>
  55. public RenderTexture CameraRenderTexture
  56. {
  57. get { return renderTexture; }
  58. }
  59. }