//private readonly string[] newTypeOptions = new string[] { "Tool or Weapon", "Projectile Weapon", "Agent Goes In", "Uses Resources", // "Fixed Storage", "Carriable Storage", "No Inventory" }; public override void OnEnable() { base.OnEnable(); worldObject = (WorldObject)target; totalAIManager = FindObjectOfType <TotalAIManager>(); }
public void DrawOnGUI(Rect position, Agent selectedAgent, TotalAIManager totalAIManager) { GUI.backgroundColor = new Color(.4f, .4f, .4f, 2f); GUI.Box(new Rect(0, 0, 4000, 4000), ""); GUI.backgroundColor = new Color(.8f, .8f, .8f, 1f); DrawGrid(position, 10, 0.2f, new Color(.2f, .2f, .2f, 2f)); DrawGrid(position, 50, 0.4f, new Color(.2f, .2f, .2f, 2f)); if (selectedAgent != null && selectedAgent.decider.AllCurrentPlans != null) { Dictionary <DriveType, float> drivesRanked = selectedAgent.decider.currentDriveTypesRanked; List <DriveType> driveTypes = drivesRanked.Keys.ToList(); List <float> driveUtilities = drivesRanked.Values.ToList(); string driveUtilityRound = "0."; for (int i = 0; i < selectedAgent.totalAIManager.settings.roundDriveUtility; i++) { driveUtilityRound += "0"; } DrawDriveButtons(driveTypes, driveUtilities, selectedAgent.decider.CurrentDriveType, 1, driveUtilityRound); if (selectedDrive != null) { DrawAgent(position, selectedAgent, null, false, totalAIManager); } } }
private void OnEnable() { // TODO: Better way to find this is customer moves folders? logoImage = (Texture)EditorGUIUtility.Load("Assets/TotalAI/Editor/Images/TotalAILogo.png"); currentTab = 0; createTotalAIManager = true; createTotalAISettings = true; createTimeManager = true; createGOAPManager = true; createLayers = true; createFolders = true; totalAIManager = FindObjectOfType<TotalAIManager>(); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(serializedObject.FindProperty("settings")); GUILayout.Space(10f); if (GUILayout.Button("Refresh Lists - Done Automatically On Play", GUILayout.Width(400))) { TotalAIManager.CreateTypeLists(manager); } GUILayout.Space(10f); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.PropertyField(serializedObject.FindProperty("allTypeCategories")); EditorGUILayout.PropertyField(serializedObject.FindProperty("allInputOutputTypes")); EditorGUILayout.PropertyField(serializedObject.FindProperty("allEntityTypes")); EditorGUILayout.PropertyField(serializedObject.FindProperty("allTypeGroups")); EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); }
private void OnEnable() { manager = (TotalAIManager)target; }
private void DrawAgent(Rect position, Agent agent, AgentType agentType, bool resetPlans, TotalAIManager totalAIManager) { if (agent == null) { return; } allCurrentPlans = agent.decider.AllCurrentPlans; Plans selectedPlans = null; if (allCurrentPlans != null && allCurrentPlans.TryGetValue(selectedDrive, out selectedPlans) && selectedPlans.rootMappings != null && selectedPlans.rootMappings.Count > 0) { if (selectedPlan == -1 && agent != null) { selectedPlan = agent.decider.CurrentPlanIndex; } else if (selectedPlan == -1) { selectedPlan = 0; } List <Mapping> rootMappings = selectedPlans.rootMappings; if (onlyComplete) { rootMappings = selectedPlans.GetCompletePlans(); } string title = (agent != null ? agent.name : agentType.name) + " : " + (selectedPlan + 1) + "/" + rootMappings.Count + "\n" + selectedPlans.driveType.name; GUI.Box(new Rect(position.width / 2 - 175 / 2, 10, 175, 35), title, "Button"); if (agent != null) { onlyComplete = GUI.Toggle(new Rect(position.width / 2 + 175 / 2 + 10, 10, 175, 25), onlyComplete, "Complete Plans"); } if (GUI.Button(new Rect(position.width / 2 - 175 / 2, 45, 50, 25), "Down")) { --selectedPlan; } if (agent != null && GUI.Button(new Rect(position.width / 2 - 175 / 2 + 50, 45, 75, 25), "Current")) { selectedPlan = agent.decider.CurrentPlanIndex; selectedDrive = agent.decider.CurrentDriveType; } if (GUI.Button(new Rect(position.width / 2 - 175 / 2 + 125, 45, 50, 25), "Up")) { ++selectedPlan; } //DrawICTCheckBoxes(agentType, totalAIManager); if (selectedPlan >= rootMappings.Count) { selectedPlan = 0; } else if (selectedPlan < 0) { selectedPlan = rootMappings.Count - 1; } if (selectedPlan < rootMappings.Count) { if (agent != null) { rootMappings[selectedPlan].Draw(position.width / 2 - 175 / 2, 80, 175, 75, 120, 100, agent.decider.CurrentMapping, agent); DrawPlanStats(position, selectedPlans); } else { rootMappings[selectedPlan].Draw(position.width / 2 - 175 / 2, 80, 175, 75, 120, 100, null, null); } } } else if (selectedPlans != null) { selectedPlan = -1; GUI.Box(new Rect(position.width / 2 - 200 / 2, 10, 200, 35), "Planned - No Plans Found", new GUIStyle("largeLabel") { alignment = TextAnchor.MiddleCenter }); } else { selectedPlan = -1; GUI.Box(new Rect(position.width / 2 - 175 / 2, 10, 175, 35), "Did Not Plan", new GUIStyle("largeLabel") { alignment = TextAnchor.MiddleCenter }); } }
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; }
private void DoSetup() { Debug.Log("Starting Total AI Setup:"); if (createFolders) { if (!defaultSOFolderRoot.EndsWith(Path.DirectorySeparatorChar.ToString())) { defaultSOFolderRoot += Path.DirectorySeparatorChar; } Debug.Log("Creating SO Folders"); if (!Directory.Exists(defaultSOFolderRoot)) { Debug.Log("Creating Root Directory: " + defaultSOFolderRoot); Directory.CreateDirectory(defaultSOFolderRoot); Debug.Log("Creating Sub Directories"); foreach (string typeName in allTypeNameDirectories) { Directory.CreateDirectory(defaultSOFolderRoot + typeName); } } else { Debug.Log("Root Directory: " + defaultSOFolderRoot + " Already Exists. NOT creating any folders."); } AssetDatabase.Refresh(); } if (createPrefabsFolders) { if (!defaultPrefabsFolderRoot.EndsWith(Path.DirectorySeparatorChar.ToString())) { defaultPrefabsFolderRoot += Path.DirectorySeparatorChar; } Debug.Log("Creating Prefabs Folders"); if (!Directory.Exists(defaultPrefabsFolderRoot)) { Debug.Log("Creating Root Directory: " + defaultPrefabsFolderRoot); Directory.CreateDirectory(defaultPrefabsFolderRoot); Debug.Log("Creating Sub Directories"); Directory.CreateDirectory(defaultPrefabsFolderRoot + "Agents"); Directory.CreateDirectory(defaultPrefabsFolderRoot + "WorldObjects"); Directory.CreateDirectory(defaultPrefabsFolderRoot + "AgentEvents"); } else { Debug.Log("Root Directory: " + defaultPrefabsFolderRoot + " Already Exists. NOT creating any folders."); } AssetDatabase.Refresh(); } if (createTotalAIManager) { GameObject manager = null; TotalAIManager totalAIManager = FindObjectOfType<TotalAIManager>(); if (totalAIManager != null) { Debug.LogError("TotalAIManager already exists in the Scene. NOT creating a new one."); manager = totalAIManager.gameObject; } else { manager = new GameObject("TotalAIManager", typeof(TotalAIManager)); Debug.Log("Created TotalAIManager in the Scene."); } if (createTotalAISettings) { if (!defaultSettingsPath.EndsWith(Path.DirectorySeparatorChar.ToString()) || !defaultSettingsPath.EndsWith(Path.AltDirectorySeparatorChar.ToString())) { defaultSettingsPath += Path.DirectorySeparatorChar; } if (!Directory.Exists(defaultSettingsPath)) { Debug.Log("Creating Directory: " + defaultSettingsPath); Directory.CreateDirectory(defaultSettingsPath); AssetDatabase.Refresh(); } else { Debug.Log("Directory Exists: " + defaultSettingsPath); } if (File.Exists(defaultSettingsPath + defaultSettingsName + ".asset")) { Debug.Log("Total AI Settings file already exists. NOT overwritting it."); } else { TotalAISettings settings = CreateInstance<TotalAISettings>(); AssetDatabase.CreateAsset(settings, defaultSettingsPath + defaultSettingsName + ".asset"); manager.GetComponent<TotalAIManager>().settings = settings; // TODO: Add in defaults - maybe search for commone ICTs and OCTs settings.scriptableObjectsDirectory = defaultSOFolderRoot.Remove(defaultSOFolderRoot.Length - 1, 1); settings.prefabsDirectory = defaultPrefabsFolderRoot.Remove(defaultPrefabsFolderRoot.Length - 1, 1); settings.movementTypes = new List<MovementType>(); settings.for2D = for2D; EditorUtility.SetDirty(settings); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Debug.Log("Created '" + defaultSettingsPath + defaultSettingsName + ".asset' and attached it to the TotalAIManager."); } } } if (createTimeManager) { TimeManager timeManager = FindObjectOfType<TimeManager>(); if (timeManager != null) { Debug.Log("TimeManager already exists in the Scene. NOT creating a new one."); } else { new GameObject("TimeManager", typeof(TimeManager)); Debug.Log("Created TimeManager in the Scene."); } } if (createGOAPManager) { GOAPPlannerManager manager = FindObjectOfType<GOAPPlannerManager>(); if (manager != null) { Debug.Log("GOAPPlannerManager already exists in the Scene. NOT creating a new one."); } else { new GameObject("GOAPPlannerManager", typeof(GOAPPlannerManager)); Debug.Log("Created GOAPPlannerManager in the Scene."); } } if (createLayers) { Debug.Log("Creating layers: Ground, Agent, WorldObject, AgentEvent, Inventory"); List<string> layersToCreate = new List<string>() { "Ground", "Agent", "WorldObject", "AgentEvent", "Inventory" }; CreateLayers(layersToCreate); } if (createScriptableObjects) { CreateCoreScriptableObjects(); } }