private Rect DrawEvents(Rect pos, Rect labelPos, SerializedProperty arrayEnter, string name)
        {
            labelPos.y += DragHeight;
            DrawerHelper.BoldLabel(labelPos, name + " Events", boldStyle);

            if (arrayEnter.hasMultipleDifferentValues)
            {
                labelPos.y += DragHeight;
                EditorGUI.HelpBox(labelPos, "Cannot edit with multiple different values.", MessageType.Info);
            }
            else
            {
                labelPos.y += DragHeight;
                DrawEventArray(pos, arrayEnter, ref labelPos, boldStyle);
                GUI.Button(labelPos, "Drag event here to add to " + name + " event");
                if (labelPos.Contains(Event.current.mousePosition))
                {
                    DrawerHelper.HandleEventDrag(arrayEnter);
                }
            }
            return(labelPos);
        }
Ejemplo n.º 2
0
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            var labelPos = pos;

            labelPos.y += 2;
            Color backgroundColor = GUI.color;

            TextAnchor defaultAnchor = GUI.skin.label.alignment;

            GUI.skin.label.alignment = TextAnchor.UpperLeft;
            var labelStyle = GUI.skin.GetStyle("label");

            if (eventTypeStyle == null)
            {
                eventTypeStyle = new GUIStyle(GUI.skin.GetStyle("label"));
            }

            SerializedProperty array = prop.FindPropertyRelative("Events");

            labelPos.height          = 18;
            eventTypeStyle.fontStyle = FontStyle.Bold;

            EditorStyles.foldout.fontStyle = FontStyle.Bold;
            Rect nameRect = labelPos;

            if (FieldName == null)
            {
                prop.isExpanded = EditorGUI.Foldout(nameRect, prop.isExpanded, "Event " + ObjectNames.NicifyVariableName(fieldInfo.Name), true);
            }
            else
            {
                prop.isExpanded = EditorGUI.Foldout(nameRect, prop.isExpanded, "Event " + FieldName.EventType, true);
            }

            EditorStyles.foldout.fontStyle = FontStyle.Normal;

            if (prop.isExpanded)
            {
                if (prop.hasMultipleDifferentValues)
                {
                    EditorGUILayout.HelpBox("Cannot edit with multiple different values.", MessageType.Info);
                }
                else
                {
                    GUI.skin.label.alignment = TextAnchor.MiddleLeft;
                    for (int i = 0; i < array.arraySize; ++i)
                    {
                        labelPos.y     += LineHeight;
                        labelPos.height = 20;
                        var audioEvent = array.GetArrayElementAtIndex(i).FindPropertyRelative("Event").objectReferenceValue as InAudioEventNode;

                        if (audioEvent != null)
                        {
                            GUI.Label(labelPos, audioEvent.GetName, labelStyle);
                        }
                        else
                        {
                            GUI.Label(labelPos, "Missing event", labelStyle);
                        }

                        Rect buttonPos = labelPos;
                        buttonPos.x     = pos.width - 200; //Align to right side
                        buttonPos.width = 100;
                        if (audioEvent == null)
                        {
                            GUI.enabled = false;
                        }

                        SerializedProperty postAtProperty = array.GetArrayElementAtIndex(i).FindPropertyRelative("PostAt");
                        buttonPos.y += 1.5f;
                        var currentValue =
                            Convert.ToInt32(EditorGUI.EnumPopup(buttonPos,
                                                                (EventHookListData.PostEventAt)postAtProperty.enumValueIndex));
                        buttonPos.y -= 1.5f;
                        if (currentValue != postAtProperty.enumValueIndex)
                        {
                            GUI.changed = true;
                        }
                        postAtProperty.enumValueIndex = currentValue;

                        buttonPos.x    += 108;
                        buttonPos.width = 50;
                        if (GUI.Button(buttonPos, "Find"))
                        {
                            EditorWindow.GetWindow <EventWindow>().Find(audioEvent);
                        }
                        GUI.enabled     = true;
                        buttonPos.x     = pos.width - 38;
                        buttonPos.width = 35;
                        if (GUI.Button(buttonPos, "X"))
                        {
                            array.DeleteArrayElementAtIndex(i);
                            GUI.changed = true;
                        }
                    }
                }

                if (!prop.hasMultipleDifferentValues)
                {
                    labelPos.y              += DragHeight + 4;
                    labelPos.height          = DragHeight;
                    GUI.skin.label.alignment = TextAnchor.MiddleCenter;
                    GUI.color = backgroundColor;

                    if (FieldName == null)
                    {
                        GUI.Button(labelPos,
                                   "Drag event here to add " + ObjectNames.NicifyVariableName(fieldInfo.Name) + " event");
                    }
                    else
                    {
                        GUI.Button(labelPos,
                                   "Drag event here to add " + FieldName.EventType + " event");
                    }

                    if (labelPos.Contains(Event.current.mousePosition))
                    {
                        DrawerHelper.HandleEventDrag(array);
                    }
                }
            }
            GUI.color = backgroundColor;

            labelPos.height         += 4;
            GUI.skin.label.alignment = defaultAnchor;
        }
Ejemplo n.º 3
0
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            EditorGUI.BeginProperty(pos, label, prop);
            var actions = prop.FindPropertyRelative("Actions");

            var labelPos = pos;

            var labelStyle = GUI.skin.GetStyle("label");
            var alignment  = labelStyle.alignment;

            labelStyle.alignment = TextAnchor.MiddleLeft;
            ;

            labelPos.height = 14;
            DrawerHelper.BoldLabel(labelPos, prop.FindPropertyRelative("Title").stringValue, labelStyle);

            for (int i = 0; i < actions.arraySize; ++i)
            {
                var currentElement = actions.GetArrayElementAtIndex(i);
                labelPos.y     += LineHeight;
                labelPos.height = 20;
                InAudioBankLink bankLink =
                    currentElement.FindPropertyRelative("Bank").objectReferenceValue as InAudioBankLink;
                if (bankLink != null)
                {
                    GUI.Label(labelPos, bankLink.GetName, labelStyle);
                }
                else
                {
                    GUI.Label(labelPos, "Missing event", labelStyle);
                }

                Rect buttonPos = labelPos;
                buttonPos.x     = pos.width - 172; //Align to right side
                buttonPos.width = 70;
                var actionProp = currentElement.FindPropertyRelative("BankAction");
                actionProp.enumValueIndex =
                    Convert.ToInt32(EditorGUI.EnumPopup(buttonPos, (BankHookActionType)actionProp.enumValueIndex));

                buttonPos.width = 50;

                buttonPos.x = pos.width - 100; //Align to right side
                if (bankLink == null)
                {
                    GUI.enabled = false;
                }

                if (GUI.Button(buttonPos, "Find"))
                {
                    EditorWindow.GetWindow <AuxWindow>().FindBank(bankLink);
                }
                GUI.enabled     = true;
                buttonPos.x     = pos.width - 44;
                buttonPos.width = 35;
                if (GUI.Button(buttonPos, "X"))
                {
                    actions.DeleteArrayElementAtIndex(i);
                }
            }
            labelPos.y              += DragHeight + 4;
            labelPos.height          = DragHeight;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;

            GUI.Button(labelPos, "Drag bank here for " + prop.FindPropertyRelative("Title").stringValue);
            if (labelPos.Contains(Event.current.mousePosition))
            {
                DrawerHelper.HandleBankDrag(actions);
            }

            labelStyle.alignment = alignment;
            EditorGUI.EndProperty();
        }