Exemplo n.º 1
0
        ///<summary>
        ///Creates an instance for the specified AI.
        ///</summary>
        ///<param name = "aiId" > The name of the ai that gets registered.</param>
        ///<param name = "aiName" > Name of the asset file.</param>
        ///<returns></returns>
        public virtual UtilityAIAsset CreateAsset(string aiId, string aiName, bool isSelect = true)
        {
            UtilityAIAsset asset = ScriptableObject.CreateInstance <UtilityAIAsset>();

            string assetDir = AssetDatabase.GenerateUniqueAssetPath(AiManager.StorageFolder + "/" + aiName + ".asset");


            asset.friendlyName  = Path.GetFileNameWithoutExtension(assetDir);
            asset.aiId          = aiId;
            asset.configuration = new UtilityAI(asset.friendlyName);

            asset.aiConfig = ProjectAsset.GetData(asset.configuration);

            ////  Creating Demo AI
            //if (isMockAI){
            //    var config = new UtilityAIConfig(asset);
            //    asset = config.asset;
            //}

            AssetDatabase.CreateAsset(asset, assetDir);
            AssetDatabase.SaveAssets();

            if (isSelect)
            {
                Selection.activeObject = asset;
            }


            return(asset);
        }
Exemplo n.º 2
0
        protected void DrawCreateDemoAIContents()
        {
            //  Section for new name
            CreateClientDrawer(true);

            EditorGUILayout.Space();


            if (GUILayout.Button("Create Scan AI"))
            {
                var utilityAIAsset = new UtilityAIAsset();
                var aiAsset        = utilityAIAsset.CreateAsset <ScanAIConfig>("DemoScanAI", "DemoScanAI", taskNetwork.selectAiAssetOnCreate);
                //  Add asset and client to TaskNetwork
                AddAIAsset(aiAsset);
                CloseWindow();
            }
            if (GUILayout.Button("Create Move AI"))
            {
                var utilityAIAsset = new UtilityAIAsset();
                var aiAsset        = utilityAIAsset.CreateAsset <MoveAIConfig>("DemoMoveAI", "DemoMoveAI", taskNetwork.selectAiAssetOnCreate);
                //  Add asset and client to TaskNetwork
                AddAIAsset(aiAsset);
                CloseWindow();
            }
        }
Exemplo n.º 3
0
        public virtual UtilityAIAsset CreateAsset <T>(string aiId, string aiName, bool isSelect = true) where T : UtilityAIConfig
        {
            UtilityAIAsset asset = CreateAsset(aiId, aiName, isSelect);

            SetAssetConfig <T>(asset);
            AssetDatabase.SaveAssets();
            return(asset);
        }
Exemplo n.º 4
0
        public void OnEnable()
        {
            obj = target as UtilityAIAsset;

            textStyle = new GUIStyle();
            //textStyle.normal.textColor = Color.white;
            textStyle.richText = true;
        }
Exemplo n.º 5
0
        //void UpdateClientList(){
        //    clientList = new GenericMenu();
        //    foreach (UtilityAIClient client in taskNetwork.clients){
        //        clientList.AddItem(new GUIContent(client.ai.name), false, SetActiveClient, client);
        //    }
        //}


        //public void AddUtilityAIAsset(UtilityAIAsset aiAsset){
        //    UtilityAIClient client = new UtilityAIClient(aiAsset.configuration, taskNetwork.contextProvider);
        //    //  Add to Lists
        //    taskNetwork.clients.Add(client);
        //    taskNetwork.assets.Add(aiAsset);
        //    //  Update Editor.
        //    EditorUtility.SetDirty(target);
        //    UpdateClientList();
        //    Repaint();

        //}


        public void RemoveUtilityAIAsset(int index)
        {
            activeClient = null;
            taskNetwork.clients.RemoveAt(index);
            taskNetwork.assets.RemoveAt(index);
            //  Update Editor.
            EditorUtility.SetDirty(target);
            //UpdateClientList();
            Repaint();
        }
