public void LoadSpawnsData(string data, List <SpawnEntityData> creaturesData) { string[] array = data.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries); int num = 0; while (true) { if (num < array.Length) { string[] array2 = array[num].Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (array2.Length < 4) { break; } SpawnEntityData spawnEntityData = new SpawnEntityData { TemplateName = array2[0], Position = new Vector3 { X = float.Parse(array2[1], CultureInfo.InvariantCulture), Y = float.Parse(array2[2], CultureInfo.InvariantCulture), Z = float.Parse(array2[3], CultureInfo.InvariantCulture) } }; if (array2.Length >= 5) { spawnEntityData.ConstantSpawn = bool.Parse(array2[4]); } creaturesData.Add(spawnEntityData); num++; continue; } return; } throw new InvalidOperationException("Invalid spawn data string."); }
public Entity SpawnEntity(SpawnEntityData data) { try { Entity entity = DatabaseManager.CreateEntity(base.Project, data.TemplateName, throwIfNotFound: true); entity.FindComponent <ComponentBody>(throwOnError: true).Position = data.Position; entity.FindComponent <ComponentBody>(throwOnError: true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.Float(0f, (float)Math.PI * 2f)); ComponentCreature componentCreature = entity.FindComponent <ComponentCreature>(); if (componentCreature != null) { componentCreature.ConstantSpawn = data.ConstantSpawn; } base.Project.AddEntity(entity); return(entity); } catch (Exception ex) { Log.Error($"Unable to spawn entity with template \"{data.TemplateName}\". Reason: {ex.Message}"); return(null); } }