DragonBonesIcons.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 UnityEditor;
  25. using UnityEditorInternal;
  26. using System.Reflection;
  27. using System.IO;
  28. namespace DragonBones
  29. {
  30. [InitializeOnLoad]
  31. public class DragonBonesIcons : Editor
  32. {
  33. static Texture2D /*textureBone,*/ textureArmature, textureImg, textureMesh/* , textureIk */;
  34. static string editorPath = "";
  35. static string editorGUIPath = "";
  36. static bool isInited = false;
  37. static DragonBonesIcons()
  38. {
  39. Initialize();
  40. }
  41. static void Initialize()
  42. {
  43. if (isInited)
  44. {
  45. return;
  46. }
  47. DirectoryInfo rootDir = new DirectoryInfo(Application.dataPath);
  48. FileInfo[] files = rootDir.GetFiles("DragonBonesIcons.cs", SearchOption.AllDirectories);
  49. editorPath = Path.GetDirectoryName(files[0].FullName.Replace("\\", "/").Replace(Application.dataPath, "Assets"));
  50. editorGUIPath = editorPath + "/GUI";
  51. // textureBone = AssetDatabase.LoadAssetAtPath<Texture2D>(editorGUIPath + "/icon-bone.png");
  52. //textureIk = AssetDatabase.LoadAssetAtPath<Texture2D>(editorGUIPath + "/icon-ik.png");
  53. textureArmature = AssetDatabase.LoadAssetAtPath<Texture2D>(editorGUIPath + "/icon-skeleton.png");
  54. textureImg = AssetDatabase.LoadAssetAtPath<Texture2D>(editorGUIPath + "/icon-image.png");
  55. textureMesh = AssetDatabase.LoadAssetAtPath<Texture2D>(editorGUIPath + "/icon-mesh.png");
  56. EditorApplication.hierarchyWindowItemOnGUI -= HierarchyIconsOnGUI;
  57. EditorApplication.hierarchyWindowItemOnGUI += HierarchyIconsOnGUI;
  58. isInited = true;
  59. }
  60. static void HierarchyIconsOnGUI(int instanceId, Rect selectionRect)
  61. {
  62. GameObject go = (GameObject)EditorUtility.InstanceIDToObject(instanceId);
  63. if (!go)
  64. {
  65. return;
  66. }
  67. Rect rect = new Rect(selectionRect.x - 25f, selectionRect.y + 2, 15f, 15f);
  68. if (go.GetComponent<UnityArmatureComponent>())
  69. {
  70. rect.x = selectionRect.x + selectionRect.width - 15f;
  71. GUI.Label(rect, textureArmature);
  72. return;
  73. }
  74. UnityUGUIDisplay ugui = go.GetComponent<UnityUGUIDisplay>();
  75. if (ugui && ugui.sharedMesh)
  76. {
  77. if (ugui.sharedMesh.vertexCount == 4)
  78. {
  79. GUI.Label(rect, textureImg);
  80. }
  81. else
  82. {
  83. GUI.Label(rect, textureMesh);
  84. }
  85. return;
  86. }
  87. MeshFilter mf = go.GetComponent<MeshFilter>();
  88. if (mf && mf.sharedMesh &&
  89. mf.transform.parent != null &&
  90. mf.transform.parent.GetComponent<UnityArmatureComponent>() != null)
  91. {
  92. if (mf.sharedMesh.vertexCount == 4)
  93. {
  94. GUI.Label(rect, textureImg);
  95. }
  96. else
  97. {
  98. GUI.Label(rect, textureMesh);
  99. }
  100. return;
  101. }
  102. }
  103. }
  104. }