Exemplo n.º 6
0
        public static UtilityAIAsset[] GetAllClients()
        {
            string filterType = "t:UtilityAIAsset";
            var    aiAssets   = new List <UtilityAIAsset>();

            foreach (var guid in AssetDatabase.FindAssets(filterType))
            {
                string         assetPath = AssetDatabase.GUIDToAssetPath(guid);
                UtilityAIAsset aiAsset   = AssetDatabase.LoadMainAssetAtPath(assetPath) as UtilityAIAsset;
                aiAssets.Add(aiAsset);
            }
            return(aiAssets.ToArray());
        }
Exemplo n.º 7
0
        void AddAIAsset(UtilityAIAsset aiAsset)
        {
            //  Add asset and client to TaskNetwork
            UtilityAIClient client = new UtilityAIClient(aiAsset.configuration, taskNetwork.contextProvider);

            taskNetwork.clients.Add(client);
            taskNetwork.assets.Add(aiAsset);

            aiAsset.configuration.OnBeforeSerialize();
            aiAsset.configuration.OnAfterDeserialize();

            EditorUtility.SetDirty(taskNetwork);
        }
        protected void DrawWindowContents()
        {
            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                EditorGUILayout.LabelField("New AI Name", Styles.TextCenterStyle);
                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.Label("Name: ", GUILayout.Width(window.minSize.x * 0.18f));
                    aiName = GUILayout.TextField(aiName);
                }
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button("Ok"))
                    {
                        var utilityAIAsset = new UtilityAIAsset();
                        var aiAsset        = utilityAIAsset.CreateAsset(String.IsNullOrEmpty(aiName) || String.IsNullOrWhiteSpace(aiName) ? defaultAiID : aiName,
                                                                        String.IsNullOrEmpty(aiName) || String.IsNullOrWhiteSpace(aiName) ? defaultAiName : aiName);

                        CloseWindow();
                    }
                    if (GUILayout.Button("Cancel"))
                    {
                        CloseWindow();
                    }
                }
            }



            //var oldColor = GUI.backgroundColor;
            //GUI.backgroundColor = Color.cyan;
            if (GUILayout.Button("Create Scan AI"))
            {
                var utilityAIAsset = new UtilityAIAsset();
                var aiAsset        = utilityAIAsset.CreateAsset <ScanAIConfig>("DemoMockAI", "DemoMockAI");
                CloseWindow();
            }
            if (GUILayout.Button("Create Move AI"))
            {
                var utilityAIAsset = new UtilityAIAsset();
                var aiAsset        = utilityAIAsset.CreateAsset <MoveAIConfig>("DemoMockAI", "DemoMockAI");
                CloseWindow();
            }
            //GUI.backgroundColor = oldColor;
        }
Exemplo n.º 9
0
        public static void CreateClientDrawer(string aiName, TaskNetworkComponent taskNetwork, bool isDemoAI = false)
        {
            int    windowSize        = 250;
            string defaultAiID       = "NewUtilityAI";
            string defaultAiName     = "New Utility AI";
            string defaultDemoAiID   = "NewDemoMockAI";
            string defaultDemoAiName = "NewDemoMockAI";

            string _defaultAiID   = isDemoAI == false ? defaultDemoAiID : defaultAiID;
            string _defaultAiName = isDemoAI == false ? defaultDemoAiName : defaultAiName;

            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                EditorGUILayout.LabelField("New AI Name", Styles.TextCenterStyle);
                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.Label("Name: ", GUILayout.Width(windowSize * 0.18f));
                    aiName = GUILayout.TextField(aiName);
                }
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button("Ok"))
                    {
                        var utilityAIAsset = new UtilityAIAsset();
                        //var aiAsset = utilityAIAsset.CreateAsset(String.IsNullOrEmpty(aiName) || String.IsNullOrWhiteSpace(aiName) ? _defaultAiID : aiName,
                        //String.IsNullOrEmpty(aiName) || String.IsNullOrWhiteSpace(aiName) ? _defaultAiName : aiName,
                        //taskNetwork.selectAiAssetOnCreate);

                        //editor.AddUtilityAIAsset(aiAsset);
                        //CloseWindow();
                    }
                    if (GUILayout.Button("Cancel"))
                    {
                        //CloseWindow();
                    }
                }
            }
        }
