示例#1
0
        // Get the model file name for a part by reading the cfg file contents
        UrlDir.UrlFile GetModelFile(Part part)
        {
            AvailablePart availablePart = part.partInfo;

            /*
             * TESTS
             * Debug.Log("AvailPart: " + availablePart.name);
             * Debug.Log("mesh: " + availablePart.partConfig.GetValue("mesh"));
             * Debug.Log("MODEL: " +
             *     (availablePart.partConfig.GetNode("MODEL") != null ?
             *     availablePart.partConfig.GetNode("MODEL").GetValue("model") :
             *     "none"));
             */

            // Check for an entry in either the PART.model property or the PART.MODEL.model value
            string modelName = availablePart.partConfig.GetValue("mesh");

            if (modelName != null)
            {
                // The "url" is on the firmat "Parts/<PartType>/<ConfigFileName>/<PartName>
                // We need to strip away the ConfigFileName and PartName to get the real path
                string[] urlParts = availablePart.partUrl.Split('/');
                string   url      = "";
                for (int i = 0; i < urlParts.Count() - 2; i++)
                {
                    url += urlParts[i] + "/";
                }

                modelName = url + modelName;
            }
            else
            {
                modelName = availablePart.partConfig.GetNode("MODEL").GetValue("model") + ".mu";
            }

            // Calculate the proper URLs for the file
            string   directory = Path.GetDirectoryName(modelName);
            FileInfo file      = new FileInfo("GameData/" + modelName);

            // Generate the root directory
            UrlDir root = UrlBuilder.CreateDir(directory);

            UrlDir.UrlFile modelFile = new UrlDir.UrlFile(root, file);

            // Apperently, if the file is name "model.mu" the reader is supposed to just
            // pick the first file in the folder... =S
            if (!File.Exists("GameData/" + modelName))
            {
                IEnumerable <UrlDir.UrlFile> modelFiles = root.GetFiles(UrlDir.FileType.Model);

                foreach (UrlDir.UrlFile mFile in modelFiles)
                {
                    Debug.Log("modelFiles: " + mFile.name);
                }
            }

            // Create the full path and name of the model file
            return(modelFile);
        }
