Пример #1
0
        private void InitComp(GameObject go, SerializeEntity se)
        {
            if (se.Type.StartsWith("LE_"))
            {
                InitEventComp(go, se);
                return;
            }
            Type type = SerializeReg.GetType(se.Type);

            if (type == null)
            {
                LitLogger.ErrorFormat("{0} not registe in SerializeReg", se.Type);
                return;
            }

            if (type == typeof(Transform))
            {
                var trans = go.GetComponent <Transform>();
                TryDeserializeComp(trans, se);
            }
            else
            {
                var comp = go.AddComponent(type);
                TryDeserializeComp(comp, se);
            }
        }
Пример #2
0
        private SerializeEntity TrySerialize(Component comp)
        {
            SerializeEntity retSE = null;

            if (comp is ISerializable)
            {
                var sa = comp as ISerializable;
                retSE = sa.Serialize();
            }
            if (comp is ISerializeEvent)
            {
                var se = comp as ISerializeEvent;
                var ee = se.Serialize();
                if (ee != null)
                {
                    retSE = ee.ToSerializeEntity();
                }
                return(retSE);
            }
            if (retSE == null)
            {
                retSE = TryCallSerializeByReflection(comp);
            }
            if (comp == null)
            {
                //TODO 完全通过反射的方式序列化对象
            }
            if (retSE != null && !SerializeReg.HasRegType(retSE.Type) && (!(comp is ISerializeEvent)))
            {
                LitLogger.ErrorFormat("{0} not register in SeriaLizeReg,Can'not be Serialized", retSE.Type);
                retSE = null;
            }
            return(retSE);
        }
Пример #3
0
        private void TryDeserializeComp(Component comp, SerializeEntity se)
        {
            if (comp is ISerializable)
            {
                (comp as ISerializable).DeSerialize(se);
                return;
            }
            bool tryCallExtend = SerializeReg.DeSerialize(comp, se);

            if (!tryCallExtend)
            {
                //TODO 强行反射序列化
            }
        }
Пример #4
0
        private SerializeEntity TryCallSerializeByReflection(Component comp)
        {
            #region TODO 找到合适的反射调用方式,暂时通过手动调用
            //Type type = comp.GetType();
            //var method = type.GetMethod("Serialize", BindingFlags.Static
            //            | BindingFlags.Public | BindingFlags.NonPublic);
            //if(method == null) {
            //    LitLogger.ErrorFormat("Error: Get Method {0} from  {1}", "Serialize", comp.name);
            //    return null;
            //}
            //var rst = method.Invoke(comp, null);
            //if (rst is SerializeEntity)
            //{
            //    return rst as SerializeEntity;
            //}
            #endregion

            return(SerializeReg.Serialize(comp));
        }