public IEnumerator _Finds_All_Unconnected_Adaptors() { GameObject testGameObject = new GameObject(); testGameObject.name = "TESTGAMEOBJECT"; GameObject testGameObject1 = new GameObject(); testGameObject1.name = "TESTGAMEOBJECT"; WeaponPart testPart = testGameObject1.AddComponent <WeaponPart>(); Adaptor adaptorLoadingMechanism = testGameObject1.AddComponent <Adaptor>(); Adaptor adaptorLoadingMechnaism2 = testGameObject1.AddComponent <Adaptor>(); testPart.Adaptors = new List <Adaptor> { adaptorLoadingMechanism, adaptorLoadingMechnaism2 }; testPart.TestSetup("NotSearchedPart", WeaponPartType.Trigger, null); WeaponStructure weaponStructure = testGameObject.AddComponent <WeaponStructure>(); weaponStructure.trigger = testPart; testGameObject1.transform.parent = testGameObject.transform; yield return(null); List <Adaptor> result = weaponStructure.FindUnconnectedAdaptorsRecursively(); Assert.Contains(adaptorLoadingMechanism, result); Assert.Contains(adaptorLoadingMechnaism2, result); Assert.AreEqual(2, result.Count); }
public IEnumerator _Replaces_WeaponPart_Correctly() { var testData = createTestWeaponStructure(); yield return(null); WeaponPart replacedPart = (WeaponPart)testData[1]; WeaponStructure weaponStructure = (WeaponStructure)testData[0]; GameObject testGameObject = new GameObject(); testGameObject.name = "TESTGAMEOBJECT"; WeaponPart replacementPart = testGameObject.AddComponent <WeaponPart>(); replacementPart.Adaptors = new List <Adaptor>(); replacementPart.TestSetup("ReplacementPart", WeaponPartType.FiringMechanism, null); WeaponPart parent = replacedPart.Parent; weaponStructure.ReplaceWeaponPart(replacedPart, replacementPart); yield return(null); Assert.AreSame(replacementPart, parent.Children[0]); Assert.Contains(replacementPart, parent.Children); Assert.AreSame(replacementPart.transform.parent, parent.Adaptors[0].ChildPartTransform); }
internal void Clean() { for (int i = 0; i < Weapons.Length; i++) { Weapons[i] = null; } Parts.Clean(null); Structure = null; State = PlatformState.Fresh; Comp = null; }
internal void Setup(WeaponComponent comp) { if (!comp.Session.WeaponPlatforms.ContainsKey(comp.MyCube.BlockDefinition.Id)) { Log.Line($"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) was not found in platform setup, I am crashing now Dave."); return; } Structure = comp.Session.WeaponPlatforms[comp.MyCube.BlockDefinition.Id]; Comp = comp; if (Weapons.Length != Structure.MuzzlePartNames.Length) { Array.Resize(ref Weapons, Structure.MuzzlePartNames.Length); } }
public IEnumerator _Finds_WeaponPart_In_Tree_Or_Returns_Null() { var testData = createTestWeaponStructure(); yield return(null); WeaponStructure weaponStructure = (WeaponStructure)testData[0]; WeaponPart searchedPart = (WeaponPart)testData[1]; WeaponPart foundPart = weaponStructure.FindWeaponPartRecursive(x => x == searchedPart); WeaponPart notFoundPart = weaponStructure.FindWeaponPartRecursive(x => x.PartName == "LDSKFLSDLSDLLL"); WeaponPart foundFromAlternateStart = weaponStructure.FindWeaponPartRecursive(x => x == searchedPart, foundPart.Parent); yield return(new WaitForSeconds(1)); Assert.AreSame(searchedPart, foundPart); Assert.AreEqual(null, notFoundPart); Assert.AreSame(searchedPart, foundFromAlternateStart); }
public IEnumerator _Removes_Part_Correctly() { var testData = createTestWeaponStructure(); yield return(null); WeaponPart removedPart = (WeaponPart)testData[1]; WeaponStructure weaponStructure = (WeaponStructure)testData[0]; WeaponPart parent = removedPart.Parent; removedPart.gameObject.name = "REMOVEDPART"; weaponStructure.RemoveWeaponPart(removedPart); yield return(null); Assert.That(parent.Children, Has.No.Member(removedPart)); var go = GameObject.Find("REMOVEDPART"); Assert.IsNull(go); }
public IEnumerator _Finds_All_Parts_Of_Type_Or_Returns_Empty_List() { var testData = createTestWeaponStructure(); yield return(null); WeaponStructure weaponStructure = (WeaponStructure)testData[0]; WeaponPart loadingMechanism = (WeaponPart)testData[3]; WeaponPart loadingMechanism2 = (WeaponPart)testData[4]; var result = weaponStructure.FindAllWeaponPartsOfTypeRecursively(WeaponPartType.LoadingMechanism); Assert.Contains(loadingMechanism, result); Assert.Contains(loadingMechanism2, result); Assert.AreEqual(result.Count, 2); result = weaponStructure.FindAllWeaponPartsOfTypeRecursively(WeaponPartType.EnergyContainer); Assert.AreEqual(result.Count, 0); }
public IEnumerator _Replaces_TopLevel_WeaponPart_Correctly() { var testData = createTestWeaponStructure(); yield return(null); WeaponPart replacedPart = (WeaponPart)testData[2]; WeaponStructure weaponStructure = (WeaponStructure)testData[0]; GameObject testGameObject = new GameObject(); testGameObject.name = "TESTGAMEOBJECT"; WeaponPart replacementPart = testGameObject.AddComponent <WeaponPart>(); Adaptor adaptorLoadingMechanism = testGameObject.AddComponent <Adaptor>(); Adaptor adaptorLoadingMechnaism2 = testGameObject.AddComponent <Adaptor>(); adaptorLoadingMechanism.ChildPartTransform = adaptorLoadingMechanism.transform; adaptorLoadingMechnaism2.ChildPartTransform = adaptorLoadingMechnaism2.transform; adaptorLoadingMechanism.WeaponTypeOfAdaptor = WeaponPartType.LoadingMechanism; adaptorLoadingMechnaism2.WeaponTypeOfAdaptor = WeaponPartType.LoadingMechanism; replacementPart.Adaptors = new List <Adaptor> { adaptorLoadingMechanism, adaptorLoadingMechnaism2 }; replacementPart.TestSetup("ReplacementPart", WeaponPartType.Trigger, null); WeaponPart parent = replacedPart.Parent; weaponStructure.ReplaceWeaponPart(replacedPart, replacementPart); yield return(null); Assert.AreSame(((WeaponPart)testData[3]).Parent, replacementPart); //child's parent is replaced correctly Assert.Contains((WeaponPart)testData[3], replacementPart.Children); Assert.AreSame(((WeaponPart)testData[4]).Parent, replacementPart); //child's parent is replaced correctly Assert.Contains((WeaponPart)testData[4], replacementPart.Children); }
public IEnumerator _Adds_Part_To_Adaptor_Correctly() { var testData = createTestWeaponStructure(); yield return(null); WeaponStructure weaponStructure = (WeaponStructure)testData[0]; WeaponPart firingMechanism = (WeaponPart)testData[1]; Adaptor adaptor = firingMechanism.Adaptors[0]; GameObject testGameObject = new GameObject(); testGameObject.name = "TESTGAMEOBJECT"; WeaponPart newPart = testGameObject.AddComponent <WeaponPart>(); newPart.Adaptors = new List <Adaptor>(); newPart.TestSetup("NewPart", WeaponPartType.Barrel, null); weaponStructure.AddWeaponPart(adaptor, newPart); Assert.Contains(newPart, firingMechanism.Children); Assert.AreSame(newPart.transform.parent, adaptor.ChildPartTransform); }
internal void Init() { if (Inited) { return; } Inited = true; Log.Init("debugdevelop.log"); Log.Line($"Logging Started"); foreach (var x in WeaponDefinitions) { foreach (var ammo in x.Ammos) { var ae = ammo.AreaEffect; var areaRadius = ae.AreaEffectRadius; var detonateRadius = ae.Detonation.DetonationRadius; var fragments = ammo.Shrapnel.Fragments > 0 ? ammo.Shrapnel.Fragments : 1; if (areaRadius > 0) { if (!LargeBlockSphereDb.ContainsKey(ModRadius(areaRadius, true))) { GenerateBlockSphere(MyCubeSize.Large, ModRadius(areaRadius, true)); } if (!LargeBlockSphereDb.ContainsKey(ModRadius(areaRadius / fragments, true))) { GenerateBlockSphere(MyCubeSize.Large, ModRadius(areaRadius / fragments, true)); } if (!SmallBlockSphereDb.ContainsKey(ModRadius(areaRadius, false))) { GenerateBlockSphere(MyCubeSize.Small, ModRadius(areaRadius, false)); } if (!SmallBlockSphereDb.ContainsKey(ModRadius(areaRadius / fragments, false))) { GenerateBlockSphere(MyCubeSize.Small, ModRadius(areaRadius / fragments, false)); } } if (detonateRadius > 0) { if (!LargeBlockSphereDb.ContainsKey(ModRadius(detonateRadius, true))) { GenerateBlockSphere(MyCubeSize.Large, ModRadius(detonateRadius, true)); } if (!LargeBlockSphereDb.ContainsKey(ModRadius(detonateRadius / fragments, true))) { GenerateBlockSphere(MyCubeSize.Large, ModRadius(detonateRadius / fragments, true)); } if (!SmallBlockSphereDb.ContainsKey(ModRadius(detonateRadius, false))) { GenerateBlockSphere(MyCubeSize.Small, ModRadius(detonateRadius, false)); } if (!SmallBlockSphereDb.ContainsKey(ModRadius(detonateRadius / fragments, false))) { GenerateBlockSphere(MyCubeSize.Small, ModRadius(detonateRadius / fragments, false)); } } } } foreach (var weaponDef in WeaponDefinitions) { foreach (var mount in weaponDef.Assignments.MountPoints) { var subTypeId = mount.SubtypeId; var muzzlePartId = mount.MuzzlePartId; var azimuthPartId = mount.AzimuthPartId; var elevationPartId = mount.ElevationPartId; var extraInfo = new MyTuple <string, string, string> { Item1 = weaponDef.HardPoint.WeaponName, Item2 = azimuthPartId, Item3 = elevationPartId }; if (!_turretDefinitions.ContainsKey(subTypeId)) { foreach (var def in AllDefinitions) { MyDefinitionId defid; if (def.Id.SubtypeName == subTypeId || (ReplaceVanilla && VanillaCoreIds.TryGetValue(MyStringHash.GetOrCompute(subTypeId), out defid) && defid == def.Id)) { var gunDef = def as MyLargeTurretBaseDefinition; if (gunDef != null) { var blockDefs = weaponDef.HardPoint.HardWare; gunDef.MinAzimuthDegrees = blockDefs.MinAzimuth; gunDef.MaxAzimuthDegrees = blockDefs.MaxAzimuth; gunDef.MinElevationDegrees = blockDefs.MinElevation; gunDef.MaxElevationDegrees = blockDefs.MaxElevation; gunDef.RotationSpeed = blockDefs.RotateRate / 60; gunDef.ElevationSpeed = blockDefs.ElevateRate / 60; gunDef.AiEnabled = false; } WeaponCoreBlockDefs[subTypeId] = def.Id; } } _turretDefinitions[subTypeId] = new Dictionary <string, MyTuple <string, string, string> > { [muzzlePartId] = extraInfo }; _subTypeIdToWeaponDefs[subTypeId] = new List <WeaponDefinition> { weaponDef }; } else { _turretDefinitions[subTypeId][muzzlePartId] = extraInfo; _subTypeIdToWeaponDefs[subTypeId].Add(weaponDef); } } } foreach (var tDef in _turretDefinitions) { var subTypeIdHash = MyStringHash.GetOrCompute(tDef.Key); SubTypeIdHashMap[tDef.Key] = subTypeIdHash; var weapons = _subTypeIdToWeaponDefs[tDef.Key]; var hasTurret = false; foreach (var wepDef in weapons) { if (wepDef.HardPoint.Ai.TurretAttached) { hasTurret = true; } } MyDefinitionId defId; if (WeaponCoreBlockDefs.TryGetValue(tDef.Key, out defId)) { if (hasTurret) { WeaponCoreTurretBlockDefs.Add(defId); } else { WeaponCoreFixedBlockDefs.Add(defId); } } WeaponPlatforms[subTypeIdHash] = new WeaponStructure(this, tDef, weapons); } MyAPIGateway.TerminalControls.CustomControlGetter += CustomControlHandler; }
internal void Init() { if (Inited) { return; } Inited = true; Log.Init("debug", this); Log.Init("perf", this, false); Log.Init("stats", this, false); Log.Init("net", this, false); Log.Init("report", this, false); Log.Init("combat", this, false); MpActive = MyAPIGateway.Multiplayer.MultiplayerActive; IsServer = MyAPIGateway.Multiplayer.IsServer; DedicatedServer = MyAPIGateway.Utilities.IsDedicated; IsCreative = MyAPIGateway.Session.CreativeMode; IsClient = !IsServer && !DedicatedServer && MpActive; HandlesInput = !IsServer || IsServer && !DedicatedServer; IsHost = IsServer && !DedicatedServer && MpActive; MpServer = IsHost || DedicatedServer; foreach (var x in WeaponDefinitions) { foreach (var ammo in x.Ammos) { var ae = ammo.AreaEffect; var areaRadius = ae.Base.Radius > 0 ? ae.Base.Radius : ae.AreaEffectRadius; var detonateRadius = ae.Detonation.DetonationRadius; var fragments = ammo.Shrapnel.Fragments > 0 ? ammo.Shrapnel.Fragments : 1; if (areaRadius > 0) { if (!LargeBlockSphereDb.ContainsKey(ModRadius(areaRadius, true))) { GenerateBlockSphere(MyCubeSize.Large, ModRadius(areaRadius, true)); } if (!LargeBlockSphereDb.ContainsKey(ModRadius(areaRadius / fragments, true))) { GenerateBlockSphere(MyCubeSize.Large, ModRadius(areaRadius / fragments, true)); } if (!SmallBlockSphereDb.ContainsKey(ModRadius(areaRadius, false))) { GenerateBlockSphere(MyCubeSize.Small, ModRadius(areaRadius, false)); } if (!SmallBlockSphereDb.ContainsKey(ModRadius(areaRadius / fragments, false))) { GenerateBlockSphere(MyCubeSize.Small, ModRadius(areaRadius / fragments, false)); } } if (detonateRadius > 0) { if (!LargeBlockSphereDb.ContainsKey(ModRadius(detonateRadius, true))) { GenerateBlockSphere(MyCubeSize.Large, ModRadius(detonateRadius, true)); } if (!LargeBlockSphereDb.ContainsKey(ModRadius(detonateRadius / fragments, true))) { GenerateBlockSphere(MyCubeSize.Large, ModRadius(detonateRadius / fragments, true)); } if (!SmallBlockSphereDb.ContainsKey(ModRadius(detonateRadius, false))) { GenerateBlockSphere(MyCubeSize.Small, ModRadius(detonateRadius, false)); } if (!SmallBlockSphereDb.ContainsKey(ModRadius(detonateRadius / fragments, false))) { GenerateBlockSphere(MyCubeSize.Small, ModRadius(detonateRadius / fragments, false)); } } } } foreach (var weaponDef in WeaponDefinitions) { foreach (var mount in weaponDef.Assignments.MountPoints) { var subTypeId = mount.SubtypeId; var muzzlePartId = mount.MuzzlePartId; var azimuthPartId = mount.AzimuthPartId; var elevationPartId = mount.ElevationPartId; var extraInfo = new MyTuple <string, string, string> { Item1 = weaponDef.HardPoint.WeaponName, Item2 = azimuthPartId, Item3 = elevationPartId }; if (!_turretDefinitions.ContainsKey(subTypeId)) { _turretDefinitions[subTypeId] = new Dictionary <string, MyTuple <string, string, string> > { [muzzlePartId] = extraInfo }; _subTypeIdToWeaponDefs[subTypeId] = new List <WeaponDefinition> { weaponDef }; } else { _turretDefinitions[subTypeId][muzzlePartId] = extraInfo; _subTypeIdToWeaponDefs[subTypeId].Add(weaponDef); } } } foreach (var tDef in _turretDefinitions) { var subTypeIdHash = MyStringHash.GetOrCompute(tDef.Key); SubTypeIdHashMap[tDef.Key] = subTypeIdHash; WeaponAreaRestriction areaRestriction; if (this.WeaponAreaRestrictions.ContainsKey(subTypeIdHash)) { areaRestriction = this.WeaponAreaRestrictions[subTypeIdHash]; } else { areaRestriction = new WeaponAreaRestriction(); WeaponAreaRestrictions[subTypeIdHash] = areaRestriction; } var weapons = _subTypeIdToWeaponDefs[tDef.Key]; var hasTurret = false; var firstWeapon = true; string modPath = null; foreach (var wepDef in weapons) { try { modPath = wepDef.ModPath; if (wepDef.HardPoint.Ai.TurretAttached) { hasTurret = true; } if (wepDef.HardPoint.HardWare.Armor != WeaponDefinition.HardPointDef.HardwareDef.ArmorState.IsWeapon) { DamageHandler = true; } foreach (var def in AllDefinitions) { MyDefinitionId defid; var matchingDef = def.Id.SubtypeName == tDef.Key || (ReplaceVanilla && VanillaCoreIds.TryGetValue(MyStringHash.GetOrCompute(tDef.Key), out defid) && defid == def.Id); if (matchingDef) { if (wepDef.HardPoint.Other.RestrictionRadius > 0) { if (wepDef.HardPoint.Other.CheckForAnyWeapon && !areaRestriction.CheckForAnyWeapon) { areaRestriction.CheckForAnyWeapon = true; } if (wepDef.HardPoint.Other.CheckInflatedBox) { if (areaRestriction.RestrictionBoxInflation < wepDef.HardPoint.Other.RestrictionRadius) { areaRestriction.RestrictionBoxInflation = wepDef.HardPoint.Other.RestrictionRadius; } } else { if (areaRestriction.RestrictionRadius < wepDef.HardPoint.Other.RestrictionRadius) { areaRestriction.RestrictionRadius = wepDef.HardPoint.Other.RestrictionRadius; } } } WeaponCoreBlockDefs[tDef.Key] = def.Id; var designator = false; for (int i = 0; i < wepDef.Assignments.MountPoints.Length; i++) { if (wepDef.Assignments.MountPoints[i].MuzzlePartId == "Designator") { designator = true; break; } } if (!designator) { var wepBlockDef = def as MyWeaponBlockDefinition; if (wepBlockDef != null) { if (firstWeapon) { wepBlockDef.InventoryMaxVolume = 0; } wepBlockDef.InventoryMaxVolume += wepDef.HardPoint.HardWare.InventorySize; var weaponCsDef = MyDefinitionManager.Static.GetWeaponDefinition(wepBlockDef.WeaponDefinitionId); if (weaponCsDef.WeaponAmmoDatas[0] == null) { Log.Line($"WeaponAmmoData is null, check the Ammo definition for {tDef.Key}"); } weaponCsDef.WeaponAmmoDatas[0].RateOfFire = wepDef.HardPoint.Loading.RateOfFire; weaponCsDef.WeaponAmmoDatas[0].ShotsInBurst = wepDef.HardPoint.Loading.ShotsInBurst; } else if (def is MyConveyorSorterDefinition) { if (firstWeapon) { ((MyConveyorSorterDefinition)def).InventorySize = Vector3.Zero; } var size = Math.Pow(wepDef.HardPoint.HardWare.InventorySize, 1d / 3d); ((MyConveyorSorterDefinition)def).InventorySize += new Vector3(size, size, size); } firstWeapon = false; for (int i = 0; i < wepDef.Assignments.MountPoints.Length; i++) { var az = !string.IsNullOrEmpty(wepDef.Assignments.MountPoints[i].AzimuthPartId) ? wepDef.Assignments.MountPoints[i].AzimuthPartId : "MissileTurretBase1"; var el = !string.IsNullOrEmpty(wepDef.Assignments.MountPoints[i].ElevationPartId) ? wepDef.Assignments.MountPoints[i].ElevationPartId : "MissileTurretBarrels"; if (def is MyLargeTurretBaseDefinition && (VanillaSubpartNames.Contains(az) || VanillaSubpartNames.Contains(el))) { var gunDef = (MyLargeTurretBaseDefinition)def; var blockDefs = wepDef.HardPoint.HardWare; gunDef.MinAzimuthDegrees = blockDefs.MinAzimuth; gunDef.MaxAzimuthDegrees = blockDefs.MaxAzimuth; gunDef.MinElevationDegrees = blockDefs.MinElevation; gunDef.MaxElevationDegrees = blockDefs.MaxElevation; gunDef.RotationSpeed = blockDefs.RotateRate / 60; gunDef.ElevationSpeed = blockDefs.ElevateRate / 60; gunDef.AiEnabled = false; gunDef.IdleRotation = false; } var cubeDef = def as MyCubeBlockDefinition; if (cubeDef != null) { for (int x = 0; x < wepDef.Assignments.MountPoints.Length; x++) { var mp = wepDef.Assignments.MountPoints[x]; if (mp.SubtypeId == def.Id.SubtypeName) { cubeDef.GeneralDamageMultiplier = mp.DurabilityMod > 0 ? mp.DurabilityMod : cubeDef.CubeSize == MyCubeSize.Large ? 0.25f : 0.05f; break; } } } } } } } } catch (Exception e) { Log.Line($"Failed to load {wepDef.HardPoint.WeaponName}"); } } MyDefinitionId defId; if (WeaponCoreBlockDefs.TryGetValue(tDef.Key, out defId)) { if (hasTurret) { WeaponCoreTurretBlockDefs.Add(defId); } else { WeaponCoreFixedBlockDefs.Add(defId); } } WeaponPlatforms[defId] = new WeaponStructure(this, tDef, weapons, modPath); } MyAPIGateway.TerminalControls.CustomControlGetter += CustomControlHandler; }
public Object[] createTestWeaponStructure() { GameObject testGameObject = new GameObject(); testGameObject.name = "TESTGAMEOBJECT"; GameObject testGameObject1 = new GameObject(); testGameObject1.name = "TESTGAMEOBJECT"; GameObject testGameObject2 = new GameObject(); testGameObject2.name = "TESTGAMEOBJECT"; GameObject testGameObject3 = new GameObject(); testGameObject3.name = "TESTGAMEOBJECT"; GameObject testGameObject4 = new GameObject(); testGameObject4.name = "TESTGAMEOBJECT"; WeaponPart notSearchedPart = testGameObject1.AddComponent <WeaponPart>(); WeaponPart notSearchedPart2 = testGameObject2.AddComponent <WeaponPart>(); WeaponPart notSearchedPart3 = testGameObject3.AddComponent <WeaponPart>(); WeaponPart searchedPart = testGameObject4.AddComponent <WeaponPart>(); Adaptor adaptorLoadingMechanism = testGameObject1.AddComponent <Adaptor>(); Adaptor adaptorLoadingMechnaism2 = testGameObject1.AddComponent <Adaptor>(); Adaptor adaptorFiringMechanism = testGameObject2.AddComponent <Adaptor>(); Adaptor adaptorBarrel = testGameObject4.AddComponent <Adaptor>(); adaptorFiringMechanism.ChildPartTransform = adaptorFiringMechanism.transform; adaptorLoadingMechanism.ChildPartTransform = adaptorLoadingMechanism.transform; adaptorLoadingMechnaism2.ChildPartTransform = adaptorLoadingMechanism.transform; adaptorBarrel.ChildPartTransform = adaptorBarrel.transform; adaptorFiringMechanism.WeaponTypeOfAdaptor = WeaponPartType.FiringMechanism; adaptorLoadingMechanism.WeaponTypeOfAdaptor = WeaponPartType.LoadingMechanism; adaptorLoadingMechnaism2.WeaponTypeOfAdaptor = WeaponPartType.LoadingMechanism; adaptorBarrel.WeaponTypeOfAdaptor = WeaponPartType.Barrel; notSearchedPart.Adaptors = new List <Adaptor> { adaptorLoadingMechanism, adaptorLoadingMechnaism2 }; notSearchedPart2.Adaptors = new List <Adaptor> { adaptorFiringMechanism }; searchedPart.Adaptors = new List <Adaptor> { adaptorBarrel }; notSearchedPart.TestSetup("NotSearchedPart", WeaponPartType.Trigger, null); notSearchedPart2.TestSetup("NotSearchedPart2", WeaponPartType.LoadingMechanism, notSearchedPart); notSearchedPart3.TestSetup("NotSearchedPart3", WeaponPartType.LoadingMechanism, notSearchedPart); searchedPart.TestSetup("searchedPart", WeaponPartType.FiringMechanism, notSearchedPart2); notSearchedPart.AddChild(notSearchedPart2); notSearchedPart.AddChild(notSearchedPart3); notSearchedPart2.AddChild(searchedPart); notSearchedPart.ConnectChildToAdaptor(adaptorLoadingMechanism, notSearchedPart2); notSearchedPart.ConnectChildToAdaptor(adaptorLoadingMechnaism2, notSearchedPart3); notSearchedPart2.ConnectChildToAdaptor(adaptorFiringMechanism, searchedPart); WeaponStructure weaponStructure = testGameObject.AddComponent <WeaponStructure>(); weaponStructure.trigger = notSearchedPart; testGameObject1.transform.parent = testGameObject.transform; testGameObject2.transform.parent = testGameObject1.transform; testGameObject3.transform.parent = testGameObject1.transform; testGameObject4.transform.parent = testGameObject2.transform; Object[] result = new Object[5]; result[0] = weaponStructure; result[1] = searchedPart; result[2] = notSearchedPart; result[3] = notSearchedPart2; result[4] = notSearchedPart3; return(result); }