private bool RemoveAdditionalPin() { if (script.muscle.additionalPin == null) { return(false); } //script.muscle.additionalPin.gameObject.hideFlags = HideFlags.None; //script.muscle.additionalPinTarget.gameObject.hideFlags = HideFlags.None; PuppetMasterInspector.DestroyImmediateSafe(script.muscle.additionalPin.gameObject); PuppetMasterInspector.DestroyImmediateSafe(script.muscle.additionalPinTarget.gameObject); var puppetMasterS = new SerializedObject(script.puppetMaster); puppetMasterS.FindProperty("muscles").GetArrayElementAtIndex(script.muscle.index).FindPropertyRelative("additionalPin").objectReferenceValue = null; puppetMasterS.FindProperty("muscles").GetArrayElementAtIndex(script.muscle.index).FindPropertyRelative("additionalPinTarget").objectReferenceValue = null; puppetMasterS.ApplyModifiedProperties(); return(true); }
public override void OnInspectorGUI() { if (script == null) { return; } serializedObject.Update(); style.wordWrap = true; style.normal.textColor = EditorGUIUtility.isProSkin ? pro : free; miniLabelStyle.wordWrap = true; miniLabelStyle.fontSize = 10; miniLabelStyle.normal.textColor = EditorStyles.miniLabel.normal.textColor; if (!Application.isPlaying) { if (GUILayout.Button("Remove This Prop Muscle")) { //int index = script.muscle.index; //Debug.Log(index); var puppetMasterS = new SerializedObject(script.puppetMaster); SerializedProperty muscles = puppetMasterS.FindProperty("muscles"); int index = 0; ConfigurableJoint joint = script.GetComponent <ConfigurableJoint>(); for (int i = 0; i < puppetMasterS.FindProperty("muscles").arraySize; i++) { muscles.GetArrayElementAtIndex(i).FindPropertyRelative("index").intValue = i; if (muscles.GetArrayElementAtIndex(i).FindPropertyRelative("joint").objectReferenceValue == joint) { index = i; } } /* * if (script.muscle.additionalPin != null) * { * script.muscle.additionalPin.gameObject.hideFlags = HideFlags.None; * script.muscle.additionalPinTarget.gameObject.hideFlags = HideFlags.None; * } * * script.muscle.target.gameObject.hideFlags = HideFlags.None; */ var target = script.muscle.target; muscles.DeleteArrayElementAtIndex(index); for (int i = 0; i < puppetMasterS.FindProperty("muscles").arraySize; i++) { muscles.GetArrayElementAtIndex(i).FindPropertyRelative("index").intValue = i; } puppetMasterS.ApplyModifiedProperties(); PuppetMasterInspector.DestroyImmediateSafe(target.gameObject); PuppetMasterInspector.DestroyImmediateSafe(script.gameObject); return; } } DrawDefaultInspector(); //GUILayout.Space(10); if (!Application.isPlaying) { if (script.muscle.additionalPin == null) { if (GUILayout.Button("Add Additional Pin")) { AddAdditionalPin(); } } else { if (GUILayout.Button("Remove Additional Pin")) { RemoveAdditionalPin(); } } EditorGUILayout.LabelField("Additional Pins help to pin this prop muscle to animation from another point. Without it, the prop muscle would be actuated by Muscle Spring only, which is likely not enough to follow fast swinging animations. Move the additional pin by 'Additional Pin Offset' towards the end of the prop (tip of the sword).", miniLabelStyle); } serializedObject.ApplyModifiedProperties(); }