public static void create(string type, SpawnData data) { if (ShipData.enemyShips.ContainsKey(type)) { Vector3 pos = new Vector3(Mathf.Sin(data.angle), Mathf.Cos(data.angle), 0) * data.distance; HexaShip enemy = HexaShip.createShip(ShipData.enemyShips[type].ship, pos); enemy.speed = data.speed; enemy.type = "enemy"; return; } GameObject prefab = Resources.Load(type) as GameObject; if (prefab == null) { return; } float delay = 0f; for (int i = 0; i < data.count; i++) { float angle = data.angle + (Random.Range(-10f, 10f) * Mathf.Deg2Rad); Vector3 pos = new Vector3(Mathf.Sin(angle), Mathf.Cos(angle), 0) * data.distance; Enemy enemy = (Instantiate(prefab, pos, Quaternion.identity) as GameObject).GetComponent <Enemy>(); enemy.delay = delay; enemy.data = data; delay += data.delay; } }
public ShipData() { JSONNode json; if (!initMainData) { initMainData = true; Sprite[] sprites; sprites = Resources.LoadAll <Sprite>("textures/devices"); for (int i = 0; i < sprites.Length; i++) { if (sprites[i].name.IndexOf("mainShip") > -1) { string s = sprites[i].name.Remove(0, 8); tiles.Add(int.Parse(s), sprites[i]); } if (sprites[i].name.IndexOf("pirateShip") > -1) { string s = sprites[i].name.Remove(0, 10); tilesPirate.Add(int.Parse(s), sprites[i]); } } tileResource = Resources.Load("Tile") as GameObject; json = JSONNode.Parse(Resources.Load <TextAsset>("Data/Devices").text)["devices"]; for (int i = 0; i < json.Count; i++) { int id = int.Parse(json.AsObject.keyAt(i)); devices.Add(id, new DeviceData(id, json[i])); } json = JSONNode.Parse(Resources.Load <TextAsset>("Data/MainShip").text); for (int i = 0; i < json["ship"].Count; i++) { ship.Add(new TilePoint(json["ship"][i]["x"].AsInt, json["ship"][i]["y"].AsInt), new DeviceData(json["ship"][i]["device"]["id"].AsInt, json["ship"][i]["device"])); } json = JSONNode.Parse(Resources.Load <TextAsset>("Data/Enemies").text)["enemies"]; for (int i = 0; i < json.Count; i++) { enemyShips.Add(json.AsObject.keyAt(i), new EnemyData(json[i])); } } levels = new Dictionary <int, LevelData>(); json = JSONNode.Parse(Resources.Load <TextAsset>("Data/EnemyWaves").text)["levels"]; for (int i = 0; i < json.Count; i++) { int id = int.Parse(json.AsObject.keyAt(i)); levels.Add(id, new LevelData(json[i])); } levelCount = levels.Count; json = JSONNode.Parse(Resources.Load <TextAsset>("Data/MainShip").text); knowledge = json["properties"]["knowledge"].AsInt; scraps = json["properties"]["scraps"].AsInt; scrapInventory = json["properties"]["scrapInventory"].AsInt; metals = json["properties"]["metals"].AsInt; metalPrice = json["properties"]["metalPrice"].AsInt; Gui.UpdateScraps(); Gui.UpdateMetals(); Gui.UpdateKnowledge(); mainShip = HexaShip.createShip(ship, Vector3.zero); loadLevel(1); }