private void OnEnable() { inputConditionType = (InputConditionType)target; }
private void CreateCoreScriptableObjects() { TotalAIManager totalAIManager = FindObjectOfType<TotalAIManager>(); if (totalAIManager == null) { Debug.LogError("Trying to create core ScriptableObjects but there is no TotalAIManager."); return; } TotalAISettings settings = totalAIManager.settings; if (!Directory.Exists(defaultSOFolderRoot)) { Debug.LogError("Trying to create core ScriptableObjects but root directory is missing: " + defaultSOFolderRoot); return; } if (!defaultSOFolderRoot.EndsWith(Path.DirectorySeparatorChar.ToString())) { defaultSOFolderRoot += Path.DirectorySeparatorChar; } InputConditionType currentActionTypeICT = null; AttributeType movementSpeedAT = null; AttributeType detectionRadiusAT = null; Sphere3DST sphere3DST = null; Circle2DST circle2DST = null; UtilityAIPT utilityAIPT = null; GoToBT goToBT = null; foreach (KeyValuePair<string, string[]> DirToSOType in coreSOTypesToCreate) { string directory = DirToSOType.Key; string[] typeNames = DirToSOType.Value; int inventorySlotNum = 0; int attributeTypeNum = 0; foreach (string typeName in typeNames) { if (directory == "InventoryTypes" || directory == "MovementTypes" || directory == "SensorTypes") { if (typeName.Contains("2D") && !settings.for2D) continue; else if (typeName.Contains("3D") && settings.for2D) continue; } string fullDirectoryPath = defaultSOFolderRoot + directory; if (!Directory.Exists(fullDirectoryPath)) { try { Directory.CreateDirectory(fullDirectoryPath); AssetDatabase.Refresh(); } catch (Exception e) { Debug.LogError("Trying to create directory for Core SO " + typeName + " at " + fullDirectoryPath + " - Error = " + e); return; } } string assetName = typeName; if (typeName == "InventorySlot") { assetName = inventorySlotNames[inventorySlotNum]; ++inventorySlotNum; } else if (typeName == "MinMaxFloatAT") { assetName = attributeTypeNames[attributeTypeNum]; ++attributeTypeNum; } else if (typeName == "TypeCategory") { assetName = "All"; } string fullPath = fullDirectoryPath + Path.DirectorySeparatorChar + assetName + ".asset"; // See if this Asset already exists if (AssetDatabase.AssetPathToGUID(fullPath) != null && AssetDatabase.AssetPathToGUID(fullPath) != "" && AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(fullPath) != null) { Debug.Log("This core SO already exists: " + fullPath + " - Skipping it."); continue; } ScriptableObject asset = CreateInstance(typeName); if (asset == null) { Debug.LogError("Unable to create SO " + typeName + " - Skipping it."); continue; } AssetDatabase.CreateAsset(asset, fullPath); // See if this Asset has any Setup required if (asset is InputConditionType inputConditionType) { if (inputConditionType.name == "DriveLevelICT") { if (settings.driveLevelOCT == null) { Debug.LogError("Trying to create DriveLevelICT and set its mathingOCTs to DriveLevelOCT but settings.driveLevelOCT " + "is not set. Please set it and manually fix DriveLevelICT MatchingOCTs."); } else { inputConditionType.matchingOCTs = new List<OutputChangeType> { settings.driveLevelOCT }; EditorUtility.SetDirty(inputConditionType); } settings.driveLevelICT = inputConditionType; } else if (inputConditionType.name == "CurrentActionTypeICT") { currentActionTypeICT = inputConditionType; } } else if (asset is OutputChangeType outputChangeType && outputChangeType.name == "DriveLevelOCT") { settings.driveLevelOCT = outputChangeType; }