Beispiel #1
0
                private bool DrawAddBackgroundLogicButton()
                {
                    int index = 0;

                    Type[] logicTypes = SystemUtils.GetAllSubTypes(typeof(ConditionalStateBackgroundLogic));

                    string[] logicTypeNames = new string[logicTypes.Length + 1];
                    logicTypeNames[index++] = "(Add State Background Logic)";

                    foreach (Type type in logicTypes)
                    {
                        logicTypeNames[index] = type.Name;
                        index++;
                    }

                    int newIndex = EditorGUILayout.Popup(string.Empty, 0, logicTypeNames);

                    if (0 != newIndex)
                    {
                        Type branchType = logicTypes[newIndex - 1];

                        ConditionalStateBackgroundLogic newBackgroundLogic = Activator.CreateInstance(branchType) as ConditionalStateBackgroundLogic;
                        ConditionalState conditionalState = (ConditionalState)GetEditableObject();

                        ArrayUtils.Add(ref conditionalState._backgroundLogic, newBackgroundLogic);

                        StateMachineEditor editor = (StateMachineEditor)GetEditor();
                        editor.OnAddedNewObjectToTimeline(newBackgroundLogic);

                        return(true);
                    }

                    return(false);
                }
Beispiel #2
0
                public override bool RenderObjectProperties(GUIContent label)
                {
                    bool dataChanged = false;

                    ConditionalState conditionalState = (ConditionalState)GetEditableObject();
                    Color            orig             = GUI.backgroundColor;

                    dataChanged |= RenderStateDescriptionField();
                    dataChanged |= RenderStateColorField();

                    EditorGUILayout.Separator();

                    #region Render Brances
                    EditorGUILayout.LabelField("State Exit Conditions:", EditorStyles.boldLabel);
                    EditorGUILayout.Separator();

                    if (conditionalState._branches != null)
                    {
                        for (int i = 0; i < conditionalState._branches.Length; i++)
                        {
                            GUI.backgroundColor = _titleLabelColor;
                            EditorGUILayout.LabelField(GetConditionLabel(conditionalState._branches[i], i == 0), EditorUtils.TextTitleStyle, GUILayout.Height(24.0f));
                            GUI.backgroundColor = orig;

                            //Draw condition properties
                            SerializationEditorGUILayout.ObjectField(conditionalState._branches[i], string.Empty, ref dataChanged);

                            if (DrawEditConditionsButtons(i))
                            {
                                dataChanged = true;
                                break;
                            }
                        }
                    }

                    dataChanged |= DrawAddConditionButton();
                    #endregion

                    EditorGUILayout.Separator();
                    EditorGUILayout.Separator();

                    #region Render Background Logic Threads
                    EditorGUILayout.LabelField("Background Logic:", EditorStyles.boldLabel);
                    EditorGUILayout.Separator();

                    if (conditionalState._backgroundLogic != null)
                    {
                        for (int i = 0; i < conditionalState._backgroundLogic.Length; i++)
                        {
                            ConditionalStateBackgroundLogic backgroundLogic = conditionalState._backgroundLogic[i];

                            GUI.backgroundColor = _titleLabelColor;
                            EditorGUILayout.LabelField(backgroundLogic.GetDescription(), EditorUtils.TextTitleStyle, GUILayout.Height(24.0f));
                            GUI.backgroundColor = orig;

                            //Draw backgroundLogic properties
                            {
                                int origIndent = EditorGUI.indentLevel;
                                EditorGUI.indentLevel++;

                                backgroundLogic = SerializationEditorGUILayout.ObjectField(backgroundLogic, "", ref dataChanged);

                                EditorGUI.indentLevel = origIndent;
                            }

                            if (DrawEditBackgroundLogicButtons(i))
                            {
                                dataChanged = true;
                                break;
                            }
                        }
                    }

                    dataChanged |= DrawAddBackgroundLogicButton();
                    #endregion

                    return(dataChanged);
                }