void OnMouseUp() { BallUpdate script = gameObject.GetComponent <BallUpdate>(); MDDriver mddriverScript = GameObject.FindObjectOfType <MDDriver>(); mddriverScript.applyForces(new int[] { (int)script.number }, new float[] { 0.0f, 0.0f, 0.0f }); maxCamera.cameraStop = false; stopCamera = false; if (arrowParent != null) { GameObject.DestroyImmediate(arrowParent); arrowParent = null; } }
public void selectResidue(int resid) { if (MoleculeModel.residues.ContainsKey(resid) == false) { return; } clearSelection(); ArrayList atomIds = MoleculeModel.residues[resid]; foreach (int id in atomIds) { GameObject atom = MoleculeModel.atoms[id] as GameObject; BallUpdate comp = atom.GetComponent <BallUpdate>(); selections.Add(comp); // comp.independant = true; comp.AtomColor = Color.magenta; comp.SetRayonFactor(3.0f); } }
// Use this for initialization // Does something as a response // to the user clicking on the object void OnMouseDrag() { if (arrowParent == null) { arrowParent = new GameObject("Arrow"); GameObject arrow; arrow = GameObject.CreatePrimitive(PrimitiveType.Cube); arrow.transform.parent = arrowParent.transform; arrow.transform.localScale = new Vector3(0.4f, 3.5f, 0.4f); arrow.transform.Translate(arrow.transform.up * 2.0f); arrow.renderer.enabled = true; arrowParent.transform.position = transform.position; arrowParent.transform.parent = transform; } MDDriver mddriverScript = GameObject.FindObjectOfType <MDDriver>(); BallUpdate script = gameObject.GetComponent <BallUpdate>(); if (Input.GetMouseButton(0)) { maxCamera.cameraStop = true; stopCamera = true; Vector3 p = Input.mousePosition; p.z = Camera.main.WorldToScreenPoint(transform.position).z; Vector3 worldCoords = Camera.main.ScreenToWorldPoint(p); Vector3 force = worldCoords - transform.position; mddriverScript.applyForces(new int[] { (int)script.number }, new float[] { force.x, force.y, force.z }); // transform.position = Camera.main.ScreenToWorldPoint(p); float distance = Vector3.Distance(worldCoords, transform.position); float arrowZScale = distance / 8.0f; float arrowScale = distance / 12.0f; arrowParent.transform.up = force; arrowParent.transform.localScale = new Vector3(arrowScale, arrowZScale, arrowScale); } }
/* * private void CreateAtomArray(int size) { * Debug.Log("AtomArray"); * Debug.Log(size); * hyperballs = new GameObject[size]; * GameObject first = GameObject.CreatePrimitive(PrimitiveType.Cube); * first.transform.parent = AtomCubeParent.transform; * hyperballs[0] = first; * for(int i=1; i<size; i++) * hyperballs[i] = (GameObject) GameObject.Instantiate(first); * } */ //iAtom : Atom index in atomLocationalist private void CreateAtomHB(int iAtom, IList coordinates, IList atomModels) { GameObject Atom; Atom = GameObject.CreatePrimitive(PrimitiveType.Cube); float[] fLocation = coordinates[iAtom] as float[]; Vector3 location = new Vector3(fLocation[0], fLocation[1], fLocation[2]); AtomModel atomModel = atomModels[iAtom] as AtomModel; Atom.transform.Translate(location); Atom.transform.parent = AtomCubeParent.transform; MoleculeModel.atoms.Add(Atom); if (atomtype == UIData.AtomType.hyperball) { //Test platform to choose the good shader RuntimePlatform platform = Application.platform; switch (platform) { case RuntimePlatform.WindowsPlayer: case RuntimePlatform.WindowsWebPlayer: case RuntimePlatform.WindowsEditor: Atom.renderer.material.shader = Shader.Find("FvNano/Ball HyperBalls OpenGL"); break; default: Atom.renderer.material.shader = Shader.Find("FvNano/Ball HyperBalls OpenGL"); // Atom.renderer.material.shader=Shader.Find("Custom/BallImprovedZ"); break; } Atom.AddComponent("BallUpdateHB"); if (UI.GUIDisplay.file_extension == "xgmml") { Atom.GetComponent <BallUpdateHB>().z = (float)(fLocation[2]); } } else { Atom.AddComponent("BallUpdateCube"); BallUpdateCube comp1 = Atom.GetComponent <BallUpdateCube>(); comp1.SetRayonFactor(atomModel.scale / 100); } BallUpdate comp = Atom.GetComponent <BallUpdate>(); // Debug.Log ("%%%%%%%%%%%%%%%%%%%%% Creating Atom"); // Debug.Log (iAtom); comp.rayon = atomModel.radius; comp.atomcolor = atomModel.baseColor; comp.number = iAtom; // Debug.Log (comp.number); comp.oldrayonFactor = atomModel.scale / 100; // Why division by 100 ??? if (UI.GUIDisplay.file_extension == "xgmml") { comp.rayon = ((MoleculeModel.CSRadiusList[iAtom]) as float[])[0]; comp.atomcolor = HexToColor((MoleculeModel.CSColorList[iAtom] as string[])[0]); } Atom.renderer.material.SetColor("_Color", comp.atomcolor); // Projector proj = Atom.AddComponent<Projector>(); Atom.AddComponent <Projector>(); comp.enabled = true; comp.isSplineNode = UIData.secondarystruct; Atom.tag = atomModel.type; if (atomtype == UIData.AtomType.particleball) { Atom.renderer.enabled = false; } BoxCollider collider = Atom.collider as BoxCollider; float newSize = comp.rayon * 60 / 100; collider.size = new Vector3(newSize, newSize, newSize); }