Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- using System.IO;
- using System.Linq;
- using System.Text;
- public class Players : MonoBehaviour
- {
- public Camera CameraPrincipal;
- public InputField InputBot;
- public Button SetButton;
- public Button DelButton;
- public int BotID;
- public List<string> BotTokenList;
- public List<string> BotNameList;
- public List<InputField> BotTokenInputList;
- public List<InputField> BotNameInputList;
- public List<Button> SetButtonList;
- public List<Button> DelButtonList;
- public string[] Lines;
- public bool SetNotLoad;
- public bool FirstFile;
- public bool LoadNotSet;
- public Image Scroll;
- //public GameObject Areia;
- // Use this for initialization
- void Start()
- {
- BotID = 1;
- FirstFile = false;
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- Application.Quit();
- }
- if (Input.GetKeyDown(KeyCode.F12))
- {
- Screen.SetResolution(1280,720,false);
- }
- /*if (CameraPrincipal.GetComponent<TwitchChatExample>().msgString == "!up")
- {
- transform.position = new Vector3(transform.position.x,transform.position.y+1,0);
- CameraPrincipal.GetComponent<TwitchChatExample>().msgString = "";
- }
- if (CameraPrincipal.GetComponent<TwitchChatExample>().msgString == "!down")
- {
- transform.position = new Vector3(transform.position.x,transform.position.y-1,0);
- CameraPrincipal.GetComponent<TwitchChatExample>().msgString = "";
- }
- if (CameraPrincipal.GetComponent<TwitchChatExample>().msgString == "!left")
- {
- transform.position = new Vector3(transform.position.x-1,transform.position.y,0);
- CameraPrincipal.GetComponent<TwitchChatExample>().msgString = "";
- }
- if (CameraPrincipal.GetComponent<TwitchChatExample>().msgString == "!right")
- {
- transform.position = new Vector3(transform.position.x+1,transform.position.y,0);
- CameraPrincipal.GetComponent<TwitchChatExample>().msgString = "";
- }
- if (Input.GetMouseButton(0))
- {
- Instantiate(Areia, Camera.main.ScreenToWorldPoint(Input.mousePosition - transform.position),
- Quaternion.identity);
- }
- //Ray Raio = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit2D Hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
- if (Input.GetKey("w"))
- {
- transform.GetComponent<Rigidbody>().velocity = new Vector3(0,0,10); //(new Vector3(0, 0, 5));
- //transform.Translate(0, 0, 1 * Time.deltaTime);
- }
- if (Input.GetMouseButton(1))
- {
- if (Hit.transform.tag == "Areia")
- {
- Destroy(Hit.transform.gameObject);
- }
- else
- {
- print("Nada");
- }
- }*/
- }
- public void AdicionarBot()
- {
- Scroll.rectTransform.sizeDelta = new Vector2(460,Scroll.rectTransform.sizeDelta.y+30);
- InputField InputToken = Instantiate(InputBot, new Vector3(640, 360, 0), Quaternion.identity);
- InputToken.transform.SetParent(GameObject.Find("BotPanel").transform);
- InputToken.transform.name = "BotToken "+BotID;
- InputToken.GetComponentInChildren<Text>().text = "Bot code.";
- //BotTokenList.Add("");
- BotTokenInputList.Add(InputToken);
- InputField InputName = Instantiate(InputBot, new Vector3(640, 360, 0), Quaternion.identity);
- InputName.transform.SetParent(GameObject.Find("BotPanel").transform);
- InputName.transform.name = "BotName "+BotID;
- InputName.GetComponentInChildren<Text>().text = "Bot name.";
- //BotNameList.Add("");
- BotNameInputList.Add(InputName);
- Button SetB = Instantiate(SetButton,new Vector3(0,0,0),Quaternion.identity);
- SetB.gameObject.SetActive(true);
- SetB.transform.SetParent(GameObject.Find("ButtonPanel").transform);
- SetB.transform.name = "SetButton " + BotID;
- SetButtonList.Add(SetB);
- Button DelB = Instantiate(DelButton,new Vector3(0,0,0),Quaternion.identity);
- DelB.gameObject.SetActive(true);
- DelB.transform.SetParent(GameObject.Find("ButtonPanel").transform);
- DelB.transform.name = "DelButton " + BotID;
- DelButtonList.Add(DelB);
- BotID++;
- }
- public void SetBotInfo()
- {
- SetNotLoad = true;
- print(BotID); //Here i choose to create 3 bots, and the ID = 1,2,3 and (4) but it's not a problem.
- LoadConfig(); // Here it loads the txt file which has the configurations.
- print(BotID);
- // But after the LoadConfig() finish, the ID is = 7, but there is no BotID++ or BotID += 1 in the LoadConfig(),
- // and I get a error for having more than it should.
- if (SetNotLoad == true)
- {
- if (Lines.Length == 0)
- {
- if (BotTokenList.Count == 0)
- {
- int i2 = 1;
- while (i2 != BotID)
- {
- BotTokenList.Add("");
- i2++;
- }
- }
- if (BotNameList.Count == 0)
- {
- int i2 = 1;
- while (i2 != BotID)
- {
- BotNameList.Add("");
- i2++;
- }
- }
- }
- if (LoadNotSet == true)
- {
- while (BotTokenList.Count != BotID - 1)
- {
- BotTokenList.Add("");
- print("Erro");
- }
- while (BotNameList.Count != BotID - 1)
- {
- BotNameList.Add("");
- }
- }
- string[] BT = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name.Split(new string[] {" "}, StringSplitOptions.None);
- print(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);
- GameObject CurrentBotCode = GameObject.Find("BotToken " + BT[1]);
- GameObject CurrentBotName = GameObject.Find("BotName " + BT[1]);
- InputField CodeText = CurrentBotCode.GetComponent<InputField>();
- InputField NameText = CurrentBotName.GetComponent<InputField>();
- print(CurrentBotCode.transform.name);
- print(CurrentBotName.transform.name);
- print(CodeText.text);
- //BotTokenList[int.Parse(BT[1])] = CodeText.text;
- //BotNameList[int.Parse(BT[1])] = NameText.text;
- StreamWriter BotFile = new StreamWriter("BotFile.txt");
- if (Lines.Length != 0)
- {
- FirstFile = false;
- LoadNotSet = true;
- }
- int i = 1;
- while (i != BotID)
- {
- if (Lines.Length != 0)
- {
- if (i == int.Parse(BT[1]))
- {
- BotFile.WriteLine(i + " " + CodeText.text + " " + NameText.text);
- BotTokenList[int.Parse(BT[1]) - 1] = CodeText.text;
- print(BotTokenList[int.Parse(BT[1]) - 1]);
- BotNameList[int.Parse(BT[1]) - 1] = NameText.text;
- print("Aqui");
- }
- else
- {
- if (i != int.Parse(BT[1]))
- {
- print(i);
- if (BotTokenList[i - 1] != "")
- {
- BotFile.WriteLine(i + " " + BotTokenList[i - 1] + " " + BotNameList[i - 1]);
- }
- else
- {
- BotFile.WriteLine(i);
- }
- }
- }
- }
- else
- {
- if (FirstFile == false)
- {
- BotFile.WriteLine(i);
- }
- if (i == BotID - 1)
- {
- FirstFile = true;
- }
- }
- i++;
- }
- SetNotLoad = false;
- BotFile.Close();
- if (FirstFile == true)
- {
- FirstFile = false;
- LoadNotSet = true;
- SetBotInfo();
- }
- }
- }
- public void LoadConfig()
- {
- Lines = File.ReadAllLines("BotFile.txt");
- if (SetNotLoad == false)
- {
- LoadNotSet = true;
- }
- if (Lines.Length != 0)
- {
- if (BotTokenList.Count == 0)
- {
- int i2 = 0;
- while (i2 != Lines.Length)
- {
- BotTokenList.Add("");
- AdicionarBot();
- i2++;
- }
- }
- if (BotNameList.Count == 0)
- {
- int i2 = 0;
- while (i2 != Lines.Length)
- {
- BotNameList.Add("");
- i2++;
- }
- }
- //BotTokenList = new List<string>(Lines.Length);
- //BotNameList = new List<string>(Lines.Length);
- if (SetNotLoad == false)
- {
- int i = 0;
- while (i != Lines.Length)
- {
- //Calcular o numero da linha para a lista.
- if (Lines[i] != (i + 1).ToString())
- {
- //Adicionar Input fields carregados com a informação abaixo e usar a bool (SetNotLoad) para usar no Set.
- print(Lines[i]);
- BotTokenList[i] = Lines[i].Split(' ')[1];
- BotTokenInputList[i].text = BotTokenList[i];
- BotNameList[i] = Lines[i].Split(' ')[2];
- BotNameInputList[i].text = BotNameList[i];
- }
- print(Lines[i]);
- i++;
- }
- }
- }
- }
- public void ResetInputs()
- {
- if (BotTokenInputList.Count != 0 && BotNameInputList.Count != 0)
- {
- int i = 0;
- while (i != BotTokenInputList.Count)
- {
- BotTokenInputList[i].text = "";
- BotNameInputList[i].text = "";
- i++;
- }
- }
- }
- public void RemoverInput()
- {
- string[] BT = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name.Split(new string[] {" "}, StringSplitOptions.None);
- Lines = File.ReadAllLines("BotFile.txt");
- if (BotTokenInputList.Count != 0 && BotNameInputList.Count != 0)
- {
- Scroll.rectTransform.sizeDelta = new Vector2(460, Scroll.rectTransform.sizeDelta.y - 30);
- Destroy(BotTokenInputList[int.Parse(BT[1]) - 1].gameObject);
- Destroy(BotNameInputList[int.Parse(BT[1]) - 1].gameObject);
- Destroy(SetButtonList[int.Parse(BT[1]) - 1].gameObject);
- Destroy(DelButtonList[int.Parse(BT[1]) - 1].gameObject);
- BotTokenInputList.RemoveAt(int.Parse(BT[1]) - 1);
- BotNameInputList.RemoveAt(int.Parse(BT[1]) - 1);
- if (BotTokenList.Count != 0 && BotNameList.Count != 0)
- {
- BotTokenList.RemoveAt(int.Parse(BT[1]) - 1);
- BotNameList.RemoveAt(int.Parse(BT[1]) - 1);
- }
- SetButtonList.RemoveAt(int.Parse(BT[1]) - 1);
- DelButtonList.RemoveAt(int.Parse(BT[1]) - 1);
- BotID--;
- int i = 0;
- while (i != BotTokenInputList.Count)
- {
- BotTokenInputList[i].transform.name = "BotToken " + (i + 1);
- BotNameInputList[i].transform.name = "BotName " + (i + 1);
- SetButtonList[i].transform.name = "SetButton " + (i + 1);
- DelButtonList[i].transform.name = "DelButton " + (i + 1);
- i++;
- }
- if (LoadNotSet == true)
- {
- StreamWriter BotFile = new StreamWriter("BotFile.txt");
- if (Lines.Length != 0)
- {
- i = 1;
- while (i != Lines.Length)
- {
- if (i < int.Parse(BT[1]) - 1)
- {
- BotFile.WriteLine(i + " " + BotTokenList[i - 1] + " " + BotNameList[i - 1]);
- }
- else
- {
- if (i >= int.Parse(BT[1]) - 1)
- {
- BotFile.WriteLine(i + " " + BotTokenList[i - 1] + " " + BotNameList[i - 1]);
- }
- }
- i++;
- }
- }
- BotFile.Close();
- }
- }
- }
- public void ApagarData()
- {
- StreamWriter BotFile = new StreamWriter("BotFile.txt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement