private void UpdateValues(object obs, string key = "", HashSet <object> antiloop = null, Field oldAtr = null) { var isgui = Event.current != null; if (isgui) { GuiClasses.Indent(); } if (antiloop == null) { antiloop = new HashSet <object>(); } const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; if (obs == null) { throw new NullReferenceException(); } var obsType = obs.GetType(); foreach (FieldInfo fi in obsType.GetFields(flags)) { id++; var varCache = values[id]; if (varCache == null) { var atr2 = (Field)fi.GetCustomAttributes(true).Union(obsType.GetCustomAttributes(true)).FirstOrDefault(b => b is Field) ?? oldAtr; varCache = values[id] = new VarCache { atr = atr2, curKey = key + "/" + fi.Name, fi = fi, obs = obs }; superVars[varCache.curKey] = varCache; } var atr = varCache.atr; if (atr == null || atr.ignore) { continue; } if (atr.Name == null || Equals(atr, oldAtr)) { atr.Name = fi.Name; } var curKey = varCache.curKey; var curValue = fi.GetValue(obs); if (!string.IsNullOrEmpty(fi.FieldType.Namespace)) { atr.save2 = atr.save && (pl == null || pl.isLocal) && (bs.room == null || PhotonNetwork.isMasterClient); if (varCache.isSet) { if (!Equals(varCache.value, curValue)) { OnValueSet(curKey, curValue, atr.save2); } } else if (atr.save2) { curValue = PlayerPrefGet(curValue, curKey); } if (pl != null) { pl.customProperties.TryGetValue2(curKey, ref curValue); } if (roomInfo != null) { roomInfo.customProperties.TryGetValue2(curKey, ref curValue); } varCache.value = curValue; varCache.isSet = true; if (isgui && !atr.dontDraw && (filter == "" || atr.Name.ToLower().Contains(filter))) { var drawValue = DrawValue(curValue, atr); if ((roomInfo == null || PhotonNetwork.isMasterClient) && (pl == null || pl.isLocal)) { curValue = drawValue; } } fi.SetValue(obs, curValue); } else if (curValue != null && antiloop.Add(curValue)) { if (isgui && !GuiClasses.BeginVertical(atr.Name, false)) { continue; } UpdateValues(curValue, curKey, antiloop, atr.recursive ? atr : null); if (isgui) { gui.EndVertical(); } } } if (isgui) { GuiClasses.UnIndent(); } }
private void UpdateValues(object obs, string key = "", HashSet<object> antiloop = null, Field oldAtr = null) { var isgui = Event.current != null; if (isgui) GuiClasses.Indent(); if (antiloop == null) antiloop = new HashSet<object>(); const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; if (obs == null) throw new NullReferenceException(); var obsType = obs.GetType(); foreach (FieldInfo fi in obsType.GetFields(flags)) { id++; var varCache = values[id]; if (varCache == null) { var atr2 = (Field)fi.GetCustomAttributes(true).Union(obsType.GetCustomAttributes(true)).FirstOrDefault(b => b is Field) ?? oldAtr; varCache = values[id] = new VarCache { atr = atr2, curKey = key + "/" + fi.Name, fi = fi, obs = obs }; superVars[varCache.curKey] = varCache; } var atr = varCache.atr; if (atr == null || atr.ignore) continue; if (atr.Name == null || Equals(atr, oldAtr)) atr.Name = fi.Name; var curKey = varCache.curKey; var curValue = fi.GetValue(obs); if (!string.IsNullOrEmpty(fi.FieldType.Namespace)) { atr.save2 = atr.save && (pl == null || pl.isLocal) && (bs.room == null || PhotonNetwork.isMasterClient); if (varCache.isSet) { if (!Equals(varCache.value, curValue)) OnValueSet(curKey, curValue, atr.save2); } else if (atr.save2) curValue = PlayerPrefGet(curValue, curKey); if (pl != null) pl.customProperties.TryGetValue2(curKey, ref curValue); if (roomInfo != null) roomInfo.customProperties.TryGetValue2(curKey, ref curValue); varCache.value = curValue; varCache.isSet = true; if (isgui && !atr.dontDraw && (filter == "" || atr.Name.ToLower().Contains(filter))) { var drawValue = DrawValue(curValue, atr); if ((roomInfo == null || PhotonNetwork.isMasterClient) && (pl == null || pl.isLocal)) curValue = drawValue; } fi.SetValue(obs, curValue); } else if (curValue != null && antiloop.Add(curValue)) { if (isgui && !GuiClasses.BeginVertical(atr.Name, false)) continue; UpdateValues(curValue, curKey, antiloop, atr.recursive ? atr : null); if (isgui) gui.EndVertical(); } } if (isgui) GuiClasses.UnIndent(); }