MB2_MBVersion.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. * \brief Hax! DLLs cannot interpret preprocessor directives, so this class acts as a "bridge"
  3. */
  4. using System;
  5. using UnityEngine;
  6. using System.Collections;
  7. namespace DigitalOpus.MB.Core{
  8. public interface MBVersionInterface{
  9. string version();
  10. int GetMajorVersion();
  11. int GetMinorVersion();
  12. bool GetActive(GameObject go);
  13. void SetActive(GameObject go, bool isActive);
  14. void SetActiveRecursively(GameObject go, bool isActive);
  15. UnityEngine.Object[] FindSceneObjectsOfType(Type t);
  16. bool IsRunningAndMeshNotReadWriteable(Mesh m);
  17. Vector2[] GetMeshUV3orUV4(Mesh m, bool get3, MB2_LogLevel LOG_LEVEL);
  18. void MeshClear(Mesh m, bool t);
  19. void MeshAssignUV3(Mesh m, Vector2[] uv3s);
  20. void MeshAssignUV4(Mesh m, Vector2[] uv4s);
  21. Vector4 GetLightmapTilingOffset(Renderer r);
  22. Transform[] GetBones(Renderer r);
  23. void OptimizeMesh(Mesh m);
  24. int GetBlendShapeFrameCount(Mesh m, int shapeIndex);
  25. float GetBlendShapeFrameWeight(Mesh m, int shapeIndex, int frameIndex);
  26. void GetBlendShapeFrameVertices(Mesh m, int shapeIndex, int frameIndex, Vector3[] vs, Vector3[] ns, Vector3[] ts);
  27. void ClearBlendShapes(Mesh m);
  28. void AddBlendShapeFrame(Mesh m, string nm, float wt, Vector3[] vs, Vector3[] ns, Vector3[] ts);
  29. int MaxMeshVertexCount();
  30. void SetMeshIndexFormatAndClearMesh(Mesh m, int numVerts, bool vertices, bool justClearTriangles);
  31. }
  32. public class MBVersion
  33. {
  34. private static MBVersionInterface _MBVersion;
  35. private static MBVersionInterface _CreateMBVersionConcrete(){
  36. Type vit = null;
  37. #if EVAL_VERSION
  38. vit = Type.GetType("DigitalOpus.MB.Core.MBVersionConcrete,Assembly-CSharp");
  39. #else
  40. vit = typeof(MBVersionConcrete);
  41. #endif
  42. return (MBVersionInterface) Activator.CreateInstance(vit);
  43. }
  44. public static string version(){
  45. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  46. return _MBVersion.version();
  47. }
  48. public static int GetMajorVersion(){
  49. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  50. return _MBVersion.GetMajorVersion();
  51. }
  52. public static int GetMinorVersion(){
  53. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  54. return _MBVersion.GetMinorVersion();
  55. }
  56. public static bool GetActive(GameObject go){
  57. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  58. return _MBVersion.GetActive(go);
  59. }
  60. public static void SetActive(GameObject go, bool isActive){
  61. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  62. _MBVersion.SetActive(go,isActive);
  63. }
  64. public static void SetActiveRecursively(GameObject go, bool isActive){
  65. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  66. _MBVersion.SetActiveRecursively(go,isActive);
  67. }
  68. public static UnityEngine.Object[] FindSceneObjectsOfType(Type t){
  69. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  70. return _MBVersion.FindSceneObjectsOfType(t);
  71. }
  72. public static bool IsRunningAndMeshNotReadWriteable(Mesh m){
  73. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  74. return _MBVersion.IsRunningAndMeshNotReadWriteable(m);
  75. }
  76. public static Vector2[] GetMeshUV3orUV4(Mesh m, bool get3, MB2_LogLevel LOG_LEVEL) {
  77. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  78. return _MBVersion.GetMeshUV3orUV4(m,get3,LOG_LEVEL);
  79. }
  80. public static void MeshClear(Mesh m, bool t){
  81. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  82. _MBVersion.MeshClear(m,t);
  83. }
  84. public static void MeshAssignUV3(Mesh m, Vector2[] uv3s){
  85. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  86. _MBVersion.MeshAssignUV3(m,uv3s);
  87. }
  88. public static void MeshAssignUV4(Mesh m, Vector2[] uv4s) {
  89. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  90. _MBVersion.MeshAssignUV4(m, uv4s);
  91. }
  92. public static Vector4 GetLightmapTilingOffset(Renderer r){
  93. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  94. return _MBVersion.GetLightmapTilingOffset(r);
  95. }
  96. public static Transform[] GetBones(Renderer r){
  97. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  98. return _MBVersion.GetBones(r);
  99. }
  100. public static void OptimizeMesh(Mesh m)
  101. {
  102. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  103. _MBVersion.OptimizeMesh(m);
  104. }
  105. public static int GetBlendShapeFrameCount(Mesh m, int shapeIndex)
  106. {
  107. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  108. return _MBVersion.GetBlendShapeFrameCount(m, shapeIndex);
  109. }
  110. public static float GetBlendShapeFrameWeight(Mesh m, int shapeIndex, int frameIndex)
  111. {
  112. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  113. return _MBVersion.GetBlendShapeFrameWeight(m, shapeIndex, frameIndex);
  114. }
  115. public static void GetBlendShapeFrameVertices(Mesh m, int shapeIndex, int frameIndex, Vector3[] vs, Vector3[] ns, Vector3[] ts)
  116. {
  117. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  118. _MBVersion.GetBlendShapeFrameVertices(m, shapeIndex, frameIndex, vs, ns, ts);
  119. }
  120. public static void ClearBlendShapes(Mesh m)
  121. {
  122. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  123. _MBVersion.ClearBlendShapes(m);
  124. }
  125. public static void AddBlendShapeFrame(Mesh m, string nm, float wt, Vector3[] vs, Vector3[] ns, Vector3[] ts)
  126. {
  127. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  128. _MBVersion.AddBlendShapeFrame(m, nm, wt, vs, ns, ts);
  129. }
  130. public static int MaxMeshVertexCount()
  131. {
  132. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  133. return _MBVersion.MaxMeshVertexCount();
  134. }
  135. public static void SetMeshIndexFormatAndClearMesh(Mesh m, int numVerts, bool vertices, bool justClearTriangles)
  136. {
  137. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  138. _MBVersion.SetMeshIndexFormatAndClearMesh(m, numVerts, vertices, justClearTriangles);
  139. }
  140. }
  141. }