// 回收所有属性对象到对象池中. virtual public void RecycleAllAttribute() { Dictionary <int, GKCommonValue> .Enumerator it = _attrDict.GetEnumerator(); while (it.MoveNext()) { GKCommonValue attr = it.Current.Value; if (null != attr) { attr.Clear(); GKCommonValue.commonValuePool.Recycle(attr); } } _attrDict.Clear(); Dictionary <int, GKCommonListValue> .Enumerator it_ = _attrListDict.GetEnumerator(); while (it.MoveNext()) { GKCommonListValue attr = it_.Current.Value; if (null != attr) { attr.Clear(); GKCommonListValue.commonValuePool.Recycle(attr); } } _attrListDict.Clear(); }
public GKCommonValue CopyAttribute(GKCommonValue src, GKCommonValue dest, bool bDoEvent) { dest.CopyVale(src); if (bDoEvent) { dest.DoEvent(this); } return(dest); }
public GKCommonValue CopyAttribute(int idx, GKCommonValue src, bool bDoEvent) { GKCommonValue attr = GetOrCreateAttribute((int)idx); if (null == attr) { return(null); } return(CopyAttribute(attr, src, bDoEvent)); }
// 只清除数据, 不清除事件. 调用频繁, 故使用新函数而不拓展参数. public void ClearValueWithOutEvent() { _longValue = 0; _floatValue = 0f; _stringValue = null; _bufferValue = null; if (null != _lastValue) { _lastValue.Clear(); commonValuePool.Recycle(_lastValue); _lastValue = null; } }
public void SetValue(byte[] newValue) { type = AttributeType.Type_Blob; if (null != OnAttrbutChangedEvent) { if (null == _lastValue) { _lastValue = commonValuePool.Spawn(true); } _lastValue._bufferValue = _bufferValue; } _bufferValue = newValue; }
public void SetValue(string newValue) { type = AttributeType.Type_String; if (null != OnAttrbutChangedEvent) { if (null == _lastValue) { _lastValue = commonValuePool.Spawn(true); } _lastValue._stringValue = _stringValue; } _stringValue = newValue; }
public void SetValue(float newValue) { type = AttributeType.Type_Float; if (null != OnAttrbutChangedEvent) { if (null == _lastValue) { _lastValue = commonValuePool.Spawn(true); } _lastValue._floatValue = _floatValue; } _floatValue = newValue; }
// 以下代码部分代码重复性高, 因为代用频率高. 为了性能, 牺牲部分美观. public void SetValue(int newValue) { type = AttributeType.Type_Int32; if (null != OnAttrbutChangedEvent) { if (null == _lastValue) { _lastValue = commonValuePool.Spawn(true); } _lastValue._longValue = _longValue; } _longValue = newValue; }
public GKCommonValue SetAttribute(int idx, string value, bool bDoEvent) { GKCommonValue attr = GetOrCreateAttribute((int)idx); if (null == attr) { return(null); } attr.SetValue(value); if (bDoEvent) { attr.DoEvent(this); } return(attr); }
virtual public GKCommonValue GetOrCreateAttribute(int idx) { GKCommonValue attr = null; if (!_attrDict.TryGetValue(idx, out attr) || null == attr) { attr = GKCommonValue.commonValuePool.Spawn(true); // 如果取出来的对象存在监听, 意味着对象仍旧存在外部代理或同一个对象呗多次放回内存池中. // 为了避免意外情况发生, 抛弃此对象使用. 重新获取. while (attr.HasEvent()) { Debug.LogWarning(string.Format("GetOrCreateAttribute target still has event. target: {0}", attr.GetEventTarget())); attr = GKCommonValue.commonValuePool.Spawn(true); } attr.index = idx; _attrDict[idx] = attr; } return(attr); }
// 清空所有属性值, 绑定事件不清楚. (用途类似游戏中断线重连等) virtual public void ClearAllAttributeValue() { Dictionary <int, GKCommonValue> .Enumerator it = _attrDict.GetEnumerator(); while (it.MoveNext()) { GKCommonValue attr = it.Current.Value; if (null != attr) { attr.ClearValueWithOutEvent(); } } Dictionary <int, GKCommonListValue> .Enumerator it_ = _attrListDict.GetEnumerator(); while (it_.MoveNext()) { GKCommonListValue attr = it_.Current.Value; if (null != attr) { attr.ClearValueWithOutEvent(); } } }
public void CopyVale(GKCommonValue src, bool bDoEvent = false) { if (null != OnAttrbutChangedEvent) { if (null == _lastValue) { _lastValue = commonValuePool.Spawn(true); } _lastValue._longValue = _longValue; _lastValue._floatValue = _floatValue; _lastValue._stringValue = _stringValue; _lastValue._bufferValue = _bufferValue; } if (null != src) { _longValue = src._longValue; _floatValue = src._floatValue; _stringValue = src._stringValue; _bufferValue = src._bufferValue; type = src.type; } }
string _GetCurValueToString(GKCommonValue data) { switch (data.type) { case AttributeType.Type_Int8: case AttributeType.Type_Int16: case AttributeType.Type_Int32: return(data.ValInt.ToString()); case AttributeType.Type_Int64: return(data.ValLong.ToString()); case AttributeType.Type_Float: case AttributeType.Type_Double: return(data.ValFloat.ToString()); case AttributeType.Type_String: return(data.ValString); case AttributeType.Type_Blob: return(data.ValBuffer.ToString()); } return(""); }