public void EditCraftFromBlueprint(CraftBlueprint bp) { ClearCurrCraft(); PlayerManager.instance.SetCraftInputEnabled(false); PlayerManager.instance.PlayerCraft = null; PlayerManager.instance.playerCraftWasNull = true; //To prevent spawn menu from opening again currCraft = CraftBlueprint.SpawnCraftFromBlueprint(bp, transform.position, transform.eulerAngles); SmoothFollowCam camComp = PlayerManager.instance.cam; camComp.followTarget = CamLookTarget; camComp.lookMode = SmoothFollowCam.LookMode.ORBIT; camComp.freelook_xrot = 25; camComp.freelook_yrot = 0; camComp.rotation = 45; camComp.zoom = 1f; camRot = Vector2.zero; foreach (PhysPart part in currCraft.GetComponentsInChildren <PhysPart>()) { MakePartEditorFriendly(part); } currCraft.rb.isKinematic = true; currCraft.enabled = false; }
void FixedUpdate() { if (debug_CraftToSave != null) { debug_CraftBlueprint = CraftBlueprint.GetBlueprintFromCraft(debug_CraftToSave); debug_CraftToSave = null; } if (debug_CraftBlueprint != null) { if (debug_SaveCraftBlueprint) { debug_SaveCraftBlueprint = false; CraftBlueprint.SaveToFile(debug_CraftBlueprint); } if (debug_LoadCraftBlueprint) { debug_LoadCraftBlueprint = false; debug_CraftBlueprint = CraftBlueprint.LoadFromFileByName(debug_LoadCraftBlueprintFileName); } if (debug_SpawnCraftBlueprint) { CraftBlueprint.SpawnCraftFromBlueprint(debug_CraftBlueprint, Vector3.up * 10f, Vector3.zero); debug_SpawnCraftBlueprint = false; } if (debug_ForgetCraftBlueprint) { debug_ForgetCraftBlueprint = false; debug_CraftBlueprint = null; } } }
public void UpdateTransformStructureIfDisconnected() { MultipartPhysBody oldParent = GetBody(); if (!CheckConnectedToOrigin()) { PhysPart[] ConnectedParts = PartConnection.GetConnectedParts(this); Transform newDebrisCraft = new GameObject(oldParent.name + " debris").transform; newDebrisCraft.SetParent(GameplayManager.GameplayTransform); Transform newParent = new GameObject("Body").transform; newParent.SetParent(newDebrisCraft); newParent.transform.position = newDebrisCraft.transform.position = transform.position; newParent.transform.rotation = newDebrisCraft.transform.rotation = transform.rotation; foreach (PhysPart p in ConnectedParts) { p.transform.SetParent(newParent); } newDebrisCraft.gameObject.AddComponent <Rigidbody>().velocity = oldParent.rb.GetPointVelocity(transform.TransformPoint(CoMoffset)); newDebrisCraft.gameObject.AddComponent <MultipartPhysBody>(); oldParent.FullRecalcPhysics(); foreach (PhysPart p in ConnectedParts) { foreach (PartComponent c in p.components) { c.OnBodyChanged(); } } } }
public void OnPlayerCraftSpawned(MultipartPhysBody craft) { //disable player input on previous craft SetCraftInputEnabled(false); //assign current craft and make camera follow it PlayerCraft = craft; cam.followTarget = null; camSearchTimer = 0f; //enable player input on current craft SetCraftInputEnabled(true); CraftEditor.instance.ClearCurrCraft(); }
public CraftBlueprint GetBlueprintFromCurrCraft() { //ignore held part if (currPart != null) { currPart.transform.SetParent(null); currPart.DestroyPartLite(); } MultipartPhysBody physBody = currCraft.GetComponent <MultipartPhysBody>(); physBody.UpdatePhysParts(true); foreach (PhysPart p in physBody.Parts) { p.connections = CalculatePartConnections(p); } return(CraftBlueprint.GetBlueprintFromCraft(physBody)); }
public static CraftBlueprint GetBlueprintFromCraft(MultipartPhysBody craft) { CraftBlueprint bp = new CraftBlueprint(); bp.craftName = craft.name; //Generate parts list int i = 0; foreach (PhysPart part in craft.Parts) { //save part info PartBlueprint p = part.GetBlueprint(); //Check if this is the origin part if originPartIndex isn't assigned yet. If it is the origin part, assign originPartIndex to reference it. if (bp.originPartIndex == -1 && part == craft.originPart) { bp.originPartIndex = i; } bp.parts.Add(p); i++; } //Generate part connections list now that we have all the parts. //We can use indices interchangably between the physical craft and the blueprint because the parts were added in the same order. int partIndex = 0; foreach (PhysPart part in craft.Parts) { foreach (PartConnection connection in part.connections) { ConnectionBlueprint c = new ConnectionBlueprint(); c.fromIndex = partIndex; //set fromIndex to reference the part we are currently processing int toIndex = craft.Parts.IndexOf(connection.toPart); c.toIndex = toIndex; bp.connections.Add(c); } partIndex++; } return(bp); }
public void DestroyPart(float carryStress = 0f, bool useFX = true, DestructionType destructionType = DestructionType.GENERIC) { if (useFX) { bool fallbackToGeneric = false; switch (destructionType) { case DestructionType.GENERIC: fallbackToGeneric = true; break; default: fallbackToGeneric = true; break; } if (fallbackToGeneric) { if (DestroyGenericSounds) { DestroyGenericSounds.PlayRandomSoundAtPosition(transform.position); } if (DestroyGenericParticles) { DestroyGenericParticles.PlayRandomEffectAtPosition(transform.position, transform.eulerAngles, pfxScale); } } } while (connections.Count > 0) { DisconnectPart(connections[0].toPart, carryStress); } MultipartPhysBody body = GetBody(); body.StartCoroutine(body.FullRecalcPhysNextFixedUpdate()); Destroy(gameObject); }
public static MultipartPhysBody SpawnCraftFromBlueprint(CraftBlueprint bp, Vector3 position, Vector3 rotation) { //Set up transform structure before adding any parts etc. Transform t = new GameObject(bp.craftName).transform; //Main craft t.position = position; t.eulerAngles = rotation; t.SetParent(GameplayManager.GameplayTransform); Transform body = new GameObject("Body").transform; //Body (part holder) body.SetParent(t); body.localPosition = body.localEulerAngles = Vector3.zero; //Set up components t.gameObject.AddComponent <Rigidbody>(); MultipartPhysBody craft = t.gameObject.AddComponent <MultipartPhysBody>(); //Set up parts List <PhysPart> spawnedParts = new List <PhysPart>(); foreach (PartBlueprint p in bp.parts) { PhysPart part = p.SpawnPart(body); spawnedParts.Add(part); } //Set up part connections foreach (ConnectionBlueprint c in bp.connections) { spawnedParts[c.fromIndex].connections.Add(new PartConnection(spawnedParts[c.toIndex], spawnedParts[c.fromIndex])); } //Disable input until it gets overriden by a system which is responsible for this (player spawning, AI spawning, etc.) craft.SetBalancerInputActive(false); return(craft); }
/// <summary> /// Called when craft breaks into multiple pieces for example /// </summary> public virtual void OnBodyChanged() { body = part.GetBody(); }
public void SpawnCraftFromBlueprint(CraftBlueprint bp) { MultipartPhysBody craft = CraftBlueprint.SpawnCraftFromBlueprint(bp, SpawnPoint.position, SpawnPoint.eulerAngles); PlayerManager.instance.OnPlayerCraftSpawned(craft); }