145 lines
3.8 KiB
C#
145 lines
3.8 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Numerics;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using UnityEngine.UIElements;
|
||
|
||
public class Rtool : MonoBehaviour
|
||
{
|
||
public GameObject Settings;
|
||
private GameObject It;
|
||
|
||
public GameObject O2;
|
||
public UnityEngine.Vector3 pos;
|
||
public UnityEngine.Vector4 rot;
|
||
public UnityEngine.Vector3 scale;
|
||
public List<float> values;
|
||
public int BlockID;
|
||
public UnityEngine.Vector3 pos1;
|
||
public UnityEngine.UI.Toggle[] xy;
|
||
public UnityEngine.UI.Slider[] rgb;
|
||
//а можно ставить слеши в конце?
|
||
// нельзя
|
||
private void Start()
|
||
{
|
||
It = this.gameObject;
|
||
values = new List<float>{0,0,0,0};
|
||
switch(BlockID)
|
||
{
|
||
case 0:
|
||
values = new List<float>{4,8,0,0};
|
||
break;
|
||
|
||
case 1:
|
||
values = new List<float> {255,255,255,0};
|
||
var img = It.GetComponent<UnityEngine.UI.Image>();
|
||
img.color = new Color((float)values[0] / 255, (float)values[1] / 255, (float)values[2] / 255);
|
||
break;
|
||
|
||
case 5:
|
||
values = new List<float>{2,0,0,0};
|
||
break;
|
||
|
||
case 7:
|
||
values = new List<float>{3,3,0,0};
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void UpdateData()
|
||
{
|
||
pos = transform.position - transform.parent.transform.position;
|
||
rot = new UnityEngine.Vector4(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w);
|
||
scale = transform.localScale;
|
||
if(O2 != null)
|
||
pos1 = O2.transform.position - transform.parent.transform.position;
|
||
}
|
||
public void Dest()
|
||
{
|
||
Destroy(It);
|
||
}
|
||
public void OpenBlockSettings()
|
||
{
|
||
Settings.SetActive(true);
|
||
}
|
||
public void CloseBlockSettings()
|
||
{
|
||
Settings.SetActive(false);
|
||
}
|
||
public void Rotate(int gr)
|
||
{
|
||
It.transform.Rotate(new UnityEngine.Vector3(0, 0, gr));
|
||
Settings.transform.Rotate(new UnityEngine.Vector3(0, 0, -gr));
|
||
UpdateData();
|
||
}
|
||
|
||
public void SetColor(int num)
|
||
{
|
||
values[num] = (int)rgb[num].value;
|
||
|
||
var img = It.GetComponent<UnityEngine.UI.Image>();
|
||
|
||
if (img == null) print("null");
|
||
img.color = new Color((float)values[0] / 255, (float)values[1] / 255, (float)values[2] / 255);
|
||
}
|
||
|
||
public void SetValue0(string cost)
|
||
{
|
||
values[0] = float.Parse(cost);
|
||
}
|
||
public void SetValue1(string cost)
|
||
{
|
||
values[1] = float.Parse(cost);
|
||
}
|
||
public void SetValue2(string cost)
|
||
{
|
||
values[2] = float.Parse(cost);
|
||
}
|
||
|
||
public void ReToggle()
|
||
{
|
||
//xy[num].isOn = !xy[num].isOn;
|
||
|
||
if (xy[1].isOn && xy[0].isOn)
|
||
values[3] = 3;
|
||
else if(xy[0].isOn)
|
||
values[3] = 1;
|
||
else if(xy[1].isOn)
|
||
values[3] = 2;
|
||
else values[3] = 0;
|
||
}
|
||
|
||
public void Setx(string x)
|
||
{
|
||
pos1 = new UnityEngine.Vector3(int.Parse(x), pos1.y, pos1.z);
|
||
}
|
||
public void Sety(string y)
|
||
{
|
||
pos1 = new UnityEngine.Vector3(pos1.x, int.Parse(y), pos1.z);
|
||
}
|
||
public void Setz(string z)
|
||
{
|
||
pos1 = new UnityEngine.Vector3(pos1.x, pos1.y, int.Parse(z));
|
||
}
|
||
|
||
public void clone()
|
||
{
|
||
GameObject NO = Instantiate(this.gameObject, transform.position, transform.rotation, transform.parent);
|
||
NO.transform.GetChild(1).gameObject.SetActive(false);
|
||
}
|
||
|
||
public void MoveX(float step)
|
||
{
|
||
It.transform.Translate(step, 0, 0);
|
||
UpdateData();
|
||
}
|
||
|
||
public void MoveY(float step)
|
||
{
|
||
It.transform.Translate(0,step,0);
|
||
UpdateData();
|
||
}
|
||
|
||
|
||
}
|