Esempio n. 1
0
    public ObjectDetails ImportTemplate(int lot, string objectName)
    {
        var template = ObjectInterface.Import(lot, out var error);

        if (template == null)
        {
            Debug.LogError(error);
        }

        var zoneObject = new GameObject(objectName);

        var objectDetails = zoneObject.AddOrGetComponent <ObjectDetails>();

        objectDetails.Lot = lot;

        zoneObject.transform.parent = Scene.transform;

        template.transform.parent = zoneObject.transform;

        return(objectDetails);
    }
        public static GameObject Import(string workingFile)
        {
            const float scale = 3.125f;

            using var stream = File.OpenRead(workingFile);
            using var reader = new BitReader(stream);

            var zone = new LuzFile();

            zone.Deserialize(reader);

            return(null);

            var zoneInstance = new GameObject($"Zone {Path.GetFileName(workingFile)}");

            var zoneDetails = zoneInstance.AddOrGetComponent <ZoneDetails>();

            zoneDetails.ZoneName = Path.GetFileName(workingFile);

            zoneDetails.ZoneId = zone.WorldId;

            var spawnPoint = new GameObject("Zone Spawnpoint");

            spawnPoint.transform.parent = zoneInstance.transform;

            spawnPoint.transform.position = new Vector3(zone.SpawnPoint.X, zone.SpawnPoint.Y, zone.SpawnPoint.Z);
            spawnPoint.transform.rotation = new Quaternion(zone.SpawnRotation.X, zone.SpawnRotation.Y, zone.SpawnRotation.Z, zone.SpawnRotation.W);

            zoneDetails.SpawnPoint = spawnPoint.transform;

            var sourceDir = Path.GetDirectoryName(workingFile) ?? WorkspaceControl.CurrentWorkspace.AssetPath;

            var terrain = TerrainInterface.Import(Path.Combine(
                                                      sourceDir,
                                                      zone.TerrainFileName)
                                                  );

            terrain.transform.parent = zoneInstance.transform;

            foreach (var sceneInfo in zone.Scenes)
            {
                var scenePath = Path.Combine(sourceDir, sceneInfo.FileName);

                var sceneInstance = new GameObject($"Scene {sceneInfo.SceneName} ({sceneInfo.SceneId}, {sceneInfo.LayerId})");

                var sceneDetails = sceneInstance.AddOrGetComponent <SceneDetails>();

                sceneInstance.transform.parent = zoneInstance.transform;

                using var lvlStream = File.OpenRead(scenePath);
                using var lvlReader = new BitReader(lvlStream);

                var lvl = new LvlFile();

                lvl.Deserialize(lvlReader);

                sceneDetails.SceneName = sceneInfo.SceneName;

                sceneDetails.SceneLayer = sceneInfo.LayerId;

                sceneDetails.SkyBox = lvl.LevelSkyConfig == null ? sceneDetails.SkyBox : lvl.LevelSkyConfig.Skybox;

                if (lvl.LevelObjects == null)
                {
                    continue;
                }

                foreach (var template in lvl.LevelObjects.Templates)
                {
                    GameObject lwoObject;

                    try
                    {
                        lwoObject = ObjectInterface.Import(template.Lot, out var error);

                        if (lwoObject == null)
                        {
                            Debug.LogError(error);

                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e);

                        continue;
                    }

                    lwoObject.transform.parent = sceneInstance.transform;

                    lwoObject.transform.position = new Vector3(template.Position.X, template.Position.Y, template.Position.Z);
                    lwoObject.transform.rotation = new Quaternion(template.Rotation.X, template.Rotation.Y, template.Rotation.Z, template.Rotation.W);
                }
            }

            return(zoneInstance);
        }