I wanted help with something related to C# and Unity. I am developing a simulation in Unity that involves the representation of biological systems, such as the human circulatory system. In this context, I have to deal with the modeling and organization of various graphic elements, such as arteries, veins, heart.
In our case, I have a three-dimensional model of a human body on the computer screen. Still on the same screen, on the right side, I have a menu with the names of all the model objects that I am seeing on the screen. To visualize the model, made in Blender, I use Unity and generate an executable that runs in the browser (google chrome or iexplorer).
To make the representation of this system more organized, I need to group these elements in a hierarchical and logical way. For example, I want to group the superior mesenteric artery with other arteries in the digestive system artery group. Then I want to group this group with the groups of arteries of the respiratory system, arteries of the urinary system within a larger group called arteries. So I want to group the group of arteries with the group of veins and the heart into a larger group called the cardiovascular system. The organization in the menu on the right should look like this:
- List item
Circulatory system
-Heart
-Right atrium
-Left atrium
-...
-Veins
-Digestive system veins
-D vein
-...
-Veins of the urinary system
-V vein
-...
-Veins of the respiratory system
-Z vein
-Vein...
-Arteries
-Digestive system arteries
-Superior mesenteric artery
-Inferior mesenteric artery
-...
-Urinary system arteries
-Artery X
-...
-Arteries of the respiratory system
-Artery Y
-...
In the menu on the right side there will be a button that, when clicked, will show the subgroups that exist within the groups. When viewing the subgroups, there will be another button for each subgroup which, when clicked, will display the elements (arteries, veins) that are within the subgroups.
It is to manipulate the GameObjects equally as those that are within the Groups. I can’t access objects that are within another Group within another Group. I’m using the following script:
// Método chamado a cada frame
void Update()
{
// Obtém os painéis do objeto principal
panels = principalObject.GetComponent<listadeObjetos>().listpanel.ToArray();
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Verifica se o bisturi não está ativo
if (!bisturi)
{
open = true;
cursorBisturi.SetActive(false);
// Verifica se há colisão com um objeto
if (Physics.Raycast(ray, out hit))
{
Nome = hit.collider.name;
Debug.Log(Nome);
// Verifica se o painel não está ativo e se ocorreu um clique do mouse
if (painel.activeSelf == false && Input.GetMouseButtonDown(0))
{
nomeObjeto.text = Nome;
painel.SetActive(true);
painel.transform.position = new Vector3(Input.mousePosition.x + painel.GetComponent<RectTransform>().sizeDelta.x / 2 + 5, Input.mousePosition.y, 0);
}
else if (painel.activeSelf == true && Input.GetMouseButtonDown(0))
{
painel.SetActive(false);
}
// Atualiza a posição do painel
if (painel.activeSelf == false)
{
painel.transform.position = new Vector3(Input.mousePosition.x + painel.GetComponent<RectTransform>().sizeDelta.x, Input.mousePosition.y, 0);
}
}
else if (painel.activeSelf == true && Input.GetMouseButtonDown(0))
{
painel.SetActive(false);
}
}
// Verifica se o bisturi está ativo
if (bisturi)
{
open = false;
cursorBisturi.SetActive(true);
// Lança um raio a partir do centro da tela
if (Physics.Raycast(ray, out hit) && Input.GetMouseButtonDown(0))
{
// Realiza operações relacionadas ao objeto atingido
// hit.collider.gameObject.GetComponent<ColorMaterial>().valor = 0;
for (int i = 0; i < principalObject.GetComponent<listadeObjetos>().sliderList.Length; i++)
{
if (hit.collider.gameObject.GetComponent<ReferenceName>().reference == principalObject.GetComponent<listadeObjetos>().sliderList[i].GetComponent<ReferenceName>().reference)
{
principalObject.GetComponent<listadeObjetos>().sliderList[i].GetComponent<Slider>().value = 0;
}
}
}
// Adiciona um listener para o evento de mudança de valor nos sliders
for (int i = 0; i < principalObject.GetComponent<listadeObjetos>().sliderList.Length; i++)
{
principalObject.GetComponent<listadeObjetos>().sliderList[i].GetComponent<Slider>().onValueChanged.AddListener(delegate { SliderModificado(); });
}
}
// Atualiza a posição do cursor do bisturi
cursorBisturi.transform.position = new Vector3(Input.mousePosition.x + cursorBisturi.GetComponent<RectTransform>().sizeDelta.x / 2 + 2, Input.mousePosition.y - cursorBisturi.GetComponent<RectTransform>().sizeDelta.y / 2 - 2);
}
// Método para controlar o bisturi
void buttonBisturiControler()
{
if (bisturi)
{
bisturi = false;
Cursor.visible = true;
}
else if (!bisturi && open)
{
bisturi = true;
Cursor.visible = false;
}
}
// Método chamado quando um slider é modificado
void SliderModificado()
{
// Aqui você pode adicionar a lógica relacionada à modificação do slider
}
// Método para fazer um botão aparecer ou desaparecer
void aparece(GameObject botao)
{
if (botao.GetComponent<boolO>().Active == false)
{
botao.GetComponent<boolO>().Active = true;
botao.GetComponent<buttonImage>().image.transform.Rotate(0, 0, -90);
}
else
{
botao.GetComponent<boolO>().Active =`your text` false;
botao.GetComponent<buttonImage>().image.transform.Rotate(0, 0, 90);
}
}
I tried to make this list and be able to interact with the cursor in Scalpel mode with the objects that are grouped within other groups, but I was unsuccessful.