Example #1
0
 public Guid GetGuid(ConvertBundle bun, List <object[]> newCmds)
 {
     // Load material from asset bundle
     if (!bundleIds.TryGetValue(bun, out Guid id))
     {
         id = Guid.NewGuid();
         bundleIds.Add(bun, id);
         newCmds.Add(new object[] { VT.CmdLoadAssetBundle, bun.Dir, bun.Name, id });
     }
     return(id);
 }
Example #2
0
 public bool TryGetGameObject(string name, out ConvertBundle bundle)
 {
     foreach (var bun in settings.bundles)
     {
         if (bun.GameObjects.Contains(name))
         {
             bundle = bun;
             return(true);
         }
     }
     bundle = null;
     return(false);
 }
Example #3
0
 public bool TryGetMaterial(string name, out string newName, out ConvertBundle bundle)
 {
     foreach (var bun in settings.bundles)
     {
         if (bun.Materials.TryGetValue(name, out newName))
         {
             bundle = bun;
             return(true);
         }
     }
     newName = null;
     bundle  = null;
     return(false);
 }
Example #4
0
        private void ConvertCurrent(bool isAuto)
        {
            AddMessage(null);
            string filename = LvlFile.Text;

            if (Directory.Exists(filename))
            {
                AddMessage("Error: " + filename + " is a directory. Specify a single level file");
                return;
            }
            AddMessage((isAuto ? "Auto converting " : "Converting ") + filename);

            var dirs       = new List <string>();
            var ignoreDirs = new List <string>();

            string editorDir = EditorDir.Text;

            if (!editorDir.Equals(""))
            {
                if (!Directory.Exists(editorDir))
                {
                    AddMessage("Warning: ignoring non-existing level editor directory " + editorDir);
                }
                else
                {
                    foreach (var name in new string[] { "LevelTextures", "DecalTextures" })
                    {
                        string subdir = editorDir + @"\" + name;
                        if (Directory.Exists(subdir))
                        {
                            ignoreDirs.Add(subdir);
                        }
                    }
                }
            }

            for (int i = 1; i <= texDirCount; i++)
            {
                TextBox dir = (TextBox)this.FindName(String.Format("TexDir{0}", i));
                string  val = dir.Text;
                if (!val.Equals(""))
                {
                    if (!Directory.Exists(val))
                    {
                        AddMessage("Warning: ignoring non-existing directory " + val);
                        continue;
                    }
                    dirs.Add(val);
                }
            }

            int texPointPx = 0;

            Int32.TryParse(TexPointPx.Text, out texPointPx);

            ConvertSettings settings = new ConvertSettings()
            {
                texDirs       = dirs,
                ignoreTexDirs = ignoreDirs,
                texPointPx    = texPointPx
            };

            settings.defaultProbeHide   = DefaultProbes_ForceOn.IsChecked.Value;
            settings.defaultProbeRemove = DefaultProbes_Remove.IsChecked.Value;
            settings.boxLavaNormalProbe = BoxLavaNormalProbe.IsChecked.Value;
            settings.probeRes           = 256;
            foreach (var res in resArray)
            {
                if (((RadioButton)FindName("ProbeRes_" + res)).IsChecked.Value)
                {
                    settings.probeRes = res;
                }
            }

            var paths   = BundlesGet();
            var dupMats = new Dictionary <string, List <ConvertBundle> >(StringComparer.OrdinalIgnoreCase);
            var dupGOs  = new Dictionary <string, List <ConvertBundle> >(StringComparer.OrdinalIgnoreCase);

            foreach (var path in paths)
            {
                BundleInfo info;
                try
                {
                    info = bundleFiles.CachedBundleInfo(path);
                }
                catch (Exception ex)
                {
                    AddMessage("Error: cannot read bundle file: " + MsgAddFilename(ex.Message, paths.Count == 1 ? null : path));
                    return;
                }

                var f       = new DirectoryInfo(path);
                var convBun = new ConvertBundle()
                {
                    Name        = f.Name,
                    OS          = f.Parent.Name,
                    Dir         = f.Parent.Parent.Name,
                    Materials   = info.materials,
                    GameObjects = info.gameObjects
                };
                settings.bundles.Add(convBun);
                foreach (var mat in convBun.Materials)
                {
                    DictListAdd(dupMats, mat.Key, convBun);
                }
                foreach (var go in convBun.GameObjects)
                {
                    DictListAdd(dupGOs, go, convBun);
                }

                var parts = new List <string>();
                int n;
                if (convBun.Materials != null && (n = convBun.Materials.Count) != 0)
                {
                    parts.Add(FmtCount(n, "material", "materials") +
                              " (" + string.Join(", ", convBun.Materials.Keys.Take(5)) + (n > 5 ? ", ..." : "") + ")");
                }
                if (convBun.GameObjects != null && (n = convBun.GameObjects.Count) != 0)
                {
                    parts.Add(FmtCount(n, "entity", "entities"));
                }
                AddMessage("Using bundle " + convBun.BundleName +
                           (parts.Count != 0 ? ": " + String.Join(", ", parts) : ", but no materials or entities found!"));

                string levelDir       = new DirectoryInfo(filename).Parent.FullName;
                var    bundleLevelDir = f.Parent?.Parent?.Parent;
                if (bundleLevelDir == null || !bundleLevelDir.FullName.Equals(levelDir, StringComparison.OrdinalIgnoreCase))
                {
                    AddMessage("Warning: the bundle file is not in correct subdirectory of the level file!");
                    AddMessage("The bundle file must be at " + Path.Combine(levelDir, convBun.BundleName));
                }
            }
            ShowDups(dupMats, "material", "materials");
            ShowDups(dupGOs, "entity", "entities");

            new Task(() => Convert(filename, settings)).Start();
        }