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 System.Threading.Tasks;
- using UnityEngine;
- using spaar;
- using System.IO;
- namespace BesiegeBot
- {
- [spaar.Mod("BesiegeBotLoader",author="ITR",version="BB needs no version. BB is sentient and is always improving itself, thus always is the perfect version. Hail Besiege Bot you pleb!")]
- public class BesiegeBotLoader : MonoBehaviour
- {
- public BesiegeBotLoader() {
- gameObject.AddComponent<ViewMapper>();
- gameObject.AddComponent<ControlMachine>();
- gameObject.AddComponent<SelectVictim>();
- gameObject.AddComponent<BesiegeBotCore>();
- Debug.Log("You have been visited by BB. He bless your besiege game by playing on it, until he decides to leave.");
- }
- }
- public class BesiegeBotCore : MonoBehaviour{
- ViewMapper viewMapper;
- ControlMachine controlMachine;
- SelectVictim selectVictim;
- MachineObjectTracker machineObjectTracker;
- AddPiece addPiece;
- HudInputControl hudInputControl;
- int state = -1;
- int currentMachineController = 0;
- bool foundEverythingNeeded = false;
- public BesiegeBotCore() {
- }
- public void startGame(bool wantedAddPieceState) {
- if(AddPiece.isSimulating!=wantedAddPieceState) {
- addPiece.Simulate();
- }
- }
- public void startGame() {
- startGame(true);
- }
- public bool getEverythingNeededToRunTheClass() {
- state = -1;
- if(viewMapper==null) {
- viewMapper = GetComponent<ViewMapper>();
- if(viewMapper==null) {
- return false;
- }
- Debug.Log("Found ViewMapper");
- }
- if(controlMachine==null) {
- controlMachine = GetComponent<ControlMachine>();
- if(controlMachine==null) {
- return false;
- }
- Debug.Log("Found ControlMachine");
- }
- if(selectVictim==null) {
- selectVictim = GetComponent<SelectVictim>();
- if(selectVictim==null) {
- return false;
- }
- Debug.Log("Found SelectVictim");
- }
- state = 0;
- if(machineObjectTracker==null) {
- try{
- machineObjectTracker = UnityEngine.Object.FindObjectOfType<MachineObjectTracker>();
- }
- catch{
- }
- if(machineObjectTracker==null) {
- return false;
- }
- Debug.Log("Found MachineObjectTracker");
- }
- if(addPiece==null) {
- try {
- addPiece = GameObject.Find("BUILDER").GetComponent<AddPiece>();
- }
- catch {
- }
- if(addPiece==null) {
- return false;
- }
- Debug.Log("Found AddPiece");
- }
- if(hudInputControl==null) {
- hudInputControl = UnityEngine.Object.FindObjectOfType<HudInputControl>();
- if(hudInputControl==null) {
- return false;
- }
- Debug.Log("Found HudInputControl");
- }
- if(!foundEverythingNeeded) {
- foundEverythingNeeded = true;
- Debug.Log("BBCore found everything needed!");
- }
- state = 1;
- return true;
- }
- public void viewMapperHandler() {
- if(viewMapper.state==0) {
- if(AddPiece.isSimulating&&controlMachine.state>1) {
- Debug.Log("Changing viewLoggerState to 1");
- viewMapper.defaultScale = viewMapper.mouseOrbit.distance;
- viewMapper.state = 1;
- }
- }
- else if(viewMapper.state==2) {
- if(!AddPiece.isSimulating) {
- Debug.Log("Changing viewLoggerState to 4");
- viewMapper.state = 4;
- }
- }
- else if(viewMapper.state==3) {
- if(AddPiece.isSimulating&&controlMachine.state==4) {
- // startGame(false);
- Debug.Log("Changing viewLoggerState to 5");
- viewMapper.state = 5;
- }
- }
- else if(viewMapper.state==4) {
- if(AddPiece.isSimulating) {
- Debug.Log("Changing viewLoggerState to 1");
- viewMapper.state = 1;
- }
- }
- else if(viewMapper.state==5) {
- if(!AddPiece.isSimulating) {
- Debug.Log("Changing viewLoggerState to 4");
- viewMapper.state = 4;
- }
- }
- }
- public void controlMachineHandler() {
- if(controlMachine.state==0) {
- if(!AddPiece.isSimulating) {
- startGame();
- controlMachine.state = 1;
- }
- else {
- controlMachine.state = 1;
- }
- }
- if(controlMachine.state==2) {
- if(AddPiece.isSimulating&&viewMapper.state==3) {
- controlMachine.state = 3;
- }
- }
- if(controlMachine.state==3) {
- selectVictim.state = 0;
- controlMachine.hasControl = requestControl(0);
- }
- if(controlMachine.state==5) {
- if(controlMachine.requestToViewMachine) {
- viewMapper.requestViewMachine();
- }
- }
- }
- public void selectVictimHandler() {
- if(!AddPiece.isSimulating) {
- viewMapper.victim = -1;
- selectVictim.state = 0;
- return;
- }
- if(selectVictim.requestAttackVictim) {
- attackVictim();
- selectVictim.requestAttackVictim = false;
- }
- if(selectVictim.requestingVictim) {
- viewMapper.selectVictim();
- if(viewMapper.victim!=-1) {
- selectVictim.requestingVictim = false;
- selectVictim.victimPosition = viewMapper.allWorldlastPositionGameObjectWasSeen[viewMapper.victim];
- selectVictim.victimState = 5;
- selectVictim.state = 4;
- }
- else {
- selectVictim.state = 0;
- }
- }
- else {
- selectVictim.victimPosition = viewMapper.allWorldlastPositionGameObjectWasSeen[viewMapper.victim];
- if(selectVictim.state==1) {
- requestControl(1);
- if((Vector3.Project(selectVictim.victimPosition,Vector3.up)-Vector3.Project(controlMachine.baseBlock.transform.position,Vector3.up)).magnitude<4) {
- selectVictim.state = 2;
- }
- }
- if(selectVictim.state==2) {
- requestControl(1);
- viewMapper.requestViewMachine();
- }
- if(selectVictim.state==3) {
- requestControl(1);
- viewMapper.requestViewMachine();
- }
- if(selectVictim.state==4) {
- if(requestControl(1)) {
- selectVictim.state = 1;
- }
- }
- }
- }
- public bool requestControl(int newController) {
- if(newController!=currentMachineController) {
- if(controlMachine.wantedArrivalTime-Time.realtimeSinceStartup>=0) {
- return false;
- }
- if(currentMachineController==0&&controlMachine.state<=3) {
- return false;
- }
- if(currentMachineController==1&&selectVictim.state>0){
- return false;
- }
- controlMachine.hasControl = false;
- selectVictim.hasControl = false;
- currentMachineController = newController;
- }
- if(currentMachineController==1) {
- if(selectVictim.moveToPosition.y<0)
- selectVictim.moveToPosition -= new Vector3(0,selectVictim.moveToPosition.y,0);
- controlMachine.moveToPosition = selectVictim.moveToPosition;
- controlMachine.wantedArrivalTime = selectVictim.wantedArrivalTime;
- }
- return true;
- }
- public void attackVictim() {
- if(viewMapper.victim==-1)
- return;
- int r = UnityEngine.Random.Range(0,4);
- if(r==0) {
- controlMachine.baseBlock.rigidbody.AddForce(100*(viewMapper.allWorldlastPositionGameObjectWasSeen[viewMapper.victim]-controlMachine.baseBlock.transform.position).normalized);
- }
- else if(r==1){
- Transform item;
- try {
- item = (Transform)Instantiate(machineObjectTracker.AllPrefabs[23].transform,viewMapper.allWorldlastPositionGameObjectWasSeen[viewMapper.victim],controlMachine.baseBlock.transform.rotation);
- }
- catch {
- return;
- }
- try {
- item.gameObject.GetComponent<ExplodeOnCollide>().Explodey();
- }
- catch {
- Debug.Log("Could not explode");
- }
- if(item!=null) {
- Destroy(item.gameObject);
- }
- }
- else if(r==2) {
- viewMapper.allWorldGameObjects[viewMapper.victim].transform.position += Vector3.up*50;
- }
- else if(r==3) {
- viewMapper.allWorldGameObjects[viewMapper.victim].transform.Rotate(Vector3.forward,180);
- }
- else if(r==4) {
- Destroy(viewMapper.allWorldGameObjects[viewMapper.victim].gameObject);
- }
- }
- public void Update() {
- if(!getEverythingNeededToRunTheClass()) {
- return;
- }
- viewMapperHandler();
- controlMachineHandler();
- selectVictimHandler();
- }
- public void OnGUI() {
- if(state==-1)
- return;
- if(hudInputControl!=null)
- if(!hudInputControl.hudCam.enabled)
- return;
- string tempString = "";
- GUILayout.Space(58);
- GUILayout.Label("Besiege Bot Information: ");
- GUILayout.Label("Current Position: "+controlMachine.currentPosition);
- tempString = "Current victim: ";
- if(viewMapper.victim==-1) {
- tempString += "None. BB is merciful. BB decides to let you live. For now.";
- }
- else {
- if(viewMapper.allWorldGameObjects[viewMapper.victim]==null) {
- tempString += "BB has already ended their existance. Their name is no longer important.";
- }
- else {
- tempString += viewMapper.allWorldGameObjects[viewMapper.victim].name;
- }
- }
- GUILayout.Label(tempString);
- tempString = "ViewMapper: Current state: "+viewMapper.state.ToString()+", Current Action: ";
- if(viewMapper.state==-1) {tempString+="Searching for everything needed for the class to work";}
- if(viewMapper.state==0) {tempString+="Waiting for simulation to start";}
- if(viewMapper.state==1) {tempString+="Obtaining list over all gameObjects";}
- if(viewMapper.state==2) {tempString+="Obtaining information over all gameObjects, Current object: "+viewMapper.allWorldGameObjectsChecked.ToString()+"/"+viewMapper.allWorldGameObjects.Length.ToString();}
- if(viewMapper.state==3) {tempString+="Waiting. Just waiting. For how long? No one knows. (Except BB, BB knows everything)";}
- if(viewMapper.state==4) {tempString+="Resting";}
- if(viewMapper.state==5) {tempString+="Considering if moving to an object is a good idea, Chose not to move "+viewMapper.choseNotToMove+" times";}
- GUILayout.Label(tempString);
- tempString = "ControlMachine: Current state: "+controlMachine.state.ToString()+", Blocks: "+(controlMachine.n+controlMachine.n2).ToString()+", Current Action: ";
- if(controlMachine.state==-2) { tempString+="Searching for everything needed for the class to work";};
- if(controlMachine.state==-1) { tempString+="Finishing setting up";};
- if(controlMachine.state==0) { tempString+="Waiting for simulation to start"; };
- if(controlMachine.state==1) { tempString+="Obtaining information about the machine"; };
- if(controlMachine.state==2) { tempString+="Considering if it should continue working"; };
- if(controlMachine.state==3) { tempString+="Remembering how to move. BB knows everything, and never learns anything, it just KNOWS!"; }
- if(controlMachine.state==4) { tempString+="Deciding where to move"; }
- if(controlMachine.state==5) { tempString+="Moving to "+controlMachine.moveToPosition.ToString()+" in "+(Mathf.Floor((controlMachine.wantedArrivalTime-Time.realtimeSinceStartup)*100)/100).ToString(); }
- GUILayout.Label(tempString);
- tempString = "SelectVictim: Current state: "+selectVictim.state.ToString()+", Substate: "+selectVictim.victimState.ToString()+", Current Action: ";
- if(selectVictim.state==0) { tempString += "Selecting a victim";}
- if(selectVictim.state==1) { tempString += "Moving towards a victim";}
- if(selectVictim.state==2) { tempString += "Preparing to attack victim";}
- if(selectVictim.state==3) { tempString += "Relentlessly attacking victim"; }
- if(selectVictim.state==4) { tempString += "He who fights with BB should be careful lest he thereby become a victim. And if thou gaze long at BB, then BB will also gaze into thee."; }
- GUILayout.Label(tempString);
- }
- }
- public class SelectVictim : MonoBehaviour {
- public SelectVictim(){
- }
- public int state = 0;
- public int victimState = 5;
- public bool hasControl = false;
- public bool requestAttackVictim = false;
- public bool requestingVictim = true;
- public Vector3 victimPosition;
- public Vector3 moveToPosition = new Vector3(5,5,0);
- public float wantedArrivalTime = 0;
- public void FixedUpdate() {
- if(requestingVictim||!AddPiece.isSimulating)
- return;
- if(state==0) {
- victimState = 5;
- requestingVictim = true;
- return;
- }
- if(state==2){
- moveToPosition=victimPosition;
- wantedArrivalTime = Time.realtimeSinceStartup+3;
- state=3;
- }
- if(state==3){
- moveToPosition=victimPosition;
- wantedArrivalTime += Time.fixedDeltaTime/2;
- if(wantedArrivalTime<=Time.realtimeSinceStartup){
- requestAttackVictim = true;
- state = 0;
- victimState = 5;
- }
- }
- if(victimState==5) {
- moveToPosition = victimPosition;
- wantedArrivalTime = Time.realtimeSinceStartup+5;
- victimState = 0;
- }
- if(victimState==0) {
- moveToPosition=victimPosition;
- if(wantedArrivalTime<=Time.realtimeSinceStartup) {
- moveToPosition = victimPosition+new Vector3(0,10+UnityEngine.Random.Range(0,10),0);
- wantedArrivalTime = Time.realtimeSinceStartup+10;
- victimState = 1;
- }
- }
- if(victimState==1) {
- if(wantedArrivalTime<=Time.realtimeSinceStartup) {
- moveToPosition = victimPosition;
- wantedArrivalTime = Time.realtimeSinceStartup+5;
- victimState = 2;
- }
- }
- if(victimState==2) {
- moveToPosition=victimPosition;
- wantedArrivalTime += Time.fixedDeltaTime/2;
- if(wantedArrivalTime<=Time.realtimeSinceStartup) {
- victimState=3;
- wantedArrivalTime = Time.realtimeSinceStartup+3;
- }
- }
- if(victimState==3) {
- moveToPosition=victimPosition;
- wantedArrivalTime += Time.fixedDeltaTime/4;
- if(wantedArrivalTime<=Time.realtimeSinceStartup) {
- victimState=4;
- wantedArrivalTime = Time.realtimeSinceStartup+1;
- }
- }
- if(victimState==4) {
- moveToPosition=victimPosition;
- wantedArrivalTime += Time.fixedDeltaTime/8;
- if(wantedArrivalTime<=Time.realtimeSinceStartup) {
- victimState=5;
- state = 0;
- }
- }
- }
- }
- public class ControlMachine : MonoBehaviour {
- public string currentPosition = "Pan";
- Texture2D texture2D = new Texture2D(1,1);
- public GameObject baseBlock = null;
- public int state = -2;
- public bool hasControl = false;
- List<GameObject> flyBlockList = new List<GameObject>();
- public Vector3 moveToPosition = new Vector3(0,10,0);
- public float wantedArrivalTime = 0;
- public bool requestToViewMachine = false;
- public float forceMultiplier = 5;
- public Vector3 previousDistanceAwayFromObject = Vector3.zero;
- public int n = 0;
- public int n2 = 0;
- public bool BBpngExists = File.Exists(Application.dataPath+"/Resources/BB.png");
- public ControlMachine() {
- }
- public void useTheForce() {
- baseBlock.rigidbody.AddForce(-Physics.gravity*Time.fixedDeltaTime,ForceMode.Acceleration);
- float wantedTimeLeftUntilArrival = wantedArrivalTime-Time.realtimeSinceStartup;
- if(wantedTimeLeftUntilArrival<=0)
- return;
- Vector3 distanceAwayFromPosition = moveToPosition-baseBlock.transform.position;
- if((distanceAwayFromPosition-previousDistanceAwayFromObject).magnitude<0.63f) {
- return;
- }
- previousDistanceAwayFromObject = distanceAwayFromPosition;
- Vector3 wantedVelocity = distanceAwayFromPosition/wantedTimeLeftUntilArrival;
- if((wantedVelocity-baseBlock.rigidbody.velocity).magnitude*forceMultiplier<=0.15f)
- return;
- baseBlock.rigidbody.AddForce((wantedVelocity-baseBlock.rigidbody.velocity),ForceMode.VelocityChange);
- }
- public void getBlockCount() {
- for(int i=n; i<=n; i++) {
- if(GameObject.Find("bsg"+i.ToString())!=null) {
- n++;
- }
- }
- for(int i=n2;i<=n2;i++) {
- if(GameObject.Find("bgeL"+i.ToString())!=null) {
- n2++;
- }
- }
- }
- public void findFlyBlocks() {
- flyBlockList = new List<GameObject>();
- for(int i = 0;i<n;i++) {
- GameObject currentGameObject = GameObject.Find("bsg"+i.ToString());
- if(currentGameObject!=null) {
- if(currentGameObject.GetComponent<MyBlockInfo>().blockName=="FLYING SPIRAL") {
- flyBlockList.Add(currentGameObject);
- }
- }
- }
- for(int i = 0;i<n2;i++) {
- GameObject currentGameObject = GameObject.Find("bgeL"+i.ToString());
- if(currentGameObject!=null) {
- if(currentGameObject.GetComponent<MyBlockInfo>().blockName=="FLYING SPIRAL") {
- flyBlockList.Add(currentGameObject);
- }
- }
- }
- }
- public bool getEverythingNeededToRunTheClass() {
- currentPosition = "Pan";
- if(texture2D.width==1&&BBpngExists) {
- Debug.Log(Application.dataPath+"/Resources/BB.png");
- byte[] imageData = File.ReadAllBytes(Application.dataPath+"/Resources/BB.png");
- texture2D.LoadImage(imageData);
- if(texture2D.width==1) {
- return false;
- }
- Debug.Log("Found BB.png");
- }
- if(baseBlock==null) {
- baseBlock = GameObject.Find("bgeL0");
- if(baseBlock==null) {
- return false;
- }
- Debug.Log("Found bgeL0");
- }
- else {
- baseBlock = GameObject.Find("bgeL0");
- }
- currentPosition = baseBlock.transform.position.ToString();
- return true;
- }
- public void FixedUpdate() {
- if(!getEverythingNeededToRunTheClass()) {
- if(state>-2) {
- n = 0;
- n2 = 0;
- state = -1;
- }
- return;
- }
- getBlockCount();
- if(state==-2) {
- state = -1;
- }
- if(state==-1) {
- Renderer[] tempRenderers;
- try {
- tempRenderers = baseBlock.GetComponentsInChildren<Renderer>();
- }
- catch {
- Debug.Log("Could not find renderers");
- state = 0;
- return;
- }
- Texture tempTexture = new Texture();
- try {
- tempTexture = texture2D;
- }
- catch {
- Debug.Log("Could not save Texture");
- state = 0;
- return;
- }
- tempTexture.wrapMode = TextureWrapMode.Clamp;
- foreach(Renderer tempRenderer in tempRenderers) {
- try {
- tempRenderer.material.mainTexture = tempTexture;
- }
- catch {
- continue;
- }
- Debug.Log("Applied BB texture to "+tempRenderer.name);
- }
- Collider[] colliders = baseBlock.GetComponentsInChildren<Collider>();
- foreach(Collider ccollider in colliders) {
- try {
- ccollider.material.bounciness = 0.75f;
- ccollider.material.bounceCombine = PhysicMaterialCombine.Maximum;
- }
- catch {
- continue;
- }
- Debug.Log("Applied bounciness to "+ccollider.name);
- }
- foreach(Collider ccollider in colliders) {
- try {
- ccollider.material.staticFriction = 0;
- ccollider.material.dynamicFriction = 0;
- ccollider.material.frictionCombine = PhysicMaterialCombine.Minimum;
- }
- catch {
- continue;
- }
- Debug.Log("Applied friction to "+ccollider.name);
- }
- state = 0;
- }
- if(state==1) {
- if(AddPiece.isSimulating) {
- Debug.Log(baseBlock.transform.position.ToString());
- findFlyBlocks();
- state = 2;
- }
- }
- if(state==3) {
- if(hasControl) {
- Debug.Log(baseBlock.transform.position.ToString());
- //SOME FANCY FUNCTION, OKAY?
- wantedArrivalTime = Time.realtimeSinceStartup + 5;
- state = 4;
- }
- }
- if(state==4) {
- if(AddPiece.isSimulating) {
- if(wantedArrivalTime>Time.realtimeSinceStartup&&(baseBlock.transform.position-moveToPosition).magnitude>2) {
- state = 5;
- }
- }
- else {
- state = 1;
- }
- }
- if(state==5) {
- if(AddPiece.isSimulating) {
- if(wantedArrivalTime<=Time.realtimeSinceStartup) {
- state = 4;
- return;
- }
- // if(n==0&&n2==1) {
- useTheForce();
- // return;
- // }
- }
- else {
- state = 1;
- }
- }
- }
- }
- public class ViewMapper : MonoBehaviour {
- public int state = -1;
- public float timeSinceLastCheck = 0;
- public int allWorldGameObjectsChecked = 0;
- public float defaultScale = 1;
- public int choseNotToMove = 0;
- public int gotToViewMachine = 0;
- public float viewMachineImmunity = 0;
- public MouseOrbit mouseOrbit;
- public GameObject[] allWorldGameObjects;
- public List<float> allWorldlastTimeGameObjectWasSeen = new List<float>();
- public List<bool> allWorldlastMovedGameObjectWasSeen = new List<bool>();
- public List<bool> allWorldhasMoved = new List<bool>();
- public List<Vector3> allWorldlastPositionGameObjectWasSeen = new List<Vector3>();
- public List<Vector3> allWorldlastVelocityGameObjectWasSeen = new List<Vector3>();
- public int victim = -1;
- public ViewMapper() {
- state = 0; //Nothing mapped state
- }
- public void selectVictim() {
- if(state<3)
- return;
- for(int i = 0;i<1000;i++) {
- int current = 0;
- try {
- current = UnityEngine.Random.Range(0,allWorldGameObjects.Length-1);
- }
- catch {
- Debug.Log("Could not get random number");
- continue;
- }
- try {
- if(allWorldGameObjects[current]==null) {
- i--;
- continue;
- }
- }
- catch {
- Debug.Log("Could not check if null");
- continue;
- }
- try {
- if(allWorldGameObjects[current].transform.position.magnitude>1000) {
- i--;
- continue;
- }
- }
- catch {
- Debug.Log("Could not check position");
- continue;
- }
- try {
- if(allWorldGameObjects[current].rigidbody==null)
- continue;
- }
- catch {
- Debug.Log("Could not check if rigidbody is null");
- continue;
- }
- try {
- if(allWorldhasMoved[current]) {
- victim = current;
- return;
- }
- }
- catch {
- Debug.Log("Could not select victim");
- continue;
- }
- }
- victim = -1;
- }
- public bool checkIfLikelyToViewMachine(int n) {
- int r = UnityEngine.Random.Range(0,1+gotToViewMachine);
- if(r<=n)
- return true;
- return false;
- }
- public bool requestViewMachine() {
- if(timeSinceLastCheck<0) {
- return true;
- }
- if(viewMachineImmunity>0) {
- viewMachineImmunity -= Time.deltaTime;
- return false;
- }
- if(checkIfLikelyToViewMachine(3)) {
- mouseOrbit.target = GameObject.Find("bgeL0").transform;
- // mouseOrbit.wasdPOSdelegate = Vector3.zero;
- // mouseOrbit.distance = defaultScale*GameObject.Find("bgeL0").transform.localScale.magnitude;
- mouseOrbit.zoomSmooth = 10;
- // mouseOrbit.x = 0;
- gotToViewMachine++;
- return true;
- }
- gotToViewMachine--;
- if(gotToViewMachine<=3)
- gotToViewMachine=0;
- return false;
- }
- public bool saveObject(int allWorldN) {
- if(allWorldGameObjects.Length<=allWorldN||allWorldN<0)
- return false;
- if(allWorldGameObjects[allWorldN]==null)
- return false;
- if(!allWorldGameObjects[allWorldN].activeInHierarchy) {
- if(allWorldlastTimeGameObjectWasSeen.Count==allWorldN-1) {
- allWorldlastTimeGameObjectWasSeen.Add(Time.realtimeSinceStartup);
- allWorldlastPositionGameObjectWasSeen.Add(Vector3.zero);
- allWorldlastVelocityGameObjectWasSeen.Add(Vector3.zero);
- allWorldhasMoved.Add(false);
- allWorldlastMovedGameObjectWasSeen.Add(false);
- }
- return false;
- }
- if(allWorldGameObjects[allWorldN].rigidbody==null) {
- if(allWorldlastTimeGameObjectWasSeen.Count==allWorldN-1) {
- allWorldlastTimeGameObjectWasSeen.Add(Time.realtimeSinceStartup);
- allWorldlastPositionGameObjectWasSeen.Add(Vector3.zero);
- allWorldlastVelocityGameObjectWasSeen.Add(Vector3.zero);
- allWorldhasMoved.Add(false);
- allWorldlastMovedGameObjectWasSeen.Add(false);
- }
- return false;
- }
- if(allWorldlastTimeGameObjectWasSeen.Count<=allWorldN){
- if(allWorldlastTimeGameObjectWasSeen.Count==allWorldN-1){
- allWorldlastTimeGameObjectWasSeen.Add(Time.realtimeSinceStartup);
- allWorldlastPositionGameObjectWasSeen.Add(allWorldGameObjects[allWorldN].transform.position);
- allWorldlastVelocityGameObjectWasSeen.Add(allWorldGameObjects[allWorldN].rigidbody.velocity);
- allWorldhasMoved.Add(false);
- allWorldlastMovedGameObjectWasSeen.Add(false);
- }
- else {
- return false;
- }
- }
- else {
- allWorldlastTimeGameObjectWasSeen[allWorldN] = Time.realtimeSinceStartup;
- if(allWorldGameObjects[allWorldN].rigidbody.velocity.magnitude>=0.15f||allWorldGameObjects[allWorldN].transform.position!=allWorldlastPositionGameObjectWasSeen[allWorldN]) {
- allWorldhasMoved[allWorldN] = true;
- allWorldlastMovedGameObjectWasSeen[allWorldN] = true;
- }
- else {
- allWorldlastMovedGameObjectWasSeen[allWorldN] = false;
- }
- allWorldlastPositionGameObjectWasSeen[allWorldN] = allWorldGameObjects[allWorldN].transform.position;
- allWorldlastVelocityGameObjectWasSeen[allWorldN] = allWorldGameObjects[allWorldN].rigidbody.velocity;
- }
- return true;
- }
- public bool getEverythingNeededToRunTheClass(){
- if(mouseOrbit==null) {
- mouseOrbit = Camera.main.GetComponent<MouseOrbit>();
- if(mouseOrbit==null) {
- return false;
- }
- Debug.Log("Found MouseOrbit");
- }
- return true;
- }
- public void goToNextObject() {
- timeSinceLastCheck += Time.deltaTime;
- if(state==2) {
- timeSinceLastCheck += Time.deltaTime*(allWorldGameObjects.Length/125+1);
- }
- while(timeSinceLastCheck>=0.5f) {
- timeSinceLastCheck -= 0.5f;
- if(state==2) {
- if(allWorldGameObjectsChecked>=allWorldGameObjects.Length) {
- Debug.Log("Changing viewLoggerState to 3");
- state = 3;
- mouseOrbit.target = GameObject.Find("bgeL0").transform;
- // mouseOrbit.wasdPOSdelegate = Vector3.zero;
- // mouseOrbit.distance = defaultScale/2;
- mouseOrbit.zoomSmooth = 10;
- // mouseOrbit.x = 0;
- return;
- }
- else {
- while(allWorldGameObjectsChecked<=allWorldGameObjects.Length) {
- if(saveObject(allWorldGameObjectsChecked)) {
- mouseOrbit.target = allWorldGameObjects[allWorldGameObjectsChecked].transform;
- // mouseOrbit.wasdPOSdelegate = Vector3.zero;
- allWorldGameObjectsChecked++;
- return;
- }
- allWorldGameObjectsChecked++;
- }
- }
- }
- else if(state==5) {
- for(int i = 0;i<allWorldGameObjects.Length/10;i++) {
- int current = 0;
- try {
- current = UnityEngine.Random.Range(0,allWorldGameObjects.Length-1);
- }
- catch {
- }
- if(allWorldGameObjects[current]==null) {
- i--;
- continue;
- }
- if(allWorldGameObjects[current].activeInHierarchy) {
- if(allWorldGameObjects[current].rigidbody!=null) {
- float div = 10;
- if(!allWorldhasMoved[current]){div*=4;}
- if(!allWorldlastMovedGameObjectWasSeen[current]){div*=2;}
- if(UnityEngine.Random.Range(0f,100f)<=(Time.realtimeSinceStartup-allWorldlastTimeGameObjectWasSeen[current])/(div)) {
- mouseOrbit.target = allWorldGameObjects[current].transform;
- // mouseOrbit.wasdPOSdelegate = Vector3.zero;
- this.choseNotToMove = 0;
- return;
- }
- }
- }
- }
- choseNotToMove++;
- if(choseNotToMove==20) {
- mouseOrbit.target = GameObject.Find("bgeL0").transform;
- // mouseOrbit.wasdPOSdelegate = Vector3.zero;
- // mouseOrbit.distance = defaultScale/2;
- mouseOrbit.zoomSmooth = 10;
- // mouseOrbit.x = 0;
- }
- }
- }
- }
- public void saveEverythingYouSee() {
- for(int i = 0;i<allWorldGameObjects.Length;i++) {
- if(allWorldGameObjects[i]!=null) {
- if(allWorldGameObjects[i].activeInHierarchy) {
- if(allWorldGameObjects[i].renderer!=null) {
- if(allWorldGameObjects[i].renderer.isVisible) {
- saveObject(i);
- }
- }
- }
- }
- }
- }
- public void Update() {
- if(!getEverythingNeededToRunTheClass()) {
- return;
- }
- if(state==-1) {
- Debug.Log("Changing viewLoggerState to 0");
- state = 0;
- }
- if(state==1) {
- allWorldGameObjects = UnityEngine.Object.FindObjectsOfType<GameObject>();
- allWorldGameObjectsChecked = 0;
- allWorldlastTimeGameObjectWasSeen = new List<float>();
- allWorldlastMovedGameObjectWasSeen = new List<bool>();
- allWorldhasMoved = new List<bool>();
- allWorldlastPositionGameObjectWasSeen = new List<Vector3>();
- allWorldlastVelocityGameObjectWasSeen = new List<Vector3>();
- Debug.Log("Changing viewLoggerState to 2");
- state = 2;
- }
- if(state==2) {
- mouseOrbit.x -= 80*Time.deltaTime;
- mouseOrbit.distance = Mathf.Lerp(mouseOrbit.distance, defaultScale*mouseOrbit.target.localScale.magnitude,Time.deltaTime);
- goToNextObject();
- }
- if(state==5) {
- mouseOrbit.x += 5*Time.deltaTime;
- mouseOrbit.distance = Mathf.Lerp(mouseOrbit.distance,defaultScale*mouseOrbit.target.localScale.magnitude/2,Time.deltaTime/2);
- goToNextObject();
- saveEverythingYouSee();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement