123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- 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<Image>().color = Color.gray;
- else ButtonGrid.GetComponent<Image>().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<Image>().color = Color.white;
- button.GetComponent<Image>().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<Image>().color = Color.white;
- button.GetComponent<Image>().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;
- }
- /// <summary>
- /// old
- /// </summary>
- //public void OpenFileBrowser()
- //{
- // StartCoroutine(ShowLoadDialogCoroutine($"Выбор карты"));
- //}
- /// <summary>
- /// old
- /// </summary>
- /// <param name="name_view"></param>
- /// <returns></returns>
- //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<InputField>();
- // 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);
- // }
- // }
- //}
- }
|