private void Awake() { metaTileMap = GetComponentInChildren <MetaTileMap>(); subsystemManager = GetComponent <SubsystemManager>(); interactableTiles = GetComponent <InteractableTiles>(); networkMatrix = GetComponent <NetworkedMatrix>(); }
///Figuring out netId. NetworkIdentity is located on the pivot (parent) gameObject for MatrixMove-equipped matrices private static uint getNetId(Matrix matrix) { var netId = NetId.Invalid; if (!matrix) { return netId; } NetworkedMatrix networkedMatrix = matrix.gameObject.GetComponentInParent<NetworkedMatrix>(); if (networkedMatrix.OrNull()?.MatrixSync == null) { //Try to find if null networkedMatrix.BackUpSetMatrixSync(); } NetworkIdentity component = networkedMatrix.OrNull()?.MatrixSync.OrNull()?.GetComponent<NetworkIdentity>(); if (component && component.netId != NetId.Invalid && component.netId != NetId.Empty) { netId = component.netId; } if (netId == NetId.Invalid) { Logger.LogWarning($"Invalid NetID for matrix {matrix.gameObject.name}!", Category.Matrix); } return netId; }
private void Awake() { networkedMatrix = GetComponent <NetworkedMatrix>(); matrix = GetComponentInChildren <Matrix>(); if (RequiresFuel) { shuttleFuelSystem = GetComponent <ShuttleFuelSystem>(); } }
/// <summary> /// Resets client and server side static fields to empty / round start values. /// If you have any static pools / caches / fields, add logic here to reset them to ensure they'll be properly /// cleared when a new round begins. /// </summary> private void ResetStaticsOnNewRound() { //reset pools Spawn._ClearPools(); //clean up inventory system ItemSlot.Cleanup(); //reset matrix init events NetworkedMatrix._ClearInitEvents(); }
/// <summary> /// Invoked when networkedMatrixNetId is changed on the server, updating the client's networkedMatrixNetId. /// </summary> /// <param name="oldNetworkMatrixId"></param> /// <param name="newNetworkedMatrixNetID">uint of the new parent</param> private void SyncNetworkedMatrixNetId(uint oldNetworkMatrixId, uint newNetworkedMatrixNetID) { if (Initialized == false) { return; } networkedMatrixNetId = newNetworkedMatrixNetID; NetworkedMatrix.InvokeWhenInitialized(networkedMatrixNetId, FinishNetworkedMatrixRegistration); //note: we dont actually wait for init here anymore }
private void FinishNetworkedMatrixRegistration(NetworkedMatrix networkedMatrix) { //if we had any spin rotation, preserve it, //otherwise all objects should always have upright local rotation var rotation = transform.rotation; //only customNetTransform can have spin rotation bool hadSpinRotation = customNetTransform && Quaternion.Angle(transform.localRotation, Quaternion.identity) > 5; var newObjectLayer = networkedMatrix.GetComponentInChildren <ObjectLayer>(); if (objectLayer != newObjectLayer) { if (objectLayer) { objectLayer.ServerObjects.Remove(LocalPositionClient, this); objectLayer.ClientObjects.Remove(LocalPositionClient, this); } objectLayer = newObjectLayer; } transform.SetParent(objectLayer.transform, true); //preserve absolute rotation if there was spin rotation if (hadSpinRotation) { transform.rotation = rotation; } else { //objects are always upright w.r.t. parent matrix transform.localRotation = Quaternion.identity; } //this will fire parent change hooks so we do it last SetMatrix(networkedMatrix.GetComponentInChildren <Matrix>()); //if we are hidden, remain hidden, otherwise update because we have a new parent if (LocalPositionClient != TransformState.HiddenPos) { UpdatePositionClient(); } if (isServer) { UpdatePositionServer(); } OnParentChangeComplete.Invoke(); }
public void ClientLoading(NetworkedMatrix networkedMatrix) { var matrix = networkedMatrix.matrix; if (matrix.Initialized) { Initialize(matrix); } else { //will be gathered with a GetComponentsInChildren() and initialized by the matrix transform.SetParent(matrix.transform); } }
private void Awake() { metaTileMap = GetComponent <MetaTileMap>(); if (metaTileMap == null) { Logger.LogError($"MetaTileMap was null on {gameObject.name}"); } networkedMatrix = transform.parent.GetComponent <NetworkedMatrix>(); initialOffset = Vector3Int.CeilToInt(gameObject.transform.position); reactionManager = GetComponent <ReactionManager>(); metaDataLayer = GetComponent <MetaDataLayer>(); MatrixMove = GetComponentInParent <MatrixMove>(); tileChangeManager = GetComponentInParent <TileChangeManager>(); underFloorLayer = GetComponentInChildren <UnderFloorLayer>(); tilemapsDamage = GetComponentsInChildren <TilemapDamage>().ToList(); if (MatrixManager.Instance.InitializingMatrixes.ContainsKey(gameObject.scene) == false) { MatrixManager.Instance.InitializingMatrixes.Add(gameObject.scene, new List <Matrix>()); } MatrixManager.Instance.InitializingMatrixes[gameObject.scene].Add(this); OnEarthquake.AddListener((worldPos, magnitude) => { var cellPos = metaTileMap.WorldToCell(worldPos); var bounds = new BoundsInt(cellPos - new Vector3Int(magnitude, magnitude, 0), new Vector3Int(magnitude * 2, magnitude * 2, 1)); foreach (var pos in bounds.allPositionsWithin) { foreach (var player in Get <PlayerScript>(pos, true)) { if (player.IsGhost) { continue; } player.registerTile.ServerSlip(true); } //maybe shake items somehow, too } }); }
private void Awake() { if (transform.parent == null) { Logger.LogError($"{gameObject.name} had null transform parent", Category.Matrix); } networkedMatrix = transform.parent.GetComponent <NetworkedMatrix>(); if (networkedMatrix == null) { Logger.LogError($"{gameObject.name} had null networkedMatrix", Category.Matrix); } networkedMatrix.MatrixSync = this; matrixMove = networkedMatrix.GetComponent <MatrixMove>(); }
public override void OnStartClient() { if (isServer) { return; } if (transform.parent == null) //object spawned mid-round { NetworkedMatrix.InvokeWhenInitialized(networkedMatrixNetId, ClientLoading); } else { var matrix = transform.parent.GetComponentInParent <Matrix>(); if (matrix.Initialized) { Initialize(matrix); } } }
private void Awake() { networkedMatrix = GetComponent <NetworkedMatrix>(); }
private void Awake() { networkedMatrix = GetComponent <NetworkedMatrix>(); matrix = GetComponentInChildren <Matrix>(); }