private MapObject SpawnObject(string modelName, Vector3 position, Vector3 rotation)
        {
            Entity entity;

            if (modelName.StartsWith("0x"))
            {
                if (int.TryParse(modelName.Substring(2), NumberStyles.HexNumber, new NumberFormatInfo(), out var modelHash))
                {
                    entity = NativeUtility.CreateObject(modelHash, position);
                }
                else
                {
                    NativeUtility.UserFriendlyPrint($"Failed to spawn \"{modelName}\"");
                    return(null);
                }
            }
            else
            {
                entity = NativeUtility.CreateObject(modelName, position);
            }
            NativeUtility.SetEntityRotation(entity, rotation);
            var spawnedObject = new MapObject(modelName, position, rotation, entity);

            if (entity == null)
            {
                NativeUtility.UserFriendlyPrint($"Failed to spawn \"{modelName}\"");
                return(null);
            }
            _spawnedObjects.Add(spawnedObject);
            _selectedMapObject = spawnedObject;
            NativeUtility.UserFriendlyPrint($"Created \"{modelName}\"");
            return(spawnedObject);
        }
 private void OnMapEditorModeExit()
 {
     _mapEditorCamera.Exit();
     _mapEditorMenu.IsVisible        = false;
     Game.Player.CanControlCharacter = true;
     NativeUtility.UserFriendlyPrint("Exited Map Editor");
 }
        private void ChangeRotationAxis()
        {
            var totalRotationAxisEntries = Enum.GetValues(typeof(TransformationAxis)).Length;

            _rotationAxis = (TransformationAxis)(((int)_rotationAxis + 1) % totalRotationAxisEntries);
            NativeUtility.UserFriendlyPrint($"Rotation Axis: {_rotationAxis}");
        }
        private void ChangeTransformationMode()
        {
            var totalTransformationModeEntries = Enum.GetValues(typeof(TransformationMode)).Length;

            _transformationMode = (TransformationMode)(((int)_transformationMode + 1) % totalTransformationModeEntries);
            NativeUtility.UserFriendlyPrint($"Transformation Mode: {_transformationMode}");
        }
Exemplo n.º 5
0
 public MapEditorScript()
 {
     Tick    += OnTick;
     KeyDown += _mapEditor.OnKeyDown;
     KeyUp   += _mapEditor.OnKeyUp;
     DllImportsUtility.AllocConsole();
     Console.WriteLine(LoadedText);
     NativeUtility.UserFriendlyPrint(LoadedText);
 }
        private void SaveMap()
        {
            const string mapFilePath     = "scripts/MapEditor/maps/test.map";
            var          serializableMap = new SerializableMap
            {
                MapName    = $"{Game.Player.Name}'s Map",
                AuthorName = Game.Player.Name,
                MapObjects = _spawnedObjects.Select(mapObject => new SerializableMapObject(mapObject)),
            };

            _mapPersistenceManager.SaveMap(mapFilePath, serializableMap);
            NativeUtility.UserFriendlyPrint($"Map saved to {mapFilePath}");
        }
        private void LoadMap()
        {
            const string mapFilePath     = "scripts/MapEditor/maps/test.map";
            var          serializableMap = _mapPersistenceManager.LoadMap(mapFilePath);

            foreach (var serializableMapObject in serializableMap.MapObjects)
            {
                SpawnObject(
                    serializableMapObject.ModelName,
                    serializableMapObject.Position,
                    serializableMapObject.Rotation
                    );
            }
            NativeUtility.UserFriendlyPrint($"Map loaded: \"{mapFilePath}\"");
        }
        private void DeleteSelectedObject()
        {
            if (_selectedMapObject == null)
            {
                return;
            }
            var selectedMapObjectIndex = _spawnedObjects.IndexOf(_selectedMapObject);

            _selectedMapObject.Entity.Delete();
            _spawnedObjects.Remove(_selectedMapObject);
            NativeUtility.UserFriendlyPrint($"Removed \"{_selectedMapObject.ModelName}\"");
            var totalSpawnedObjects = _spawnedObjects.Count;

            _selectedMapObject = totalSpawnedObjects > 0
                ? _spawnedObjects[(selectedMapObjectIndex - 1).Clamp(0, totalSpawnedObjects - 1)]
                : null;
        }