Exemplo n.º 10
0
        void CreateClientDrawer(bool isDemoAI = false)
        {
            string         _defaultAiID   = isDemoAI == false ? defaultDemoAiID : defaultAiID;
            string         _defaultAiName = isDemoAI == false ? defaultDemoAiName : defaultAiName;
            UtilityAIAsset utilityAIAsset;

            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                EditorGUILayout.LabelField("New AI Name", Styles.TextCenterStyle);
                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.Label("Name: ", GUILayout.Width(windowMinSize * 0.18f));
                    aiName = GUILayout.TextField(aiName);
                }
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button("Ok"))
                    {
                        //utilityAIAsset = isDemoAI == false ? new UtilityAIAsset() : new UtilityAIConfig();
                        utilityAIAsset = new UtilityAIAsset();
                        var aiAsset = utilityAIAsset.CreateAsset(String.IsNullOrEmpty(aiName) || String.IsNullOrWhiteSpace(aiName) ? _defaultAiID : aiName,
                                                                 String.IsNullOrEmpty(aiName) || String.IsNullOrWhiteSpace(aiName) ? _defaultAiName : aiName,
                                                                 taskNetwork.selectAiAssetOnCreate);
                        //  Add asset and client to TaskNetwork
                        AddAIAsset(aiAsset);
                        // -----------------------------------

                        //editor.AddUtilityAIAsset(aiAsset);
                        CloseWindow();
                    }
                    if (GUILayout.Button("Cancel"))
                    {
                        CloseWindow();
                    }
                }
            }
        }
Exemplo n.º 11
0
        protected override void DrawWindowContents()
        {
            EditorGUILayout.Space();
            using (new EditorGUILayout.VerticalScope())
            {
                foreach (var guid in AssetDatabase.FindAssets(filterType))
                {
                    string     assetPath   = AssetDatabase.GUIDToAssetPath(guid);
                    GUIContent buttonLabel = new GUIContent(Path.GetFileNameWithoutExtension(assetPath));

                    if (GUILayout.Button(buttonLabel, GUILayout.Height(18)))
                    {
                        UtilityAIAsset aiAsset = AssetDatabase.LoadMainAssetAtPath(assetPath) as UtilityAIAsset;

                        //  Add asset and client to TaskNetwork
                        AddAIAsset(aiAsset);
                        // -----------------------------------

                        //taskNetworkEditor.AddUtilityAIAsset(aiAsset);
                        CloseWindow();
                    }
                }
            }
        }
Exemplo n.º 12
0
        //private IAction a;
        //private IScorer scorer;
        //private List<IScorer> scorers;
        //private IQualifier q;
        //private Selector s;

        //private List<IQualifier> qualifiers;
        //private List<IScorer[]> allScorers;
        //private List<IAction> actions;


        public MoveAIConfig(UtilityAIAsset asset) : base(asset)
        {
            this.asset = asset;
            Init();
        }
Exemplo n.º 13
0
 public UtilityAIConfig(UtilityAIAsset asset)
 {
 }
