void Start() { /* Set the scale based on the selection radius used */ transform.localScale = 2 * new Vector3(Atoms.SELECTION_MODE_SPHERE_RADIUS, Atoms.SELECTION_MODE_SPHERE_RADIUS, Atoms.SELECTION_MODE_SPHERE_RADIUS); /* Make the selection sphere transparent */ ISphere s = GetComponent <ISphere>(); s.SetTransparent(true); s.SetRadius(Atoms.SELECTION_MODE_SPHERE_RADIUS); s.SetColor(new Color(0.1f, 0.1f, 0.1f, 0)); /* Set color circle parameters */ colors_ = new Color[3, 3]; colors_[0, 0] = color_bottom_left; colors_[0, 1] = color_bottom; colors_[0, 2] = color_bottom_right; colors_[1, 0] = color_left; colors_[1, 2] = color_right; colors_[2, 0] = color_top_left; colors_[2, 1] = color_top; colors_[2, 2] = color_top_right; /* Set arrow parameters */ arrows_ = new GameObject[3, 3]; arrows_[0, 0] = Instantiate(prefab_arrow_bottom_left, new Vector3(0, 0, 0), Quaternion.identity); arrows_[0, 1] = Instantiate(prefab_arrow_bottom, new Vector3(0, 0, 0), Quaternion.identity); arrows_[0, 2] = Instantiate(prefab_arrow_bottom_right, new Vector3(0, 0, 0), Quaternion.identity); arrows_[1, 0] = Instantiate(prefab_arrow_left, new Vector3(0, 0, 0), Quaternion.identity); arrows_[1, 2] = Instantiate(prefab_arrow_right, new Vector3(0, 0, 0), Quaternion.identity); arrows_[2, 0] = Instantiate(prefab_arrow_top_left, new Vector3(0, 0, 0), Quaternion.identity); arrows_[2, 1] = Instantiate(prefab_arrow_top, new Vector3(0, 0, 0), Quaternion.identity); arrows_[2, 2] = Instantiate(prefab_arrow_top_right, new Vector3(0, 0, 0), Quaternion.identity); //arrows_[0, 0].transform.parent = transform; //arrows_[0, 1].transform.parent = transform; //arrows_[0, 2].transform.parent = transform; //arrows_[1, 0].transform.parent = transform; //arrows_[1, 2].transform.parent = transform; //arrows_[2, 0].transform.parent = transform; //arrows_[2, 1].transform.parent = transform; //arrows_[2, 2].transform.parent = transform; arrows_[0, 0].SetActive(false); arrows_[0, 1].SetActive(false); arrows_[0, 2].SetActive(false); arrows_[1, 0].SetActive(false); arrows_[1, 2].SetActive(false); arrows_[2, 0].SetActive(false); arrows_[2, 1].SetActive(false); arrows_[2, 2].SetActive(false); if (visualization == SelectionVisualizationMethod.ARROWS) { transform.GetChild(0).gameObject.SetActive(false); } else { transform.GetChild(0).gameObject.SetActive(true); } /* Get info box object */ info_ui_ = Camera.main.transform.Find("AtomInfoBox").GetComponent <AtomInfoBox>(); /* Get parent atoms object */ atoms_object_ = transform.parent.GetComponent <Atoms>(); }
void Update() { /* Calculate the coordiinate system transformation matrix */ CalculateInverseTransform(); /* highlight and color center sphere */ center_sphere_.SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.GREEN); center_sphere_.SetCPKColor(); /* Calculate positions and reset colors and highlighting for spheres within the radius */ plane_positions_ = new List <Vector3>(spheres_.Count); for (int i = 0; i < spheres_.Count; i++) { ISphere s = spheres_[i]; Vector4 sphere_world_position = new Vector4(s.transform.position.x, s.transform.position.y, s.transform.position.z, 1); Vector4 sphere_plane_position = ITM_ * sphere_world_position; plane_positions_.Add(sphere_plane_position); s.SetHighlighted(0); s.SetCPKColor(); } /* Calculate spheres available for selection and their directions */ FillArray(); /* Highlight the spheres that can be navigated to, set the arrow directions based on the visualization used, or set the colors */ for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int s = array_[i, j]; /* If no sphere mapped in this direction, skip */ if (s == -1) { continue; } spheres_[s].SetHighlighted(HighlightColors.HIGHLIGHT_COLOR.WHITE); if (visualization == SelectionVisualizationMethod.COLOR_CIRCLE) { spheres_[s].SetColor(colors_[j, i]); } else { /* If arrows navigation used, calculate atomic radius used based on the atoms viusalization method */ float atom_radius; if (atoms_object_.GetVisualizationMethod() == Atoms.VisualizationMethod.BALL_AND_STICK) { atom_radius = AtomicRadii.ball_and_stick_radius; } else { atom_radius = AtomicRadii.GetCovalentRadius(spheres_[s].atom_.element_); } /* and set the arrow objects in front of the atom */ arrows_[j, i].SetActive(true); arrows_[j, i].transform.position = spheres_[s].transform.position + Vector3.Normalize(Camera.main.transform.position - spheres_[s].transform.position) * 1.2f * atom_radius; /* make arrows face the camera */ arrows_[j, i].transform.rotation = Quaternion.LookRotation(arrows_[j, i].transform.position - Camera.main.transform.position, Camera.main.transform.up); } } } /* Get the index for the selected sphere based on the control input */ int sphere_index = GetDirectionInput(); if (sphere_index != -1) { ISphere s = spheres_[sphere_index]; /* If clicked as well, move the selection */ if (Input.GetMouseButtonDown(0)) { MoveSelectionToSphere(s); } else { /* Make input selected sphere white */ s.SetColor(Color.white); } } }