private object CreateObjectByJsonAndType(object json, Type type) { // special case for field name not match. if (type.Name == "LayerMask") { var mask = Logic.Convert.ToInt32((json as Dictionary <string, object>)["m_Bits"]); var lm = (LayerMask)mask; return(lm); } else { Dictionary <string, object> v = json as Dictionary <string, object>; if (v == null) { return(null); } if (v.ContainsKey("guid") && v["guid"] != null) { string guid = v["guid"].ToString(); ResourceMap map = rmm.GetFromGuid(guid); if (map == null) { return(null); } if (map.ext == "prefab") { var prefab = Resources.LoadPrefab(guid); var c = prefab.GetComponent(type); if (c == null) { return(prefab); } else { return(c); } } else if (map.ext == "mat") { return(Resources.GetMaterial(guid)); } else if (map.ext == "png" || map.ext == "jpg" || map.ext == "jpeg") { return(Resources.GetTexture(guid)); } else if (map.ext == "shader") { return(Resources.GetShader(FileMap.FromJson(v))); } } else if (v.ContainsKey("fileID") && v["fileID"] != null) { return(GetComponentByFileID(v["fileID"].ToString())); } else { var obj = Activator.CreateInstance(type); // Following way fails in Duocode lib. // var target = type.Assembly.CreateInstance(type.FullName); if (obj != null) { InitObjectFromJson(obj, json, type); } return(obj); } } return(null); }