| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System.Collections.Generic;
- using MongoDB.Bson.Serialization.Attributes;
- using MongoDB.Bson.Serialization.Options;
- namespace Model
- {
- [ObjectSystem]
- public class NumericComponentSystem : AwakeSystem<NumericComponent>
- {
- public override void Awake(NumericComponent self)
- {
- self.Awake();
- }
- }
- public class NumericComponent : Component, ISerializeToEntity
- {
- [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
- public Dictionary<NumericType, int> NumericDic;
- public void Awake()
- {
- this.NumericDic = new Dictionary<NumericType, int>();
- }
- public float GetAsFloat(NumericType numericType)
- {
- return (float)GetByKey(numericType) / 10000;
- }
- public int GetAsInt(NumericType numericType)
- {
- return this[numericType];
- }
- public void Set(NumericType nt, float value)
- {
- this[nt] = (int)(value * 10000);
- }
- public void Set(NumericType nt, int value)
- {
- this[nt] = value;
- }
- public int this[NumericType numericType]
- {
- get
- {
- return this.GetByKey(numericType);
- }
- set
- {
- int v = this.GetByKey(numericType);
- if (v == value)
- {
- return;
- }
- NumericDic[numericType] = value;
- Game.EventSystem.Run(EventIdType.NumbericChange, this.Entity.Id, numericType, value);
- }
- }
- private int GetByKey(NumericType key)
- {
- int value;
- this.NumericDic.TryGetValue(key, out value);
- return value;
- }
- }
- }
|