using System.Collections.Generic; using Unity.UIWidgets.foundation; using UnityEngine; namespace UIWidgetsSample.RaycastableScene { public class ObjectItem { public GameObject obj; public Vector3 position; public string name; public bool active; } public class GameObjectManager : MonoBehaviour { public GameObject cube; public GameObject ball; public GameObject cylinder; public Transform center; public static Transform centerInstance; public static Dictionary objects = new Dictionary(); public static Vector3? cameraPosition; public static Camera cameraInstance; public Camera camera; // public static List closeObjects = new List(); public Vector3 NewPosition() { int count = objects.Count; int sq = (int) Mathf.Sqrt(count); int remain = count - sq * sq; int r = 0; int c = 0; if (remain <= sq) { r = sq; c = remain; } else { r = 2 * sq - remain; c = sq; } var s = RaycastableSceneConfig.scaterScale; return center.position + new Vector3(r * s, c * s, 0); } public void CreateGameObject(GameObject obj, int count, string name) { int sq = (int)Mathf.Sqrt(count); if (obj) { for (int i = 0; i RaycastableSceneConfig.delta) { camera.transform.position = dif.normalized * (RaycastableSceneConfig.cameraSpeed * Time.deltaTime) + camera.transform.position; } } } void OnDisable() { foreach (var obj in objects) { Destroy(obj.Value.obj); } } public static void FocusOnObject(string name) { var obj = objects.getOrDefault(name); if (obj != null && obj.active) { cameraPosition = new Vector3(obj.position.x, obj.position.y, cameraInstance.transform.position.z); } } 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; } } } }