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[] originalColors;
- public Color currentColor;
- public void BackToOriginal() {
- if(originalColors==null) {
- TintIt(Color.white);
- return;
- }
- int ccc = 0;
- 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")) {
- if(ccc<originalColors.Length) {
- material.color = originalColors[ccc];
- currentColor = originalColors[ccc];
- ccc++;
- }
- else {
- material.color = Color.white;
- currentColor = Color.white;
- }
- }
- }
- }
- }
- public void TintIt(Color color) {
- List<Color> colors = new List<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")) {
- colors.Add(material.color);
- material.color = color;
- currentColor = color;
- }
- }
- }
- if(originalColors==null&&colors.Count!=0)
- originalColors = colors.ToArray();
- }
- }
- [spaar.Mod("BesiegeSelectionMoverMod",author="TesseractCat",version="1.3")]
- public class BesiegeSelectionMoverMod : MonoBehaviour {
- Vector3 hugeSelectPos1 = Vector3.zero;
- Vector3 hugeSelectPos2 = Vector3.zero;
- public void Start() {
- spaar.Commands.RegisterHelpMessage("BesiegeSelctionHoverMod commands:\n POS1 check/[x] /[y] /[z]\n POS2 check/[x] /[y] /[z]\n SELECT /{blocktypelist}");
- spaar.Commands.RegisterCommand("POS1",(args,namedArgs) => {
- if(args.Length<1) {
- hugeSelectPos1 = Camera.main.transform.position;
- return "Set position to "+hugeSelectPos1.ToString();
- }
- if(args[0].ToLower()=="here") {
- hugeSelectPos1 = Camera.main.transform.position;
- return "Set position to "+hugeSelectPos1.ToString();
- }
- else if(args[0].ToLower()=="check") {
- return "POS1: "+hugeSelectPos1.ToString();
- }
- else if(args.Length<3) {
- return "Missing arguments";
- }
- float a,b,c;
- try {
- a = float.Parse(args[0]);
- }
- catch {
- return "Failed to parse argument 1";
- }
- try {
- b = float.Parse(args[1]);
- }
- catch {
- return "Failed to parse argument 2";
- }
- try {
- c = float.Parse(args[2]);
- }
- catch {
- return "Failed to parse argument 3";
- }
- hugeSelectPos1 = new Vector3(a,b,c);
- return "Set position to "+hugeSelectPos1.ToString();
- },"Sets the hugeselection pos1 to the camera position or inputted coordinates");
- spaar.Commands.RegisterCommand("POS2",(args,namedArgs) => {
- if(args.Length<1) {
- hugeSelectPos1 = Camera.main.transform.position;
- return "Set position to "+hugeSelectPos1.ToString();
- }
- if(args[0].ToLower()=="here") {
- hugeSelectPos2 = Camera.main.transform.position;
- return "Set position to "+hugeSelectPos2.ToString();
- }
- else if(args[0].ToLower()=="check") {
- return "POS2: "+hugeSelectPos2.ToString();
- }
- else if(args.Length<3) {
- return "Missing arguments";
- }
- float a,b,c;
- try {
- a = float.Parse(args[0]);
- }
- catch {
- return "Failed to parse argument 1";
- }
- try {
- b = float.Parse(args[1]);
- }
- catch {
- return "Failed to parse argument 2";
- }
- try {
- c = float.Parse(args[2]);
- }
- catch {
- return "Failed to parse argument 3";
- }
- hugeSelectPos2 = new Vector3(a,b,c);
- return "Set position to "+hugeSelectPos2.ToString();
- },"Sets the hugeselection pos2 to the camera position or inputted coordinates");
- spaar.Commands.RegisterCommand("SELECT",(args,namedArgs) => {
- if(!namedArgs.ContainsKey("keep")) {
- namedArgs["keep"] = "false";
- }
- if(!namedArgs.ContainsKey("deselect")) {
- namedArgs["deselect"] = "false";
- }
- MyBlockInfo[] myBlockInfos = FindObjectsOfType<MyBlockInfo>();
- if(namedArgs["deselect"].ToLower() == "false") {
- for(int i = 0;i<myBlockInfos.Length;i++) {
- if(myBlockInfos[i].GetComponent<Tint>()==null) {
- bool valid = true;
- if(namedArgs["keep"]=="false") {
- foreach(string blockname in args) {
- if(myBlockInfos[i].blockName==blockname) {
- valid = false;
- break;
- }
- }
- }
- else {
- valid = false;
- foreach(string blockname in args) {
- if(myBlockInfos[i].blockName==blockname) {
- valid = true;
- break;
- }
- }
- }
- if(!valid)
- continue;
- if(hugeSelectPos1.x<=hugeSelectPos2.x) {
- if(myBlockInfos[i].transform.position.x<hugeSelectPos1.x||myBlockInfos[i].transform.position.x>hugeSelectPos2.x) {
- continue;
- }
- }
- else {
- if(myBlockInfos[i].transform.position.x>hugeSelectPos1.x||myBlockInfos[i].transform.position.x<hugeSelectPos2.x) {
- continue;
- }
- }
- if(hugeSelectPos1.y<=hugeSelectPos2.y) {
- if(myBlockInfos[i].transform.position.y<hugeSelectPos1.y||myBlockInfos[i].transform.position.y>hugeSelectPos2.y) {
- continue;
- }
- }
- else {
- if(myBlockInfos[i].transform.position.y>hugeSelectPos1.y||myBlockInfos[i].transform.position.y<hugeSelectPos2.y) {
- continue;
- }
- }
- if(hugeSelectPos1.z<=hugeSelectPos2.z) {
- if(myBlockInfos[i].transform.position.z<hugeSelectPos1.z||myBlockInfos[i].transform.position.z>hugeSelectPos2.z) {
- continue;
- }
- }
- else {
- if(myBlockInfos[i].transform.position.z>hugeSelectPos1.z||myBlockInfos[i].transform.position.z<hugeSelectPos2.z) {
- continue;
- }
- }
- myBlockInfos[i].gameObject.AddComponent<Tint>().TintIt(Color.green);
- }
- }
- }
- else {
- for(int i = 0;i<myBlockInfos.Length;i++) {
- if(myBlockInfos[i].GetComponent<Tint>()!=null) {
- bool valid = true;
- if(namedArgs["keep"]=="false") {
- foreach(string blockname in args) {
- if(myBlockInfos[i].blockName==blockname) {
- valid = false;
- break;
- }
- }
- }
- else {
- valid = false;
- foreach(string blockname in args) {
- if(myBlockInfos[i].blockName==blockname) {
- valid = true;
- break;
- }
- }
- }
- if(!valid)
- continue;
- if(hugeSelectPos1.x<=hugeSelectPos2.x) {
- if(myBlockInfos[i].transform.position.x<hugeSelectPos1.x||myBlockInfos[i].transform.position.x>hugeSelectPos2.x) {
- continue;
- }
- }
- else {
- if(myBlockInfos[i].transform.position.x>hugeSelectPos1.x||myBlockInfos[i].transform.position.x<hugeSelectPos2.x) {
- continue;
- }
- }
- if(hugeSelectPos1.y<=hugeSelectPos2.y) {
- if(myBlockInfos[i].transform.position.y<hugeSelectPos1.y||myBlockInfos[i].transform.position.y>hugeSelectPos2.y) {
- continue;
- }
- }
- else {
- if(myBlockInfos[i].transform.position.y>hugeSelectPos1.y||myBlockInfos[i].transform.position.y<hugeSelectPos2.y) {
- continue;
- }
- }
- if(hugeSelectPos1.z<=hugeSelectPos2.z) {
- if(myBlockInfos[i].transform.position.z<hugeSelectPos1.z||myBlockInfos[i].transform.position.z>hugeSelectPos2.z) {
- continue;
- }
- }
- else {
- if(myBlockInfos[i].transform.position.z>hugeSelectPos1.z||myBlockInfos[i].transform.position.z<hugeSelectPos2.z) {
- continue;
- }
- }
- Tint tint = myBlockInfos[i].gameObject.GetComponent<Tint>();
- tint.BackToOriginal();
- Destroy(tint);
- }
- }
- }
- return "";
- },"Selects all blocks between hugeselection pos1 and hugeselection pos2, write all blocks you want to exclude from the copy after \"SELECT\", use \"--keep true\" if you want to *only* use those blocks instead, and \"--deselect true\" if you want to deselect");
- }
- public Rect windowRect = new Rect(20,20,250,150);
- public float Step = 1f;
- public string ModifierKey = "q";
- 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.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>().BackToOriginal();
- Destroy(objectHit.GetComponent<Tint>());
- }
- }
- }
- }
- 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>().BackToOriginal();
- //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>().BackToOriginal();
- Destroy(Block.GetComponent<Tint>());
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement