public static GameObject Spawn(string prefab, Vector3 position, Quaternion rotation, int count) { GameObject gameObject = null; for (int i = 0; i < count; i++) { if (prefab == ":player_soldier") { gameObject = NetCull.InstantiateDynamic(uLink.NetworkPlayer.server, prefab, position, rotation); } else if (prefab.Contains("C130")) { gameObject = NetCull.InstantiateClassic(prefab, position, rotation, 0); } else { gameObject = NetCull.InstantiateStatic(prefab, position, rotation); gameObject.GetComponent <StructureComponent>(); DeployableObject component = gameObject.GetComponent <DeployableObject>(); if (component != null) { component.ownerID = 0uL; component.creatorID = 0uL; component.CacheCreator(); component.CreatorSet(); } } } return(gameObject); }
private object Spawn(string prefab, Vector3 location, Quaternion rotation, int rep) { prefab = prefab.Trim(); object obj2 = null; try { for (int i = 0; i < rep; i++) { if (prefab == ":player_soldier") { obj2 = NetCull.InstantiateDynamic(uLink.NetworkPlayer.server, prefab, location, rotation); } else if (prefab.Contains("C130")) { obj2 = NetCull.InstantiateClassic(prefab, location, rotation, 0); } else { GameObject obj3 = NetCull.InstantiateStatic(prefab, location, rotation); obj2 = obj3; StructureComponent component = obj3.GetComponent <StructureComponent>(); if (component != null) { obj2 = new Entity(component); } else if (obj3.GetComponent <LootableObject>()) { obj2 = new Entity(obj3.GetComponent <LootableObject>()); } else if (obj3.GetComponent <SupplyCrate>()) { obj2 = new Entity(obj3.GetComponent <SupplyCrate>()); } else if (obj3.GetComponent <ResourceTarget>()) { obj2 = new Entity(obj3.GetComponent <ResourceTarget>()); } else { DeployableObject obj4 = obj3.GetComponent <DeployableObject>(); if (obj4 != null) { obj4.ownerID = 0L; obj4.creatorID = 0L; obj4.CacheCreator(); obj4.CreatorSet(); obj2 = new Entity(obj4); } } } } } catch (Exception e) { Logger.LogError("Spawn error: " + e.ToString()); } return(obj2); }
/// <summary> /// Spawns a prefab at the given vector, rotation, N times. /// IMPORTANT: Returns the prefab as an Entity class. /// Entity class only supports specific types, like LootableObject /// SupplyCrate, ResourceTarget, DeployableObject, StructureComponent, /// StructureMaster. /// The other spawn methods are returning the gameobject instead. /// </summary> /// <param name="prefab"></param> /// <param name="location"></param> /// <param name="rotation"></param> /// <param name="rep"></param> /// <returns></returns> public Entity SpawnEntity(string prefab, Vector3 location, Quaternion rotation, int rep = 1) { Entity obj2 = null; prefab = prefab.Trim(); try { for (int i = 0; i < rep; i++) { GameObject obj3 = NetCull.InstantiateStatic(prefab, location, rotation); StructureComponent build = obj3.GetComponent <StructureComponent>(); if (build != null) { obj2 = new Entity(build); } else if (obj3.GetComponent <LootableObject>()) { obj2 = new Entity(obj3.GetComponent <LootableObject>()); } else if (obj3.GetComponent <SupplyCrate>()) { obj2 = new Entity(obj3.GetComponent <SupplyCrate>()); } else if (obj3.GetComponent <ResourceTarget>()) { obj2 = new Entity(obj3.GetComponent <ResourceTarget>()); } else { DeployableObject obj4 = obj3.GetComponent <DeployableObject>(); if (obj4 != null) { obj4.ownerID = 0L; obj4.creatorID = 0L; obj4.CacheCreator(); obj4.CreatorSet(); obj2 = new Entity(obj4); } } } } catch (Exception e) { Logger.LogError("SpawnEntity error: " + e.ToString()); } return(obj2); }
private object Spawn(string prefab, Vector3 location, Quaternion rotation, int rep) { Contract.Requires(!string.IsNullOrEmpty(prefab)); Contract.Requires(rep >= 0); object obj2 = null; for (int i = 0; i < rep; i++) { if (prefab == ":player_soldier") { obj2 = NetCull.InstantiateDynamic(uLink.NetworkPlayer.server, prefab, location, rotation); } else if (prefab.Contains("C130")) { obj2 = NetCull.InstantiateClassic(prefab, location, rotation, 0); } else { GameObject obj3 = NetCull.InstantiateStatic(prefab, location, rotation); obj2 = obj3; StructureComponent component = obj3.GetComponent <StructureComponent>(); if (component != null) { obj2 = new Entity(component); } else { DeployableObject obj4 = obj3.GetComponent <DeployableObject>(); if (obj4 != null) { obj4.ownerID = 0L; obj4.creatorID = 0L; obj4.CacheCreator(); obj4.CreatorSet(); obj2 = new Entity(obj4); } } } } return(obj2); }
private object Spawn(string prefab, Vector3 location, Quaternion rotation, int rep) { object result = null; for (int i = 0; i < rep; i++) { if (prefab == ":player_soldier") { result = NetCull.InstantiateDynamic(uLink.NetworkPlayer.server, prefab, location, rotation); } else if (prefab.Contains("C130")) { result = NetCull.InstantiateClassic(prefab, location, rotation, 0); } else { GameObject gameObject = NetCull.InstantiateStatic(prefab, location, rotation); result = gameObject; StructureComponent component = gameObject.GetComponent <StructureComponent>(); if (component != null) { result = new Entity(component); } else { DeployableObject component2 = gameObject.GetComponent <DeployableObject>(); if (component2 != null) { component2.ownerID = 0uL; component2.creatorID = 0uL; component2.CacheCreator(); component2.CreatorSet(); result = new Entity(component2); } } } } return(result); }