void ShowEventNameTooltip(SerializedProperty property, Rect position)
        {
            if (eventType == k_CustomEvent)
            {
                return;
            }

            int index = Array.IndexOf(eventTypes, eventType);

            if (index < 0 || index >= EventPayloads.s_EventTypes.Length)
            {
                return;
            }

            Type t = EventPayloads.s_EventTypes [index];

            if (t != null)
            {
                AnalyticsEventTracker tracker = property.serializedObject.targetObject as AnalyticsEventTracker;
                tracker.payload.standardEventType = t;

                StandardEventName attr =
                    (StandardEventName)Attribute.GetCustomAttribute(t, typeof(StandardEventName));
                if (attr != null)
                {
                    string tooltip = (attr as StandardEventName).tooltip;
                    GUI.Box(position, new GUIContent("", tooltip), GUIStyle.none);
                }
            }
        }
Beispiel #2
0
        void ConformEventType(SerializedProperty property, string eventType)
        {
            int  index = Array.IndexOf(eventTypes, eventType);
            Type t     = EventPayloads.s_EventTypes [index];

            if (t != null)
            {
                AnalyticsEventTracker tracker = property.serializedObject.targetObject as AnalyticsEventTracker;
                tracker.payload.standardEventType = t;

                StandardEventName attr =
                    (StandardEventName)Attribute.GetCustomAttribute(t, typeof(StandardEventName));
                if (attr != null)
                {
                    UpdateEventName(property, (attr as StandardEventName).sendName);
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            base.OnGUI(position, property, label);
            if (tracker == null)
            {
                tracker        = property.serializedObject.targetObject as AnalyticsEventTracker;
                refreshTracker = true;
            }
            BuildRequirementsList(tracker.payload.standardEventType);

            //ensure that we are never selecting off the end of the array
            if (m_ReorderableList.index >= m_FieldsArray.arraySize)
            {
                m_ReorderableList.index = -1;
            }

            UpdateDisplayAdd(m_ReorderableList);
            UpdateDisplayRemove(m_ReorderableList);

            refreshTracker = false;
        }
Beispiel #4
0
        float ParametersGUI(Rect position, SerializedProperty property, bool draw)
        {
            float height = 0;

            Rect rect = position;

            height = rect.height = EditorGUIUtility.singleLineHeight;

            SerializedProperty parameters = property.FindPropertyRelative("m_Parameters");

            rect.y += EditorGUIUtility.singleLineHeight;
            if (draw)
            {
                EditorGUI.PropertyField(rect, parameters, true);
            }
            height += EditorGUI.GetPropertyHeight(parameters);

            AnalyticsEventTracker tracker = property.serializedObject.targetObject as AnalyticsEventTracker;

            if (tracker != null)
            {
                string warningMsg = string.Empty;
                int    lineCount  = 0;

                // find warnings for required types and create dictionary for either or parameter types (required with group id)
                Dictionary <string, List <AnalyticsEventParam> > selectRequired = new Dictionary <string, List <AnalyticsEventParam> >();
                Dictionary <string, int> nameCounts = new Dictionary <string, int>();
                foreach (AnalyticsEventParam param in tracker.payload.parameters.parameters)
                {
                    if (param.requirementType == AnalyticsEventParam.RequirementType.Required)
                    {
                        if (string.IsNullOrEmpty(param.groupID))
                        {
                            if (!param.valueProperty.IsValid())
                            {
                                warningMsg += string.Format(k_NeedRequiredParam, param.name);
                                ++lineCount;
                            }
                        }
                        else
                        {
                            if (!selectRequired.ContainsKey(param.groupID))
                            {
                                selectRequired[param.groupID] = new List <AnalyticsEventParam>();
                            }

                            selectRequired[param.groupID].Add(param);
                        }
                    }

                    if (!string.IsNullOrEmpty(param.name))
                    {
                        if (!nameCounts.ContainsKey(param.name))
                        {
                            nameCounts[param.name] = 1;
                        }
                        else
                        {
                            nameCounts[param.name] = nameCounts[param.name] + 1;
                        }
                    }
                }

                // look at all the either or parameters and see if there are any errors
                foreach (string groupId in selectRequired.Keys)
                {
                    bool anyValid = false;
                    foreach (AnalyticsEventParam param in selectRequired[groupId])
                    {
                        if (param.valueProperty.IsValid())
                        {
                            anyValid = true;
                            break;
                        }
                    }

                    if (!anyValid)
                    {
                        warningMsg += string.Format(k_NeedRequiredParam, string.Join(" or ", selectRequired[groupId].Select(param => param.name).ToArray()));
                        ++lineCount;
                    }
                }

                // add any custom parameter warnings
                bool nameMissing  = false;
                bool valueMissing = false;
                foreach (AnalyticsEventParam param in tracker.payload.parameters.parameters)
                {
                    if (param.requirementType == AnalyticsEventParam.RequirementType.None)
                    {
                        if (string.IsNullOrEmpty(param.name))
                        {
                            nameMissing = true;
                        }
                        if (!param.valueProperty.IsValid())
                        {
                            valueMissing = true;
                        }
                    }
                }

                if (nameMissing && valueMissing)
                {
                    warningMsg += k_NeedNameValueCustomParam;
                    ++lineCount;
                }
                else if (nameMissing)
                {
                    warningMsg += k_NeedNameCustomParam;
                    ++lineCount;
                }
                else if (valueMissing)
                {
                    warningMsg += k_NeedValueCustomParam;
                    ++lineCount;
                }

                if (eventType == k_CustomEvent && string.IsNullOrEmpty(property.FindPropertyRelative("m_Name").stringValue))
                {
                    warningMsg += k_NeedCustomEventName;
                    ++lineCount;
                }

                // check for duplicated names
                foreach (string name in nameCounts.Keys)
                {
                    if (nameCounts[name] > 1)
                    {
                        warningMsg += string.Format(k_DuplicateNameParam, name);
                        ++lineCount;
                    }
                }

                if (lineCount > 0)
                {
                    warningMsg = warningMsg.Trim('\n');
                    int oldFontSize = EditorStyles.helpBox.fontSize;
                    EditorStyles.helpBox.fontSize = 11;

                    rect.y      += height - EditorGUIUtility.singleLineHeight / 2.0f;
                    rect.height += (Math.Max(lineCount, 2) - 0.5f) * EditorStyles.helpBox.lineHeight;
                    height      += rect.height;

                    EditorGUI.HelpBox(rect, warningMsg, MessageType.Warning);
                    EditorStyles.helpBox.fontSize = oldFontSize;
                }
            }

            return(height);
        }