示例#2
0
        /*
         * public static Texture GetTexture(string url, bool asNormalMap)
         * {
         *  List<TextureInfo> databaseTexture = GameDatabase.Instance.databaseTexture;
         *
         *  foreach (TextureInfo textureInfo in databaseTexture)
         *  {
         *      //if (textureInfo.file.fullPath.IndexOf("Squad") == -1)
         *      //    Debug.Log("- textureInfo: " + textureInfo.name);
         *
         *      if (textureInfo != null && string.Equals(textureInfo.name, url, StringComparison.OrdinalIgnoreCase))
         *          continue;
         *
         *      if (asNormalMap)
         *          return textureInfo.normalMap;
         *      else
         *          return textureInfo.texture;
         *  }
         *
         *  return null;
         * }
         */

        public static void ReloadTextures(DateTime lastLoadTime)
        {
            if (textureLoaders == null)
            {
                Debug.LogError("Loader.ReloadTextures: Call Loader.Init first");
                return;
            }

            /*
             * PartLoader.Instance.Recompile = true;
             * AssemblyLoader.ClearPlugins();
             * foreach (UrlDir.UrlFile urlFile in GameDatabase.Instance.root.GetFiles(UrlDir.FileType.Assembly))
             * {
             *  UnityEngine.Debug.Log("Load(Assembly): " + urlFile.url);
             *  ConfigNode assemblyNode = null;
             *  List<UrlDir.UrlConfig> list = new List<UrlDir.UrlConfig>(urlFile.parent.GetConfigs("ASSEMBLY", urlFile.name, false));
             *  if (list.Count > 0)
             *  {
             *      assemblyNode = list[0].config;
             *  }
             *  AssemblyLoader.LoadPlugin(new FileInfo(urlFile.fullPath), urlFile.parent.url, assemblyNode);
             * }
             * AssemblyLoader.LoadAssemblies();
             * VesselModuleManager.CompileModules();
             *
             * foreach (AssemblyLoader.LoadedAssembly loadedAssembly in AssemblyLoader.loadedAssemblies)
             * {
             *  if (!string.IsNullOrEmpty(loadedAssembly.assembly.Location))
             *  {
             *      AssemblyName name = loadedAssembly.assembly.GetName();
             *      FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(loadedAssembly.assembly.Location);
             *      string text2 = string.Concat(new object[]
             *      {
             *  name.Name,
             *  " v",
             *  name.Version,
             *  (!(versionInfo.ProductVersion != " ") || !(versionInfo.ProductVersion != name.Version.ToString())) ? string.Empty : (" / v" + versionInfo.ProductVersion),
             *  (!(versionInfo.FileVersion != " ") || !(versionInfo.FileVersion != name.Version.ToString()) || !(versionInfo.FileVersion != versionInfo.ProductVersion)) ? string.Empty : (" / v" + versionInfo.FileVersion)
             *      });
             *      if (this.assemblyWhitelist.Contains(name.Name))
             *      {
             *          text2 = "Stock assembly: " + text2;
             *      }
             *      else
             *      {
             *          GameDatabase.modded = true;
             *          GameDatabase.loaderInfo.Add(text2);
             *          GameDatabase.loadedModsInfo.Add(text2);
             *      }
             *      modlist = modlist + text2 + "\n";
             *  }
             * }
             * AddonLoader.Instance.StartAddons(KSPAddon.Startup.Instantly);
             */
            /*
             * foreach (UrlDir.UrlFile file in root.GetFiles(UrlDir.FileType.Audio))
             * {
             *  if (db.ExistsAudioClip(file.url))
             *  {
             *      UnityEngine.Debug.Log("Load(Audio): " + file.url + " OUT OF DATE");
             *      PartLoader.Instance.Recompile = true;
             *  }
             *  UnityEngine.Debug.Log("Load(Audio): " + file.url);
             *  foreach (DatabaseLoader<AudioClip> loader in this.loadersAudio)
             *  {
             *      if (loader.extensions.Contains(file.fileExtension))
             *      {
             *          if (loadAudio)
             *          {
             *              yield return base.StartCoroutine(loader.Load(file, new FileInfo(file.fullPath)));
             *          }
             *          if (loader.successful)
             *          {
             *              loader.obj.name = file.url;
             *              this.databaseAudio.Add(loader.obj);
             *              this.databaseAudioFiles.Add(file);
             *          }
             *      }
             *      if (Time.realtimeSinceStartup > nextFrameTime)
             *      {
             *          nextFrameTime = Time.realtimeSinceStartup + LoadingScreen.minFrameTime;
             *          yield return null;
             *      }
             *  }
             *  this.progressFraction += delta;
             * }
             */

            GameDatabase db = GameDatabase.Instance;

            UrlDir root = GetRoot();

            List <TextureInfo> textures = db.databaseTexture;

            // PrintTextures(false);

            foreach (UrlDir.UrlFile textureFile in root.GetFiles(UrlDir.FileType.Texture))
            {
                if (textureFile.fullPath.IndexOf("Squad") != -1)
                {
                    continue;
                }

                if (textureFile.fileTime < lastLoadTime)
                {
                    continue;
                }

                /*
                 * if (!db.ExistsTexture(textureFile.url))
                 * {
                 *  Debug.LogError("Load texture: " + textureFile.url + " doesn's exist");
                 *  continue;
                 * }
                 */
                // Find the correct texture loader for this texture
                foreach (DatabaseLoader <GameDatabase.TextureInfo> textureLoader in textureLoaders)
                {
                    if (!textureLoader.extensions.Contains(textureFile.fileExtension))
                    {
                        continue;
                    }

                    Debug.Log("  Loading texture " + textureFile.url + " using loader " + textureLoader.ToString());

                    // Load the texture and wait for the coroutine to finish.
                    db.StartCoroutine(textureLoader.Load(textureFile, new FileInfo(textureFile.fullPath)));

                    if (textureLoader.successful)
                    {
                        //textureLoader.obj.name = textureFile.url;
                        textureLoader.obj.texture.name = textureFile.url;

                        foreach (TextureInfo existingTexture in textures)
                        {
                            //if (existingTexture.file.fullPath.IndexOf("Squad") != -1)
                            //    continue;

                            // Update an existing texture
                            if (existingTexture.file.url == textureFile.url)
                            {
                                existingTexture.texture = textureLoader.obj.texture;
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("Failed to load texture: " + textureFile.name);
                    }
                }
            }

            /*
             * foreach (UrlDir.UrlFile file3 in root.GetFiles(UrlDir.FileType.Model))
             * {
             *  if (db.ExistsModel(file3.url))
             *  {
             *      if (!(file3.fileTime > this.lastLoadTime))
             *      {
             *          continue;
             *      }
             *      UnityEngine.Debug.Log("Load(Model): " + file3.url + " OUT OF DATE");
             *      db.RemoveModel(file3.url);
             *  }
             *  UnityEngine.Debug.Log("Load(Model): " + file3.url);
             *  foreach (DatabaseLoader<GameObject> loader3 in db.loadersModel)
             *  {
             *      if (loader3.extensions.Contains(file3.fileExtension))
             *      {
             *          if (loadParts)
             *          {
             *              yield return base.StartCoroutine(loader3.Load(file3, new FileInfo(file3.fullPath)));
             *          }
             *          if (loader3.successful)
             *          {
             *              GameObject obj = loader3.obj;
             *              obj.transform.name = file3.url;
             *              obj.transform.parent = base.transform;
             *              obj.transform.localPosition = Vector3.zero;
             *              obj.transform.localRotation = Quaternion.identity;
             *              obj.SetActive(false);
             *              this.databaseModel.Add(obj);
             *              this.databaseModelFiles.Add(file3);
             *          }
             *      }
             *      if (Time.realtimeSinceStartup > nextFrameTime)
             *      {
             *          nextFrameTime = Time.realtimeSinceStartup + LoadingScreen.minFrameTime;
             *          yield return null;
             *      }
             *  }
             * }
             */
        }