Ejemplo n.º 1
0
        /// <summary>
        /// Generates the UI unrelated to a mesh or to manipulate the <i>active mesh</i> <see cref="MeshManager.ActiveMesh"/>
        /// </summary>
        private void InitializeStaticUi()
        {
            // -- Tools
            _toolGroup            = Instantiate(groupPrefab, genericUiListParent).GetComponent <UiCollapsible>();
            _toolGroup.title.text = "Tools & Actions";
            _toolGroup.SetVisibility(true);

            var selectionMode = Instantiate(selectionModePrefab, genericUiListParent).GetComponent <UiSelectionMode>();

            _toolGroup.AddItem(selectionMode.gameObject);
            selectionMode.Initialize();

            CurrentPivotMode = Instantiate(pivotModePrefab, genericUiListParent).GetComponent <UiPivotMode>();
            _toolGroup.AddItem(CurrentPivotMode.gameObject);
            CurrentPivotMode.Initialize();


            // -- Meshes
            _meshGroup            = Instantiate(groupPrefab, genericUiListParent).GetComponent <UiCollapsible>();
            _meshGroup.title.text = "Load Mesh";
            _meshGroup.SetVisibility(true);

            foreach (var meshPrefab in MeshManager.get.meshPrefabs)
            {
                // Create button to load each mesh
                var iconAction = Instantiate(iconActionPrefab, genericUiListParent).GetComponent <UiIconAction>();
                _meshGroup.AddItem(iconAction.gameObject);
                var textField = iconAction.actionBtn.GetComponentInChildren <TMP_Text>();
                textField.text = meshPrefab.name;

                // Setup callbacks/events
                iconAction.actionBtn.onClick.AddListener(() => MeshManager.get.LoadMesh(meshPrefab));
                iconAction.iconBtn.onClick.AddListener(() => MeshManager.get.LoadMesh(meshPrefab, false));

                var validMesh = MeshManager.CheckPrefabValidity(meshPrefab);
                iconAction.actionBtn.interactable = validMesh;
                iconAction.iconBtn.interactable   = validMesh;
            }


            // -- Debug
            _debugGroup            = Instantiate(groupPrefab, genericUiListParent).GetComponent <UiCollapsible>();
            _debugGroup.title.text = "Debug";
            _debugGroup.SetVisibility(true);

            var toggleBounds = Instantiate(UiManager.get.buttonPrefab, genericUiListParent).GetComponent <Button>();

            _debugGroup.AddItem(toggleBounds.gameObject);
            toggleBounds.GetComponentInChildren <TMP_Text>().text = "Toggle Bounds";
            toggleBounds.onClick.AddListener(() =>
            {
                InputManager.State.BoundsVisible = !InputManager.State.BoundsVisible;
                foreach (var mesh in MeshManager.get.AllMeshes)
                {
                    mesh.RepaintBounds();
                }
            });

            var toggleUvGridAction = Instantiate(buttonPrefab, genericUiListParent).GetComponent <Button>();

            _debugGroup.AddItem(toggleUvGridAction.gameObject);
            toggleUvGridAction.GetComponentInChildren <TMP_Text>().text = "Toggle UV Grid";

            // Get references to normal materials
            _uvGridInitialMaterials = new Material[toggleUvGridRenderers.Length];
            for (var i = 0; i < toggleUvGridRenderers.Length; i++)
            {
                _uvGridInitialMaterials[i] = toggleUvGridRenderers[i].material;
            }

            toggleUvGridAction.onClick.AddListener(() =>
            {
                // Toggle uv debug material
                _isShowingUvGrid = !_isShowingUvGrid;
                for (var i = 0; i < toggleUvGridRenderers.Length; i++)
                {
                    toggleUvGridRenderers[i].material = _isShowingUvGrid ? uvGridMaterial : _uvGridInitialMaterials[i];
                }
            });
        }