/// <summary> /// Will set the active mesh as the first hovered, if we are not hovering over the active mesh. /// Hovering is detected and visualized by the bounding boxes. /// </summary> /// <returns>True if the active mesh has been set</returns> public bool SetActiveMesh() { if (InsideActiveMeshBounds || _currentLibiglMeshes.Count == 0) { return(false); } MeshManager.SetActiveMesh(_currentLibiglMeshes.First()); return(true); }
/// <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(); }