private void DeconstructionBegin(DeconstructionBeginEvent begin) { GameObject deconstructing = NitroxIdentifier.RequireObjectFrom(begin.PieceId); Constructable constructable = deconstructing.RequireComponent <Constructable>(); constructable.SetState(false, false); }
private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted) { Log.Info("Constructed completed " + constructionCompleted.PieceId); GameObject constructing = NitroxIdentifier.RequireObjectFrom(constructionCompleted.PieceId); ConstructableBase constructableBase = constructing.GetComponent <ConstructableBase>(); // For bases, we need to transfer the GUID off of the ghost and onto the finished piece. // Furniture just re-uses the same piece. if (constructableBase) { constructableBase.constructedAmount = 1f; constructableBase.SetState(true, true); Optional <object> opBasePiece = TransientLocalObjectManager.Get(TransientObjectType.LATEST_CONSTRUCTED_BASE_PIECE); GameObject finishedPiece = (GameObject)opBasePiece.Get(); UnityEngine.Object.Destroy(constructableBase.gameObject); NitroxIdentifier.SetNewId(finishedPiece, constructionCompleted.PieceId); } else { Constructable constructable = constructing.GetComponent <Constructable>(); constructable.constructedAmount = 1f; constructable.SetState(true, true); } if (constructionCompleted.BaseId != null && NitroxIdentifier.GetObjectFrom(constructionCompleted.BaseId).IsEmpty()) { Log.Info("Creating base: " + constructionCompleted.BaseId); ConfigureNewlyConstructedBase(constructionCompleted.BaseId); } }
private void ConstructionAmountChanged(ConstructionAmountChangedEvent amountChanged) { Log.Info("Processing ConstructionAmountChanged " + amountChanged.Id + " " + amountChanged.Amount); GameObject constructing = NitroxIdentifier.RequireObjectFrom(amountChanged.Id); BaseDeconstructable baseDeconstructable = constructing.GetComponent <BaseDeconstructable>(); // Bases don't send a deconstruct being packet. Instead, we just make sure // that if we are changing the amount that we set it into deconstruction mode // if it still has a BaseDeconstructable object on it. if (baseDeconstructable != null) { baseDeconstructable.Deconstruct(); // After we have begun the deconstructing for a base piece, we need to transfer the id Optional <object> opGhost = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE); if (opGhost.IsPresent()) { GameObject ghost = (GameObject)opGhost.Get(); UnityEngine.Object.Destroy(constructing); NitroxIdentifier.SetNewId(ghost, amountChanged.Id); } else { Log.Info("Could not find newly created ghost to set deconstructed id "); } } else { Constructable constructable = constructing.GetComponentInChildren <Constructable>(); constructable.constructedAmount = amountChanged.Amount; using (packetSender.Suppress <ConstructionAmountChanged>()) { constructable.Construct(); } } }
private void DeconstructionCompleted(DeconstructionCompletedEvent completed) { GameObject deconstructing = NitroxIdentifier.RequireObjectFrom(completed.PieceId); UnityEngine.Object.Destroy(deconstructing); }