using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Model3dController : MonoBehaviour { // Start is called before the first frame update public Model3dConfig config = null; public NavigationManager navigationManager = null; public RectTransform reference3dPanel = null; protected GameObject model3d; virtual protected void Start() { if (!config) { Debug.LogError("Model3dController -> Start() : configuration is null"); return; } if (!config.model3d) { Debug.LogError("Model3dController -> Start() : 3d model is null"); return; } model3d = Instantiate(config.model3d); ConfigureNavigationManager(model3d); ConfigureViewport(navigationManager._camera.GetComponent()); } protected void ConfigureNavigationManager(GameObject focus) { if (!navigationManager) { GameObject navigationManagerGO = Instantiate(Resources.Load("Prefabs/Model3dExplorerNavigationManager")); navigationManager = navigationManagerGO.GetComponent(); } else { if (navigationManager.gameObject.activeSelf) Debug.LogError("Model3dController -> ConfigureNavigationManager(...): the GameObject '" + navigationManager.name + "' should be disabled"); } if(navigationManager._camera == null) navigationManager._camera = Camera.main.gameObject; if(navigationManager.focus == null) navigationManager.focus = focus; navigationManager.gameObject.SetActive(true); } protected void ConfigureViewport(Camera camera) { if (!reference3dPanel) { Debug.LogError("Model3dController -> ConfigureViewport() : Reference 3d Panel is null"); return; } Rect viewportRect = exprivia.ui.Utils.CameraViewportFromPanel(reference3dPanel); Rect r = viewportRect; camera.rect = r; } virtual protected void OnDestroy() { Destroy(navigationManager.gameObject); Destroy(model3d); } }