/// <summary> /// Creates tee /// </summary> /// <param name="holeIndex"></param> /// <param name="type"></param> /// <param name="par"></param> /// <param name="strokeIndex"></param> /// <param name="width">random box width</param> /// <param name="height">random box height</param> public static void CreateTee(int holeIndex, TeeBase.Info.Type type, TeeBase.Info.Par par, int strokeIndex, float width, float height) { TeeBase tee = (TeeBase) new GameObject(GetTeeName(holeIndex, type, par, strokeIndex)).AddComponent(Types.GetType("PerfectParallel.CourseForge.Tee", "Assembly-CSharp")); tee.Position = CameraTerrainHit.Value.point; tee.Type = type; tee.Par = par; tee.StrokeIndex = strokeIndex; tee.Width = width; tee.Height = height; tee.HoleIndex = holeIndex; tee.OrderIndex = FreePlantIndex(Tees, holeIndex); if (PlatformBase.IO.IsEditor) { PlatformBase.Editor.RegisterCreatedObjectUndo(tee.gameObject, "Plant tool Creation"); tee.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); } }