123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Globalization;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class Editor2DController : MonoBehaviour
- {
- public InputField Image;
- public InputField SizeX;
- public InputField SizeY;
- public GameObject plane;
- public GameObject Grid;
- public float Length = 20;
- // Start is called before the first frame update
- void Start()
- {
- CreateGrid(10);
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- public void UpdatePanel()
- {
- if (!Image.text.Equals(""))
- StartCoroutine(SendingFormController.LoadImage(Image.text, plane));
- var x = 1f;
- if (!SizeX.text.Equals(""))
- x = float.Parse(SizeX.text, CultureInfo.InvariantCulture);
- var y = 1f;
- if (!SizeY.text.Equals(""))
- y = float.Parse(SizeY.text, CultureInfo.InvariantCulture);
- plane.transform.localScale = new Vector3(x, 1, y);
- var scale = plane.transform.localScale;
- plane.transform.position = new Vector3(scale.x * 5, 0, scale.z * 5);
- }
- public void Save()
- {
- SceneManager.LoadScene("Location");
- }
- public void Back()
- {
- SceneManager.LoadScene("Location");
- }
- public void CreateGrid(int l)
- {
- float s = -0.5f;
- for (int i = 0; i < l; i++)
- {
- var posX = new Vector3(0, 0, i);
- var positionX_start = new Vector3(0, 0, i);
- var positionX_end = new Vector3(Length, 0, i);
- var LineX = NewLine(posX, positionX_start, positionX_end, "LineX_" + i);
- //LineX.transform.parent = Grid.transform;
- var posY = new Vector3(i, 0, 0);
- var positionY_start = new Vector3(i, 0, 0);
- var positionY_end = new Vector3(i, 0, Length);
- var LineY = NewLine(posY, positionY_start, positionY_end, "LineY_" + i);
- //LineY.transform.parent = Grid.transform;
- //var positionY_start = new Vector3(i, 10, 0);
- //var positionY_end = new Vector3(i, 10, 0);
- //var LineY = NewLine(pos, positionY_start, positionY_end, "LineY_" + i);
- //LineY.transform.parent = Grid.transform;
- //var positionZ_start = new Vector3(i, 0, 10);
- //var positionZ_end = new Vector3(i, 0, 10);
- //var LineZ = NewLine(pos, positionZ_start, positionZ_end, "LineZ_" + i);
- //LineZ.transform.parent = Grid.transform;
- //if (positionX.y == 0)
- //{
- // var cubeRendererX = LineX.GetComponent<Renderer>();
- // cubeRendererX.material.SetColor("_Color", Color.red);
- // LineX_zero = LineX;
- // cubeRendererX_zero = LineX_zero.GetComponent<Renderer>();
- //}
- //if (positionY.x == 0)
- //{
- // var cubeRendererY = LineY.GetComponent<Renderer>();
- // cubeRendererY.material.SetColor("_Color", Color.green);
- // LineY_zero = LineY;
- // cubeRendererY_zero = LineY_zero.GetComponent<Renderer>();
- //}
- s += 0.05f;
- }
- Grid.transform.position = new Vector3(0, 0.01f, 0);
- }
- LineRenderer NewLine(Vector3 pos, Vector3 start, Vector3 end, string name_line)
- {
- var line = Instantiate(Resources.Load("GameObjects/Line", typeof(LineRenderer))) as LineRenderer;
- line.transform.position = pos;
- line.name = name_line;
- line.SetPosition(line.positionCount++, start);
- line.SetPosition(line.positionCount++, end);
- line.startColor = Color.gray;
- line.endColor = Color.gray;
- line.material.color = Color.gray;
- line.transform.parent = Grid.transform;
- //line.name = name_line;
- //line.transform.localScale = localScale;
- //line.transform.position = position;
- return line;
- }
- }
|