2017-05-07 18:48:56 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Spawner : MonoBehaviour {
|
2017-05-08 05:20:29 +02:00
|
|
|
|
public SyncDB SyncDB;
|
2017-05-07 21:44:35 +02:00
|
|
|
|
public GameObject PCEntityPrefab;
|
|
|
|
|
public GameObject NPCEntityPrefab;
|
2017-05-07 18:48:56 +02:00
|
|
|
|
|
2017-05-07 21:44:35 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Spawns an entity and returns that entity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">Type.</param>
|
|
|
|
|
/// <param name="position">Position.</param>
|
2017-05-08 05:20:29 +02:00
|
|
|
|
public GameObject Spawn(EntityType type, Vector3 position, uint[] ids) {
|
2017-05-07 21:44:35 +02:00
|
|
|
|
GameObject Spawned = null;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case EntityType.PC:
|
|
|
|
|
Spawned = Instantiate(PCEntityPrefab, position, new Quaternion(), transform);
|
|
|
|
|
break;
|
|
|
|
|
case EntityType.NPC:
|
|
|
|
|
Spawned = Instantiate(NPCEntityPrefab, position, new Quaternion(), transform);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (Spawned != null) {
|
2017-05-08 05:20:29 +02:00
|
|
|
|
SyncDB.AddEntity(Spawned, ids);
|
2017-05-07 21:44:35 +02:00
|
|
|
|
}
|
|
|
|
|
return Spawned;
|
|
|
|
|
}
|
2017-05-07 18:48:56 +02:00
|
|
|
|
|
2017-05-07 21:44:35 +02:00
|
|
|
|
private void Start() {
|
2017-05-08 05:20:29 +02:00
|
|
|
|
Spawn(EntityType.PC, new Vector3(), new uint[]{ SyncDB.CreateID() });
|
2017-05-07 21:44:35 +02:00
|
|
|
|
}
|
2017-05-07 18:48:56 +02:00
|
|
|
|
|
2017-05-07 21:44:35 +02:00
|
|
|
|
private void Update() {
|
2017-05-08 01:29:12 +02:00
|
|
|
|
if (Input.GetButtonDown("Jump") && !Term.IsVisible()) {
|
2017-05-08 05:20:29 +02:00
|
|
|
|
Spawn(EntityType.NPC, new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-2f, 2f)), new uint[]{ SyncDB.CreateID() });
|
2017-05-07 21:44:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-07 18:48:56 +02:00
|
|
|
|
}
|