Exemplo n.º 14
0
        /// <summary>
        /// Client Inspector
        /// </summary>
        protected virtual void DrawTaskNetworkInspector()
        {
            //  Displaying header options.
            using (new EditorGUILayout.HorizontalScope()){
                EditorGUILayout.LabelField("AIs", EditorStyles.boldLabel);

                //  Add a new UtilityAIClient
                if (GUILayout.Button("Add", EditorStyles.miniButton, GUILayout.Width(65f)))
                {
                    InspectorUtility.ShowOptionsWindow <AddClientWindow>(taskNetwork);
                    //ShowOptionsWindow<AddClientWindow>();
                }
            }


            //  Displaying the AI Clients
            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                if (taskNetwork.clients.Count == 0)
                {
                    EditorGUILayout.HelpBox("There are no AI's attached to this TaskNetworkComponent.", MessageType.Info);
                }


                for (int i = 0; i < taskNetwork.clients.Count; i++)
                {
                    UtilityAIClient client = taskNetwork.clients[i];
                    UtilityAIAsset  asset  = taskNetwork.assets[i];
                    using (new EditorGUILayout.VerticalScope())
                    {
                        if (asset != null && client != null)
                        {
                            //  For Client Options
                            using (new EditorGUILayout.HorizontalScope())
                            {
                                EditorGUILayout.ToggleLeft(GUIContent.none, true);                            // GUILayout.Width(Screen.width * 0.6f)

                                if (GUILayout.Button("Debug", EditorStyles.miniButton, GUILayout.Width(48f))) //  GUILayout.Width(Screen.width * 0.15f)
                                {
                                    Debug.Log(client.ai.name);
                                    Selection.activeObject = asset;
                                }

                                if (InspectorUtility.OptionsPopupButton(InspectorUtility.DeleteContent))
                                {
                                    RemoveUtilityAIAsset(i);
                                }
                            }


                            using (new EditorGUILayout.HorizontalScope())
                            {
                                EditorGUILayout.LabelField(new GUIContent("AI: "), GUILayout.Width(Screen.width * 0.33f));
                                EditorGUILayout.LabelField(new GUIContent(asset.friendlyName));
                                //EditorGUILayout.LabelField(new GUIContent(client.ai.name));  //  Name resets after scene reload
                            }


                            using (new EditorGUILayout.HorizontalScope())
                            {
                                EditorGUILayout.LabelField("Interval: ", GUILayout.Width(Screen.width * 0.33f));
                                client.intervalMin = EditorGUILayout.FloatField(client.intervalMin, GUILayout.Width(35f));
                                EditorGUILayout.LabelField("to ", GUILayout.Width(20f));
                                client.intervalMax = EditorGUILayout.FloatField(client.intervalMax, GUILayout.Width(35f));
                            }

                            //  For Client StartDelay
                            using (new EditorGUILayout.HorizontalScope())
                            {
                                //EditorGUILayout.LabelField("Start Delay: ", GUILayout.Width(Screen.width * 0.33f));
                                //client.startDelayMin = EditorGUILayout.FloatField(client.startDelayMin, GUILayout.Width(35f));
                                //EditorGUILayout.LabelField("to ", GUILayout.Width(20f));
                                //client.startDelayMax = EditorGUILayout.FloatField(client.startDelayMax, GUILayout.Width(35f));
                                float min = client.startDelayMin;
                                float max = client.startDelayMax;
                                InspectorUtility.MinMaxInputField(ref min, ref max, new GUIContent("Start Delay: "));
                            }
                            EditorGUILayout.Space();
                        }
                    }
                }
            }  // The group is now ended



            //  -- Active Client Info
            if (taskNetwork.assets.Count > 0)
            {
                ContextMessageBox();
                //ActiveClientMessageBox();
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Editor", EditorStyles.miniButton, GUILayout.Width(65f)))
                {
                    AIAssetEditor.Init();
                }
            }
            GUILayout.Space(8);
        }
Exemplo n.º 15
0
        public void SetAssetConfig <TConfig>(UtilityAIAsset asset) where TConfig : UtilityAIConfig
        {
            TConfig config = (TConfig)Activator.CreateInstance(typeof(TConfig), new object[] { asset });

            asset = config.asset;
        }
Exemplo n.º 16
0
 void SetActiveClient(object c)
 {
     currentClient    = c as UtilityAIAsset;
     serializedObject = new SerializedObject(currentClient);
 }
