182 lines
4.8 KiB
C#
182 lines
4.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
public enum Axis
|
|
{
|
|
posX,
|
|
posY,
|
|
posZ,
|
|
rotX,
|
|
rotY,
|
|
rotZ,
|
|
scale,
|
|
other
|
|
}
|
|
/// <summary>
|
|
/// 放置面板
|
|
/// </summary>
|
|
public class PlaceThePanels : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
|
|
{
|
|
public bool isAdd;
|
|
|
|
private bool flayAdd = false;
|
|
private bool flaySub = false;
|
|
|
|
private float timer = -1;
|
|
private float interval = 0.5f;
|
|
|
|
public Axis axis;
|
|
public Transform target;
|
|
private float speed = 0.01f;
|
|
public static int offset = 1;
|
|
public TextMeshProUGUI offsetText;
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (timer >= 0)
|
|
{
|
|
timer += Time.deltaTime;
|
|
}
|
|
if (timer >= interval)
|
|
{
|
|
if (flayAdd)
|
|
{
|
|
Add();
|
|
}
|
|
else if (flaySub)
|
|
{
|
|
Sub();
|
|
}
|
|
}
|
|
|
|
}
|
|
public void PointClick()
|
|
{
|
|
if (isAdd)
|
|
{
|
|
Add();
|
|
}
|
|
else
|
|
{
|
|
Sub();
|
|
}
|
|
}
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
timer = 0;
|
|
if (isAdd)
|
|
{
|
|
flayAdd = true;
|
|
}
|
|
else
|
|
{
|
|
flaySub = true;
|
|
}
|
|
}
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
if (timer < interval)
|
|
{
|
|
PointClick();
|
|
}
|
|
|
|
if (isAdd)
|
|
{
|
|
flayAdd = false;
|
|
}
|
|
else
|
|
{
|
|
flaySub = false;
|
|
}
|
|
|
|
timer = -1;
|
|
}
|
|
public void Add()
|
|
{
|
|
switch (axis)
|
|
{
|
|
case Axis.posX:
|
|
target.localPosition += new Vector3(speed * offset, 0, 0);
|
|
break;
|
|
case Axis.posY:
|
|
target.localPosition += new Vector3(0, speed * offset, 0);
|
|
break;
|
|
case Axis.posZ:
|
|
target.localPosition += new Vector3(0, 0, speed * offset);
|
|
break;
|
|
case Axis.rotX:
|
|
target.Rotate(speed * offset, 0, 0);
|
|
//target.localEulerAngles += new Vector3(speed * offset, 0, 0);
|
|
break;
|
|
case Axis.rotY:
|
|
target.Rotate(0, speed * offset, 0);
|
|
//target.localEulerAngles += new Vector3(0, speed * offset, 0);
|
|
break;
|
|
case Axis.rotZ:
|
|
target.Rotate(0, 0, speed * offset);
|
|
//target.localEulerAngles += new Vector3(0, 0, speed * offset);
|
|
break;
|
|
case Axis.scale:
|
|
target.localScale = new Vector3(Mathf.Clamp(target.localScale.x, speed, 0.49f), Mathf.Clamp(target.localScale.y, speed, 0.49f), Mathf.Clamp(target.localScale.z, speed, 0.49f));
|
|
target.localScale += new Vector3(speed, speed, speed);
|
|
break;
|
|
case Axis.other:
|
|
offset += 1;
|
|
offset = Mathf.Clamp(offset, 1, 1000);
|
|
if (offsetText)
|
|
{
|
|
offsetText.text = offset.ToString();
|
|
}
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
public void Sub()
|
|
{
|
|
switch (axis)
|
|
{
|
|
case Axis.posX:
|
|
target.localPosition -= new Vector3(speed * offset, 0, 0);
|
|
break;
|
|
case Axis.posY:
|
|
target.localPosition -= new Vector3(0, speed * offset, 0);
|
|
break;
|
|
case Axis.posZ:
|
|
target.localPosition -= new Vector3(0, 0, speed * offset);
|
|
break;
|
|
case Axis.rotX:
|
|
target.Rotate(-speed * offset, 0, 0);
|
|
//target.localEulerAngles -= new Vector3(speed * offset, 0, 0);
|
|
break;
|
|
case Axis.rotY:
|
|
target.Rotate(0, -speed * offset, 0);
|
|
//target.localEulerAngles -= new Vector3(0, speed * offset, 0);
|
|
break;
|
|
case Axis.rotZ:
|
|
target.Rotate(0, 0, -speed * offset);
|
|
//target.localEulerAngles -= new Vector3(0, 0, speed * offset);
|
|
break;
|
|
case Axis.scale:
|
|
target.localScale = new Vector3(Mathf.Clamp(target.localScale.x, speed, 0.5f), Mathf.Clamp(target.localScale.y, speed, 0.5f), Mathf.Clamp(target.localScale.z, speed, 0.5f));
|
|
target.localScale -= new Vector3(speed, speed, speed);
|
|
break;
|
|
case Axis.other:
|
|
offset -= 1;
|
|
offset = Mathf.Clamp(offset, 1, 1000);
|
|
if (offsetText)
|
|
{
|
|
offsetText.text = offset.ToString();
|
|
}
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|