Пример #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];
                }
            });
        }
Пример #2
0
        /// <summary>
        /// Main function where UI is generated.
        /// </summary>
        /// <param name="behaviour">The behaviour we are generating the UI panel for.</param>
        public void Initialize(LibiglBehaviour behaviour)
        {
            _behaviour = behaviour;
            MeshManager.OnActiveMeshChanged += RepaintActiveMesh;
            _defaultBackgroundColor          = background.color;

            // -- Existing UI in Prefab
            activeBtn.onClick.AddListener(() => { MeshManager.SetActiveMesh(_behaviour.Mesh); });
            var isActive = _behaviour.Mesh.IsActiveMesh();

            activeImage.sprite = isActive ? activeSprite : editSprite;
            UiInputHints.AddTooltip(activeBtn.gameObject,
                                    () => _behaviour.Mesh.IsActiveMesh() ? "This is the active mesh" : "Make this mesh active");

            deleteBtn.onClick.AddListener(() => { MeshManager.get.DestroyMesh(behaviour.Mesh); });

            _listParent = GetComponentInChildren <VerticalLayoutGroup>().transform;

            // -- Start UI Generation
            var meshName = Instantiate(UiManager.get.headerPrefab, _listParent).GetComponent <TMP_Text>();

            meshName.text = _behaviour.Mesh.name;

            _vertexCount = Instantiate(UiManager.get.textPrefab, _listParent).GetComponent <TMP_Text>();
            UpdateVertexCountText();


            // -- Selection
            _selectionGroup            = Instantiate(UiManager.get.groupPrefab, _listParent).GetComponent <UiCollapsible>();
            _selectionGroup.title.text = "Selections";
            _selectionGroup.SetVisibility(true);

            var addSelectionBtn = Instantiate(UiManager.get.buttonPrefab, _listParent).GetComponent <Button>();

            addSelectionBtn.GetComponentInChildren <TMP_Text>().text = "Add Selection";
            _selectionGroup.AddItem(addSelectionBtn.gameObject);
            addSelectionBtn.onClick.AddListener(() => AddSelection());

            // Setup first selection
            behaviour.OnActiveSelectionChanged += RepaintActiveSelection;
            AddSelection();

            var clearAllSelections = Instantiate(UiManager.get.buttonPrefab, _listParent).GetComponent <Button>();

            _selectionGroup.AddItem(clearAllSelections.gameObject);
            clearAllSelections.GetComponentInChildren <TMP_Text>().text = "Clear All";
            clearAllSelections.onClick.AddListener(() =>
            {
                // Clear and remove all but the first selection
                _behaviour.SetActiveSelection(0);
                _behaviour.Input.DoClearSelection = uint.MaxValue;
                for (var i = _selections.Count - 1; i > 0; i--)
                {
                    _selections[i].Clear(true);
                }
            });


            // -- Operations
            var operationsGroup = Instantiate(UiManager.get.groupPrefab, _listParent).GetComponent <UiCollapsible>();

            operationsGroup.title.text = "Operations";
            operationsGroup.SetVisibility(true);

            _harmonicToggle = Instantiate(UiManager.get.toggleActionPrefab, _listParent).GetComponent <UiToggleAction>();
            operationsGroup.AddItem(_harmonicToggle.gameObject);
            _harmonicToggle.text.text = "Harmonic";
            _harmonicToggle.button.onClick.AddListener(() => { behaviour.Input.DoHarmonic = true; });
            _harmonicToggle.toggle.isOn = behaviour.Input.DoHarmonicRepeat;
            UiInputHints.AddTooltip(_harmonicToggle.button.gameObject, "Run harmonic once");
            UiInputHints.AddTooltip(_harmonicToggle.toggle.gameObject, "Run harmonic continuously");
            _harmonicToggle.toggle.onValueChanged.AddListener(value =>
            {
                behaviour.Input.DoHarmonic       = value;
                behaviour.Input.DoHarmonicRepeat = value;
                if (value && behaviour.Input.DoArapRepeat)
                {
                    behaviour.Input.DoArap       = false;
                    behaviour.Input.DoArapRepeat = false;
                    _arapToggle.toggle.isOn      = false;
                }
            });

            var harmonicShowDisplacements = Instantiate(UiManager.get.togglePrefab, _listParent).GetComponent <Toggle>();

            operationsGroup.AddItem(harmonicShowDisplacements.gameObject);
            harmonicShowDisplacements.GetComponentInChildren <TMP_Text>().text = "Toggle deform field";
            harmonicShowDisplacements.isOn = behaviour.Input.HarmonicShowDisplacement;
            harmonicShowDisplacements.onValueChanged.AddListener((value) =>
            {
                behaviour.Input.HarmonicShowDisplacement = value;
            });

            _arapToggle = Instantiate(UiManager.get.toggleActionPrefab, _listParent).GetComponent <UiToggleAction>();
            operationsGroup.AddItem(_arapToggle.gameObject);
            _arapToggle.text.text = "ARAP";
            _arapToggle.button.onClick.AddListener(() => { behaviour.Input.DoArap = true; });
            _arapToggle.toggle.isOn = behaviour.Input.DoArapRepeat;
            UiInputHints.AddTooltip(_arapToggle.button.gameObject, "Run As-Rigid-As-Possible once");
            UiInputHints.AddTooltip(_arapToggle.toggle.gameObject, "Run As-Rigid-As-Possible continuously");
            _arapToggle.toggle.onValueChanged.AddListener(value =>
            {
                behaviour.Input.DoArap       = value;
                behaviour.Input.DoArapRepeat = value;
                if (value && behaviour.Input.DoHarmonicRepeat)
                {
                    behaviour.Input.DoHarmonic       = false;
                    behaviour.Input.DoHarmonicRepeat = false;
                    _harmonicToggle.toggle.isOn      = false;
                }
            });

            var resetMeshBtn = Instantiate(UiManager.get.buttonPrefab, _listParent).GetComponent <Button>();

            operationsGroup.AddItem(resetMeshBtn.gameObject);
            resetMeshBtn.GetComponentInChildren <TMP_Text>().text = "Reset Mesh Vertices";
            resetMeshBtn.onClick.AddListener(() => { behaviour.Input.ResetV = true; });

            var resetTransformBtn = Instantiate(UiManager.get.buttonPrefab, _listParent).GetComponent <Button>();

            operationsGroup.AddItem(resetTransformBtn.gameObject);
            resetTransformBtn.GetComponentInChildren <TMP_Text>().text = "Reset Transform";
            resetTransformBtn.onClick.AddListener(() => { behaviour.Mesh.ResetTransformToSpawn(); });


            // -- Shaders
            var shaderGroup = Instantiate(UiManager.get.groupPrefab, _listParent).GetComponent <UiCollapsible>();

            shaderGroup.title.text = "Selections";
            shaderGroup.SetVisibility(true);

            var toggleWireframe = Instantiate(UiManager.get.togglePrefab, _listParent).GetComponent <Toggle>();

            shaderGroup.AddItem(toggleWireframe.gameObject);
            toggleWireframe.GetComponentInChildren <TMP_Text>().text = "Wireframe";
            toggleWireframe.onValueChanged.AddListener(value => _behaviour.Mesh.SetWireframe(value));
            toggleWireframe.isOn = false;


            // -- Debug
            _debugGroup            = Instantiate(UiManager.get.groupPrefab, _listParent).GetComponent <UiCollapsible>();
            _debugGroup.title.text = "Show Debug";
            _debugGroup.SetVisibility(false);

            // Call when constructed as we likely just missed this
            RepaintActiveMesh();
        }