Exemplo n.º 17
0
        public static UtilityAIAsset ElementInspector(UtilityAIAsset activeClient)
        {
            if (activeClient == null)
            {
                return(null);
            }

            Selector rootSelector = activeClient.configuration.rootSelector;

            bool   elementIsDisable;
            string elementType = rootSelector.GetType().Name;
            string elementName;
            string elementDisplayName = "Qualifiers";
            string elementDescription;

            List <Type>     items = new List <Type>();
            ReorderableList itemsList;


            //var attr = activeClient.rootSelector.GetType().GetProperty("FriendlyNameAttribute").GetCustomAttribute(typeof(FriendlyNameAttribute));
            //var friendlyName = attr as FriendlyNameAttribute;
            using (new EditorGUILayout.HorizontalScope())
            {
                elementIsDisable = EditorGUILayout.ToggleLeft(new GUIContent(elementType + " | TASKNETWORK AI"), true);

                //  Change Element
                if (InspectorUtility.OptionsPopupButton(InspectorUtility.ChangeContent))
                {
                    //ShowOptionsWindow<AddOptionsWindow>(typeof(Selector));
                    Debug.Log("Show Option Popup Window");
                }
                //  Delete Element
                if (InspectorUtility.OptionsPopupButton(InspectorUtility.DeleteContent))
                {
                    Debug.Log("Deleting");
                }
            }


            //  NameField of Selected Selector, Qualifier or Action
            elementName = InspectorUtility.NameField("Test Name");
            //  Description of Selector.
            elementDescription = InspectorUtility.DescriptionField("", 2);


            //  Custom Attribute Fields.
            EditorGUILayout.LabelField(" <Custom Attributes> ");
            EditorGUILayout.IntField("First Test Field", 1);
            EditorGUILayout.IntField("Second Test Field", 2);



            //  Header for list of itemsList.
            EditorGUILayout.Space();
            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField(new GUIContent(elementDisplayName));

                if (InspectorUtility.OptionsPopupButton(InspectorUtility.AddContent))
                {
                    Debug.Log("Show Option Popup Window");
                    //ShowOptionsWindow<AddOptionsWindow>(typeof(QualifierBase));
                    //activeClient.rootSelector.qualifiers.Add(new CompositeScoreQualifier());
                    //aiAssets[0].ApplyModifiedProperties();
                }
            }

            //  list of itemsList.
            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                if (rootSelector.qualifiers.Count != 0)
                {
                    itemsList = new ReorderableList(rootSelector.qualifiers, typeof(IQualifier), true, false, false, false);
                    itemsList.showDefaultBackground = false;
                    itemsList.DoLayoutList();
                }

                //  Default Qualifier
                EditorGUILayout.LabelField(new GUIContent(rootSelector.defaultQualifier.GetType().Name));
            }


            return(activeClient);
        }
Exemplo n.º 18
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();


            using (new EditorGUILayout.HorizontalScope())
            {
                taskNetwork.showDefaultInspector = EditorGUILayout.ToggleLeft("Show Default Inspector", taskNetwork.showDefaultInspector);

                if (GUILayout.Button("Clear", EditorStyles.miniButton, GUILayout.Width(65f)))
                {
                    taskNetwork.clients.Clear();
                    taskNetwork.assets.Clear();
                    activeClient = null;
                    //Repaint();
                }
            }
            using (new EditorGUILayout.HorizontalScope())
            {
                taskNetwork.showDeleteAssetOption = EditorGUILayout.ToggleLeft("Show Delete Asset Btn", taskNetwork.showDeleteAssetOption);
                if (taskNetwork.showDeleteAssetOption)
                {
                    if (GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.Width(65f)))
                    {
                        activeClient = null;
                        taskNetwork.clients.Clear();
                        taskNetwork.assets.Clear();
                        var results = AssetDatabase.FindAssets("t:UtilityAIAsset", new string[] { AiManager.StorageFolder });
                        foreach (string guid in results)
                        {
                            AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(guid));
                        }
                        //Repaint();
                    }
                }
            }
            using (new EditorGUILayout.HorizontalScope())
            {
                taskNetwork.selectAiAssetOnCreate = EditorGUILayout.ToggleLeft("Select Asset On Create", taskNetwork.selectAiAssetOnCreate);
            }

            GUILayout.Space(8);
            if (taskNetwork.showDefaultInspector)
            {
                DrawDefaultInspector();
                GUILayout.Space(8);
            }
            DrawTaskNetworkInspector();


            //currentTab = GUILayout.Toolbar(currentTab, new string[] { "Clients", "Client Editor", "Preferences" });
            //switch (currentTab)
            //{
            //    case 0:
            //        if(taskNetwork.showDefaultInspector) DrawDefaultInspector();
            //        DrawTaskNetworkInspector();
            //        break;
            //    case 1:
            //        DrawTaskNetworkClientInspector();
            //        break;
            //    case 2:
            //        DrawPreferenceInspector();
            //        break;
            //}


            serializedObject.ApplyModifiedProperties();
        }