源战役客户端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

187 righe
5.7 KiB

  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 LuaFramework;
  8. namespace DigitalOpus.MB.Core{
  9. public class MBVersionConcrete:MBVersionInterface{
  10. public string version(){
  11. return "3.13.1";
  12. }
  13. public int GetMajorVersion(){
  14. #if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
  15. return 3;
  16. #elif UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
  17. return 4;
  18. #else
  19. return 5;
  20. #endif
  21. }
  22. public int GetMinorVersion(){
  23. #if UNITY_3_0 || UNITY_3_0_0
  24. return 0;
  25. #elif UNITY_3_1
  26. return 1;
  27. #elif UNITY_3_2
  28. return 2;
  29. #elif UNITY_3_3
  30. return 3;
  31. #elif UNITY_3_4
  32. return 4;
  33. #elif UNITY_3_5
  34. return 5;
  35. #elif UNITY_4_0 || UNITY_4_0_1
  36. return 0;
  37. #elif UNITY_4_1
  38. return 1;
  39. #elif UNITY_4_2
  40. return 2;
  41. #elif UNITY_4_3
  42. return 3;
  43. #elif UNITY_4_4
  44. return 4;
  45. #elif UNITY_4_5
  46. return 5;
  47. #else
  48. return 0;
  49. #endif
  50. }
  51. public bool GetActive(GameObject go){
  52. #if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
  53. return go.active;
  54. #else
  55. return go.activeInHierarchy;
  56. #endif
  57. }
  58. public void SetActive(GameObject go, bool isActive){
  59. #if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
  60. go.active = isActive;
  61. #else
  62. go.SetActive(isActive);
  63. #endif
  64. }
  65. public void SetActiveRecursively(GameObject go, bool isActive){
  66. #if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
  67. go.SetActiveRecursively(isActive);
  68. #else
  69. go.SetActive(isActive);
  70. #endif
  71. }
  72. public UnityEngine.Object[] FindSceneObjectsOfType(Type t){
  73. #if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
  74. return GameObject.FindSceneObjectsOfType(t);
  75. #else
  76. return GameObject.FindObjectsOfType(t);
  77. #endif
  78. }
  79. public bool IsRunningAndMeshNotReadWriteable(Mesh m){
  80. if (Application.isPlaying){
  81. #if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
  82. return false;
  83. #else
  84. return !m.isReadable;
  85. #endif
  86. } else {
  87. return false;
  88. }
  89. }
  90. Vector2 _HALF_UV = new Vector2(.5f, .5f);
  91. public Vector2[] GetMeshUV1s(Mesh m, MB2_LogLevel LOG_LEVEL)
  92. {
  93. Vector2[] uv;
  94. #if (UNITY_4_6 || UNITY_4_7 || UNITY_4_5 || UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
  95. uv = m.uv1;
  96. #else
  97. if (LOG_LEVEL >= MB2_LogLevel.warn) MB2_Log.LogDebug("UV1 does not exist in Unity 5+");
  98. uv = m.uv;
  99. #endif
  100. if (uv.Length == 0){
  101. if (LOG_LEVEL >= MB2_LogLevel.debug) MB2_Log.LogDebug("Mesh " + m + " has no uv1s. Generating");
  102. if (LOG_LEVEL >= MB2_LogLevel.warn) LogManager.LogWarning("Mesh " + m + " didn't have uv1s. Generating uv1s.");
  103. uv = new Vector2[m.vertexCount];
  104. for (int i = 0; i < uv.Length; i++){uv[i] = _HALF_UV;}
  105. }
  106. return uv;
  107. }
  108. public Vector2[] GetMeshUV3orUV4(Mesh m, bool get3, MB2_LogLevel LOG_LEVEL) {
  109. Vector2[] uvs;
  110. #if (UNITY_4_6 || UNITY_4_7 || UNITY_4_5 || UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
  111. if (LOG_LEVEL >= MB2_LogLevel.warn) MB2_Log.LogDebug("UV3 and UV4 do not exist in Unity 4");
  112. uvs = m.uv;
  113. #else
  114. if (get3) uvs = m.uv3;
  115. else uvs = m.uv4;
  116. #endif
  117. if (uvs.Length == 0) {
  118. if (LOG_LEVEL >= MB2_LogLevel.debug) MB2_Log.LogDebug("Mesh " + m + " has no uv" + (get3 ? "3" : "4") + ". Generating");
  119. uvs = new Vector2[m.vertexCount];
  120. for (int i = 0; i < uvs.Length; i++) { uvs[i] = _HALF_UV; }
  121. }
  122. return uvs;
  123. }
  124. public void MeshClear(Mesh m, bool t){
  125. #if UNITY_3_5
  126. m.Clear();
  127. #else
  128. m.Clear(t);
  129. #endif
  130. }
  131. public void MeshAssignUV3(Mesh m, Vector2[] uv3s){
  132. #if (UNITY_4_6 || UNITY_4_7 || UNITY_4_5 || UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
  133. LogManager.LogWarning("UV3 was checked but UV3 does not exist in Unity 4");
  134. #else
  135. m.uv3 = uv3s;
  136. #endif
  137. }
  138. public void MeshAssignUV4(Mesh m, Vector2[] uv4s) {
  139. #if (UNITY_4_6 || UNITY_4_7 || UNITY_4_5 || UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
  140. LogManager.LogWarning("UV4 was checked but UV4 does not exist in Unity 4");
  141. #else
  142. m.uv4 = uv4s;
  143. #endif
  144. }
  145. public Vector4 GetLightmapTilingOffset(Renderer r){
  146. #if (UNITY_4_6 || UNITY_4_7 || UNITY_4_5 || UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
  147. return r.lightmapTilingOffset ;
  148. #else
  149. return r.lightmapScaleOffset; //r.lightmapScaleOffset ;
  150. #endif
  151. }
  152. public Transform[] GetBones(Renderer r){
  153. if (r is SkinnedMeshRenderer){
  154. Transform[] bone = ((SkinnedMeshRenderer)r).bones;
  155. #if UNITY_EDITOR
  156. if (bone.Length == 0){
  157. Mesh m = ((SkinnedMeshRenderer)r).sharedMesh;
  158. if (m.bindposes.Length != bone.Length) LogManager.LogError("SkinnedMesh (" + r.gameObject + ") in the list of objects to combine has no bones. Check that 'optimize game object' is not checked in the 'Rig' tab of the asset importer. Mesh Baker cannot combine optimized skinned meshes because the bones are not available.");
  159. }
  160. #endif
  161. return bone;
  162. } else if (r is MeshRenderer){
  163. Transform[] bone = new Transform[1];
  164. bone[0] = r.transform;
  165. return bone;
  166. } else {
  167. LogManager.LogError("Could not getBones. Object does not have a renderer");
  168. return null;
  169. }
  170. }
  171. }
  172. }