Beispiel #1
0
    public BaseDef Export()
    {
        var siteDef     = new MapSiteDef();
        var subSites    = GetComponentsInChildren <SubSiteObject>();
        var connections = GetComponentsInChildren <ConnectionObject>();
        var attachment  = GetComponentInChildren <MapSiteAttachmentObject>();

        foreach (var subSite in subSites)
        {
            siteDef.SubSites.Add(new SubSite()
            {
                Pos   = new Vec2(subSite.transform.position.x, subSite.transform.position.z),
                Rot   = subSite.transform.rotation.eulerAngles.y,
                SizeX = subSite.transform.lossyScale.x,
                SizeY = subSite.transform.lossyScale.z,
                Tags  = subSite.Tags.Select((x) => { var r = new DefRef <MapSiteTagDef>(new MapSiteTagDef()); ((IDef)r.Def).Address = new DefIDFull($"/Tags/{x}"); return(r); }).ToList()
            });
        }
        foreach (var connection in connections)
        {
            siteDef.Connections.Add(new SiteConnection()
            {
                Pos  = new Vec2(connection.transform.position.x, connection.transform.position.z),
                Rot  = 360 - connection.transform.rotation.eulerAngles.y,
                Size = connection.transform.lossyScale.x,
                Tags = connection.Tags.Select((x) => { var r = new DefRef <MapSiteTagDef>(new MapSiteTagDef()); ((IDef)r.Def).Address = new DefIDFull($"/Tags/{x}"); return(r); }).ToList()
            });
        }
        siteDef.SizeX = Size.x * transform.localScale.x;
        siteDef.SizeY = Size.z * transform.localScale.z;
        siteDef.Tags  = Tags.Select((x) => { var r = new DefRef <MapSiteTagDef>(new MapSiteTagDef()); ((IDef)r.Def).Address = new DefIDFull($"/Tags/{x}"); return(r); }).ToList();
        siteDef.Type  = new MapSiteTypeDef()
        {
            EntitiesToSpawnOn =
                EntitiesToSpawnOn.Select(x =>
            {
                var r = new DefRef <IEntityObjectDef>(new RefStubEntityObjectDef());
                ((IDef)r.Def).Address = new DefIDFull($"/{x.name}");
                return(r);
            }).ToList()
        };
        if (attachment != null)
        {
            siteDef.AttachmentPoint    = new Vec2(attachment.transform.position.x, attachment.transform.position.z);
            siteDef.AttachmentRotation = attachment.transform.rotation.eulerAngles.y;
            siteDef.AttachmentSize     = Mathf.Abs(attachment.transform.lossyScale.x);
        }

        var sceneDef = SceneDefGetter.ExportSceneFrom(gameObject.GetComponentsInChildren <ISceneExportable>());

        siteDef.AttachedScene = sceneDef;
        return(siteDef);
    }
Beispiel #2
0
    private static void ExportScene(Scene scene)
    {
        Debug.Log($"Exporting {scene.name}");
        var aPath = scene.path;

        Debug.Log(aPath);
        var assetsIndex = aPath.IndexOf("Scenes") + "Scenes".Length;
        var localPath   = aPath.Substring(assetsIndex, aPath.Length - ".unity".Length - assetsIndex);

        Debug.Log(localPath);
        var sceneDef = SceneDefGetter.ExportSceneFrom(scene.GetRootGameObjects().SelectMany(x => x.GetComponentsInChildren <ISceneExportable>()));

        if (sceneDef.Entities.Count == 0)
        {
            return;
        }
        Defs.SimpleSave(Application.dataPath + "/../../Yogollag/Defs", localPath + sceneDef.GetType().Name.Substring(0, sceneDef.GetType().Name.Length - 3), sceneDef, out var path);
        Debug.Log($"Saved at {path}");
    }