//sets the isOpen variable //isOpen = true when the door is past the half way point of movement void CheckIsOpen() { switch (widgetType) { case "Hinge": //the Hinge widget class of the object VRBasics_Hinge hinge = widgetObject.GetComponent <VRBasics_Hinge> (); //if the door is past the half way point if (hinge.percentage > 0.5f) { //it will be considered open isOpen = true; } else { //otherwise it will be considered closed isOpen = false; } break; case "Slider": //the Slider widget class of the object VRBasics_Slider slider = widgetObject.GetComponent <VRBasics_Slider> (); //if the drawer is past the half way point if (slider.percentage > 0.5f) { //it will be considered open isOpen = true; } else { //otherwise it will be considered closed isOpen = false; } break; } }
void OnSceneGUI() { //reference to the class of object used to display gizmo VRBasics_Slider slider = (VRBasics_Slider)target; //in edit mode if (!Application.isPlaying) { //at runtime these are taken care of by the physics engine //prevent the slider from moving away from the rail slider.transform.localPosition = Vector3.zero; //prevents the slider from rotating away from the rail slider.transform.localEulerAngles = Vector3.zero; //use the inspector to postion the slider along the rail slider.EditorSetPosition(); //calculate the percentage of the slider along the rail slider.CalcPercentage(); } else { //calculate the percentage of the slider along the rail slider.CalcPercentage(); //keep the position the same as the percentage at runtime slider.position = slider.percentage; } //reference to the parent rail VRBasics_Rail rail = slider.transform.parent.gameObject.GetComponent <VRBasics_Rail>(); /* * //DRAW RAIl * rail.DrawGizmo(null); * * //DRAW SLIDER * slider.DrawGizmo(null); * * //DrawDefaultInspector(); */ }
public override void OnInspectorGUI() { //always update serialized properties at start of OnInspectorGUI serializedObject.Update(); //start listening for changes in inspector values EditorGUI.BeginChangeCheck(); //display serialized properties in inspector //EditorGUILayout.PropertyField (drawCircleGizmosProp, new GUIContent ("Slider drawCircleGizmos")); //EditorGUILayout.PropertyField (drawCircleGizmos2Prop, new GUIContent ("Slider drawCircleGizmos2")); EditorGUILayout.PropertyField(minLimitPosProp, new GUIContent("Slider minLimitPos")); EditorGUILayout.PropertyField(maxLimitPosProp, new GUIContent("Slider maxLimitPos")); EditorGUILayout.PropertyField(sliderProp, new GUIContent("Slider Object")); EditorGUILayout.PropertyField(lengthProp, new GUIContent("Length")); EditorGUILayout.Slider(anchorProp, 0.0f, 1.0f, new GUIContent("Anchor")); //if there were any changes in inspector values if (EditorGUI.EndChangeCheck()) { //apply changes to serialized properties serializedObject.ApplyModifiedProperties(); VRBasics_Rail rail = (VRBasics_Rail)target; //move anchor if not in correct place float move = (rail.anchor * rail.length) - (rail.length * 0.5f); if (rail.anchorMove != move) { rail.SetAnchorMove(move); } //reference to the slider VRBasics_Slider _slider = rail._slider.GetComponent <VRBasics_Slider> (); //adjust linear limit to match the length of the rail _slider.SetLinearLimit(); } }
void Update() { //use if you want the button to be clicked just by touching it //=============================================================================== switch (buttonType) { case ButtonTypes.Slider: VRBasics_Slider slider = transform.parent.gameObject.GetComponent <VRBasics_Slider> (); if (isTouched && !pushed) { SetIsTouchable(false); GetComponent <Rigidbody> ().isKinematic = false; slider.useSpringToMin = false; slider.springToMax = 50.0f; slider.useSpringToMax = true; pushed = true; } if (pushed) { if (slider.percentage > 0.75f) { slider.springToMin = 50.0f; slider.useSpringToMin = true; slider.useSpringToMax = false; pushed = false; } } if (!pushed && !isTouchable) { if (slider.percentage < 0.25f) { SetIsTouchable(true); } } break; case ButtonTypes.Hinge: VRBasics_Hinge hinge = transform.parent.gameObject.GetComponent <VRBasics_Hinge> (); if (isTouched && !pushed) { SetIsTouchable(false); GetComponent <Rigidbody> ().isKinematic = false; hinge.springToMin = 50.0f; hinge.useSpringToMin = true; hinge.useSpringToMax = false; pushed = true; } if (hinge.percentage < 0.5f && pushed && !isOn) { isOn = true; SetIsTouchable(true); } if (isTouched && isOn) { SetIsTouchable(false); hinge.useSpringToMin = false; hinge.springToMax = 50.0f; hinge.useSpringToMax = true; pushed = false; } if (hinge.percentage > 0.5f && !pushed && isOn) { isOn = false; SetIsTouchable(true); } break; } //=============================================================================== //use if you want the button to be clicked by physically pushing it down with collision //=============================================================================== /* * if (isTouched && !pushed) { * * GetComponent<Rigidbody> ().isKinematic = false; * * pushed = true; * } */ //=============================================================================== }
public override void OnInspectorGUI() { //always update serialized properties at start of OnInspectorGUI serializedObject.Update(); //start listening for changes in inspector values EditorGUI.BeginChangeCheck(); //reference to the slider VRBasics_Slider slider = (VRBasics_Slider)target; //in edit mode if (!Application.isPlaying) { //used to position the slider at the start //at runtime it will change automatically to what the percentage of the slider is EditorGUILayout.Slider(positionProp, 0.0f, 1.0f, new GUIContent("Position")); } EditorGUILayout.PropertyField(useSpringToMaxProp, new GUIContent("Use Spring To Max")); if (slider.useSpringToMax) { showSpringToMax = EditorGUILayout.Foldout(showSpringToMax, "Spring To Max"); if (showSpringToMax) { EditorGUILayout.PropertyField(springToMaxProp, new GUIContent("Spring")); EditorGUILayout.PropertyField(damperToMaxProp, new GUIContent("Damper")); } } EditorGUILayout.PropertyField(useSpringToMidProp, new GUIContent("Use Spring To Middle")); if (slider.useSpringToMid) { showSpringToMid = EditorGUILayout.Foldout(showSpringToMid, "Spring To Middle"); if (showSpringToMid) { EditorGUILayout.PropertyField(springToMidProp, new GUIContent("Spring")); EditorGUILayout.PropertyField(damperToMidProp, new GUIContent("Damper")); } } EditorGUILayout.PropertyField(useSpringToMinProp, new GUIContent("Use Spring To Min")); if (slider.useSpringToMin) { showSpringToMin = EditorGUILayout.Foldout(showSpringToMin, "Spring To Min"); if (showSpringToMin) { EditorGUILayout.PropertyField(springToMinProp, new GUIContent("Spring")); EditorGUILayout.PropertyField(damperToMinProp, new GUIContent("Damper")); } } //if there were any changes in inspector values if (EditorGUI.EndChangeCheck()) { //apply changes to serialized properties serializedObject.ApplyModifiedProperties(); //adjust the spring of the slider slider.SetSpring(); } //in play mode if (Application.isPlaying) { EditorGUILayout.LabelField("Percentage", slider.percentage.ToString()); } }