using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Vector3 = UnityEngine.Vector3;
[RequireComponent(typeof(UnityEngine.EventSystems.EventTrigger))]
public class OnChlickDrag1 : MonoBehaviour, IPointerDownHandler
{
public GameObject prefab;
private GameObject dragGO;
///
/// 货架父物体
///
public List framesList = new List();
//private List frames = new List();
///
/// 选项Btn;
///
public Button SelectBtn;
void OnEnable()
{
AddCollider(prefab.transform);
}
private void Start()
{
}
public Transform TT;
//[ContextMenu("TT")]
//public void SetUWei()
//{
// for (int i = 0; i < TT.childCount; i++)
// {
// if (TT.GetChild(i).transform.Find("U位"))
// {
// GameObject o = TT.GetChild(i).transform.Find("U位").gameObject;
// framesList.Add(o);
// }
// }
//}
public void OnPointerDown(PointerEventData eventData)
{
if (dragGO == null)
{
dragGO = Instantiate(prefab);
dragGO.GetComponent().frames = framesList;
//dragGO.GetComponent().GetUList();
dragGO.SetActive(false);
}
}
public void MouseExitBtn()
{
if (dragGO != null)
{
Vector3 mouse = Input.mousePosition;
//TODO:通过调整Z,调整拖拽物体显示大小
mouse.z = 1;
Vector3 WorldPos = Camera.main.ScreenToWorldPoint(mouse);
dragGO.transform.position = WorldPos;
dragGO.SetActive(true);
dragGO = null;
}
}
void AddCollider(Transform game)
{
BoxCollider boxCollider = game.GetComponent();
Renderer renderer = null;
if (!boxCollider)
{
try
{
////复杂设备
//if (game.childCount != 0)
// renderer = game.Find(game.name).GetComponent();
////简单设备
//else
// renderer = game.GetComponent();
try
{
renderer = game.Find(game.name).GetComponent();
}
catch (Exception)
{
renderer = game.GetComponent();
}
if (renderer != null)
{
var initrot = game.rotation;
game.rotation = UnityEngine.Quaternion.identity;
var bounds = renderer.bounds;
var a = game.gameObject.AddComponent();
a.isTrigger = false;
a.center = bounds.center - game.transform.position;
//a.center = new Vector3(
// a.center.x * AdjustColliderSize(10, 10, 10).x,
// a.center.y * AdjustColliderSize(10, 10, 10).y,
// a.center.z * AdjustColliderSize(10, 10, 10).z);
a.size = bounds.size;
//a.size = new Vector3(
// a.size.x * AdjustColliderSize(10, 10, 10).x,
// a.size.y * AdjustColliderSize(10, 10, 10).y,
// a.size.z * AdjustColliderSize(10, 10, 10).z);
//a.transform.rotation = game.rotation; //重置其旋转为默认值
game.rotation = initrot;
}
}
catch (Exception e)
{
Debug.Log(game);
}
}
}
}