/// <summary> /// When the client starts we populate mySceneElemetns with all the GameObjects in the scene with an "ElementScript" attribute. /// (This way we can always assign properties in ServerElements visually to the scene when there's an update) /// </summary> public override void OnStartClient() { base.OnStartClient(); // Get the master player script object on the server, if one doesn't // exist already, then assign this player object as the master instance // so that other objects will use it as such. GridPlayerScript[] players = FindObjectsOfType <GridPlayerScript>(); if (players.Length <= 1) { myMasterInstance = this; } else { foreach (GridPlayerScript player in players) { if (player.isMasterInstance == true) { myMasterInstance = player; } } } // Set up references to the paint elements that we'll be modifying from the scene ElementScript[] paintElements = FindObjectsOfType <ElementScript>(); foreach (var element in paintElements) { mySceneElements.Add(byte.Parse(element.gameObject.name), element.gameObject); } myFrameIsDirty = true; }
private void HandleSendingTouchMessage(GridPlayerScript player) { // Only send a touch up message if the colors are different (in order to keep our // bandwidth under 4k a second) if (player.GetActivePaletteColor() != GetComponent <Renderer>().material.color) { player.SendMessage("OnHandleOnChildTouchUp", this); } }
/// <summary> /// When the server starts populate ServerElements with all the default properties of the GameObjects in the scene with an "ElementScript" attribute. /// (This way our server elements are always updated dynamically based on what's actually in the scene) /// </summary> public override void OnStartServer() { base.OnStartServer(); myRpcHeartbeatTimer = 0f; // Get the master player script object on the server, if one doesn't // exist already, then assign this player object as the master instance // so that other objects will use it as such. GridPlayerScript[] players = FindObjectsOfType <GridPlayerScript>(); if (players.Length <= 1) { isMasterInstance = true; myMasterInstance = this; myMasterInstance.ServerElements.Clear(); ElementScript[] elements = FindObjectsOfType <ElementScript>(); foreach (var element in elements) { ElementProperty newProperty = new ElementProperty(byte.Parse(element.gameObject.name), (byte)Random.Range(0, 12)); myMasterInstance.ServerElements.Add(newProperty); } } else { foreach (GridPlayerScript player in players) { if (player.isMasterInstance == true) { myMasterInstance = player; } } } // Use this to print debug messages when server elements change //ServerElements.Callback = OnServerElementsChanged; }