public static void updatePlanetaryResourceMap()
        {
            if (FlightGlobals.currentMainBody.flightGlobalsIndex != current_body)
            {
                loadPlanetaryResourceData(FlightGlobals.currentMainBody.flightGlobalsIndex);
            }

            if (body_resource_maps.ContainsKey(displayed_resource) && (FlightGlobals.currentMainBody.flightGlobalsIndex != map_body || displayed_resource != map_resource))
            {
                foreach (ORSResourceAbundanceMarker abundance_marker in abundance_markers)
                {
                    removeAbundanceSphere(abundance_marker.getPlanetarySphere());
                    removeAbundanceSphere(abundance_marker.getScaledSphere());
                }
                abundance_markers.Clear();
                CelestialBody celbody = FlightGlobals.currentMainBody;
                sphere_texture = body_resource_maps[displayed_resource].getDisplayTexturePath();
                Vector2d[] abundance_points_list = body_abudnance_angles[displayed_resource];
                if (abundance_points_list != null && celbody.pqsController != null)
                {
                    foreach (Vector2d abundance_point in abundance_points_list)
                    {
                        double theta = abundance_point.x;
                        double phi = abundance_point.y;
                        Vector3d up = celbody.GetSurfaceNVector(phi, theta).normalized;
                        double surface_height = celbody.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis(theta, Vector3d.down) * QuaternionD.AngleAxis(phi, Vector3d.forward) * Vector3d.right);
                        GameObject resource_prim = createAbundanceSphere();
                        GameObject resource_prim_scaled = createAbundanceSphere();

                        Vector3d center = celbody.position + surface_height * up;
                        Vector3d scaledcenter = ScaledSpace.LocalToScaledSpace(celbody.position) + surface_height * up * ScaledSpace.InverseScaleFactor;

                        Transform scaled_trans = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == celbody.name);
                        resource_prim_scaled.transform.position = scaledcenter;
                        resource_prim_scaled.transform.localScale = sphere_scale_scaled * (FlightGlobals.currentMainBody.Radius / FlightGlobals.Bodies[ORSGameConstants.REF_BODY_KERBIN].Radius);
                        resource_prim_scaled.transform.localRotation = Quaternion.identity;
                        resource_prim_scaled.transform.parent = scaled_trans;
                        resource_prim_scaled.layer = 10;

                        resource_prim.transform.position = center;
                        resource_prim.transform.parent = celbody.transform;
                        resource_prim.transform.localScale = sphere_scale * (FlightGlobals.currentMainBody.Radius / FlightGlobals.Bodies[ORSGameConstants.REF_BODY_KERBIN].Radius);
                        resource_prim.transform.localRotation = Quaternion.identity;

                        ORSResourceAbundanceMarker abundance_marker = new ORSResourceAbundanceMarker(resource_prim_scaled, resource_prim);
                        abundance_markers.Add(abundance_marker);
                    }
                    map_body = current_body;
                    map_resource = displayed_resource;
                    stored_scale = ScaledSpace.ScaleFactor;
                }
            }
            else
            {
                if (body_resource_maps.ContainsKey(displayed_resource) && FlightGlobals.currentMainBody.flightGlobalsIndex == map_body && displayed_resource == map_resource)
                {
                    CelestialBody celbody = FlightGlobals.currentMainBody;
                    foreach (ORSResourceAbundanceMarker abundance_marker in abundance_markers)
                    {
                        if (lineOfSightToPosition(abundance_marker.getPlanetarySphere().transform.position, celbody))
                        {
                            if (MapView.MapIsEnabled)
                            {
                                abundance_marker.getScaledSphere().renderer.enabled = true;
                                abundance_marker.getPlanetarySphere().renderer.enabled = false;
                            }
                            else
                            {
                                abundance_marker.getScaledSphere().renderer.enabled = false;
                                abundance_marker.getPlanetarySphere().renderer.enabled = true;
                            }
                        }
                        else
                        {
                            abundance_marker.getScaledSphere().renderer.enabled = false;
                            abundance_marker.getPlanetarySphere().renderer.enabled = false;
                        }
                    }
                }
            }
        }
示例#2
0
        public static void updatePlanetaryResourceMap()
        {
            if (FlightGlobals.currentMainBody.flightGlobalsIndex != current_body)
            {
                loadPlanetaryResourceData(FlightGlobals.currentMainBody.flightGlobalsIndex);
            }

            if (body_resource_maps.ContainsKey(displayed_resource) && (FlightGlobals.currentMainBody.flightGlobalsIndex != map_body || displayed_resource != map_resource))
            {
                foreach (ORSResourceAbundanceMarker abundance_marker in abundance_markers)
                {
                    removeAbundanceSphere(abundance_marker.getPlanetarySphere());
                    removeAbundanceSphere(abundance_marker.getScaledSphere());
                }

                abundance_markers.Clear();
                CelestialBody celbody = FlightGlobals.currentMainBody;
                sphere_texture = body_resource_maps[displayed_resource].getDisplayTexturePath();
                Vector2d[] abundance_points_list = body_abudnance_angles[displayed_resource];
                if (abundance_points_list != null && celbody.pqsController != null)
                {
                    foreach (Vector2d abundance_point in abundance_points_list)
                    {
                        double   theta = abundance_point.x;
                        double   phi   = abundance_point.y;
                        Vector3d up    = celbody.GetSurfaceNVector(phi, theta).normalized;

                        double     surface_height       = celbody.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis(theta, Vector3d.down) * QuaternionD.AngleAxis(phi, Vector3d.forward) * Vector3d.right);
                        GameObject resource_prim        = createAbundanceSphere();
                        GameObject resource_prim_scaled = createAbundanceSphere();

                        Vector3d center       = celbody.position + surface_height * up;
                        Vector3d scaledcenter = ScaledSpace.LocalToScaledSpace(celbody.position) + surface_height * up * ScaledSpace.InverseScaleFactor;

                        Transform scaled_trans = PSystemManager.Instance.localBodies.Select(b => b.scaledBody.transform).Single(t => t.name == celbody.name);
                        resource_prim_scaled.transform.position      = scaledcenter;
                        resource_prim_scaled.transform.localScale    = sphere_scale_scaled * (FlightGlobals.currentMainBody.Radius / FlightGlobals.Bodies[ORSGameConstants.REF_BODY_KERBIN].Radius);
                        resource_prim_scaled.transform.localRotation = Quaternion.identity;
                        resource_prim_scaled.transform.parent        = scaled_trans;
                        resource_prim_scaled.layer = 10;

                        resource_prim.transform.position      = center;
                        resource_prim.transform.parent        = celbody.transform;
                        resource_prim.transform.localScale    = sphere_scale * (FlightGlobals.currentMainBody.Radius / FlightGlobals.Bodies[ORSGameConstants.REF_BODY_KERBIN].Radius);
                        resource_prim.transform.localRotation = Quaternion.identity;

                        ORSResourceAbundanceMarker abundance_marker = new ORSResourceAbundanceMarker(resource_prim_scaled, resource_prim);
                        abundance_markers.Add(abundance_marker);
                    }
                    map_body     = current_body;
                    map_resource = displayed_resource;
                    //stored_scale = ScaledSpace.ScaleFactor;
                }
                //celbody.renderer.material.mainTexture.
            }
            else
            {
                if (body_resource_maps.ContainsKey(displayed_resource) && FlightGlobals.currentMainBody.flightGlobalsIndex == map_body && displayed_resource == map_resource)
                {
                    CelestialBody celbody = FlightGlobals.currentMainBody;
                    foreach (ORSResourceAbundanceMarker abundance_marker in abundance_markers)
                    {
                        if (lineOfSightToPosition(abundance_marker.getPlanetarySphere().transform.position, celbody))
                        {
                            if (MapView.MapIsEnabled)
                            {
                                abundance_marker.getScaledSphere().GetComponent <Renderer>().enabled    = true;
                                abundance_marker.getPlanetarySphere().GetComponent <Renderer>().enabled = false;
                            }
                            else
                            {
                                abundance_marker.getScaledSphere().GetComponent <Renderer>().enabled    = false;
                                abundance_marker.getPlanetarySphere().GetComponent <Renderer>().enabled = true;
                            }
                        }
                        else
                        {
                            abundance_marker.getScaledSphere().GetComponent <Renderer>().enabled    = false;
                            abundance_marker.getPlanetarySphere().GetComponent <Renderer>().enabled = false;
                        }
                    }
                }
            }
        }