public static PrefsGUISync.KeyObj _Get <T>(this SyncListStruct <T> sl, int idx) where T : struct { var kvField = GetField(typeof(T)); return(new PrefsGUISync.KeyObj() { key = (string)kvField.keyField.GetValue(sl[idx]), _value = kvField.valueField.GetValue(sl[idx]) }); }
public static void _Set <T>(this SyncListStruct <T> sl, int idx, object obj) where T : struct { var kvField = GetField(typeof(T)); if (false == kvField.valueField.GetValue(sl[idx]).Equals(obj)) { var key = (string)kvField.keyField.GetValue(sl[idx]); sl[idx] = CreateInstance <T>(key, obj); } }
private void OnIntChanged(SyncListStruct <block> .Operation op, int index) { Debug.Log("list changed " + op); int x = (int)blockdifferntiator[index].position.x; int y = (int)blockdifferntiator[index].position.y; int z = (int)blockdifferntiator[index].position.z; map[x, y, z] = blockdifferntiator[index].material; if ((x < 0) || (z < 0) || (y < 0) || (y >= height) || (x >= width) || (z >= width)) { Chunk chunk = Chunk.FindChunk(new Vector3(x + 1, y + 1, z + 1)); StartCoroutine(chunk.CreateVisualMesh()); } StartCoroutine(CreateVisualMesh()); }
private Vector3[] ToVector3Array(SyncListStruct <Vector2> points) { var vectors = new Vector3[points.Count * 4]; var index = 0; var reverse = vectors.Length - 2; foreach (var point in points) { vectors[index] = new Vector3(point.x, 0, 0); vectors[index + 1] = new Vector3(point.x, point.y, 0); vectors[reverse] = new Vector3(point.x, 0, 1); vectors[reverse + 1] = new Vector3(point.x, point.y, 1); index += 2; reverse -= 2; } return(vectors); }
/// <summary> /// Method called by the SyncList operation over the Network when its content changes. /// This is an implementation for changes to the buffered Collectibles, updating their position and assignment. /// Parameters: type of operation, index of Collectible which received updates. /// </summary> public void OnCollectibleStateChanged(SyncListStruct <CollectibleState> .Operation op, int index) { //get reference by index CollectibleState state = collects[index]; if (state.objId.Value <= 0) { return; } //get game object instance by network ID GameObject obj = ClientScene.FindLocalObject(state.objId); if (obj == null) { return; } //get Collectible component on that object Collectible colComp = obj.GetComponent <Collectible>(); if (colComp == null) { return; } //targetId is assigned: handle pickup on the corresponding player //or position is not at origin: handle drop at that position //otherwise when the entry has changed it got returned to its spawn position if (state.targetId.Value > 0) { colComp.spawner.Pickup(state.targetId); } else if (state.pos != colComp.spawner.transform.position) { colComp.spawner.Drop(state.pos); } else { colComp.spawner.Return(); } }
/// <summary> /// 同步结构体列表数据变化回调 /// </summary> /// <param name="op"></param> /// <param name="itemIndex"></param> void TransChanged(SyncListStruct <TransSimple> .Operation op, int itemIndex) { if (!sync) { return; } if (hasAuthority) { return; } if (proxyList != null && proxyList.Count > itemIndex && (op.Equals(SyncListStruct <TransSimple> .Operation.OP_ADD) || op.Equals(SyncListStruct <TransSimple> .Operation.OP_DIRTY) ) ) { lerpTimes[itemIndex] = syncRateFrames; ResetOldTransform(itemIndex); } }
private void OnChatMessagesUpdated(SyncListStruct <ChatEntry> .Operation op, int itemIndex) { Debug.Log("Operation: " + op.ToString() + " index: " + itemIndex); if (SyncListStruct <ChatEntry> .Operation.OP_ADD.ToString().Equals(op.ToString())) { Debug.Log("updating and creating prefab."); //swap the two lines below if you are going to maintain a local cache of players to prevent searching entire scene for them. //uint playerTeam = cachedPlayers.Find(player => player.isLocalPlayer).teamIndex; uint playerTeam; try { playerTeam = new List <NaokoController>(GameObject.FindObjectsOfType <NaokoController>()).Find(player => player.isLocalPlayer).teamIndex; } catch { playerTeam = new List <YuriController>(GameObject.FindObjectsOfType <YuriController>()).Find(player => player.isLocalPlayer).teamIndex; } //if you are in the wrong channel, do not create text prefab for that message if (chatMessages[itemIndex].Channel == UNSET_TEAM || chatMessages[itemIndex].Channel == playerTeam) { CreatePrefabAndAddToScreen(chatMessages[itemIndex]); if (openChatOnNewMessageReceived) { OpenChat(false); } timeLastChatEntryHappened = Time.time; Invoke("TryToHideChat", DELAY_BEFORE_HIDING_CHAT); } //and if you are feeling adventurous, you may think about even removing it from the list. } //last condition should only happen when user is first connecting to a game in progress, and they have not filled up their queue else if (SyncListString.Operation.OP_REMOVEAT.ToString().Equals(op.ToString()) && !isServer && messagesOnUI.Count > MAX_MESSAGES) { Debug.Log("Destroying message: " + itemIndex); Destroy(messagesOnUI[itemIndex]); messagesOnUI.RemoveAt(itemIndex); } }
private void OnPSChanged(SyncListStruct <PlayerState> .Operation op, int index) { Debug.Log("list changed " + op); }
void DeviceIdListChanged(SyncListStruct <ID> .Operation op, int itemIndex) { //Debug.Log("Changed interactable ID list. Num interactables: " + _interactableIdList.Count); }
private void OnChatUpdated(SyncListStruct <ChatStruct> .Operation op, int index) { chatline.text += chatLog[chatLog.Count - 1].msg + "\n"; chatline.color = chatLog[chatLog.Count - 1].color; }
void RefreshChatLog(SyncListStruct <ChatEvent> .Operation op, int index) { RefreshLog(); }
/// <summary> /// Callback on chat log updated /// </summary> /// <param name="op"></param> /// <param name="index"></param> private void OnChatMsgBoxUpdated(SyncListStruct <ChatStruct> .Operation op, int index) { _chatMsgBox.text += "User_" + _chatLog[_chatLog.Count - 1].PlayerId + ": " + _chatLog[_chatLog.Count - 1].Msg + "\n"; _chatMsgBox.color = _chatLog[_chatLog.Count - 1].Color; }
public static void _Add <T>(this SyncListStruct <T> sl, string key, object obj) where T : struct { sl.Add(CreateInstance <T>(key, obj)); }
private void OnDeckListChanged(SyncListStruct <MDCard> .Operation op, int index) { GameObject.Find("Visual/MainDeckDiscardPile/Canvas/Card").GetComponent <Image>().sprite = spriteDict[mainDeckDiscardPile[0].name]; GameObject.Find("Visual/MainDeckDiscardPile").GetComponent <DeckThickness>().updateThickness(mainDeckDiscardPile.Count); //Debug.Log("list changed " + op); }
public Players players; //The player list private void PlayersChanged(SyncListStruct <Player.PlayerInfo> .Operation op, int itemIndex) { Debug.Log("Playerlist operation: " + op + " " + players[itemIndex]); }
private void OnDeckListChanged(SyncListStruct <MDCard> .Operation op, int index) { GameObject.Find("Visual/MainDeck").GetComponent <DeckThickness>().updateThickness(mainDeck.Count); //Debug.Log("list changed " + op); }
public static void _SetCallback <T>(this SyncListStruct <T> sl, Action <int, int> callback) where T : struct { sl.Callback = (op, idx) => callback((int)op, idx); }