示例#1
0
        public void Initialize()
        {
            // Setup onClick callbacks
            for (var i = 0; i < icons.Length; i++)
            {
                var i1 = i;
                icons[i].GetComponent <Button>().onClick.AddListener(() => { SetMode((PivotMode)i1); });
            }

            Repaint();

            // Tooltips
            UiInputHints.AddTooltip(icons[0].gameObject, "Pivot around mesh center");
            UiInputHints.AddTooltip(icons[1].gameObject, "Pivot around hand");
            UiInputHints.AddTooltip(icons[2].gameObject, "Pivot around active selection mean");

            InputManager.OnActiveToolChanged += Repaint;
        }
示例#2
0
        public void Initialize()
        {
            // Setup onClick callbacks
            for (var i = 0; i < icons.Length; i++)
            {
                var i1 = i;
                icons[i].GetComponent <Button>().onClick.AddListener(() => { SetMode((SelectionMode)i1); });
            }

            newSelectionOnDrawBtn.onClick.AddListener(ToggleNewSelectionOnDraw);
            discardSelectionOnDrawBtn.onClick.AddListener(ToggleDiscardSelectionOnDraw);

            Repaint();

            // Tooltips
            UiInputHints.AddTooltip(icons[0].gameObject, "Add to selection");
            UiInputHints.AddTooltip(icons[1].gameObject, "Remove from selection");
            UiInputHints.AddTooltip(icons[2].gameObject, "Invert selection");
            UiInputHints.AddTooltip(newSelectionOnDrawBtn.gameObject, "Add each stroke into a new selection");
            UiInputHints.AddTooltip(discardSelectionOnDrawBtn.gameObject, "Clear the selection before each stroke");
        }
示例#3
0
        public void Initialize(int selectionId, UiCollapsible uiCollapsible, LibiglBehaviour behaviour,
                               IList <UiSelection> selections)
        {
            _behaviour     = behaviour;
            _uiCollapsible = uiCollapsible;
            _selectionId   = selectionId;
            _selections    = selections;

            uiCollapsible.AddItem(gameObject);

            UpdateText();
            visibleBtn.image.color = Colors.Get(selectionId);

            // Behaviour when clicking buttons
            visibleBtn.onClick.AddListener(ToggleVisible);
            editBtn.onClick.AddListener(SetAsActive);
            clearBtn.onClick.AddListener(() => Clear());

            // Tooltips
            UiInputHints.AddTooltip(visibleBtn.gameObject, "Toggle visibility");
            UiInputHints.AddTooltip(editBtn.gameObject,
                                    () => _selectionId == _behaviour.Input.ActiveSelectionId ? "Active selection" : "Edit selection");
            UiInputHints.AddTooltip(clearBtn.gameObject, "Clear selection, delete if empty & last selection");

            // Apply current values
            ToggleVisibleSprite((behaviour.Input.VisibleSelectionMask & 1u << selectionId) > 0);

            if (_selections.Count > 0)
            {
                transform.SetSiblingIndex(_selections[_selections.Count - 1].transform.GetSiblingIndex() + 1);
            }
            _selections.Add(this);

            // Call once fully initialized
            SetAsActive();
        }
示例#4
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();
        }