/// <summary> /// Hit Add button, so finished slicing /// </summary> /// <param name="g"></param> public void AddSlices(Graspable g) { controlKnob.callOnUpdate = null; controlKnob.clickUpAction = null; if (currrentSliceTarget) { addedItems[currrentSliceTarget.name] = currrentSliceTarget.SliceCount; if (dropInfo) { dropInfo.SetText("Added " + currrentSliceTarget.SliceCount + " slices"); dropInfo.ShowFor(1f); LeanTween.delayedCall(1f, () => { baguetteSlicesPrep.Show(); activeMenu = true; }); } currrentSliceTarget.Show(false); currrentSliceTarget = null; } else if (dropInfo) { dropInfo.Show(false); } controlKnob.Show(false); addSlicesButton.Show(false); activeMenu = false; }
/// <summary> /// This means we've finished the slicing /// session. UPDATE: noit doesn't /// </summary> /// <param name="g"></param> private void KnobReleased(Graspable g) { if (dropInfo) { dropInfo.SetText("Add " + currrentSliceTarget.SliceCount + " slices"); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); Graspable gScript = (Graspable)target; if (GUILayout.Button("Transform to home")) { Undo.RecordObject(gScript, "Transform to home"); gScript.TransformToHome(); } else if (GUILayout.Button("Transform to dest")) { Undo.RecordObject(gScript, "Transform to dest"); gScript.TransformToDest(); } else if (GUILayout.Button("!! Set home transform !!")) { Undo.RecordObject(gScript, "Set home transform"); gScript.SetHomeTransform(); } else if (GUILayout.Button("!! Set dest transform !!")) { Undo.RecordObject(gScript, "Set destination transform"); gScript.SetDestTransform(); } }
public static void RotateTo(Graspable Graspable, Vector3 eulerAngles, float time = 1.5f) { Graspable.Dormant = true; // Don't allow hits Graspable.EnableRb(false); LeanTween.rotate(Graspable.gameObject, eulerAngles, time) .setEase(LeanTweenType.easeOutQuad); }
public static void MoveToPositionAlongPath(Graspable Graspable, Vector3[] path, float time = 1.5f, bool orientToPath = true) { Graspable.Dormant = true; // Don't allow hits Graspable.EnableRb(false); LeanTween.moveSpline(Graspable.gameObject, path, time) .setEase(LeanTweenType.easeOutQuad) .setOrientToPath(orientToPath); }
public static T GetA <T>(this Graspable g) { if (g) { return(g.GetComponent <T>()); } else { return(default);
public static bool IsA <T>(this Graspable g) { if (g) { return(g.GetComponent <T>() != null); } else { return(false); } }
/// <summary> /// Looks for any objects of interest and /// sets RaycastHitPosition, which will either /// correspond with the raycast hit point /// or the end of the beam of specificed /// length /// </summary> private VrEventInfo UpdateRaycaster(VrEventInfo vrEventInfo) { vrEventInfo.PrevHitObject = vrEventInfo.HitObject; vrEventInfo.genericHitObject = null; #if USING_UUI if (CheckUiObjects(ref vrEventInfo)) { vrEventInfo.RaycastHit = true; // Do we need a separate UI cast hit flag? Probably not, as we're only interested in positioning the reticle vrEventInfo.RaycastNormal = -vrEventInfo.UiTargetGameObject.transform.forward; vrEventInfo.HitObject = null; } else #endif bool gotHit = false; if (Physics.RaycastNonAlloc(vrEventInfo.ControllerPosition, vrEventInfo.ControllerDirection, physicsRaycasts, ActivitySettings.Asset.raycastDistance, ActivitySettings.Asset.interactableTarget) > 0) { gotHit = true; Graspable hitObject = physicsRaycasts[0].transform.gameObject.GetComponent <Graspable>(); if (!hitObject) // This might be a child 'trap' for a raycast such as a label { hitObject = physicsRaycasts[0].transform.gameObject.GetComponentInParent <Graspable>(); } // Ignore anything with a Graspable that's marked as dormant if (hitObject && hitObject.Dormant) { gotHit = false; } if (gotHit) { vrEventInfo.RaycastHit = true; vrEventInfo.RaycastHitPosition = physicsRaycasts[0].point; vrEventInfo.RaycastNormal = physicsRaycasts[0].normal; vrEventInfo.BeamDistance = physicsRaycasts[0].distance; vrEventInfo.PointerDotWithUp = Vector3.Dot(vrEventInfo.ControllerDirection, Vector3.up); vrEventInfo.HitObject = hitObject; vrEventInfo.genericHitObject = physicsRaycasts[0].transform.gameObject; } } if (!gotHit) { vrEventInfo.RaycastHit = false; vrEventInfo.RaycastHitPosition = vrEventInfo.ControllerPosition + vrEventInfo.ControllerDirection * ActivitySettings.Asset.raycastDistance; vrEventInfo.BeamDistance = ActivitySettings.Asset.raycastDistance; vrEventInfo.HitObject = null; } return(vrEventInfo); }
/// <summary> /// For dropping a Placeable into a pot /// </summary> /// <param name="Graspable"></param> /// <param name="destination"></param> /// <param name="time"></param> public static void MoveToPositionAndHide(Graspable Graspable, Vector3 destination, float time) { Graspable.Dormant = true; // Don't allow hits Graspable.EnableRb(false); LeanTween.sequence().append(() => { LeanTween.move(Graspable.gameObject, destination, time); }).append(time).append(() => { Graspable.EnableRb(true); Graspable.Show(false); Graspable.Dormant = true; // Don't need dormant flag if disabled }); }
/// <summary> /// For dropping a Placeable into a pot /// </summary> /// <param name="Graspable"></param> /// <param name="destination"></param> /// <param name="time"></param> public static void MoveToPositionThenHideAtPosition(Graspable Graspable, Vector3 destination, Vector3 hidePosition, float time) { Graspable.Dormant = true; // Don't allow hits Graspable.EnableRb(false); LeanTween.sequence().append(() => { LeanTween.move(Graspable.gameObject, destination, time); }).append(time).append(() => { Graspable.EnableRb(true); Graspable.Show(false); Graspable.transform.position = hidePosition; }); }
/// <summary> /// Useful for returning a dropped object to /// its original position and orientation /// </summary> /// <param name="Graspable"></param> /// <param name="destination"></param> /// <param name="rotation"></param> /// <param name="time"></param> public static void MoveToPosition(Graspable Graspable, Vector3 destination, Quaternion rotation, float time) { Graspable.Dormant = true; // Don't allow hits Graspable.EnableRb(false); LeanTween.sequence().append(() => { LeanTween.move(Graspable.gameObject, destination, time); }).append(() => { Graspable.gameObject.transform.rotation = rotation; Graspable.EnableRb(true); Graspable.Dormant = false; }); }
/// <summary> /// Have an issue here: it never gets a hit on the Graspable and /// always (in the case of something on the floor like a broom) /// returns the floor collider. Haven't figured out what's going /// on here, as it hits just fine in the main raycast routine /// when it picks up the Graspable component. No idea why an /// independent raycast doesn't get a hit. /// </summary> /// <param name="g"></param> /// <returns></returns> public static bool DirectLineToObject(Graspable g) { ray.origin = ControllerInput.Instance.ControllerPosition; ray.direction = (g.transform.position - ray.origin).normalized; if (Physics.RaycastNonAlloc(ray, physicsRaycasts, ActivitySettings.Asset.raycastDistance) > 0) { Debug.Log("Direct line to: " + physicsRaycasts[0].collider.name); if (physicsRaycasts[0].collider.gameObject == g) { return(true); } } return(false); }
public void BringInChef(Graspable g) { continueButton.Show(false); chefEvaluation.SetActive(true); }
public static bool IsTagged(this Graspable g, string tag) { return(g && g.CompareTag(tag)); }
public static bool IsEqualTo(this Graspable g, GameObject other) { return(g && g.gameObject.Equals(other)); }
public static void MoveToPositionImmediate(Graspable Graspable, Vector3 destination, Quaternion rotation) { MoveToPosition(Graspable, destination, rotation, 0.05f); }
public void Score(Graspable grabbable) { string result = ""; int score = 0; int total = 0; foreach (var p in pourables) { bool correct = saladRecipe.IsCorrect(p.name, p.ActualAmount); if (correct) { score++; } total++; result += string.Format("\n{0}: {1}. ", p.name, correct ? "correct" : "wrong"); } foreach (var kv in addedItems) { bool correct = true; // made false if there are prep steps and they're wrong if (prepSteps.ContainsKey(kv.Key)) { var arr = prepSteps[kv.Key].ToArray(); if (arr.Length > 0) { if (!saladRecipe.PreparationCorrect(kv.Key, arr)) { correct = false; } } } else if (kv.Value != 0) { correct = false; } correct = correct && saladRecipe.IsCorrect(kv.Key, kv.Value); if (correct) { score++; } total++; result += string.Format("\n{0}: {1}", kv.Key, correct ? "correct" : "wrong"); } Debug.Log(result); float unitVal = Utils.UnitValueChallengeScore(score, total); int activityScore = Utils.ConvertToActivityScore(unitVal); Utils.RegisterActivityAndUpdateExperience(activityScore); infoPanel.SetText(string.Format("Your score is {0} out of {1}", activityScore, ActivitySettings.pointsPerChallenge)); if (unitVal > .85f) { chefExpression.Happy(); } else if (unitVal > .45f) { chefExpression.Skeptical(); } else { chefExpression.Angry(); } infoPanel.ShowFor(ActivitySettings.Asset.infoDisplayTime, () => { ActivityManager.Instance.FadeOutThen(() => { ActivityManager.Instance.Next(); }); }); }
public static bool IsNamed(this Graspable g, string name) { return(g && g.name.Equals(name, System.StringComparison.CurrentCultureIgnoreCase)); }