您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
119 行
4.0 KiB
119 行
4.0 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Unity.UIWidgets.foundation;
|
|
using UnityEngine;
|
|
|
|
namespace UIWidgetsSample.RaycastableScene
|
|
{
|
|
public class ItemInfo
|
|
{
|
|
public string itemObjName;
|
|
public string itemDesc;
|
|
public GameObject obj;
|
|
public Vector3 position;
|
|
public bool active;
|
|
public Vector3 cameraPosition;
|
|
|
|
public ItemInfo(string name, string desc, Vector3 cameraPosition)
|
|
{
|
|
itemObjName = name;
|
|
itemDesc = desc;
|
|
this.cameraPosition = cameraPosition;
|
|
}
|
|
}
|
|
|
|
public class GameObjectManager : MonoBehaviour
|
|
{
|
|
public static ItemInfo[] itemInfos = new[]
|
|
{
|
|
new ItemInfo("Crane", "1", new Vector3(-5.69f, 2.38f, -1.36f)),
|
|
new ItemInfo("Dog", "2", new Vector3(-2.44f, 1.31f, -2.96f)),
|
|
new ItemInfo("Dragon", "3", new Vector3(-0.38f, 4.21f, -2.74f)),
|
|
new ItemInfo("Goat", "4", new Vector3(-0.1f, 1.55f, -4.42f)),
|
|
new ItemInfo("Horse", "5", new Vector3(-4.21f, 1.55f, -4.96f)),
|
|
new ItemInfo("Monkey", "6", new Vector3(2.88f, 3.66f, -7.28f)),
|
|
new ItemInfo("Ox", "7", new Vector3(1.08f, 1.23f, -1.86f)),
|
|
new ItemInfo("Pig", "8", new Vector3(-4.2f, 0.95f, -2.49f)),
|
|
new ItemInfo("Rabbit", "9", new Vector3(0.53f, 6.7f, -10.19f)),
|
|
new ItemInfo("Rat", "10", new Vector3(-8.8f, 1.19f, -1.99f)),
|
|
new ItemInfo("Rooster", "11", new Vector3(-13.71f, 6.8f, -9.48f)),
|
|
new ItemInfo("Snake", "12", new Vector3(-6.88f, 4.9f, -9.6f)),
|
|
new ItemInfo("Tiger", "13", new Vector3(-6.85f, 1.51f, -6.41f))
|
|
};
|
|
|
|
public Transform center;
|
|
public static Transform centerInstance;
|
|
|
|
public static List<PickListItem> listItems => itemInfos.Select(x => new PickListItem(x.itemObjName, true, x.itemObjName)).ToList();
|
|
|
|
public static Dictionary<string, ItemInfo> objects = new Dictionary<string, ItemInfo>();
|
|
|
|
public static Vector3? cameraPosition;
|
|
|
|
public static Camera cameraInstance;
|
|
|
|
public Camera camera;
|
|
|
|
private void OnEnable()
|
|
{
|
|
objects.Clear();
|
|
|
|
centerInstance = center;
|
|
cameraInstance = camera;
|
|
|
|
foreach (var item in itemInfos)
|
|
{
|
|
var newInfo = new ItemInfo(item.itemObjName, item.itemDesc, item.cameraPosition);
|
|
newInfo.active = true;
|
|
newInfo.obj = GameObject.Find(item.itemObjName);
|
|
newInfo.position = newInfo.obj.transform.position;
|
|
|
|
objects.Add(item.itemObjName, newInfo);
|
|
}
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (cameraPosition != null )
|
|
{
|
|
var dif = cameraPosition.Value - camera.transform.position;
|
|
if (dif.sqrMagnitude > RaycastableSceneConfig.delta)
|
|
{
|
|
camera.transform.position = dif.normalized * (RaycastableSceneConfig.cameraSpeed * Time.deltaTime)
|
|
+ camera.transform.position;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void FocusOnObject(string name)
|
|
{
|
|
var obj = objects.getOrDefault(name);
|
|
if (obj != null && obj.active)
|
|
{
|
|
cameraPosition = obj.cameraPosition;
|
|
}
|
|
}
|
|
|
|
public static void MoveCenter(string name)
|
|
{
|
|
var obj = objects.getOrDefault(name);
|
|
if (obj != null)
|
|
{
|
|
obj.obj.transform.position = obj.position;
|
|
obj.active = true;
|
|
}
|
|
}
|
|
|
|
public static void MoveFar(string name)
|
|
{
|
|
var obj = objects.getOrDefault(name);
|
|
if (obj != null)
|
|
{
|
|
obj.obj.transform.position = RaycastableSceneConfig.far;
|
|
obj.active = false;
|
|
}
|
|
}
|
|
}
|
|
}
|