コード例 #1
0
    private static void Generate_SOInstance(TypeData pTypeData, Type pType_SO, JArray pJArray_Instance, ScriptableObject pContainerInstance, Dictionary <string, FieldInfo> mapFieldInfo_SO, List <Container_CachingLogicBase> listCachingLogic, List <FieldTypeData> listFieldData)
    {
        string strHeaderField = pTypeData.strHeaderFieldName;
        string strFileName    = pType_SO.Name;
        int    iLoopIndex     = 0;

        FieldTypeData pFieldData_Header = listFieldData.FirstOrDefault(pFieldData => pFieldData.strFieldName == strHeaderField);

        FieldTypeData[] arrRealField    = listFieldData.Where((pFieldData) => pFieldData.bIsVirtualField == false && pFieldData.bDeleteThisField_InCode == false).ToArray();
        FieldTypeData[] arrVirtualField = listFieldData.Where((pFieldData) => pFieldData.bIsVirtualField && pFieldData.bDeleteThisField_InCode == false).ToArray();


        foreach (JObject pInstanceData in pJArray_Instance)
        {
            ScriptableObject pSO = GenerateSO(pType_SO, pContainerInstance);
            Process_RealField(pTypeData, mapFieldInfo_SO, pInstanceData, pSO, arrRealField);
            Process_VirtualField(pTypeData, mapFieldInfo_SO, pInstanceData, pSO, listFieldData, arrVirtualField);
            Process_SOName(strFileName, iLoopIndex, pSO, pFieldData_Header, pInstanceData);
            EditorUtility.SetDirty(pSO);

            for (int i = 0; i < listCachingLogic.Count; i++)
            {
                listCachingLogic[i].Process_CachingLogic(pSO, listFieldData);
            }

            iLoopIndex++;
        }

        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(pContainerInstance));
        AssetDatabase.SaveAssets();
    }
コード例 #2
0
    private static void Process_VirtualField(TypeData pTypeData, Dictionary <string, FieldInfo> mapFieldInfo_SO, JObject pInstanceData, ScriptableObject pSO, IEnumerable <FieldTypeData> listField, IEnumerable <FieldTypeData> listVirtualField)
    {
        foreach (var pMember in listVirtualField)
        {
            FieldInfo pFieldInfo  = mapFieldInfo_SO[pMember.strFieldName];
            Type      pType_Field = GetTypeFromAssemblies(pMember.strFieldType);
            if (pType_Field == null)
            {
                Debug.LogError($"{pTypeData.strFileName}-{pMember.strFieldName} - Field Type Not Found - {pMember.strFieldType}");
                continue;
            }
            FieldTypeData pFieldData_Dependency = listField.FirstOrDefault(pFieldData => pFieldData.strFieldName == pMember.strDependencyFieldName);
            if (pFieldData_Dependency == null)
            {
                Debug.LogError($"{pTypeData.strFileName}-{pMember.strFieldName} - Dependency Not Found - Name : {pMember.strDependencyFieldName}");
                continue;
            }

            string strDependencyValue = (string)pInstanceData[pFieldData_Dependency.strFieldName];
            if (strDependencyValue == "None")
            {
                continue;
            }

            if (pType_Field.IsEnum)
            {
                if (string.IsNullOrEmpty(strDependencyValue))
                {
                    Debug.LogWarning("TODO string null check");
                    continue;
                }

                try
                {
                    pFieldInfo.SetValue(pSO, Enum.Parse(pType_Field, strDependencyValue));
                }
                catch (Exception e)
                {
                    if (pTypeData.eType != ESheetType.Global)
                    {
                        Debug.LogError($"{pTypeData.strFileName} Enum Parse Error - ({pType_Field.MemberType})\"{strDependencyValue}\"" + e);
                    }
                }
            }
            else
            {
                FieldTypeData pFieldData_Dependency_Sub = listField.FirstOrDefault(pFieldData => pFieldData.strFieldName == pMember.strDependencyFieldName_Sub);
                if (pFieldData_Dependency_Sub != null)
                {
                    string strDependencyValue_Sub = (string)pInstanceData[pFieldData_Dependency_Sub.strFieldName];

                    UnityEngine.Object[] arrObject = AssetDatabase.LoadAllAssetsAtPath(strDependencyValue);
                    if (arrObject == null || arrObject.Length == 0)
                    {
                        Debug.LogError($"Value Is Null Or Empty - Type : {pMember.strFieldType} {strDependencyValue}");
                        continue;
                    }

                    var pObject = arrObject.FirstOrDefault(p => p.name == strDependencyValue_Sub && p.GetType() == pType_Field);
                    if (pObject == null)
                    {
                        Debug.LogError($"{pTypeData.strFileName} - DependencyValue Sub {strDependencyValue_Sub} Is Null");
                    }

                    pFieldInfo.SetValue(pSO, pObject);
                }
                else
                {
                    switch (pMember.strFieldType)
                    {
                    case "System.DateTime": pFieldInfo.SetValue(pSO, DateTime.Parse(strDependencyValue)); break;

                    default:
                        UnityEngine.Object pObject = AssetDatabase.LoadAssetAtPath(strDependencyValue, pType_Field);
                        if (pObject == null)
                        {
                            Debug.LogError($"{pTypeData.strFileName}-{pMember.strFieldName}({pMember.strFieldType})  - Value Is Null Or Empty - Value : {strDependencyValue}");
                        }
                        pFieldInfo.SetValue(pSO, pObject);
                        break;
                    }
                }
            }
        }
    }
コード例 #3
0
 private static void Process_SOName(string strFileName, int iLoopIndex, ScriptableObject pSO, FieldTypeData pFieldHeader, JObject pInstanceData)
 {
     pSO.name = pFieldHeader != null ? (string)pInstanceData[pFieldHeader.strFieldName] : $"{strFileName}_{iLoopIndex}";
     if (string.IsNullOrEmpty(pSO.name))
     {
         Debug.LogError($"{strFileName} - {nameof(Process_SOName)} -  {string.IsNullOrEmpty(pSO.name)}, pFieldHeader : {pFieldHeader?.strFieldName}");
     }
 }