private void OnChangedAttribute(Stats.EventArgs ev) { if (PhotonNetwork.InRoom && photonView.IsMine && gameObject.activeSelf) { //Debug.Log("OnChangedAttribute " + ev.name, gameObject); if (string.IsNullOrEmpty(ev.name)) { return; } if (!cachedAttributesSync.Contains(ev.name)) { return; } RequireInit(); float current = this.stats.GetAttrValue(ev.name); float last = -1; bool changed = false; if (cachedAttributes.TryGetValue(ev.name, out last)) { if (!Mathf.Approximately(current, last)) { changed = true; } } else { //cachedAttributesIndex.Add(ev.name); cachedAttributes.Add(ev.name, current); changed = true; } //Debug.Log("OnChangedAttribute " + ev.name +" / current: " + current); int index = cachedAttributesKeys[ev.name]; #if PHOTON_RPG if (changed && gameObject.activeSelf && (actor ? !actor.objectDestroyer.InProgress : true)) #else if (changed && gameObject.activeSelf) #endif { if (attributesChanged.ContainsKey(index)) { attributesChanged[index] = (int)current; } else { attributesChanged.Add(index, (int)current); } //Debug.Log("Changed index: " + index + " name: " + ev.name +" / attributesChanged: " + attributesChanged.ToStringFull()); //photonView.RPC(RPC_ATT, RpcTarget.Others, index, current); //PhotonNetwork.SendAllOutgoingCommands(); lastChange = Time.time + refreshRate; } } }
/*private void RegisterEvents() * { * if (!registered) * { * stats.AddOnChangeAttr(OnChangedAttribute); * stats.AddOnChangeStat(OnChangedStat); * registered = true; * } * }*/ private void OnChangedStat(Stats.EventArgs ev) { if (!PhotonNetwork.InRoom || !photonView.IsMine || !gameObject.activeSelf) { return; } if (string.IsNullOrEmpty(ev.name)) { return; } if (!cachedStatsSync.Contains(ev.name)) { return; } RequireInit(); //Debug.Log("OnChangedStat " + ev.name + " / " + cachedStats.Count+ " / cachedStats: " + cachedStats.ToStringFull()); float current = this.stats.GetStat(ev.name); float last = cachedStats[ev.name]; bool changed = false; //if (cachedStats.TryGetValue(ev.name, out last)) //{ if (!Mathf.Approximately(current, last)) { cachedStats[ev.name] = current; changed = true; } /*} * else * { * cachedStats.Add(ev.name, current); * cachedStatsIndex.Add(ev.name); * changed = true; * }*/ int index = cachedStatsKeys[ev.name];// cachedStatsIndex.IndexOf(ev.name); if (changed && gameObject.activeInHierarchy) { photonView.RPC(RPC_STAT, RpcTarget.Others, index, current); } }