void pin_rotate_ready() { //GameObject[] twoparticle = new GameObject[2]; // Debug.Log("wang"); ObiPinConstraints pins = this.GetComponent <ObiPinConstraints>(); pins.RemoveFromSolver(null); ObiPinConstraintBatch batch = pins.GetFirstBatch() as ObiPinConstraintBatch; //attach more particle to pin kdtreesearch(); for (int j = 0; j < 4; j++) { particleindexsphere[0][j] = particleindexsphere[0][4] - j - 1; particleindexsphere[1][j] = particleindexsphere[1][4] - j - 1; } for (int j = 5; j < 9; j++) { particleindexsphere[0][j] = particleindexsphere[0][4] + j - 4; particleindexsphere[1][j] = particleindexsphere[1][4] + j - 4; } for (int i = 0; i < 2; i++) { for (int j = 0; j < 9; j++) { batch.AddConstraint(particleindexsphere[i][j], twoobject[i].GetComponent <ObiCollider>(), Vector3.zero, 1.0f); } twoobject[i].GetComponent <ObiCollider>().Phase = 1; twoobject[i].AddComponent <ObjectDragger>(); //Debug.Log(twoobject[i].transform.position); } pins.AddToSolver(null); }
public override void OnInspectorGUI() { serializedObject.UpdateIfRequiredOrScript(); Editor.DrawPropertiesExcluding(serializedObject, "m_Script"); // Get the particle actor editor to retrieve selected particles: ObiParticleActorEditor[] editors = (ObiParticleActorEditor[])Resources.FindObjectsOfTypeAll(typeof(ObiParticleActorEditor)); // If there's any particle actor editor active, we can show pin constraints: if (editors.Length > 0) { List <int> selectedPins = new List <int>(); List <int> removedPins = new List <int>(); if (constraints.GetFirstBatch() != null) { ObiPinConstraintBatch batch = constraints.GetFirstBatch(); // Get the list of pin constraints from the selected particles: for (int i = 0; i < batch.ConstraintCount; i++) { int particleIndex = batch.pinIndices[i]; if (particleIndex >= 0 && particleIndex < ObiParticleActorEditor.selectionStatus.Length && ObiParticleActorEditor.selectionStatus[particleIndex]) { selectedPins.Add(i); } } if (selectedPins.Count > 0) { //Iterate over all constraints: foreach (int i in selectedPins) { GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); bool allowSceneObjects = !EditorUtility.IsPersistent(target); batch.pinBodies[i] = EditorGUILayout.ObjectField("Pinned to:", batch.pinBodies[i], typeof(ObiColliderBase), allowSceneObjects) as ObiColliderBase; // Calculate initial pin offset value after changing the rigidbody. if (EditorGUI.EndChangeCheck() && batch.pinBodies[i] != null) { batch.pinOffsets[i] = batch.pinBodies[i].transform.InverseTransformPoint(constraints.Actor.GetParticlePosition(batch.pinIndices[i])); batch.restDarbouxVectors[i] = ObiUtils.RestDarboux(constraints.Actor.GetParticleOrientation(batch.pinIndices[i]), batch.pinBodies[i].transform.rotation); } Color oldColor = GUI.color; GUI.color = Color.red; if (GUILayout.Button("X", GUILayout.Width(30))) { // Mark this constraint to be removed outside of the loop. removedPins.Add(i); continue; } GUI.color = oldColor; GUILayout.EndHorizontal(); batch.pinOffsets[i] = EditorGUILayout.Vector3Field("Offset:", batch.pinOffsets[i]); batch.pinBreakResistance[i] = EditorGUILayout.DelayedFloatField("Break Resistance:", batch.pinBreakResistance[i]); GUILayout.EndVertical(); } } else { EditorGUILayout.HelpBox("No pin constraints for the selected particles.", MessageType.Info); } if (GUILayout.Button("Remove selected")) { for (int i = 0; i < batch.ConstraintCount; i++) { int particleIndex = batch.pinIndices[i]; if (particleIndex >= 0 && particleIndex < ObiParticleActorEditor.selectionStatus.Length && ObiParticleActorEditor.selectionStatus[particleIndex]) { removedPins.Add(i); } } } if (GUILayout.Button("Add Pin Constraint")) { Undo.RecordObject(constraints, "Add pin constraints"); bool wasInSolver = constraints.InSolver; constraints.RemoveFromSolver(null); for (int i = 0; i < ObiParticleActorEditor.selectionStatus.Length; i++) { if (ObiParticleActorEditor.selectionStatus[i]) { batch.AddConstraint(i, null, Vector3.zero, Quaternion.identity, 0); } } if (wasInSolver) { constraints.AddToSolver(null); } } // Remove selected constraint outside of constraint listing loop: if (removedPins.Count > 0) { Undo.RecordObject(constraints, "Remove pin constraints"); bool wasInSolver = constraints.InSolver; constraints.RemoveFromSolver(null); // Remove from last to first, to avoid throwing off subsequent indices: foreach (int i in removedPins.OrderByDescending(i => i)) { batch.RemoveConstraint(i); } if (wasInSolver) { constraints.AddToSolver(null); } } } } // Apply changes to the serializedProperty if (GUI.changed) { serializedObject.ApplyModifiedProperties(); constraints.PushDataToSolver(); } }