Advertisement
Guest User

More Cameras Mod

a guest
Jul 19th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using UnityEngine;
  8.  
  9. namespace meta
  10. {
  11.     public class Mod : MonoBehaviour
  12.     {
  13.         public Rect windowRect = new Rect(20, 20, 250, 300);
  14.         //public RenderTexture renderTexture = new RenderTexture(450,300,32);
  15.         //public Camera renderCamera = (Camera)Camera.Instantiate (Camera.main);
  16.         public List<RenderTexture> renderTextureList = new List<RenderTexture>();
  17.         public List<GameObject> cameraList = new List<GameObject>();
  18.         public List<GameObject> cameraChildList = new List<GameObject>();
  19.         public List<Rect> windowRectList = new List<Rect>();
  20.         public bool listCameras = false;
  21.         public int fullscreen = -1;
  22.         public Vector2 ScrollPosition;
  23.  
  24.         public void Start() {
  25.             //renderTexture.Create ();k
  26.         }
  27.  
  28.         public void Update() {
  29.             /**if (Input.GetKeyDown (KeyCode.C)) {
  30.                 renderTextureList.Add (new RenderTexture (450, 300, 32));
  31.                 cameraList.Add ((Camera)Camera.Instantiate (Camera.main));
  32.                 windowRectList.Add (new Rect (20, 20, 450, 300));
  33.                 renderTextureList [renderTextureList.Count - 1].Create ();
  34.             }
  35.             if (Input.GetKeyDown (KeyCode.R)) {
  36.                 renderTextureList = new List<RenderTexture>();
  37.                 cameraList = new List<Camera>();
  38.                 windowRectList = new List<Rect>();
  39.             }**/
  40.             GameObject.Find ("Main Camera").SetActive (true);
  41.             for (int i=0;i<cameraList.Count;i++) {
  42.                
  43.             }
  44.  
  45.             if (Input.GetKeyDown (KeyCode.Escape) && fullscreen != -1) {
  46.                 windowRectList [fullscreen] = new Rect(0,0, 450, 300);
  47.                 fullscreen = -1;
  48.             }
  49.         }
  50.  
  51.         IEnumerator<WaitForSeconds> OnLevelLoadedFunc () {
  52.             yield return new WaitForSeconds (1);
  53.             if (GameObject.Find ("bgeL0")) {
  54.                 renderTextureList = new List<RenderTexture> ();
  55.                 cameraList = new List<GameObject> ();
  56.                 cameraChildList = new List<GameObject> ();
  57.                 windowRectList = new List<Rect> ();
  58.                 foreach (GameObject gameObject in GameObject.FindObjectsOfType<GameObject>()) {
  59.                     if (gameObject.name == "CamModCam") {
  60.                         Destroy (gameObject.transform.FindChild ("CamModCamChild").gameObject);
  61.                         Vector3 TempPos = gameObject.transform.position;
  62.                         Quaternion TempRot = new Quaternion ();
  63.                         TempRot.eulerAngles = gameObject.transform.rotation.eulerAngles;
  64.                         Destroy (gameObject);
  65.                         NewCam ();
  66.                         cameraList [cameraList.Count - 1].transform.position = TempPos;
  67.                         cameraList [cameraList.Count - 1].transform.rotation = TempRot;
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.  
  73.         void OnLevelWasLoaded(int level) {
  74.             //Debug.Log ("QUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACK");
  75.             StartCoroutine(OnLevelLoadedFunc());
  76.         }
  77.  
  78.         public void NewCam() {
  79.             //Create's the rect for the camera's window
  80.             windowRectList.Add (new Rect (20, 20, 450, 300));
  81.  
  82.             //Create's and add's the renderTexture
  83.             renderTextureList.Add (new RenderTexture (450, 300, 32));
  84.             renderTextureList [renderTextureList.Count - 1].Create ();
  85.  
  86.             //Create's the camera gameObject
  87.             cameraList.Add (GameObject.CreatePrimitive (PrimitiveType.Cube));
  88.             cameraList [cameraList.Count - 1].AddComponent<Camera> ();
  89.  
  90.             //Set's the camera propertries
  91.             cameraList [cameraList.Count - 1].transform.position = new Vector3 (0, 1, 0);
  92.             cameraList [cameraList.Count - 1].name = "CamModCam";
  93.             //cameraList [cameraList.Count - 1].tag = "CamModCamTag";
  94.             cameraList [cameraList.Count - 1].collider.enabled = false;
  95.             cameraList [cameraList.Count - 1].camera.enabled = true;
  96.             cameraList [cameraList.Count - 1].transform.parent = GameObject.Find ("bgeL0").transform;
  97.             cameraList [cameraList.Count - 1].camera.targetTexture = renderTextureList [renderTextureList.Count - 1];
  98.             cameraList [cameraList.Count - 1].renderer.material.color = Color.black;
  99.  
  100.             cameraChildList.Add (GameObject.CreatePrimitive (PrimitiveType.Plane));
  101.             cameraChildList [cameraChildList.Count - 1].transform.localScale = new Vector3 (0.1f, 1, 0.1f);
  102.             cameraChildList [cameraChildList.Count - 1].transform.position = new Vector3 (0, 1, 0.53f);
  103.             cameraChildList [cameraChildList.Count - 1].transform.Rotate (90, 0, 0);
  104.             cameraChildList [cameraChildList.Count - 1].transform.parent = cameraList [cameraList.Count - 1].transform;
  105.             cameraChildList [cameraChildList.Count - 1].name = "CamModCamChild";
  106.             cameraChildList [cameraChildList.Count - 1].collider.enabled = false;
  107.         }
  108.  
  109.         void OnGUI() {
  110.            
  111.             for (int i=0; i<windowRectList.Count;i++) {
  112.                 windowRectList [i] = GUI.Window (i+1, windowRectList [i], DoMyWindow, "");
  113.             }
  114.             windowRect = GUI.Window(0, windowRect, DoMyWindowConf, "Camera Config");
  115.         }
  116.         void DoMyWindow(int windowID) {
  117.             //PUT STUFF TO GO IN WINDOW HERE
  118.  
  119.             try {
  120.                 cameraList[windowID-1].camera.targetTexture = renderTextureList[windowID-1];
  121.             } catch {
  122.                 //Destroy (cameraList [windowID - 1]);
  123.             }
  124.  
  125.             if (fullscreen != -1) {
  126.                 GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), renderTextureList [windowID - 1], ScaleMode.StretchToFill, false);
  127.             } else {
  128.                 GUI.DrawTexture (new Rect (0, 0, 450, 300), renderTextureList [windowID - 1], ScaleMode.StretchToFill, false);
  129.             }
  130.  
  131.             //DONE
  132.             if (fullscreen == -1) {
  133.                 GUI.DragWindow ();
  134.             }
  135.         }
  136.  
  137.         void DoMyWindowConf(int windowID) {
  138.  
  139.             GUILayout.BeginHorizontal ();
  140.  
  141.             if (GUILayout.Button ("Remove All Cameras")) {
  142.                 foreach (GameObject gameObject in GameObject.FindObjectsOfType<GameObject>()) {
  143.                     if (gameObject.name == "CamModCam" || gameObject.name == "CamModCamChild") {
  144.                         GameObject.Destroy (gameObject);
  145.                     }
  146.                 }
  147.  
  148.                 renderTextureList = new List<RenderTexture>();
  149.                 cameraList = new List<GameObject>();
  150.                 cameraChildList = new List<GameObject>();
  151.                 windowRectList = new List<Rect> ();
  152.             }
  153.  
  154.             if (GUILayout.Button ("Add A Camera")) {
  155.                 if (GameObject.Find ("bgeL0") != null) {
  156.                     NewCam ();
  157.                 }
  158.             }
  159.  
  160.             GUILayout.EndHorizontal ();
  161.  
  162.             ScrollPosition = GUILayout.BeginScrollView (ScrollPosition, true, false);
  163.             int i = 0;
  164.             foreach (GameObject camera in cameraList) {
  165.                 GUILayout.BeginVertical ("Box");
  166.                 GUILayout.Label ("Move:");
  167.                 GUILayout.BeginHorizontal ();
  168.                 if (GUILayout.Button (new GUIContent("Forward","Forward"))) {
  169.                     camera.transform.position = new Vector3 (camera.transform.position.x+1, camera.transform.position.y, camera.transform.position.z);
  170.                 }
  171.                 if (GUILayout.Button (new GUIContent("Backward","Backward"))) {
  172.                     camera.transform.position = new Vector3 (camera.transform.position.x-1, camera.transform.position.y, camera.transform.position.z);
  173.                 }
  174.                 if (GUILayout.Button (new GUIContent("Left","Left"))) {
  175.                     camera.transform.position = new Vector3 (camera.transform.position.x, camera.transform.position.y, camera.transform.position.z+1);
  176.                 }
  177.                 if (GUILayout.Button (new GUIContent("Right","Right"))) {
  178.                     camera.transform.position = new Vector3 (camera.transform.position.x, camera.transform.position.y, camera.transform.position.z-1);
  179.                 }
  180.                 GUILayout.EndHorizontal ();
  181.                 GUILayout.BeginHorizontal ();
  182.                 if (GUILayout.Button (new GUIContent("Up","Move up"))) {
  183.                     camera.transform.position = new Vector3 (camera.transform.position.x, camera.transform.position.y+1, camera.transform.position.z);
  184.                 }
  185.                 if (GUILayout.Button (new GUIContent("Down","Move down"))) {
  186.                     camera.transform.position = new Vector3 (camera.transform.position.x, camera.transform.position.y-1, camera.transform.position.z);
  187.                 }
  188.                 GUILayout.EndHorizontal ();
  189.                 GUILayout.Label ("Rotate:");
  190.                 GUILayout.BeginHorizontal ();
  191.                 if (GUILayout.Button (new GUIContent("Up","Rotate up"))) {
  192.                     camera.transform.Rotate (new Vector3 (-90, 0, 0));
  193.                 }
  194.                 if (GUILayout.Button (new GUIContent("Down","Rotate down"))) {
  195.                     camera.transform.Rotate (new Vector3 (90, 0, 0));
  196.                 }
  197.                 if (GUILayout.Button (new GUIContent("Left","Rotate left"))) {
  198.                     camera.transform.Rotate (new Vector3 (0, -90, 0));
  199.                 }
  200.                 if (GUILayout.Button (new GUIContent("Right","Rotate right"))) {
  201.                     camera.transform.Rotate (new Vector3 (0, 90, 0));
  202.                 }
  203.                 GUILayout.EndHorizontal ();
  204.                 if (GUILayout.Button ("Set As Main Camera")) {
  205.                     windowRectList [i] = new Rect(0,0, Screen.width, Screen.height);
  206.                     fullscreen = i;
  207.                 }
  208.                 if (GUILayout.Button ("Toggle Invisibility")) {
  209.                     if (camera.renderer.enabled == true) {
  210.                         camera.renderer.enabled = false;
  211.                         camera.transform.FindChild ("CamModCamChild").renderer.enabled = false;
  212.                     } else {
  213.                         camera.renderer.enabled = true;
  214.                         camera.transform.FindChild ("CamModCamChild").renderer.enabled = true;
  215.                     }
  216.                 }
  217.                 GUILayout.EndVertical ();
  218.                 i++;
  219.             }
  220.  
  221.             GUILayout.EndScrollView ();
  222.  
  223.             GUI.DragWindow ();
  224.         }
  225.     }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement