Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6.  
  7. namespace VRUN
  8. {
  9. class VRUN_Corruptor
  10. {
  11. public static bool corrupted = true;
  12. public static float intensity = -1f;
  13.  
  14. public static GameObject transformCube(GameObject tempobj, float x, float y, float z)
  15. {
  16. Vector3 pos = tempobj.transform.position;
  17. pos.x = pos.x + x;
  18. pos.y = pos.y + y;
  19. pos.z = pos.z + z;
  20. tempobj.transform.position = pos;
  21. return tempobj;
  22. }
  23.  
  24. public static void transformCubes(List<GameObject> cubeslist, float x, float y, float z)
  25. {
  26. foreach (GameObject obj in cubeslist)
  27. transformCube(obj, x, y, z);
  28. }
  29.  
  30.  
  31. public static GameObject corrupt(GameObject tempobj)
  32. {
  33. Mesh mesh = tempobj.GetComponent<MeshFilter>().mesh;
  34. Vector3[] vertices = mesh.vertices;
  35. int i = 0;
  36. while (i < vertices.Length)
  37. {
  38. //Corrupt later
  39. if (RollYesNoDice(intensity))
  40. vertices[i].x = corruptFloat(vertices[i].x, intensity);
  41.  
  42. if (RollYesNoDice(intensity))
  43. vertices[i].y = corruptFloat(vertices[i].y, intensity);
  44.  
  45. if (RollYesNoDice(intensity))
  46. vertices[i].z = corruptFloat(vertices[i].z, intensity);
  47.  
  48.  
  49. i++;
  50. }
  51. mesh.vertices = vertices;
  52. mesh.RecalculateBounds();
  53. return tempobj;
  54. }
  55.  
  56.  
  57. public static float corruptFloat(float input, float _intensity)
  58. {
  59. float __intensity = _intensity;
  60.  
  61. if (_intensity < 0)
  62. {
  63. __intensity = Mathf.Abs(_intensity);
  64.  
  65.  
  66.  
  67. var effectiveCoeff = (((UnityEngine.Random.Range(0, 2000) - 1000) / 1000) * (__intensity / 100));
  68.  
  69. //var effectiveCoeff = (((Random.Range(0, 2000) - 1000) / 1000) * __intensity);
  70. //var effectiveCoeff = (((Random.Range(1000, 2000) - 1000)/1000) * __intensity);
  71.  
  72. return input + (effectiveCoeff);
  73. //return input * (effectiveCoeff + 1);
  74. }
  75.  
  76. int reverser = (RollYesNoDice(0.5f) ? 1 : -1);
  77.  
  78. switch (UnityEngine.Random.Range(0, 5))
  79. {
  80. case 0:
  81. return 0;
  82. case 1:
  83. return reverser * input * UnityEngine.Random.Range(0, 100 * __intensity);
  84. case 2:
  85. return reverser * input * (System.Convert.ToSingle(UnityEngine.Random.Range(1, 10 * __intensity)) / 5f);
  86. case 3:
  87. return reverser * (System.Convert.ToSingle(UnityEngine.Random.Range(1, 10 * __intensity)) / 10f);
  88. case 4:
  89. return reverser * input * ((System.Convert.ToSingle(UnityEngine.Random.Range(1, 10)) / 10f));
  90. default:
  91. return 0;
  92. }
  93. }
  94.  
  95.  
  96. public static bool RollYesNoDice(float chances)
  97. {
  98. if (chances > 1)
  99. return true;
  100. chances = Mathf.Abs(chances);
  101. int max = UnityEngine.Random.Range(0, 1000);
  102. int threshold = System.Convert.ToInt32(max * chances);
  103.  
  104. int rng = UnityEngine.Random.Range(0, 1000);
  105.  
  106. if (rng < threshold)
  107. return true;
  108. else
  109. return false;
  110.  
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement