Advertisement
Guest User

Besiege Selection Mover Mod

a guest
Jul 18th, 2015
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.71 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.     //I got some inspiration for this class from ITR, so most of the credit for this part of the code goes to ITR, thanks!
  12.     //http://www.forum.spiderlinggames.co.uk/forum/main-forum/besiege-early-access/modding/17686-more-colors-mod-spaar-s-modloader
  13.     public class Tint : MonoBehaviour {
  14.         public Tint() {
  15.  
  16.         }
  17.  
  18.         public Color currentColor;
  19.  
  20.         public void TintIt(Color color) {
  21.             MeshRenderer[] componentsInChildren = base.GetComponentsInChildren<MeshRenderer>();
  22.             for (int i = 0; i < componentsInChildren.Length; i++)
  23.             {
  24.                 Material[] materials = componentsInChildren[i].materials;
  25.                 for (int j = 0; j < materials.Length; j++)
  26.                 {
  27.                     Material material = materials[j];
  28.                     if (material.HasProperty("_Color"))
  29.                     {
  30.                         material.color = color;
  31.                         currentColor = color;
  32.                     }
  33.                 }
  34.             }
  35.         }
  36.     }
  37.  
  38.     [spaar.Mod("BesiegeSelectionMoverMod", author = "TesseractCat", version = "0.7")]
  39.     public class Mod : MonoBehaviour
  40.     {
  41.        
  42.         public void Start() {
  43.  
  44.         }
  45.  
  46.         public Rect windowRect = new Rect(20, 20, 250, 200);
  47.         public float Step = 1f;
  48.         public string ModifierKey = "q";
  49.         public Vector3 pos1 = new Vector3(0,0,0);
  50.         public Vector3 pos2 = new Vector3(0,0,0);
  51.  
  52.         void OnGUI() {
  53.             //if (GameObject.Find ("ArrowsCenter")) {
  54.                 windowRect = GUI.Window (-1, windowRect, DoMyWindow, "Selection Move Config");
  55.             //}
  56.         }
  57.  
  58.  
  59.  
  60.         void DoMyWindow(int windowID) {
  61.  
  62.             GUILayout.BeginVertical ("Box");
  63.  
  64.             GUILayout.BeginHorizontal ();
  65.  
  66.             GUILayout.Label ("Step:");
  67.  
  68.             Step = GUILayout.HorizontalSlider (Step, 0, 1);
  69.             GUILayout.EndHorizontal ();
  70.  
  71.             string lengthText = GUILayout.TextField(Step.ToString("0.00"));
  72.  
  73.             float newLength;
  74.             if (float.TryParse(lengthText, out newLength))
  75.             {
  76.                 Step = newLength;
  77.             }
  78.             GUILayout.EndVertical ();
  79.  
  80.             GUILayout.BeginHorizontal ("Box");
  81.  
  82.             if (GUILayout.Button ("Pos1")) {
  83.                 pos1 = Camera.main.transform.position;
  84.             }
  85.             if (GUILayout.Button("Pos2")) {
  86.                 pos2 = Camera.main.transform.position;
  87.             }
  88.             if (GUILayout.Button("Select")) {
  89.                 foreach (MyBlockInfo Block in FindObjectsOfType<MyBlockInfo>() as MyBlockInfo[]) {
  90.                     if (Block.transform.position.x > pos1.x) {
  91.                         if (Block.transform.position.x < pos2.x) {
  92.                             if (Block.transform.position.z > pos1.z) {
  93.                                 if (Block.transform.position.z < pos2.z) {
  94.                                     if (Block.transform.position.y > pos1.y) {
  95.                                         if (Block.transform.position.y < pos2.y) {
  96.                                             if (Block.GetComponent<Tint> ()) {
  97.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  98.                                             } else {
  99.                                                 Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
  100.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  101.                                             }
  102.                                         }
  103.                                     } else if (Block.transform.position.y < pos1.y) {
  104.                                         if (Block.transform.position.y > pos2.y) {
  105.                                             if (Block.GetComponent<Tint> ()) {
  106.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  107.                                             } else {
  108.                                                 Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
  109.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  110.                                             }
  111.                                         }
  112.                                     }
  113.                                 }
  114.                             } else if (Block.transform.position.z < pos1.z) {
  115.                                 if (Block.transform.position.z > pos2.z) {
  116.                                     if (Block.transform.position.y > pos1.y) {
  117.                                         if (Block.transform.position.y < pos2.y) {
  118.                                             if (Block.GetComponent<Tint> ()) {
  119.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  120.                                             } else {
  121.                                                 Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
  122.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  123.                                             }
  124.                                         }
  125.                                     } else if (Block.transform.position.y < pos1.y) {
  126.                                         if (Block.transform.position.y > pos2.y) {
  127.                                             if (Block.GetComponent<Tint> ()) {
  128.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  129.                                             } else {
  130.                                                 Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
  131.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  132.                                             }
  133.                                         }
  134.                                     }
  135.                                 }
  136.                             }
  137.                         }
  138.                     } else if (Block.transform.position.x < pos1.x) {
  139.                         if (Block.transform.position.x > pos2.x) {
  140.                             if (Block.transform.position.z > pos1.z) {
  141.                                 if (Block.transform.position.z < pos2.z) {
  142.                                     if (Block.transform.position.y > pos1.y) {
  143.                                         if (Block.transform.position.y < pos2.y) {
  144.                                             if (Block.GetComponent<Tint> ()) {
  145.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  146.                                             } else {
  147.                                                 Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
  148.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  149.                                             }
  150.                                         }
  151.                                     } else if (Block.transform.position.y < pos1.y) {
  152.                                         if (Block.transform.position.y > pos2.y) {
  153.                                             if (Block.GetComponent<Tint> ()) {
  154.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  155.                                             } else {
  156.                                                 Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
  157.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  158.                                             }
  159.                                         }
  160.                                     }
  161.                                 }
  162.                             } else if (Block.transform.position.z < pos1.z) {
  163.                                 if (Block.transform.position.z > pos2.z) {
  164.                                     if (Block.transform.position.y > pos1.y) {
  165.                                         if (Block.transform.position.y < pos2.y) {
  166.                                             if (Block.GetComponent<Tint> ()) {
  167.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  168.                                             } else {
  169.                                                 Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
  170.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  171.                                             }
  172.                                         }
  173.                                     } else if (Block.transform.position.y < pos1.y) {
  174.                                         if (Block.transform.position.y > pos2.y) {
  175.                                             if (Block.GetComponent<Tint> ()) {
  176.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  177.                                             } else {
  178.                                                 Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
  179.                                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  180.                                             }
  181.                                         }
  182.                                     }
  183.                                 }
  184.                             }
  185.                         }
  186.                     }
  187.  
  188.                 }
  189.             }
  190.  
  191.  
  192.             GUILayout.EndHorizontal ();
  193.  
  194.             GUILayout.BeginVertical ("Box");
  195.  
  196.             GUILayout.BeginHorizontal ();
  197.             GUILayout.Label ("Select = Ctrl + ");
  198.             ModifierKey = GUILayout.TextField (ModifierKey,1);
  199.             GUILayout.EndHorizontal ();
  200.  
  201.             GUILayout.Label ("Click = Ctrl");
  202.  
  203.             GUILayout.EndVertical ();
  204.  
  205.             GUI.DragWindow ();
  206.         }
  207.  
  208.         public GameObject Center;
  209.         public GameObject Left;
  210.         public GameObject Right;
  211.         public GameObject Forward;
  212.         public GameObject Backward;
  213.         public GameObject Up;
  214.         public GameObject Down;
  215.  
  216.         void MakeBlock(string name,Vector3 pos, Quaternion rot) {
  217.             Debug.Log ("Test1");
  218.             //GameObject.Find ("BUILDER").GetComponent<AddPiece> ().cu
  219.             //AddPiece.currentBlockType = 2;
  220.             //GameObject.Find ("BUILDER").GetComponent<AddPiece> ().AddBlock (pos, rot);
  221.             //GameObject.Find ("BUILDER").GetComponent<AddPiece> ().AddBlockType();
  222.             //GameObject.Find ("BUILDER").GetComponent<AddPiece> ()
  223.             Debug.Log ("Test2");
  224.         }
  225.  
  226.         public void Update() {
  227.             if (AddPiece.isSimulating && GameObject.Find ("ArrowsCenter")) {
  228.                 Destroy (Center);
  229.                 Destroy (Up);
  230.                 Destroy (Down);
  231.                 /**foreach (MyBlockInfo Block in GameObject.FindObjectsOfType<MyBlockInfo>() as MyBlockInfo[]) {
  232.                     try {
  233.                         Block.GetComponent<Tint> ().TintIt (Color.white);
  234.                         Destroy(Block.GetComponent<Tint> ());
  235.                     } catch {
  236.  
  237.                     }
  238.                 }**/
  239.             } else {
  240.  
  241.             }
  242.  
  243.             if (GameObject.Find ("bgeL0")!=null&&AddPiece.isSimulating!=true) {
  244.                 if (Input.GetKey (KeyCode.LeftControl) && Input.GetKeyDown (ModifierKey) || Input.GetKey (KeyCode.RightControl) && Input.GetKeyDown (ModifierKey)) {
  245.                     RaycastHit hit;
  246.                     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  247.  
  248.                     if (Physics.Raycast(ray, out hit)) {
  249.                         Transform objectHit = hit.transform;
  250.  
  251.                         if (objectHit.GetComponent<MyBlockInfo> ()!=null) {
  252.                             if (objectHit.GetComponent<Tint> () == null) {
  253.                                 objectHit.gameObject.AddComponent<Tint> ();
  254.                                 objectHit.GetComponent<Tint> ().TintIt (Color.green);
  255.                             } else {
  256.                                 objectHit.GetComponent<Tint> ().TintIt (Color.white);
  257.                                 Destroy (objectHit.GetComponent<Tint> ());
  258.                             }
  259.                         }
  260.                     }
  261.                 }
  262.  
  263.                 if (Input.GetKey (KeyCode.LeftControl) && Input.GetKeyDown (KeyCode.A) || Input.GetKey (KeyCode.RightControl) && Input.GetKeyDown (KeyCode.A)) {
  264.                     foreach (MyBlockInfo Block in GameObject.FindObjectsOfType<MyBlockInfo>() as MyBlockInfo[]) {
  265.                         if (Block.name != "CopyPasteInfo") {
  266.                             if (Block.GetComponent<Tint> () != null) {
  267.                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  268.                             } else {
  269.                                 Block.gameObject.AddComponent<Tint> ();
  270.                                 Block.GetComponent<Tint> ().TintIt (Color.green);
  271.                             }
  272.                         }
  273.                     }
  274.                 }
  275.  
  276.                 MyBlockInfo[] Blocks = FindObjectsOfType<MyBlockInfo> () as MyBlockInfo[];
  277.                 List<Transform> SelectedBlocks = new List<Transform> ();
  278.  
  279.                 foreach (MyBlockInfo Block in Blocks) {
  280.                     if (Block.GetComponent<Tint> () != null && Block.GetComponent<Tint> ().currentColor != Color.white) {
  281.                         SelectedBlocks.Add (Block.transform);
  282.                         Block.GetComponent<Tint> ().TintIt (Color.green);
  283.                     } else if (Block.GetComponent<Tint> () != null && Block.GetComponent<Tint> ().currentColor == Color.white) {
  284.                         Destroy (Block.GetComponent<Tint> ());
  285.                     }
  286.                 }
  287.  
  288.                 if (Input.GetKey (KeyCode.LeftControl) && Input.GetKeyDown (KeyCode.C) || Input.GetKey (KeyCode.RightControl) && Input.GetKeyDown (KeyCode.C)) {
  289.                     //GameObject.Find("BUILDER").GetComponent<AddPiece>().AddBlockAtPosNoSave(0,new Vector3(0,1,0),new Quaternion());
  290.  
  291.                     for (int i=0;i<SelectedBlocks.Count;i++) {
  292.                         Transform tempBlock = (Transform) Instantiate (SelectedBlocks[i]);
  293.                         tempBlock.position = SelectedBlocks[i].position;
  294.                         tempBlock.GetComponent<Tint> ().TintIt (Color.green);
  295.                         tempBlock.transform.parent = GameObject.Find ("BUILDER").GetComponent<AddPiece> ().machineParent;
  296.                         SelectedBlocks[i].GetComponent<Tint> ().TintIt (Color.white);
  297.                         //tempBlock.name = "bsg" + (Max+1).ToString ();
  298.                         //Max++;
  299.  
  300.                         //MakeBlock (SelectedBlocks[i].GetComponent<MyBlockInfo>().blockName,new Vector3(SelectedBlocks[i].position.x,SelectedBlocks[i].position.y,SelectedBlocks[i].position.z),SelectedBlocks[i].rotation);
  301.  
  302.                         //GameObject tempBlock = new GameObject ();
  303.                         //tempBlock.AddComponent<AddPiece> ();
  304.  
  305.                         //global::AddPiece.AddBlockAtPosNoSave (0,
  306.                         //  new Vector3(Block.position.x,Block.position.y+1,Block.position.z),
  307.                         //  new Quaternion(Block.rotation.x,Block.rotation.y,Block.rotation.z,Block.rotation.w));
  308.                     }
  309.                 }
  310.  
  311.                 if (SelectedBlocks.Count > 0) {
  312.                     if (GameObject.Find ("ArrowsCenter") == null) {
  313.                         Center = GameObject.CreatePrimitive (PrimitiveType.Sphere);
  314.                         Center.name = "ArrowsCenter";
  315.                         Center.transform.position = GameObject.Find("bgeL0").transform.position;
  316.                         Center.layer = 23;
  317.                         Center.collider.isTrigger = true;
  318.  
  319.                         Up = GameObject.CreatePrimitive (PrimitiveType.Sphere);
  320.                         Up.transform.position = new Vector3 (GameObject.Find("bgeL0").transform.position.x, GameObject.Find("bgeL0").transform.position.y+1.5f, GameObject.Find("bgeL0").transform.position.z);
  321.                         Up.name = "ArrowsUp";
  322.                         Up.layer = 23;
  323.                         Up.transform.parent = Center.transform;
  324.                         Up.collider.isTrigger = true;
  325.  
  326.                         Down = GameObject.CreatePrimitive (PrimitiveType.Sphere);
  327.                         Down.transform.position = new Vector3 (GameObject.Find("bgeL0").transform.position.x, GameObject.Find("bgeL0").transform.position.y-1.5f, GameObject.Find("bgeL0").transform.position.z);
  328.                         Down.name = "ArrowsDown";
  329.                         Down.layer = 23;
  330.                         Down.transform.parent = Center.transform;
  331.                         Down.collider.isTrigger = true;
  332.  
  333.                         Forward = GameObject.CreatePrimitive (PrimitiveType.Sphere);
  334.                         Forward.transform.position = new Vector3 (GameObject.Find("bgeL0").transform.position.x+1.5f, GameObject.Find("bgeL0").transform.position.y, GameObject.Find("bgeL0").transform.position.z);
  335.                         Forward.name = "ArrowsForward";
  336.                         Forward.layer = 23;
  337.                         Forward.transform.parent = Center.transform;
  338.                         Forward.collider.isTrigger = true;
  339.  
  340.                         Backward = GameObject.CreatePrimitive (PrimitiveType.Sphere);
  341.                         Backward.transform.position = new Vector3 (GameObject.Find("bgeL0").transform.position.x-1.5f, GameObject.Find("bgeL0").transform.position.y, GameObject.Find("bgeL0").transform.position.z);
  342.                         Backward.name = "ArrowsBackward";
  343.                         Backward.layer = 23;
  344.                         Backward.transform.parent = Center.transform;
  345.                         Backward.collider.isTrigger = true;
  346.  
  347.                         Left = GameObject.CreatePrimitive (PrimitiveType.Sphere);
  348.                         Left.transform.position = new Vector3 (GameObject.Find("bgeL0").transform.position.x, GameObject.Find("bgeL0").transform.position.y, GameObject.Find("bgeL0").transform.position.z+1.5f);
  349.                         Left.name = "ArrowsLeft";
  350.                         Left.layer = 23;
  351.                         Left.transform.parent = Center.transform;
  352.                         Left.collider.isTrigger = true;
  353.  
  354.                         Right = GameObject.CreatePrimitive (PrimitiveType.Sphere);
  355.                         Right.transform.position = new Vector3 (GameObject.Find("bgeL0").transform.position.x, GameObject.Find("bgeL0").transform.position.y, GameObject.Find("bgeL0").transform.position.z-1.5f);
  356.                         Right.name = "ArrowsRight";
  357.                         Right.layer = 23;
  358.                         Right.transform.parent = Center.transform;
  359.                         Right.collider.isTrigger = true;
  360.                     }
  361.                     GameObject.Find ("ArrowsCenter").transform.position = SelectedBlocks [0].transform.position;
  362.                 } else {
  363.                     Destroy (Center);
  364.                     Destroy (Up);
  365.                     Destroy (Down);
  366.                 }
  367.  
  368.                 if (Input.GetKeyDown (KeyCode.LeftControl) || Input.GetKeyDown (KeyCode.RightControl)) {
  369.                     RaycastHit hit;
  370.                     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  371.                     int layerMask = (1 << 23);
  372.  
  373.                     if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) {
  374.                         Transform objectHit = hit.transform;
  375.  
  376.                         //Debug.Log ("The raycast has hit " + hit.transform.gameObject.name + ", layer is " + hit.transform.gameObject.layer);
  377.  
  378.                         if (objectHit.name == "ArrowsUp") {
  379.                             foreach (Transform Block in SelectedBlocks) {
  380.                                 Block.position = new Vector3 (Block.position.x, Block.position.y + Step, Block.position.z);
  381.                             }
  382.                         }
  383.  
  384.                         if (objectHit.name == "ArrowsDown") {
  385.                             foreach (Transform Block in SelectedBlocks) {
  386.                                 Block.position = new Vector3 (Block.position.x, Block.position.y - Step, Block.position.z);
  387.                             }
  388.                         }
  389.  
  390.                         if (objectHit.name == "ArrowsForward") {
  391.                             foreach (Transform Block in SelectedBlocks) {
  392.                                 Block.position = new Vector3 (Block.position.x+Step, Block.position.y, Block.position.z);
  393.                             }
  394.                         }
  395.  
  396.                         if (objectHit.name == "ArrowsBackward") {
  397.                             foreach (Transform Block in SelectedBlocks) {
  398.                                 Block.position = new Vector3 (Block.position.x-Step, Block.position.y, Block.position.z);
  399.                             }
  400.                         }
  401.  
  402.                         if (objectHit.name == "ArrowsRight") {
  403.                             foreach (Transform Block in SelectedBlocks) {
  404.                                 Block.position = new Vector3 (Block.position.x, Block.position.y, Block.position.z-Step);
  405.                             }
  406.                         }
  407.  
  408.                         if (objectHit.name == "ArrowsLeft") {
  409.                             foreach (Transform Block in SelectedBlocks) {
  410.                                 Block.position = new Vector3 (Block.position.x, Block.position.y, Block.position.z+Step);
  411.                             }
  412.                         }
  413.  
  414.  
  415.                         if (objectHit.name == "ArrowsCenter") {
  416.                             foreach (Transform Block in SelectedBlocks) {
  417.                                 Block.GetComponent<Tint> ().TintIt (Color.white);
  418.                                 Destroy(Block.GetComponent<Tint> ());
  419.                             }
  420.                         }
  421.                     }
  422.                 }
  423.             }
  424.         }
  425.     }
  426. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement