private void InitEventComp(GameObject go, SerializeEntity se) { var litLua = go.GetOrAddComponent <LitLua>(); var eventEntity = EventEntity.Parse(se); litLua.RegistEvent(eventEntity); }
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); }
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); } }
public static EventEntity Parse(SerializeEntity se) { EventEntity eventEntity = new EventEntity(); eventEntity.EventParam = se["EP"]; eventEntity.EventType = (LitEventType)System.Enum.Parse(typeof(LitEventType), se.Type); return(eventEntity); }
public SerializeEntity ToSerializeEntity() { SerializeEntity se = new SerializeEntity(); se.Type = EventType.ToString(); se.Add("EP", EventParam); return(se); }
public static void SetLong(ref long value, SerializeEntity data, string name) { if (data == null || !data.Contains(name)) { return; } value = data[name]; }
public SerializeObj AddComp(SerializeEntity entity) { if (comps == null) { comps = new List <SerializeEntity>(); } comps.Add(entity); return(this); }
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 强行反射序列化 } }
private static void InitCompsByJsonData(SerializeObj so, JsonData jsonData) { if (so == null || jsonData == null || jsonData.Count <= 0) { LitLogger.ErrorFormat("{0} components is Empty {1}", so.ObjName, jsonData); return; } for (int i = 0; i < jsonData.Count; i++) { var data = jsonData[i]; SerializeEntity se = new SerializeEntity(data); so.AddComp(se); } }
public static bool DeSerialize(object obj, SerializeEntity data) { bool ret = false; if (obj is Transform) { (obj as Transform).DeSerialize(data); ret = true; } else if (obj is LitImage) { (obj as LitImage).D_Image(data); } else if (obj is LitRawImage) { (obj as LitRawImage).D_RawImage(data); } return(ret); }