MB2_MBVersion.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. using System.Collections.Generic;
  8. namespace DigitalOpus.MB.Core{
  9. public interface MBVersionInterface{
  10. string version();
  11. int GetMajorVersion();
  12. int GetMinorVersion();
  13. bool GetActive(GameObject go);
  14. void SetActive(GameObject go, bool isActive);
  15. void SetActiveRecursively(GameObject go, bool isActive);
  16. UnityEngine.Object[] FindSceneObjectsOfType(Type t);
  17. bool IsRunningAndMeshNotReadWriteable(Mesh m);
  18. Vector2[] GetMeshUVChannel(int channel, Mesh m, MB2_LogLevel LOG_LEVEL);
  19. void MeshClear(Mesh m, bool t);
  20. void MeshAssignUVChannel(int channel, Mesh m, Vector2[] uvs);
  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. bool GraphicsUVStartsAtTop();
  32. bool IsTextureReadable(Texture2D tex);
  33. bool CollectPropertyNames(List<ShaderTextureProperty> texPropertyNames, ShaderTextureProperty[] shaderTexPropertyNames, List<ShaderTextureProperty> _customShaderPropNames, Material resultMaterial, MB2_LogLevel LOG_LEVEL);
  34. }
  35. public class MBVersion
  36. {
  37. private static MBVersionInterface _MBVersion;
  38. private static MBVersionInterface _CreateMBVersionConcrete(){
  39. Type vit = null;
  40. #if EVAL_VERSION
  41. vit = Type.GetType("DigitalOpus.MB.Core.MBVersionConcrete,Assembly-CSharp");
  42. #else
  43. vit = typeof(MBVersionConcrete);
  44. #endif
  45. return (MBVersionInterface) System.Activator.CreateInstance(vit);
  46. }
  47. public static string version(){
  48. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  49. return _MBVersion.version();
  50. }
  51. public static int GetMajorVersion(){
  52. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  53. return _MBVersion.GetMajorVersion();
  54. }
  55. public static int GetMinorVersion(){
  56. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  57. return _MBVersion.GetMinorVersion();
  58. }
  59. public static bool GetActive(GameObject go){
  60. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  61. return _MBVersion.GetActive(go);
  62. }
  63. public static void SetActive(GameObject go, bool isActive){
  64. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  65. _MBVersion.SetActive(go,isActive);
  66. }
  67. public static void SetActiveRecursively(GameObject go, bool isActive){
  68. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  69. _MBVersion.SetActiveRecursively(go,isActive);
  70. }
  71. public static UnityEngine.Object[] FindSceneObjectsOfType(Type t){
  72. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  73. return _MBVersion.FindSceneObjectsOfType(t);
  74. }
  75. public static bool IsRunningAndMeshNotReadWriteable(Mesh m){
  76. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  77. return _MBVersion.IsRunningAndMeshNotReadWriteable(m);
  78. }
  79. public static Vector2[] GetMeshChannel(int channel, Mesh m, MB2_LogLevel LOG_LEVEL) {
  80. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  81. return _MBVersion.GetMeshUVChannel(channel, m,LOG_LEVEL);
  82. }
  83. public static void MeshClear(Mesh m, bool t){
  84. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  85. _MBVersion.MeshClear(m,t);
  86. }
  87. public static void MeshAssignUVChannel(int channel, Mesh m, Vector2[] uvs)
  88. {
  89. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  90. _MBVersion.MeshAssignUVChannel(channel, m, uvs);
  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. public static bool GraphicsUVStartsAtTop()
  141. {
  142. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  143. return _MBVersion.GraphicsUVStartsAtTop();
  144. }
  145. public static bool IsTextureReadable(Texture2D tex)
  146. {
  147. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  148. return _MBVersion.IsTextureReadable(tex);
  149. }
  150. public static void CollectPropertyNames(List<ShaderTextureProperty> texPropertyNames, ShaderTextureProperty[] shaderTexPropertyNames, List<ShaderTextureProperty> _customShaderPropNames, Material resultMaterial, MB2_LogLevel LOG_LEVEL)
  151. {
  152. if (_MBVersion == null) _MBVersion = _CreateMBVersionConcrete();
  153. _MBVersion.CollectPropertyNames(texPropertyNames, shaderTexPropertyNames, _customShaderPropNames, resultMaterial, LOG_LEVEL);
  154. }
  155. }
  156. }