ShowSlotsWindow.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 System.Collections;
  24. using System.Collections.Generic;
  25. using UnityEngine;
  26. using UnityEditor;
  27. using DragonBones;
  28. namespace DragonBones
  29. {
  30. [System.Serializable]
  31. public class SlotItemData
  32. {
  33. public UnitySlot slot;
  34. public int sumLevel;
  35. public bool isSelected;
  36. }
  37. public class ShowSlotsWindow : EditorWindow
  38. {
  39. private const float WIDTH = 400.0f;
  40. private const float HEIGHT = 200.0f;
  41. private readonly List<SlotItemData> _slotItems = new List<SlotItemData>();
  42. private UnityArmatureComponent _armatureComp;
  43. private Vector2 _scrollPos;
  44. public static void OpenWindow(UnityArmatureComponent armatureComp)
  45. {
  46. if (armatureComp == null)
  47. {
  48. return;
  49. }
  50. var win = GetWindowWithRect(typeof(ShowSlotsWindow), new Rect(0.0f, 0.0f, WIDTH, HEIGHT), false) as ShowSlotsWindow;
  51. win._armatureComp = armatureComp;
  52. win.titleContent = new GUIContent("SlotList");
  53. win.Show();
  54. }
  55. void ColletSlotData(Armature armature, int sumLevel)
  56. {
  57. var slots = armature.GetSlots();
  58. foreach (UnitySlot slot in slots)
  59. {
  60. var slotItem = new SlotItemData();
  61. slotItem.slot = slot;
  62. slotItem.sumLevel = sumLevel;
  63. slotItem.isSelected = slot.isIgnoreCombineMesh || (slot.renderDisplay != null && slot.renderDisplay.activeSelf);
  64. this._slotItems.Add(slotItem);
  65. if (slot.childArmature != null)
  66. {
  67. this.ColletSlotData(slot.childArmature, sumLevel + 1);
  68. }
  69. }
  70. }
  71. void OnGUI()
  72. {
  73. if (this._slotItems.Count == 0)
  74. {
  75. this.ColletSlotData(this._armatureComp.armature, 0);
  76. }
  77. //
  78. ShowSlots(this._armatureComp.armature);
  79. //
  80. if (GUILayout.Button("Apply"))
  81. {
  82. foreach (var slotItem in this._slotItems)
  83. {
  84. var slot = slotItem.slot;
  85. if (slotItem.isSelected && slot.renderDisplay != null && !slot.renderDisplay.activeSelf)
  86. {
  87. slot.DisallowCombineMesh();
  88. var combineMeshs = (slot.armature.proxy as UnityArmatureComponent).GetComponent<UnityCombineMeshs>();
  89. if (combineMeshs != null)
  90. {
  91. combineMeshs.BeginCombineMesh();
  92. }
  93. }
  94. }
  95. //
  96. this.Close();
  97. }
  98. }
  99. void ShowSlots(Armature armature)
  100. {
  101. var leftMargin = 20;
  102. var indentSpace = 50;
  103. _scrollPos = GUILayout.BeginScrollView(_scrollPos);
  104. for (var i = 0; i < this._slotItems.Count; i++)
  105. {
  106. var slotItem = this._slotItems[i];
  107. var slot = slotItem.slot;
  108. //
  109. GUILayout.BeginHorizontal();
  110. var lableStyle = new GUIStyle();
  111. lableStyle.margin.left = slotItem.sumLevel * indentSpace + leftMargin;
  112. GUILayout.Label(slot.name, lableStyle, GUILayout.Width(100.0f));
  113. if(slot.renderDisplay == null || !slot.renderDisplay.activeSelf)
  114. {
  115. slotItem.isSelected = GUILayout.Toggle(slotItem.isSelected, "Active");
  116. }
  117. else
  118. {
  119. GUILayout.Label("Activated");
  120. }
  121. GUILayout.EndHorizontal();
  122. }
  123. GUILayout.EndScrollView();
  124. }
  125. }
  126. }