Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- namespace VRUN
- {
- class VRUN_Corruptor
- {
- public static bool corrupted = true;
- public static float intensity = -1f;
- public static GameObject transformCube(GameObject tempobj, float x, float y, float z)
- {
- Vector3 pos = tempobj.transform.position;
- pos.x = pos.x + x;
- pos.y = pos.y + y;
- pos.z = pos.z + z;
- tempobj.transform.position = pos;
- return tempobj;
- }
- public static void transformCubes(List<GameObject> cubeslist, float x, float y, float z)
- {
- foreach (GameObject obj in cubeslist)
- transformCube(obj, x, y, z);
- }
- public static GameObject corrupt(GameObject tempobj)
- {
- Mesh mesh = tempobj.GetComponent<MeshFilter>().mesh;
- Vector3[] vertices = mesh.vertices;
- int i = 0;
- while (i < vertices.Length)
- {
- //Corrupt later
- if (RollYesNoDice(intensity))
- vertices[i].x = corruptFloat(vertices[i].x, intensity);
- if (RollYesNoDice(intensity))
- vertices[i].y = corruptFloat(vertices[i].y, intensity);
- if (RollYesNoDice(intensity))
- vertices[i].z = corruptFloat(vertices[i].z, intensity);
- i++;
- }
- mesh.vertices = vertices;
- mesh.RecalculateBounds();
- return tempobj;
- }
- public static float corruptFloat(float input, float _intensity)
- {
- float __intensity = _intensity;
- if (_intensity < 0)
- {
- __intensity = Mathf.Abs(_intensity);
- var effectiveCoeff = (((UnityEngine.Random.Range(0, 2000) - 1000) / 1000) * (__intensity / 100));
- //var effectiveCoeff = (((Random.Range(0, 2000) - 1000) / 1000) * __intensity);
- //var effectiveCoeff = (((Random.Range(1000, 2000) - 1000)/1000) * __intensity);
- return input + (effectiveCoeff);
- //return input * (effectiveCoeff + 1);
- }
- int reverser = (RollYesNoDice(0.5f) ? 1 : -1);
- switch (UnityEngine.Random.Range(0, 5))
- {
- case 0:
- return 0;
- case 1:
- return reverser * input * UnityEngine.Random.Range(0, 100 * __intensity);
- case 2:
- return reverser * input * (System.Convert.ToSingle(UnityEngine.Random.Range(1, 10 * __intensity)) / 5f);
- case 3:
- return reverser * (System.Convert.ToSingle(UnityEngine.Random.Range(1, 10 * __intensity)) / 10f);
- case 4:
- return reverser * input * ((System.Convert.ToSingle(UnityEngine.Random.Range(1, 10)) / 10f));
- default:
- return 0;
- }
- }
- public static bool RollYesNoDice(float chances)
- {
- if (chances > 1)
- return true;
- chances = Mathf.Abs(chances);
- int max = UnityEngine.Random.Range(0, 1000);
- int threshold = System.Convert.ToInt32(max * chances);
- int rng = UnityEngine.Random.Range(0, 1000);
- if (rng < threshold)
- return true;
- else
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement