Exemplo n.º 1
0
            public static void LoadScaledPlanet(GameObject smallPlanet, string name, bool bLoadTemp = false)
            {
                var root = ConfigNode.Load(DataPath + name + ".cfg");

                if (root != null)
                {
                    var sConfig = root.nodes.GetNode("ScaledTransform");
                    //print(cbConfig);
                    if (sConfig != null)
                    {
                        var scaledBody = PFUtil.FindScaled(name);

                        var ratio    = float.Parse(sConfig.GetValue("ratio"));
                        var newScale = (float)PFUtil.FindCB(name).Radius *ratio;
                        scaledBody.transform.localScale = new Vector3(newScale, newScale, newScale);
                    }
                }

                var binName = name + ".bin";

                if (!bLoadTemp)
                {
                    var colorTexture = PFUtil.LoadTexture(DataPath + name + "_map.png");
                    var bumpTexture  = PFUtil.LoadTexture(DataPath + name + "_normal.png");

                    LoadScaledPlanetTextures(name, colorTexture, bumpTexture);
                }
                else
                {
                    var colorTexture = PFUtil.LoadTexture(DataPath + name + "_map_.png");
                    var bumpTexture  = PFUtil.LoadTexture(DataPath + name + "_normal_.png");
                    binName = name + "_.bin";
                    LoadScaledPlanetTextures(name, colorTexture, bumpTexture);
                }

                if (KSP.IO.File.Exists <PlanetFactory>(binName))
                {
                    //print("Loading mesh");
                    var smallPlanetMeshFilter = (MeshFilter)smallPlanet.GetComponentInChildren((typeof(MeshFilter)));
                    var newVerts = new Vector3[smallPlanetMeshFilter.mesh.vertices.Count()];
                    var reader   = KSP.IO.BinaryReader.CreateForType <PlanetFactory>(binName);
                    for (var i = 0; i < newVerts.Count(); i++)
                    {
                        newVerts[i].x = reader.ReadSingle();
                        newVerts[i].y = reader.ReadSingle();
                        newVerts[i].z = reader.ReadSingle();
                    }
                    smallPlanetMeshFilter.mesh.vertices = newVerts;
                    smallPlanetMeshFilter.mesh.RecalculateNormals();

                    //smallPlanetMeshFilter.mesh.tangents = null;
                    PFUtil.RecalculateTangents(smallPlanetMeshFilter.mesh);
                }
            }
Exemplo n.º 2
0
 void LogoWindow(int windowID)
 {
     if (logoTexture == null)
     {
         logoTexture = PFUtil.LoadTexture(DataPath + "logo_small.png");
     }
     if (logoTexture != null)
     {
         GUI.DrawTexture(new Rect(4, 20, logoTexture.width, logoTexture.height), logoTexture);
     }
     isFactoryEnabled = GUI.Toggle(new Rect(10, 20, 320, 20), isFactoryEnabled, "Load Sentar Expansion");
 }
Exemplo n.º 3
0
        //Overlay a .CFG on a given object.
        public static void LoadConfiguration(System.Object obj, ConfigNode node)
        {
            var t = obj.GetType();

            var config = ConfigToDict(node);

            foreach (var key in config.Keys)
            {
                var field = t.GetField(key);
                //print(field);
                if (field != null)
                {
                    //print(field.FieldType.ToString().ToLower() +" Was "+field.GetValue(obj));
                    switch (field.FieldType.ToString().ToLower())
                    {
                    case "system.string":
                        field.SetValue(obj, config[key]);
                        break;

                    case "system.single":
                        field.SetValue(obj, float.Parse(config[key]));
                        break;

                    case "system.double":
                        field.SetValue(obj, double.Parse(config[key]));
                        break;

                    case "system.int32":
                        field.SetValue(obj, int.Parse(config[key]));
                        break;

                    case "system.uint32":
                        field.SetValue(obj, uint.Parse(config[key]));
                        break;

                    case "system.boolean":
                        field.SetValue(obj, bool.Parse(config[key]));
                        break;

                    case "unityengine.color":
                        field.SetValue(obj, ConfigNode.ParseColor(config[key]));
                        break;

                    case "unityengine.vector3":
                        field.SetValue(obj, ConfigNode.ParseVector3(config[key]));
                        break;

                    case "unityengine.animationcurve":
                        field.SetValue(obj, ParseCurve(node.GetNode(key)));
                        break;

                    case "unityengine.gradient":
                        field.SetValue(obj, new Gradient());
                        break;

                    case "orbit":
                        field.SetValue(obj, ParseOrbit(node.GetNode(key)));
                        break;

                    case "pqsmod_pfheightcolor+landclass[]":
                        int i   = 0;
                        var lcs = new List <PQSMod_PFHeightColor.LandClass>();
                        //print("parse landclass");
                        var pn = node.GetNode(key);
                        while (true)
                        {
                            var n = pn.GetNode("LandClass", i);
                            if (n != null)
                            {
                                var nlc = new PQSMod_PFHeightColor.LandClass();
                                LoadConfiguration(nlc, n);
                                lcs.Add(nlc);
                            }
                            else
                            {
                                break;
                            }
                            i++;
                        }
                        field.SetValue(obj, lcs.ToArray());
                        break;

                    case "mapso":
                        //print("Loading map:"+config[key]);
                        if (config[key].ToLower() == "null")
                        {
                            field.SetValue(obj, null);
                        }
                        else
                        {
                            var colorTexture = PFUtil.LoadTexture(DataPath + config[key]);
                            var mapso        = (MapSO)ScriptableObject.CreateInstance(typeof(MapSO));
                            mapso.CreateMap(MapSO.MapDepth.RGBA, colorTexture);
                            field.SetValue(obj, mapso);
                        }
                        break;
                    }
                }
            }
        }