/// <summary> /// Delegate function that should be attached to the callback of Track Generator's Generated Track Pieces Sync List. /// It is called automatically when the Sync List updates on the server. /// The purpose of this is to move the camera to the latest generated track on the client. /// </summary> /// <param name="op">Operation Type</param> /// <param name="itemIndex">The index of the newly added track (unused)</param> /// <param name="oldItem">The track itself that was removed (unused in this case)</param> /// <param name="newItem">The track itself that was added</param> void SetCameraTargetOnTrackPieceGenerated(Mirror.SyncList <GameObject> .Operation op, int itemIndex, GameObject oldItem, GameObject newItem) { if (op == Mirror.SyncList <GameObject> .Operation.OP_ADD) { ClientStateMachine.Singleton.PrimaryCamera.SetTarget(newItem.transform, PrimaryCamera.CameraType.Overhead); } }
public void UpdateContainers(GameObject newOwner, List <Container> newContainers) { var oldContainers = containers; RenderContainers(newOwner, newContainers); /* C# events are very silly. * To be able to add AND remove delegates (which we need to do), we cannot allow the delegates * to be anonymous, because if they are there is no way of referencing them. Therefore we have to create * the delegate, store it, and re-use that reference to remove the delegate. * * IF at any point in the chain an anonymous function is used, the whole thing goes kaput. */ foreach (var container in oldContainers) { if (!newContainers.Contains(container)) { container.onChange -= delegates[container]; delegates.Remove(container); } } foreach (var container in newContainers) { if (!oldContainers.Contains(container)) { Mirror.SyncList <GameObject> .SyncListChanged del = (a, b, c, d) => RenderContainer(container); delegates.Add(container, del); container.onChange += del; } } owner = newOwner; if (containers == oldContainers) { containers = newContainers; } }