You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
4.5 KiB
C#
118 lines
4.5 KiB
C#
|
3 years ago
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Text;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace SiegeSong
|
||
|
|
{
|
||
|
|
[System.Serializable]
|
||
|
|
public class GamePluginList
|
||
|
|
{
|
||
|
|
public string[] MainPlugins;
|
||
|
|
public string[] SidePlugins;
|
||
|
|
}
|
||
|
|
|
||
|
|
[System.Serializable]
|
||
|
|
public class GameDataPlugin
|
||
|
|
{
|
||
|
|
public string Name;
|
||
|
|
public PluginTerrainData[] Terrains;
|
||
|
|
}
|
||
|
|
|
||
|
|
[System.Serializable]
|
||
|
|
public class PluginTerrainData
|
||
|
|
{
|
||
|
|
public string Key;
|
||
|
|
public int RowNumber;
|
||
|
|
public int ColNumber;
|
||
|
|
public LoadingCellTerrainData[] LoadingCells;
|
||
|
|
}
|
||
|
|
|
||
|
|
[System.Serializable]
|
||
|
|
public class LoadingCellTerrainData
|
||
|
|
{
|
||
|
|
public string Key;
|
||
|
|
public int RowNumber;
|
||
|
|
public int ColNumber;
|
||
|
|
public WorldObjectPlacement[] WorldObjectPlacements;
|
||
|
|
}
|
||
|
|
|
||
|
|
public class WorldObjectUnloader : MonoBehaviour
|
||
|
|
{
|
||
|
|
public bool IsInterior;
|
||
|
|
public string DataString;
|
||
|
|
public GameObject ParentTerrain;
|
||
|
|
|
||
|
|
public void UnloadAll()
|
||
|
|
{
|
||
|
|
ParentTerrain = gameObject;
|
||
|
|
|
||
|
|
if (ParentTerrain.transform.childCount == 0)
|
||
|
|
{
|
||
|
|
DataString = "ERROR - Loading Cells have not been added to this terrain.";
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
var dataObject = new PluginTerrainData()
|
||
|
|
{
|
||
|
|
Key = ParentTerrain.name,
|
||
|
|
ColNumber = int.Parse(ParentTerrain.name.Split("_")[1]),
|
||
|
|
RowNumber = int.Parse(ParentTerrain.name.Split("_")[2].Split("-")[0])
|
||
|
|
};
|
||
|
|
|
||
|
|
var terrainLoadingDataCells = new List<LoadingCellTerrainData>();
|
||
|
|
|
||
|
|
for (var i = 0; i < ParentTerrain.transform.GetChild(0).childCount; i++)
|
||
|
|
{
|
||
|
|
var loadingCell = ParentTerrain.transform.GetChild(0).GetChild(i).GetComponent<LoadingCell>();
|
||
|
|
var loadingCellData = new LoadingCellTerrainData();
|
||
|
|
loadingCellData.Key = loadingCell.name;
|
||
|
|
loadingCellData.RowNumber = loadingCell.RowNumber;
|
||
|
|
loadingCellData.ColNumber = loadingCell.ColumnNumber;
|
||
|
|
var worldObjectPlacements = new List<WorldObjectPlacement>();
|
||
|
|
for (var j = 0; j < loadingCell.gameObject.transform.childCount; j++)
|
||
|
|
{
|
||
|
|
var worldObject = loadingCell.gameObject.transform.GetChild(j).GetComponent<WorldObject>();
|
||
|
|
var worldObjectPlacement = new WorldObjectPlacement();
|
||
|
|
worldObjectPlacement.InstanceID = worldObject.InstanceID;
|
||
|
|
worldObjectPlacement.FriendlyName = worldObject.Name;
|
||
|
|
worldObjectPlacement.Type = worldObject.Type;
|
||
|
|
worldObjectPlacement.Key = worldObject.Key;
|
||
|
|
|
||
|
|
worldObjectPlacement.PositionX = worldObject.gameObject.transform.localPosition.x + loadingCell.gameObject.transform.localPosition.x;
|
||
|
|
worldObjectPlacement.PositionY = worldObject.gameObject.transform.localPosition.y + loadingCell.gameObject.transform.localPosition.y;
|
||
|
|
worldObjectPlacement.PositionZ = worldObject.gameObject.transform.position.z;
|
||
|
|
|
||
|
|
worldObjectPlacement.RotationX = worldObject.gameObject.transform.rotation.x;
|
||
|
|
worldObjectPlacement.RotationY = worldObject.gameObject.transform.rotation.y;
|
||
|
|
worldObjectPlacement.RotationZ = worldObject.gameObject.transform.rotation.z;
|
||
|
|
|
||
|
|
worldObjectPlacements.Add(worldObjectPlacement);
|
||
|
|
}
|
||
|
|
loadingCellData.WorldObjectPlacements = worldObjectPlacements.ToArray();
|
||
|
|
terrainLoadingDataCells.Add(loadingCellData);
|
||
|
|
}
|
||
|
|
dataObject.LoadingCells = terrainLoadingDataCells.ToArray();
|
||
|
|
|
||
|
|
DataString = JsonUtility.ToJson(dataObject);
|
||
|
|
var outputFileName = $"Plugins\\{ParentTerrain.name}.sieso";
|
||
|
|
if (System.IO.File.Exists(outputFileName))
|
||
|
|
System.IO.File.Delete(outputFileName);
|
||
|
|
|
||
|
|
System.IO.File.WriteAllText(outputFileName, DataString);
|
||
|
|
|
||
|
|
//var pluginList = new GamePluginList()
|
||
|
|
//{
|
||
|
|
// MainPlugins = new string[1] { "siegesong.ssgmnf" },
|
||
|
|
// SidePlugins = new string[0]
|
||
|
|
//};
|
||
|
|
//var listString = JsonUtility.ToJson(pluginList);
|
||
|
|
//System.IO.File.WriteAllText("Plugins\\siegesong.ssglst", listString);
|
||
|
|
}
|
||
|
|
|
||
|
|
void Start() { }
|
||
|
|
|
||
|
|
void Update() { }
|
||
|
|
}
|
||
|
|
}
|