Загрузка данных
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using MSCLoader;
using UnityEngine;
namespace MapExporter
{
public class MapExporterMod : Mod
{
public override string ID { get { return "MapExporter"; } }
public override string Name { get { return "Map Exporter"; } }
public override string Author { get { return "me"; } }
public override string Version { get { return "3.0"; } }
public override void ModSetup()
{
SetupFunction(Setup.OnLoad, Mod_OnLoad);
}
private void Mod_OnLoad()
{
GameObject go = new GameObject("MapExporterRunner");
go.AddComponent<MapExporterBehaviour>();
UnityEngine.Object.DontDestroyOnLoad(go);
}
}
// F7 - включать/выключать захват отключённых корневых объектов
// F8 - пробный прогон (пишет только маленький roots.txt)
// F9 - выгрузка в папку MapExport рядом с игрой
public class MapExporterBehaviour : MonoBehaviour
{
private const float ZoneSize = 200f;
private const int MaxTextureSize = 2048;
private const int TerrainMaxGrid = 513;
private const int TerrainTexSize = 2048;
private class Entry
{
public MeshFilter mf;
public int zx;
public int zz;
public bool off;
public bool rootOff;
}
private class RootInfo
{
public string name;
public bool active;
public int transforms;
public int meshes;
public int meshesOff;
public int skinned;
}
private string status = "";
private float statusUntil;
private float hintUntil;
private bool busy;
private bool includeInactiveRoots;
private string outDir;
private string texDir;
private Dictionary<int, string> texNames = new Dictionary<int, string>();
private Dictionary<int, string> matNames = new Dictionary<int, string>();
private StringBuilder mtl = new StringBuilder();
private List<Entry> collected;
private List<RootInfo> rootInfos;
private int dupeCount;
private int skippedMeshes;
private int unreadableMeshes;
private int skinnedTotal;
private int activeMeshObjs;
private int offMeshObjs;
void Start()
{
hintUntil = Time.realtimeSinceStartup + 25f;
}
void Update()
{
if (busy) return;
if (Input.GetKeyDown(KeyCode.F7))
{
includeInactiveRoots = !includeInactiveRoots;
SetStatus("MapExporter: отключённые корневые объекты " + (includeInactiveRoots ? "ВКЛ (может добавить мусор)" : "ВЫКЛ"), 6f);
}
else if (Input.GetKeyDown(KeyCode.F8))
{
StartCoroutine(DryRun());
}
else if (Input.GetKeyDown(KeyCode.F9))
{
StartCoroutine(Export());
}
}
void OnGUI()
{
float now = Time.realtimeSinceStartup;
float y = 10f;
if (status.Length > 0 && (busy || now < statusUntil))
{
GUI.Label(new Rect(10, y, 1200, 25), status);
y += 22f;
}
if (now < hintUntil)
{
GUI.Label(new Rect(10, y, 1200, 25), "MapExporter: F7 корни ВКЛ/ВЫКЛ | F8 проба | F9 выгрузка");
}
}
private void SetStatus(string s, float seconds)
{
status = s;
statusUntil = Time.realtimeSinceStartup + seconds;
}
private static string F(float v)
{
return v.ToString("0.#####", CultureInfo.InvariantCulture);
}
private static string Clean(string s)
{
if (string.IsNullOrEmpty(s)) return "unnamed";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.Length; i++)
{
char c = s[i];
if