using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using SimpleFileBrowser; public class ToolsController : MonoBehaviour { public WallCreate Cursor; public int Rounding = 1; public Button Mouse; public Button Hammer; public Button Undo; public Button Redo; public Button ButtonGrid; public Button ButtonBeacon; public Button ButtonZone; public Button ButtonBuild; public Button ButtonRoom; public Button ButtonWall; public GameObject GroundSettings; public GameObject Grid; public GameObject BuildTools; public GameObject ZonesScroll; public GameObject BeaconsScroll; Button old_btn_tools; Button old_btn_build; GameObject old_panel; bool cursor_active; bool ground_active; enum Tools { Wall, Room, Del, Cursor}; // Tools tools = Tools.Cursor; // Start is called before the first frame update void Start() { Mouse.onClick.AddListener(CursorOff); Hammer.onClick.AddListener(CursorOff); Undo.onClick.AddListener(CursorOff); Redo.onClick.AddListener(CursorOff); ButtonGrid.onClick.AddListener(GridOnOff); ButtonRoom.onClick.AddListener(RoomEdit); ButtonWall.onClick.AddListener(WallEdit); } // Update is called once per frame void Update() { if (EventSystem.current.IsPointerOverGameObject()) { if (cursor_active) Cursor.gameObject.SetActive(!cursor_active); } else if (cursor_active) Cursor.gameObject.SetActive(cursor_active); if (ground_active != GroundSettings.activeSelf) GroundSettings.SetActive(ground_active); } public void CursorOff() { cursor_active=false; Cursor.mode = WallCreate.Mode.Cursor; } public void WallEdit() { cursor_active = true; Cursor.mode = WallCreate.Mode.Wall; ground_active = false; } public void RoomEdit() { cursor_active = true; Cursor.mode = WallCreate.Mode.Room; ground_active = false; } public void BuildEdit() { SelectButton(ButtonBuild, old_btn_build); if (old_panel != null) old_panel.SetActive(false); BuildTools.SetActive(true); old_panel = BuildTools; old_btn_build = ButtonBuild; } public void GroundEdit() { if (cursor_active) { Cursor.gameObject.SetActive(false); cursor_active = false; } ground_active = true; } public void ZoneEdit() { cursor_active = true; SelectButton(ButtonZone, old_btn_build); Cursor.mode = WallCreate.Mode.Zone; if (old_panel != null) old_panel.SetActive(false); ZonesScroll.SetActive(true); old_panel = ZonesScroll; old_btn_build = ButtonZone; ground_active = false; } public void BeaconEdit() { if (cursor_active) { Cursor.gameObject.SetActive(false); cursor_active = false; } SelectButton(ButtonBeacon,old_btn_build); if (old_panel != null) old_panel.SetActive(false); BeaconsScroll.SetActive(true); old_panel = BeaconsScroll; old_btn_build = ButtonBeacon; ground_active = false; } bool grid_active = false; public void GridOnOff() { grid_active = !grid_active; Grid.SetActive(grid_active); if(grid_active) ButtonGrid.GetComponent().color = Color.gray; else ButtonGrid.GetComponent().color = Color.white; } public void Delete() { //tools = Tools.Del; } public void SelectButton(GameObject button) { GameObject old_button = null; switch (Cursor.mode) { case WallCreate.Mode.Cursor: old_button = transform.GetChild(0).gameObject; break; case WallCreate.Mode.Room: old_button = transform.GetChild(1).gameObject; break; case WallCreate.Mode.Wall: old_button = transform.GetChild(2).gameObject; break; case WallCreate.Mode.Zone: old_button = transform.GetChild(3).gameObject; break; } if (old_button != null) old_button.GetComponent().color = Color.white; button.GetComponent().color = Color.gray; } public static void SelectButton(Button button, Button old_button) { //var color = new Color(); ColorUtility.TryParseHtmlString("#C8C8C8", out var color); if (old_button != null) old_button.GetComponent().color = Color.white; button.GetComponent().color = color; } public void mouse() { SelectButton(Mouse, old_btn_tools); old_btn_tools = Mouse; } public void hammer() { SelectButton(Hammer, old_btn_tools); old_btn_tools = Hammer; } /// /// old /// //public void OpenFileBrowser() //{ // StartCoroutine(ShowLoadDialogCoroutine($"Выбор карты")); //} /// /// old /// /// /// //IEnumerator ShowLoadDialogCoroutine(string name_view) //{ // FileBrowser.SetFilters(true, new FileBrowser.Filter("Images", ".jpg", ".png")); // FileBrowser.SetDefaultFilter(".jpg"); // //FileBrowser.AddQuickLink("Users", "C:\\Users", null); // // Show a load file dialog and wait for a response from user // // Load file/folder: file, Initial path: default (Documents), Title: "Load File", submit button text: "Load" // yield return FileBrowser.WaitForLoadDialog(false, null, name_view, "Load"); // // Dialog is closed // // Print whether a file is chosen (FileBrowser.Success) // // and the path to the selected file (FileBrowser.Result) (null, if FileBrowser.Success is false) // Debug.Log(FileBrowser.Success + " " + FileBrowser.Result); // if (FileBrowser.Success) // { // var go = GameObject.Find("InputField_Image"); // if (go != null) // { // var ifield = go.GetComponent(); // if (ifield != null) // { // ifield.text = FileBrowser.Result; // } // } // // If a file was chosen, read its bytes via FileBrowserHelpers // // Contrary to File.ReadAllBytes, this function works on Android 10+, as well // byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(FileBrowser.Result); // var loc = CompanyController.instance.GetActiveLocation(); // if (loc != null) // { // loc.SaveTexture(bytes); // } // } //} }