public static void TableFillWithData(TableRecordsClass jsonData)
        {
            if (!PathDictionary.ContainsKey(jsonData.ClassName) || !ScriptPathDictionary.ContainsKey(jsonData.ClassName))
            {
                Debug.Log(jsonData.ClassName + " not presented in dictionary");
                return;
            }

            var path             = PathDictionary[jsonData.ClassName];
            var scriptableObject = Resources.Load(path);

            if (scriptableObject == null)
            {
                Debug.Log("EROROR " + path + " " + jsonData.ClassName);
            }

            Debug.Log(jsonData.ClassName);

            var tableTypeStr = string.Format(ScriptPathDictionary[jsonData.ClassName]);
            //Debug.Log(tableTypeStr);
            var tableType = Type.GetType(tableTypeStr);

            if (tableType == null)
            {
                Debug.LogError("tableTypeNotFind: " + tableTypeStr);
                return;
            }

            var field       = tableType.GetFields().FirstOrDefault(x => x.Name == Recordsname);
            var objectArray = FilledData(jsonData);

            if (field == null)
            {
                Debug.LogError("NotFindField with name: " + Recordsname);
                return;
            }

            //Debug.Log(field.Name);
            field.SetValue(scriptableObject, objectArray);

#if UNITY_EDITOR
            //try to save results by SetDirty method
            UnityEditor.EditorUtility.SetDirty(scriptableObject);
#endif
        }
        private static IEnumerable <object> FilledData(TableRecordsClass jsonData)
        {
            var recordTypeStr = string.Format(ScriptPathDictionary[jsonData.ClassName] + "Record");
            //DebugLogger.Log(null, "recordTypeStr: " + recordTypeStr);
            var genericType = Type.GetType(recordTypeStr);

            if (genericType == null)
            {
                Debug.LogError("genericType: " + recordTypeStr + " is not FIND");
                return(null);
            }

            var objectArray =
                (object[])Array.CreateInstance(genericType, jsonData.ClassData.Count);                  // new object[jsonData.ClassData.Count];
            var j = 0;

            foreach (var record in jsonData.ClassData)
            {
                var recordFields = genericType.GetFields();
                var method       =
                    typeof(TablesRecordsFiller).GetMethod("GenerateInvocatedLists", BindingFlags.NonPublic | BindingFlags.Static);
                //DebugLogger.Log(null, "method: " + method);
                var generic     = method.MakeGenericMethod(genericType);
                var instanceObj = generic.Invoke(null, null);
                objectArray[j] = instanceObj;

                for (var i = 0; i < recordFields.Length; i++)
                {
                    if (i >= record.DataList.Count)
                    {
                        DebugLogger.Log(null, "Client have more field then server : " + jsonData.ClassName + "." + recordFields[i].Name,
                                        LogColor.Orange);
                        continue;
                    }

                    var fieldNeedValueStr = record.DataList[i];

                    FieldSetValue(recordFields[i], fieldNeedValueStr, instanceObj);
                }

                j++;
            }

            return(objectArray);
        }
示例#3
0
        private static TableRecordsClass GetFields(TableDataClass data)
        {
            var innerDataList = ParseDataScheme.ParseScheme(data.ClassData).ToList();

            List <RecordData> records = new List <RecordData>();

            for (int i = 0; i < innerDataList.Count; i++)
            {
                string     str    = innerDataList[i];
                RecordData record = CreateRecord(str);
                if (record != null)
                {
                    records.Add(record);
                }
            }

            var tableRecordsClass = new TableRecordsClass
            {
                ClassName = data.ClassName,
                ClassData = records
            };

            return(tableRecordsClass);
        }