private static void LoadBuiltinAssets() { var npcSettings = NPCSettings.Load(); var prefabs = new[] { "Hatchback", "Sedan", "Jeep", "SUV", "BoxTruck", "SchoolBus", }; foreach (var entry in prefabs) { var go = npcSettings.NPCPrefabs.Find(x => x.name == entry) as GameObject; if (go == null) { // I was seeing this in editor a few times, where it was not able to find the builtin assets Debug.LogError($"Failed to load builtin {entry} " + (go == null?"null":go.ToString())); continue; } Map.NPCSizeType size = Map.NPCSizeType.MidSize; var meta = go.GetComponent <NPCMetaData>(); if (meta != null) { size = meta.SizeType; } else { Debug.LogWarning($"NPC {entry} missing meta info, setting default size"); } NPCVehicles.Add(entry, new NPCAssetData { Prefab = go, NPCType = size, Name = entry, AssetGuid = $"builtin-{entry}", }); } var behaviours = new [] { typeof(NPCLaneFollowBehaviour), typeof(NPCWaypointBehaviour), typeof(NPCManualBehaviour), }; foreach (var b in behaviours) { NPCBehaviours.Add(b.ToString(), b); } }
private bool SpawnNPC(NPCSettings settings, Vector3 spawnPosition) { if (settings != null && settings.npcPrefab) { GameObject npcGO = (GameObject)Instantiate(settings.npcPrefab, spawnPosition, Quaternion.identity); npcGO.name = settings.npcPrefab.name; NPC npc = npcGO.GetComponentInChildren <NPC>(); if (npc) { npc.npcManager = this; npc.settingsIndex = Array.IndexOf(this.npcSettings, settings); } //Terminatable terminatable = zombieGO.GetComponentInChildren<Terminatable>(); //if (terminatable) // terminatable.onDeath += delegate() { settings.zombiesToSpawn += 2; }; return(true); } return(false); }