137 lines
4.0 KiB
C#
137 lines
4.0 KiB
C#
using RTG;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
using WI.UI;
|
|
|
|
namespace XED.UI
|
|
{
|
|
public class Panel_ObjectTool : PanelBase
|
|
{
|
|
private HashSet<TwinObject> targets = new();
|
|
public event Action onClickMove;
|
|
public event Action onClickScale;
|
|
public event Action onClickRotate;
|
|
public event Action<TwinObject> onClickRemove;
|
|
public event Action<IEnumerable<TwinObject>> onClickTexture;
|
|
|
|
private Button button_texture;
|
|
|
|
public Vector3 plusPos;
|
|
public float plus;
|
|
public override void AfterAwake()
|
|
{
|
|
Button button_move = Find<Button>(nameof(button_move));
|
|
button_move.onClick.AddListener(ActiveMoveGizmo);
|
|
|
|
Button button_rotate = Find<Button>(nameof(button_rotate));
|
|
button_rotate.onClick.AddListener(ActiveRotateGizmo);
|
|
|
|
Button button_scale = Find<Button>(nameof(button_scale));
|
|
button_scale.onClick.AddListener(ActiveScaleGizmo);
|
|
|
|
Button button_remove = Find<Button>(nameof(button_remove));
|
|
button_remove.onClick.AddListener(RemoveObject);
|
|
|
|
button_texture = Find<Button>(nameof(button_texture));
|
|
button_texture.onClick.AddListener(TexturePopupOpen);
|
|
}
|
|
internal void Attach(TwinObject to)
|
|
{
|
|
targets.Add(to);
|
|
TextureButtonControl();
|
|
FindSingle<ObjectDistanceLine>().SetTarget(to);
|
|
SetActive(true);
|
|
}
|
|
|
|
private void TextureButtonControl()
|
|
{
|
|
var wallCount = targets.OfType<Wall>().Count();
|
|
var wallGroupCount = targets.OfType<WallGroup>().Count();
|
|
|
|
var value = wallCount > 0 || wallGroupCount > 0 ? true : false;
|
|
button_texture.gameObject.SetActive(value);
|
|
}
|
|
|
|
public void Detach(TwinObject to)
|
|
{
|
|
targets.Remove(to);
|
|
|
|
if (targets.Count == 0)
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
|
|
void Close()
|
|
{
|
|
targets.Clear();
|
|
SetActive(false);
|
|
FindSingle<ObjectDistanceLine>().Off();
|
|
}
|
|
private void Update()
|
|
{
|
|
var size = Vector3.zero;
|
|
var center = Vector3.zero;
|
|
foreach(var t in targets)
|
|
{
|
|
size += t.physics.Size;
|
|
center += t.transform.position;
|
|
}
|
|
plusPos = new Vector3(0, 0, size.z * plus);
|
|
center /= targets.Count;
|
|
var pos2 = Camera.main.WorldToScreenPoint(center + plusPos);
|
|
YClampPosition(ref pos2, center);
|
|
transform.position = pos2 /*+ new Vector3((rectTransform.sizeDelta.x * 0.5f), 0f)*/;
|
|
}
|
|
|
|
//높이와 위치를 제한하다
|
|
//TODO::매직넘버 삭제!!!
|
|
private void YClampPosition(ref Vector3 screenPos, Vector3 center)
|
|
{
|
|
var pos = Camera.main.WorldToScreenPoint(center);
|
|
if (pos.y < Screen.height && pos.y > 0)
|
|
{
|
|
var y = Mathf.Clamp(screenPos.y, rectTransform.sizeDelta.y, Screen.height - 100);
|
|
screenPos = new Vector3(screenPos.x, y);
|
|
}
|
|
if (pos.x < Screen.width - 500 && pos.x > 0)
|
|
{
|
|
var x = Mathf.Clamp(screenPos.x, rectTransform.sizeDelta.x, Screen.width - 500);
|
|
screenPos = new Vector3(x, screenPos.y);
|
|
}
|
|
}
|
|
|
|
private void ActiveMoveGizmo()
|
|
{
|
|
onClickMove?.Invoke();
|
|
}
|
|
|
|
private void ActiveRotateGizmo()
|
|
{
|
|
onClickRotate?.Invoke();
|
|
}
|
|
|
|
void ActiveScaleGizmo()
|
|
{
|
|
onClickScale?.Invoke();
|
|
}
|
|
|
|
public void RemoveObject()
|
|
{
|
|
foreach(var target in targets)
|
|
{
|
|
onClickRemove?.Invoke(target);
|
|
}
|
|
Close();
|
|
}
|
|
|
|
private void TexturePopupOpen()
|
|
{
|
|
onClickTexture?.Invoke(targets);
|
|
}
|
|
}
|
|
} |