Ejemplo n.º 1
0
        // Update is called once per frame
        void Update()
        {
            Rigidbody2D       character = transform.GetComponent <Rigidbody2D>();
            AlgorithmsManager manager   = new KinematicAlgorithmsManager();           // Default

            switch (aiType)
            {
            case AIType.Dynamic:
                manager = new DynamicAlgorithmsManager();
                break;

            case AIType.Kinematic:
                manager = new KinematicAlgorithmsManager();
                break;
            }
            manager.ManageAI(this, character);
        }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(aiType_Prop, new GUIContent("AI Type"));


            string selectedAIType = Enum.GetNames(AIType.None.GetType())[aiType_Prop.enumValueIndex];
            LinkedList <string> algorithmsOptionsList = new LinkedList <string>();

            string[] algorithmsNames = Enum.GetNames(AIAlgorithm.KinematicNone.GetType());
            foreach (string algName in algorithmsNames)
            {
                if (algName.Contains(selectedAIType))
                {
                    algorithmsOptionsList.AddLast(algName);
                }
            }
            string[] algorithmsOptionsArray = new string[algorithmsOptionsList.Count];
            algorithmsOptionsList.CopyTo(algorithmsOptionsArray, 0);
            int previouslySelectedIndex = 0;

            for (int i = 0; i < algorithmsOptionsArray.Length; i++)
            {
                if (algorithmsOptionsArray[i].Equals(algorithmsNames[aiAlgorithm_Prop.enumValueIndex]))
                {
                    previouslySelectedIndex = i;
                }
            }
            int newSelectedIndex             = algorithmsOptionsArray.Length - 1 < previouslySelectedIndex ? algorithmsOptionsArray.Length - 1 : previouslySelectedIndex;
            int algorithmChosenRelativeIndex = EditorGUILayout.Popup("AI Algorithm", newSelectedIndex, algorithmsOptionsArray);

            previouslySelectedIndex = algorithmChosenRelativeIndex;
            string algorithmChosenName          = algorithmsOptionsArray[algorithmChosenRelativeIndex];
            int    algorithmChosenAbsoluteIndex = 0;

            for (int i = 0; i < algorithmsNames.Length; i++)
            {
                if (algorithmsNames[i].Equals(algorithmChosenName))
                {
                    algorithmChosenAbsoluteIndex = i;
                }
            }
            aiAlgorithm_Prop.enumValueIndex = algorithmChosenAbsoluteIndex;

            AIType      aiType      = (AIType)aiType_Prop.enumValueIndex;
            AIAlgorithm aiAlgorithm = (AIAlgorithm)aiAlgorithm_Prop.enumValueIndex;

            //Debug.Log("AIType: " + aiType);
            //Debug.Log("AIAlgorithm: " + aiAlgorithm);

            EditorGUILayout.PropertyField(lookWhereYoureGoing_Prop, new GUIContent("Always look ahead"));

            AlgorithmsManager manager = new KinematicAlgorithmsManager();             // Default

            switch (aiType)
            {
            case AIType.Dynamic:
                manager = new DynamicAlgorithmsManager();
                break;

            case AIType.Kinematic:
                manager = new KinematicAlgorithmsManager();
                break;

            case AIType.None:
                if (aiAlgorithm == AIAlgorithm.KinematicNone)
                {
                    manager = new KinematicAlgorithmsManager();
                }
                else if (aiAlgorithm == AIAlgorithm.DynamicNone)
                {
                    manager = new DynamicAlgorithmsManager();
                }
                break;
            }
            manager.ManageEditor(this);

            serializedObject.ApplyModifiedProperties();
        }