源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

109 行
4.7 KiB

  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. using System;
  31. namespace Spine {
  32. /// <summary>
  33. /// An AttachmentLoader that configures attachments using texture regions from an Atlas.
  34. /// See <a href='http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data'>Loading Skeleton Data</a> in the Spine Runtimes Guide.
  35. /// </summary>
  36. public class AtlasAttachmentLoader : AttachmentLoader {
  37. private Atlas[] atlasArray;
  38. public AtlasAttachmentLoader (params Atlas[] atlasArray) {
  39. if (atlasArray == null) throw new ArgumentNullException("atlas array cannot be null.");
  40. this.atlasArray = atlasArray;
  41. }
  42. public RegionAttachment NewRegionAttachment (Skin skin, string name, string path) {
  43. AtlasRegion region = FindRegion(path);
  44. if (region == null) throw new ArgumentException(string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name));
  45. RegionAttachment attachment = new RegionAttachment(name);
  46. attachment.RendererObject = region;
  47. attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
  48. attachment.regionOffsetX = region.offsetX;
  49. attachment.regionOffsetY = region.offsetY;
  50. attachment.regionWidth = region.width;
  51. attachment.regionHeight = region.height;
  52. attachment.regionOriginalWidth = region.originalWidth;
  53. attachment.regionOriginalHeight = region.originalHeight;
  54. return attachment;
  55. }
  56. public MeshAttachment NewMeshAttachment (Skin skin, string name, string path) {
  57. AtlasRegion region = FindRegion(path);
  58. if (region == null) throw new ArgumentException(string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name));
  59. MeshAttachment attachment = new MeshAttachment(name);
  60. attachment.RendererObject = region;
  61. attachment.RegionU = region.u;
  62. attachment.RegionV = region.v;
  63. attachment.RegionU2 = region.u2;
  64. attachment.RegionV2 = region.v2;
  65. attachment.RegionRotate = region.rotate;
  66. attachment.regionOffsetX = region.offsetX;
  67. attachment.regionOffsetY = region.offsetY;
  68. attachment.regionWidth = region.width;
  69. attachment.regionHeight = region.height;
  70. attachment.regionOriginalWidth = region.originalWidth;
  71. attachment.regionOriginalHeight = region.originalHeight;
  72. return attachment;
  73. }
  74. public BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, string name) {
  75. return new BoundingBoxAttachment(name);
  76. }
  77. public PathAttachment NewPathAttachment (Skin skin, string name) {
  78. return new PathAttachment(name);
  79. }
  80. public PointAttachment NewPointAttachment (Skin skin, string name) {
  81. return new PointAttachment(name);
  82. }
  83. public ClippingAttachment NewClippingAttachment(Skin skin, string name) {
  84. return new ClippingAttachment(name);
  85. }
  86. public AtlasRegion FindRegion (string name) {
  87. AtlasRegion region;
  88. for (int i = 0; i < atlasArray.Length; i++) {
  89. region = atlasArray[i].FindRegion(name);
  90. if (region != null)
  91. return region;
  92. }
  93. return null;
  94. }
  95. }
  96. }