UnityUGUIDisplay.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2012-2017 DragonBones team and other contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. using UnityEngine;
  24. using UnityEngine.UI;
  25. namespace DragonBones
  26. {
  27. [DisallowMultipleComponent]
  28. [ExecuteInEditMode,RequireComponent(typeof(CanvasRenderer), typeof(RectTransform))]
  29. public class UnityUGUIDisplay : MaskableGraphic
  30. {
  31. [HideInInspector]
  32. public Mesh sharedMesh;
  33. private Texture _texture;
  34. public override Texture mainTexture
  35. {
  36. get { return _texture == null ? material.mainTexture : _texture; }
  37. }
  38. /// <summary>
  39. /// Texture to be used.
  40. /// </summary>
  41. public Texture texture
  42. {
  43. get { return _texture; }
  44. set
  45. {
  46. if (_texture == value)
  47. {
  48. return;
  49. }
  50. _texture = value;
  51. SetMaterialDirty();
  52. }
  53. }
  54. protected override void OnPopulateMesh (VertexHelper vh)
  55. {
  56. vh.Clear();
  57. }
  58. public override void Rebuild (CanvasUpdate update)
  59. {
  60. base.Rebuild(update);
  61. if (canvasRenderer.cull)
  62. {
  63. return;
  64. }
  65. if (update == CanvasUpdate.PreRender)
  66. {
  67. canvasRenderer.SetMesh(sharedMesh);
  68. }
  69. }
  70. void Update()
  71. {
  72. canvasRenderer.SetMesh(sharedMesh);
  73. }
  74. }
  75. }