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 System.IO;
- using UnityEngine;
- namespace meta
- {
- //I got some inspiration for this class from ITR, so most of the credit for this part of the code goes to ITR, thanks!
- //http://www.forum.spiderlinggames.co.uk/forum/main-forum/besiege-early-access/modding/17686-more-colors-mod-spaar-s-modloader
- public class Tint : MonoBehaviour {
- public Tint() {
- }
- public Color currentColor;
- public void TintIt(Color color) {
- MeshRenderer[] componentsInChildren = base.GetComponentsInChildren<MeshRenderer>();
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- Material[] materials = componentsInChildren[i].materials;
- for (int j = 0; j < materials.Length; j++)
- {
- Material material = materials[j];
- if (material.HasProperty("_Color"))
- {
- material.color = color;
- currentColor = color;
- }
- }
- }
- }
- }
- [spaar.Mod("BesiegeSelectionMoverMod", author = "TesseractCat", version = "0.7")]
- public class Mod : MonoBehaviour
- {
- public void Start() {
- }
- public Rect windowRect = new Rect(20, 20, 250, 200);
- public float Step = 1f;
- public string ModifierKey = "q";
- public Vector3 pos1 = new Vector3(0,0,0);
- public Vector3 pos2 = new Vector3(0,0,0);
- void OnGUI() {
- //if (GameObject.Find ("ArrowsCenter")) {
- windowRect = GUI.Window (-1, windowRect, DoMyWindow, "Selection Move Config");
- //}
- }
- void DoMyWindow(int windowID) {
- GUILayout.BeginVertical ("Box");
- GUILayout.BeginHorizontal ();
- GUILayout.Label ("Step:");
- Step = GUILayout.HorizontalSlider (Step, 0, 1);
- GUILayout.EndHorizontal ();
- string lengthText = GUILayout.TextField(Step.ToString("0.00"));
- float newLength;
- if (float.TryParse(lengthText, out newLength))
- {
- Step = newLength;
- }
- GUILayout.EndVertical ();
- GUILayout.BeginHorizontal ("Box");
- if (GUILayout.Button ("Pos1")) {
- pos1 = Camera.main.transform.position;
- }
- if (GUILayout.Button("Pos2")) {
- pos2 = Camera.main.transform.position;
- }
- if (GUILayout.Button("Select")) {
- foreach (MyBlockInfo Block in FindObjectsOfType<MyBlockInfo>() as MyBlockInfo[]) {
- if (Block.transform.position.x > pos1.x) {
- if (Block.transform.position.x < pos2.x) {
- if (Block.transform.position.z > pos1.z) {
- if (Block.transform.position.z < pos2.z) {
- if (Block.transform.position.y > pos1.y) {
- if (Block.transform.position.y < pos2.y) {
- if (Block.GetComponent<Tint> ()) {
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
- Block.GetComponent<Tint> ().TintIt (Color.green);
- }
- }
- } else if (Block.transform.position.y < pos1.y) {
- if (Block.transform.position.y > pos2.y) {
- if (Block.GetComponent<Tint> ()) {
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
- Block.GetComponent<Tint> ().TintIt (Color.green);
- }
- }
- }
- }
- } else if (Block.transform.position.z < pos1.z) {
- if (Block.transform.position.z > pos2.z) {
- if (Block.transform.position.y > pos1.y) {
- if (Block.transform.position.y < pos2.y) {
- if (Block.GetComponent<Tint> ()) {
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
- Block.GetComponent<Tint> ().TintIt (Color.green);
- }
- }
- } else if (Block.transform.position.y < pos1.y) {
- if (Block.transform.position.y > pos2.y) {
- if (Block.GetComponent<Tint> ()) {
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
- Block.GetComponent<Tint> ().TintIt (Color.green);
- }
- }
- }
- }
- }
- }
- } else if (Block.transform.position.x < pos1.x) {
- if (Block.transform.position.x > pos2.x) {
- if (Block.transform.position.z > pos1.z) {
- if (Block.transform.position.z < pos2.z) {
- if (Block.transform.position.y > pos1.y) {
- if (Block.transform.position.y < pos2.y) {
- if (Block.GetComponent<Tint> ()) {
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
- Block.GetComponent<Tint> ().TintIt (Color.green);
- }
- }
- } else if (Block.transform.position.y < pos1.y) {
- if (Block.transform.position.y > pos2.y) {
- if (Block.GetComponent<Tint> ()) {
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
- Block.GetComponent<Tint> ().TintIt (Color.green);
- }
- }
- }
- }
- } else if (Block.transform.position.z < pos1.z) {
- if (Block.transform.position.z > pos2.z) {
- if (Block.transform.position.y > pos1.y) {
- if (Block.transform.position.y < pos2.y) {
- if (Block.GetComponent<Tint> ()) {
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
- Block.GetComponent<Tint> ().TintIt (Color.green);
- }
- }
- } else if (Block.transform.position.y < pos1.y) {
- if (Block.transform.position.y > pos2.y) {
- if (Block.GetComponent<Tint> ()) {
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- Block.gameObject.AddComponent<Tint> ().TintIt (Color.green);
- Block.GetComponent<Tint> ().TintIt (Color.green);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- GUILayout.EndHorizontal ();
- GUILayout.BeginVertical ("Box");
- GUILayout.BeginHorizontal ();
- GUILayout.Label ("Select = Ctrl + ");
- ModifierKey = GUILayout.TextField (ModifierKey,1);
- GUILayout.EndHorizontal ();
- GUILayout.Label ("Click = Ctrl");
- GUILayout.EndVertical ();
- GUI.DragWindow ();
- }
- public GameObject Center;
- public GameObject Left;
- public GameObject Right;
- public GameObject Forward;
- public GameObject Backward;
- public GameObject Up;
- public GameObject Down;
- void MakeBlock(string name,Vector3 pos, Quaternion rot) {
- Debug.Log ("Test1");
- //GameObject.Find ("BUILDER").GetComponent<AddPiece> ().cu
- //AddPiece.currentBlockType = 2;
- //GameObject.Find ("BUILDER").GetComponent<AddPiece> ().AddBlock (pos, rot);
- //GameObject.Find ("BUILDER").GetComponent<AddPiece> ().AddBlockType();
- //GameObject.Find ("BUILDER").GetComponent<AddPiece> ()
- Debug.Log ("Test2");
- }
- public void Update() {
- if (AddPiece.isSimulating && GameObject.Find ("ArrowsCenter")) {
- Destroy (Center);
- Destroy (Up);
- Destroy (Down);
- /**foreach (MyBlockInfo Block in GameObject.FindObjectsOfType<MyBlockInfo>() as MyBlockInfo[]) {
- try {
- Block.GetComponent<Tint> ().TintIt (Color.white);
- Destroy(Block.GetComponent<Tint> ());
- } catch {
- }
- }**/
- } else {
- }
- if (GameObject.Find ("bgeL0")!=null&&AddPiece.isSimulating!=true) {
- if (Input.GetKey (KeyCode.LeftControl) && Input.GetKeyDown (ModifierKey) || Input.GetKey (KeyCode.RightControl) && Input.GetKeyDown (ModifierKey)) {
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit)) {
- Transform objectHit = hit.transform;
- if (objectHit.GetComponent<MyBlockInfo> ()!=null) {
- if (objectHit.GetComponent<Tint> () == null) {
- objectHit.gameObject.AddComponent<Tint> ();
- objectHit.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- objectHit.GetComponent<Tint> ().TintIt (Color.white);
- Destroy (objectHit.GetComponent<Tint> ());
- }
- }
- }
- }
- if (Input.GetKey (KeyCode.LeftControl) && Input.GetKeyDown (KeyCode.A) || Input.GetKey (KeyCode.RightControl) && Input.GetKeyDown (KeyCode.A)) {
- foreach (MyBlockInfo Block in GameObject.FindObjectsOfType<MyBlockInfo>() as MyBlockInfo[]) {
- if (Block.name != "CopyPasteInfo") {
- if (Block.GetComponent<Tint> () != null) {
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else {
- Block.gameObject.AddComponent<Tint> ();
- Block.GetComponent<Tint> ().TintIt (Color.green);
- }
- }
- }
- }
- MyBlockInfo[] Blocks = FindObjectsOfType<MyBlockInfo> () as MyBlockInfo[];
- List<Transform> SelectedBlocks = new List<Transform> ();
- foreach (MyBlockInfo Block in Blocks) {
- if (Block.GetComponent<Tint> () != null && Block.GetComponent<Tint> ().currentColor != Color.white) {
- SelectedBlocks.Add (Block.transform);
- Block.GetComponent<Tint> ().TintIt (Color.green);
- } else if (Block.GetComponent<Tint> () != null && Block.GetComponent<Tint> ().currentColor == Color.white) {
- Destroy (Block.GetComponent<Tint> ());
- }
- }
- if (Input.GetKey (KeyCode.LeftControl) && Input.GetKeyDown (KeyCode.C) || Input.GetKey (KeyCode.RightControl) && Input.GetKeyDown (KeyCode.C)) {
- //GameObject.Find("BUILDER").GetComponent<AddPiece>().AddBlockAtPosNoSave(0,new Vector3(0,1,0),new Quaternion());
- for (int i=0;i<SelectedBlocks.Count;i++) {
- Transform tempBlock = (Transform) Instantiate (SelectedBlocks[i]);
- tempBlock.position = SelectedBlocks[i].position;
- tempBlock.GetComponent<Tint> ().TintIt (Color.green);
- tempBlock.transform.parent = GameObject.Find ("BUILDER").GetComponent<AddPiece> ().machineParent;
- SelectedBlocks[i].GetComponent<Tint> ().TintIt (Color.white);
- //tempBlock.name = "bsg" + (Max+1).ToString ();
- //Max++;
- //MakeBlock (SelectedBlocks[i].GetComponent<MyBlockInfo>().blockName,new Vector3(SelectedBlocks[i].position.x,SelectedBlocks[i].position.y,SelectedBlocks[i].position.z),SelectedBlocks[i].rotation);
- //GameObject tempBlock = new GameObject ();
- //tempBlock.AddComponent<AddPiece> ();
- //global::AddPiece.AddBlockAtPosNoSave (0,
- // new Vector3(Block.position.x,Block.position.y+1,Block.position.z),
- // new Quaternion(Block.rotation.x,Block.rotation.y,Block.rotation.z,Block.rotation.w));
- }
- }
- if (SelectedBlocks.Count > 0) {
- if (GameObject.Find ("ArrowsCenter") == null) {
- Center = GameObject.CreatePrimitive (PrimitiveType.Sphere);
- Center.name = "ArrowsCenter";
- Center.transform.position = GameObject.Find("bgeL0").transform.position;
- Center.layer = 23;
- Center.collider.isTrigger = true;
- Up = GameObject.CreatePrimitive (PrimitiveType.Sphere);
- 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);
- Up.name = "ArrowsUp";
- Up.layer = 23;
- Up.transform.parent = Center.transform;
- Up.collider.isTrigger = true;
- Down = GameObject.CreatePrimitive (PrimitiveType.Sphere);
- 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);
- Down.name = "ArrowsDown";
- Down.layer = 23;
- Down.transform.parent = Center.transform;
- Down.collider.isTrigger = true;
- Forward = GameObject.CreatePrimitive (PrimitiveType.Sphere);
- 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);
- Forward.name = "ArrowsForward";
- Forward.layer = 23;
- Forward.transform.parent = Center.transform;
- Forward.collider.isTrigger = true;
- Backward = GameObject.CreatePrimitive (PrimitiveType.Sphere);
- 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);
- Backward.name = "ArrowsBackward";
- Backward.layer = 23;
- Backward.transform.parent = Center.transform;
- Backward.collider.isTrigger = true;
- Left = GameObject.CreatePrimitive (PrimitiveType.Sphere);
- 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);
- Left.name = "ArrowsLeft";
- Left.layer = 23;
- Left.transform.parent = Center.transform;
- Left.collider.isTrigger = true;
- Right = GameObject.CreatePrimitive (PrimitiveType.Sphere);
- 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);
- Right.name = "ArrowsRight";
- Right.layer = 23;
- Right.transform.parent = Center.transform;
- Right.collider.isTrigger = true;
- }
- GameObject.Find ("ArrowsCenter").transform.position = SelectedBlocks [0].transform.position;
- } else {
- Destroy (Center);
- Destroy (Up);
- Destroy (Down);
- }
- if (Input.GetKeyDown (KeyCode.LeftControl) || Input.GetKeyDown (KeyCode.RightControl)) {
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- int layerMask = (1 << 23);
- if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) {
- Transform objectHit = hit.transform;
- //Debug.Log ("The raycast has hit " + hit.transform.gameObject.name + ", layer is " + hit.transform.gameObject.layer);
- if (objectHit.name == "ArrowsUp") {
- foreach (Transform Block in SelectedBlocks) {
- Block.position = new Vector3 (Block.position.x, Block.position.y + Step, Block.position.z);
- }
- }
- if (objectHit.name == "ArrowsDown") {
- foreach (Transform Block in SelectedBlocks) {
- Block.position = new Vector3 (Block.position.x, Block.position.y - Step, Block.position.z);
- }
- }
- if (objectHit.name == "ArrowsForward") {
- foreach (Transform Block in SelectedBlocks) {
- Block.position = new Vector3 (Block.position.x+Step, Block.position.y, Block.position.z);
- }
- }
- if (objectHit.name == "ArrowsBackward") {
- foreach (Transform Block in SelectedBlocks) {
- Block.position = new Vector3 (Block.position.x-Step, Block.position.y, Block.position.z);
- }
- }
- if (objectHit.name == "ArrowsRight") {
- foreach (Transform Block in SelectedBlocks) {
- Block.position = new Vector3 (Block.position.x, Block.position.y, Block.position.z-Step);
- }
- }
- if (objectHit.name == "ArrowsLeft") {
- foreach (Transform Block in SelectedBlocks) {
- Block.position = new Vector3 (Block.position.x, Block.position.y, Block.position.z+Step);
- }
- }
- if (objectHit.name == "ArrowsCenter") {
- foreach (Transform Block in SelectedBlocks) {
- Block.GetComponent<Tint> ().TintIt (Color.white);
- Destroy(Block.GetComponent<Tint> ());
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement