Esempio n. 1
0
        private void TransitionListSetup()
        {
            // Step 1: Get properties.
            SerializedProperty ExConditions = serializedObject.FindProperty("_Transitions");

            // Step 1.1: Security check.
            if (ExConditions == null)
            {
                return;
            }

            // Step 2: Setup Reoderable lists.
            TransitionArray = new ReorderableList(serializedObject, ExConditions, true, true, true, true);

            // Step 2.1: CallBacks setup.
            // Draw Header
            TransitionArray.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Transition", EditorStyles.boldLabel);
            };

            // Draw Element
            TransitionArray.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocus) =>
            {
                Rect r1 = new Rect(rect.x, rect.y, rect.width * 0.75f, rect.height);
                Rect r2 = new Rect(rect.x + r1.width * 1.025f, rect.y, rect.width * 0.225f, rect.height);

                EditorGUI.ObjectField(r1, ExConditions.GetArrayElementAtIndex(index), GUIContent.none);

                SerializedProperty subscribed = ExConditions.GetArrayElementAtIndex(index);
                FSMStateTransition b          = subscribed.objectReferenceValue as FSMStateTransition;

                if (b != null)
                {
                    GUIStyle st = new GUIStyle(EditorStyles.helpBox);
                    st.fontSize          = EditorStyles.boldLabel.fontSize;
                    st.alignment         = TextAnchor.MiddleCenter;
                    st.focused.textColor = st.active.textColor = st.hover.textColor = st.normal.textColor = b.BlockTransition ? new Color(0.95f, 0.55f, 0.05f)  : Color.green;

                    b.BlockTransition = EditorGUI.ToggleLeft(r2, b.BlockTransition ? "Disabled" : "Enabled", b.BlockTransition, st);
                    ExConditions.GetArrayElementAtIndex(index).serializedObject.ApplyModifiedProperties();
                }
            };

            // On Add
            SetAddDropdownCallback(TransitionArray);

            // On Remove
            SetRemoveCallback(TransitionArray, Target.Transitions);
        }
Esempio n. 2
0
        private void SetRemoveCallback(ReorderableList list, List <FSMStateTransition> targetList)
        {
            list.onRemoveCallback = (ReorderableList rlist) =>
            {
                int j = rlist.index;

                FSMStateTransition dataCondition = targetList[j];

                targetList.RemoveAt(j);

                if (dataCondition)
                {
                    DestroyImmediate(dataCondition.gameObject);
                    EditorGUIUtility.ExitGUI();
                }
            };
        }
Esempio n. 3
0
        private void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            // Step 0: Setup.
            lineHeight      = EditorGUIUtility.singleLineHeight;
            lineHeightSpace = lineHeight + 10;

            Target = (FSMStateTransition)target;

            // Step 1: Get properties.
            SerializedProperty ExConditions = serializedObject.FindProperty("Conditions");

            // Step 1.1: Security check.
            if (ExConditions == null)
            {
                return;
            }

            // Step 2: Setup Reoderable lists.
            ConditionArray = new ReorderableList(serializedObject, ExConditions, true, true, true, true);

            // Step 2.1: CallBacks setup.
            // Draw Header
            ConditionArray.drawHeaderCallback = (Rect rect) =>
            {
                Rect r1 = new Rect(rect.x, rect.y, rect.width * 0.75f, rect.height);
                Rect r2 = new Rect(rect.x + r1.width, rect.y, rect.width * 0.25f, rect.height);
                EditorGUI.LabelField(r1, "Transition conditions", EditorStyles.boldLabel);

                GUIStyle customHelpBoxStyle = new GUIStyle(EditorStyles.helpBox);
                customHelpBoxStyle.alignment = TextAnchor.MiddleCenter;
                SerializedProperty subProp = serializedObject.FindProperty("_CurrentlySubscribed");
                if (subProp.boolValue)
                {
                    customHelpBoxStyle.fontStyle        = FontStyle.Bold;
                    customHelpBoxStyle.normal.textColor = new Color(0.95f, 0.55f, 0.05f);
                    EditorGUI.LabelField(r2, "Registered", customHelpBoxStyle);
                }
                else
                {
                    customHelpBoxStyle.normal.textColor = Color.grey;
                    EditorGUI.LabelField(r2, "Pending", customHelpBoxStyle);
                }
            };

            // Draw Element
            ConditionArray.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocus) =>
            {
                TransitionConditionDrawerUtility.DrawPropertyAsReorderableList(ConditionArray, rect, index);
            };

            // On Add
            SetAddDropdownCallback(ConditionArray);

            // On Remove
            SetRemoveCallback(ConditionArray, Target.Conditions);
        }