/// <summary> /// Creates pin /// </summary> /// <param name="holeIndex"></param> /// <param name="difficulty"></param> /// <param name="position"></param> public static void CreatePin(int holeIndex, PinBase.Info.Difficulty difficulty, Vector3 position) { PinBase pin = (PinBase) new GameObject(GetPinName(holeIndex, FreePlantIndex(Pins, holeIndex), difficulty)).AddComponent(Types.GetType("PerfectParallel.CourseForge.Pin", "Assembly-CSharp")); pin.Position = position; pin.Difficulty = difficulty; pin.HoleIndex = holeIndex; pin.OrderIndex = FreePlantIndex(Pins, holeIndex); if (PlatformBase.IO.IsEditor) { PlatformBase.Editor.RegisterCreatedObjectUndo(pin.gameObject, "Plant tool Creation"); pin.gameObject.hideFlags = HideFlags.HideInHierarchy; } }
/// <summary> /// Get the aim point from this position (i.e. next shot or pin) /// </summary> /// <param name="position"></param> /// <param name="tee"></param> /// <param name="shots"></param> /// <param name="pin"></param> /// <returns></returns> public static Vector3 AimPoint(Vector3 position, TeeBase tee, List <ShotBase> shots, PinBase pin) { if (shots.Count == 0) { return(pin.Position); } if (Vector3.Distance(position, pin.Position) < 245) { return(pin.Position); } Vector3 aimPoint = Vector3.zero; for (int i = 0; i < shots.Count; ++i) { ShotBase shot = shots[i]; if ((shot.Position - position).magnitude < 50.0f) { continue; } if (aimPoint == Vector3.zero && (position - shot.Position).magnitude < (position - pin.Position).magnitude && (shot.Position - pin.Position).magnitude < (position - pin.Position).magnitude) { aimPoint = shot.Position; } else if (aimPoint != Vector3.zero && (position - shot.Position).magnitude < (position - aimPoint).magnitude && (shot.Position - pin.Position).magnitude < (aimPoint - pin.Position).magnitude) { aimPoint = shot.Position; } } if (aimPoint != Vector3.zero) { return(aimPoint); } else { return(pin.Position); } }