示例#1
0
        public static object DeserializeClass(Hashtable table, object context)
        {
            Type      type      = JsonSerializer.typeCache[Convert.ToInt64(table[STR_CLS_TYPE_ID])];
            ArrayList arrayList = (ArrayList)table[STR_CLS_DATA_VALUE];
            object    obj       = Activator.CreateInstance(type, true);

            JsonSerializer.AddToCache(obj, table);
            if (obj is ISerializable)
            {
                (obj as ISerializable).Deserialize(new SerializationInfo(arrayList, context), context);
            }
            else
            {
                int count = arrayList.Count;
                for (int i = 0; i < count; i++)
                {
                    IDictionaryEnumerator iterator = ((Hashtable)arrayList[i]).GetEnumerator();
                    iterator.MoveNext();
                    string    text  = iterator.Key.ToString();
                    object    value = iterator.Value;
                    FieldInfo field = obj.GetType().GetFieldInfo(text, InstanceFlags);
                    if (field != null)
                    {
                        object obj2 = JsonSerializer.Deserialize(value, field.FieldType, context);
                        if (obj2 != null)
                        {
                            if (!obj2.GetType().IsSubTypeOf(field.FieldType))
                            {
                                LogCat.LogWarningFormat("Type dismatch of [{0} [{1} <-> {2}] when DeserializeClass {3}",
                                                        text,
                                                        field.FieldType,
                                                        obj2.GetType(),
                                                        type
                                                        );
                            }
                            else
                            {
                                try
                                {
                                    field.SetValue(obj, obj2);
                                }
                                catch (Exception e)
                                {
                                    LogCat.LogErrorFormat(e.ToString(), new object[0]);
                                }
                            }
                        }
                    }
                }
            }

            return(obj);
        }
示例#2
0
        private void OnTrigger(string eventKey)
        {
            if (!eventCallbackDict.ContainsKey(eventKey))
            {
                LogCat.LogWarningFormat("{0}:不存在eventCallbacks {1}", GetType().Name, eventKey);
                return;
            }

            for (var i = 0; i < eventCallbackDict[eventKey].Count; i++)
            {
                var callbackStruct = eventCallbackDict[eventKey][i];
                callbackStruct.Call();
            }
        }
示例#3
0
        private void Start()
        {
            db = new DoubleBuffer <string>(t => { LogCat.LogErrorFormat("consuming {0}", t); },
                                           t => { LogCat.LogWarningFormat("producing {0}", t); });

            CreateProduceThread("ProduceThread A", 500);
            CreateConsumeThread();
            CreateProduceThread("ProduceThread B", 500);
            CreateProduceThread("ProduceThread C", 1000);

            ThreadManager.instance.Start();

            //使用ThreadManager.Instace.Abort()退出所有线程
            //菜单是CZMTool->退出所有线程
        }
示例#4
0
        public override void Seek(int length)
        {
            if (pos + length > base.length)
            {
                LogCat.LogWarningFormat(string.Concat(
                                            "Seek out of stream, wanted:",
                                            pos + length,
                                            ", but:",
                                            base.length
                                            ));
                pos = base.length;
                return;
            }

            pos = length;
        }
示例#5
0
        /// <summary>
        /// 获取或者添加一行
        /// T要转化到的类型
        /// 如TestConfig.asset每行的数据要转化为TestConfig.cs里面的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T GetRow <T>(string id) where T : class
        {
            object value = null;

            if (!this.dataDict.TryGetValue(id, out value))
            {
                value = this.CreateRowInstance <T>(id);
                if (value != null)
                {
                    this.dataDict[id] = value;
                }
            }

            T t = value as T;

            if (t == null)
            {
                LogCat.LogWarningFormat("{0} GetRow failed with id:{1}", typeof(T), id);
            }
            return(t);
        }
示例#6
0
        public Transform GetSocketTransform(string socketName, bool isIgnoreError = false)
        {
            if (graphicComponent.gameObject == null)
            {
                return(null);
            }
            if (socketName.IsNullOrWhiteSpace() || "main".Equals(socketName))
            {
                return(graphicComponent.transform);
            }
            Transform socketTransform = null;

            if (!this.socketTransformDict.ContainsKey(socketName))
            {
                socketTransform = graphicComponent.transform.FindChildRecursive(socketName);
                if (socketTransform != null)
                {
                    this.socketTransformDict[socketName] = socketTransform;
                }
            }

            if (socketTransform == null)
            {
                if (!isIgnoreError)
                {
                    LogCat.LogErrorFormat("Can't find socket({0}) in unit({1})", socketName, this.unitId);
                }
                else
                {
                    LogCat.LogWarningFormat("Can't find socket({0}) in unit({1})", socketName, this.unitId);
                }
                return(graphicComponent.transform);
            }

            return(socketTransform);
        }