Пример #1
0
        /// <summary>
        /// try get a obj, create one if not exist
        /// </summary>
        public static T FGet <T>(string id, out bool isNew) where T : EDataObj
        {
            isNew = false;
            var      inst = Instance;
            EDataObj d    = null;

            if (inst.m_dict.TryGetValue(id, out d))
            {
                T t = d as T;
                if (t == null || d == null)
                { //missing ref, happens when switch scene
                    //Dbg.LogWarn("EData.FGet: mismatch type or missing: expected {0}: stored {1}", typeof(T).Name, d.GetType().Name);
                    T newData = ScriptableObject.CreateInstance <T>();
                    inst.m_dict[id] = newData;
                    isNew           = true;
                    return(newData);
                }
                else
                {
                    return(t);
                }
            }
            else
            {
                T newData = ScriptableObject.CreateInstance <T>();
                inst.m_dict.Add(id, newData);
                isNew = true;
                return(newData);
            }
        }
Пример #2
0
        public static EDataObj Get(string id)
        {
            EDataObj d = null;

            Instance.m_dict.TryGetValue(id, out d);
            return(d);
        }
Пример #3
0
 void OnDisable()
 {
     //Dbg.Log("EData.OnDisable: m_dict: {0}", m_dict.Count);
     m_data.Clear();
     foreach (var pr in m_dict)
     {
         string   id   = pr.Key;
         EDataObj data = pr.Value;
         m_data.Add(new DPair(id, data));
     }
 }