private void ApplyInput(ParachuteInput input, Parachute parachute) { // Toggle input // Todo: this should be wrapped into the parachute interface for (int i = 0; i < parachute.LeftToggleSections.Count; i++) { parachute.LeftToggleSections[i].BrakeLine.ApplyPull(input.Brakes.x); } for (int i = 0; i < parachute.RightToggleSections.Count; i++) { parachute.RightToggleSections[i].BrakeLine.ApplyPull(input.Brakes.y); } // Risers input for (int i = 0; i < parachute.LeftRiserSections.Count; i++) { parachute.LeftRiserSections[i].RearLine.ApplyPull(input.RearRisers.x); parachute.LeftRiserSections[i].FrontLine.ApplyPull(input.FrontRisers.x); } for (int i = 0; i < parachute.RightRiserSections.Count; i++) { parachute.RightRiserSections[i].RearLine.ApplyPull(input.RearRisers.y); parachute.RightRiserSections[i].FrontLine.ApplyPull(input.FrontRisers.y); } // Weight shift input (Todo: through parachutepilot interface) // TODO Re-implement weight-shift //pilot.Body.centerOfMass = new Vector3(input.WeightShift.x, 0f, input.WeightShift.y) * config.WeightshiftMagnitude; }
void InstallParachute(Parachute parachute) { _parachute = parachute; _liftLines = new LineSet[parachute.Sections.Count]; _dragLines = new LineSet[parachute.Sections.Count]; _brakeLines = new LineSet[parachute.Sections.Count]; _rearLines = new LineSet[parachute.Sections.Count]; _frontLines = new LineSet[parachute.Sections.Count]; for (int i = 0; i < parachute.Sections.Count; ++i) { var s = parachute.Sections[i]; _liftLines[i] = CreateLineSet("Lift line " + i, _aeroDynamicLineWidth, _aerodynamicsMaterial, _liftColor); _dragLines[i] = CreateLineSet("Drag line " + i, _aeroDynamicLineWidth, _aerodynamicsMaterial, _dragColor); var sectionHasLine = !(s.FrontLine == null || s.RearLine == null); if (sectionHasLine) { _brakeLines[i] = CreateLineSet("Brake line " + i, _lineWidth, _lineMaterial); _rearLines[i] = CreateLineSet("Rear line " + i, _lineWidth, _lineMaterial); _frontLines[i] = CreateLineSet("Front line " + i, _lineWidth, _lineMaterial); } } }
public void Initialize(Parachute parachute, GameSettingsProvider gameSettingsProvider) { if (!_isInitialized) { _gameSettingsProvider = gameSettingsProvider; _lineParent = _lineParent ?? new GameObject("Lines"); _lineParent.transform.SetParent(this.transform); _lineMaterial = Resources.Load <Material>("Parachutes/LineMaterial"); _aerodynamicsMaterial = Resources.Load <Material>("AerodynamicsVisualizerMaterial"); InstallParachute(parachute); _gameSettingChanges = _gameSettingsProvider.SettingChanges.Subscribe(settings => { for (int i = 0; i < _parachute.Sections.Count; ++i) { _liftLines[i].Renderer.gameObject.SetActive(settings.Gameplay.VisualizeAerodynamics); _dragLines[i].Renderer.gameObject.SetActive(settings.Gameplay.VisualizeAerodynamics); } }); _isInitialized = true; } }
public static void SetPhysical(Parachute p) { for (int i = 0; i < p.Sections.Count; i++) { var section = p.Sections[i]; section.SetPhysical(); } }
public static void SetKinematic(Parachute p) { for (int i = 0; i < p.Sections.Count; i++) { var section = p.Sections[i]; section.SetKinematic(); } }
public static Bounds CanopyBounds(Parachute p) { var bounds = p.Sections[0].Cell.Collider.bounds; for (int i = 1; i < p.Sections.Count; i++) { var section = p.Sections[i]; bounds.Encapsulate(section.Cell.Collider.bounds); } return(bounds); }
public static void CreateSkinnedMesh(Parachute p, ParachuteMeshConfig cf, Material mat) { if (_meshData == null) { throw new Exception("UnityParachuteMeshFactory needs to be initialized before use!"); } Clear(); // Todo: Reuse mesh, game objects, as much as possible. Create pool of cells. Profiler.BeginSample("GOCreation"); GameObject mo = new GameObject("ParachuteMesh"); mo.transform.parent = p.Root; SkinnedMeshRenderer r = mo.AddComponent <SkinnedMeshRenderer>(); r.updateWhenOffscreen = true; // Todo: This is not great r.skinnedMotionVectors = true; r.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion; Profiler.EndSample(); Profiler.BeginSample("SetupBones"); SetupBones(mo.transform, _meshData, p, cf); Profiler.EndSample(); Profiler.BeginSample("EdgeLoops"); CreateCellLoops(_meshData, _edgeLoops, p.Config, cf); Profiler.EndSample(); Profiler.BeginSample("Caps"); CreateCap(_edgeLoops[0], _meshData, cf, 0, -0.33f); int startIndex = _meshData.Indices.Count; CreateCap(_edgeLoops[_edgeLoops.Count - 1], _meshData, cf, p.Config.NumCells - 1, 0.33f); int endIndex = _meshData.Indices.Count; InvertFaces(_meshData, startIndex, endIndex); Profiler.EndSample(); Profiler.BeginSample("CreateMesh"); Mesh m = MeshData.CreateMesh(_meshData); Profiler.EndSample(); Profiler.BeginSample("Finalize"); mat.color = p.Config.Color; r.bones = _meshData.Bones.ToArray(); r.sharedMesh = m; r.material = mat; p.CanopyMesh = r; Profiler.EndSample(); }
/// <summary> /// Takes an existing parachute system and resets it to factory state /// </summary> /// <param name="p"></param> public static void LayoutCells(Parachute p) { var config = p.Config; var centroid = ParachuteMaths.GetCanopyCentroid(config); for (int i = 0; i < config.NumCells; i++) { var cell = p.Sections[i].Cell; var t = ParachuteMaths.GetCellTransform(config, centroid, i); LayoutCell(cell, t); } }
/// <summary> /// Takes a factory state parachute system and relaxes the lines to prevent physics spazzing /// </summary> /// <param name="p"></param> public static void Relax(Parachute p) { var config = p.Config; var offset = p.Root.up * 0.5f; for (int i = 0; i < config.NumCells; i++) { var cell = p.Sections[i].Cell; cell.Body.position -= offset; } }
private static Parachute CreateNewInstance(ParachuteConfig config, ImmutableTransform transform, string name) { GameObject root = new GameObject("Parachute"); root.transform.Set(transform); root.name = name; Parachute p = root.AddComponent <Parachute>(); p.Init(config); return(p); }
public static Parachute Create(ParachuteConfig config, ImmutableTransform transform, string name) { ParachuteMaths.ValidateConfig(config); Parachute p = CreateNewInstance(config, transform, name); // Todo: Differentiate between game use and editor use CreateCells(p); CreateInterCellJoints(p); CreateRiggingLines(p); CreateControlGroups(p); p.CalculateCanopyBounds(); AddSounds(p); return(p); }
private static Line CreateLine(Parachute p, Cell cell, Vector3 cellAnchor, Vector3 rigAnchor, int lineType) { var joint = cell.gameObject.AddComponent <ConfigurableJoint>(); joint.enablePreprocessing = false; joint.anchor = cellAnchor; joint.autoConfigureConnectedAnchor = false; joint.connectedAnchor = rigAnchor; joint.xMotion = ConfigurableJointMotion.Limited; joint.yMotion = ConfigurableJointMotion.Limited; joint.zMotion = ConfigurableJointMotion.Limited; joint.angularXMotion = ConfigurableJointMotion.Free; joint.angularYMotion = ConfigurableJointMotion.Free; joint.angularZMotion = ConfigurableJointMotion.Free; joint.linearLimit = new SoftJointLimit { limit = Vector3.Distance(cell.transform.TransformPoint(cellAnchor), p.Root.TransformPoint(rigAnchor)) }; var line = new Line(joint, cell.Airfoil, lineType); return(line); }
public static Vector3 GetOrbitCamCentroid(Parachute p) { return(Vector3.Lerp(p.Pilot.Torso.position, p.Sections[p.Sections.Count / 2].Cell.Body.position, 0.5f)); }
public void SetTarget(Parachute target) { _target = target; Initialize(); }
private static void AddSounds(Parachute p) { AddSound(p.Sections[0].Cell, "event:/wingsuit/wing_left"); AddSound(p.Sections[p.Sections.Count / 2].Cell, "event:/wingsuit/wing_tail"); AddSound(p.Sections[p.Sections.Count - 1].Cell, "event:/wingsuit/wing_right"); }
public static float OrbitDistance(Parachute p) { var canopyBounds = p.CanopyBounds.size; return(Mathf.Max(canopyBounds.x, canopyBounds.y, p.Config.HeightOffset)); }
private static float GetOrbitDistance(Parachute p, float zoomLevel) { return(UnityParachuteFactory.OrbitDistance(p) * zoomLevel); }