コード例 #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            int prevIndentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;
            EditorGUI.BeginProperty(position, label, property);

            SerializedProperty dataKeyProp     = property.FindPropertyRelative("m_dataKey");
            SerializedProperty intEventProp    = property.FindPropertyRelative("m_intEvent");
            SerializedProperty floatEventProp  = property.FindPropertyRelative("m_floatEvent");
            SerializedProperty boolEventProp   = property.FindPropertyRelative("m_boolEvent");
            SerializedProperty stringEventProp = property.FindPropertyRelative("m_stringEvent");
            SerializedProperty voidEventProp   = property.FindPropertyRelative("m_voidEvent");

            Rect dataKeyRect = new Rect(position.x, position.y, position.width, EditorGUI.GetPropertyHeight(dataKeyProp));

            EditorGUI.PropertyField(dataKeyRect, dataKeyProp, GUIContent.none);

            PlotAdditionalDataKey dataKey = (PlotAdditionalDataKey)dataKeyProp.objectReferenceValue;

            if (dataKey != null)
            {
                position.y += dataKeyRect.height + 2;

                switch (dataKey.GetKeyType())
                {
                case DataKeyType.INTEGER:
                    Rect intEventRect = new Rect(position.x, position.y, position.width, EditorGUI.GetPropertyHeight(intEventProp));
                    EditorGUI.PropertyField(intEventRect, intEventProp);
                    break;

                case DataKeyType.FLOAT:
                    Rect floatEventRect = new Rect(position.x, position.y, position.width, EditorGUI.GetPropertyHeight(floatEventProp));
                    EditorGUI.PropertyField(floatEventRect, floatEventProp);
                    break;

                case DataKeyType.BOOLEAN:
                    Rect boolEventRect = new Rect(position.x, position.y, position.width, EditorGUI.GetPropertyHeight(boolEventProp));
                    EditorGUI.PropertyField(boolEventRect, boolEventProp);
                    break;

                case DataKeyType.STRING:
                    Rect stringEventRect = new Rect(position.x, position.y, position.width, EditorGUI.GetPropertyHeight(stringEventProp));
                    EditorGUI.PropertyField(stringEventRect, stringEventProp);
                    break;

                case DataKeyType.VOID:
                    Rect voidEventRect = new Rect(position.x, position.y, position.width, EditorGUI.GetPropertyHeight(voidEventProp));
                    EditorGUI.PropertyField(voidEventRect, voidEventProp);
                    break;
                }
            }

            EditorGUI.EndProperty();
            EditorGUI.indentLevel = prevIndentLevel;
        }
コード例 #2
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            SerializedProperty dataKeyProp     = property.FindPropertyRelative("m_dataKey");
            SerializedProperty intEventProp    = property.FindPropertyRelative("m_intEvent");
            SerializedProperty floatEventProp  = property.FindPropertyRelative("m_floatEvent");
            SerializedProperty boolEventProp   = property.FindPropertyRelative("m_boolEvent");
            SerializedProperty stringEventProp = property.FindPropertyRelative("m_stringEvent");
            SerializedProperty voidEventProp   = property.FindPropertyRelative("m_voidEvent");

            float result = EditorGUI.GetPropertyHeight(dataKeyProp);

            PlotAdditionalDataKey dataKey = (PlotAdditionalDataKey)dataKeyProp.objectReferenceValue;

            if (dataKey == null)
            {
                return(result);
            }

            result += 2;

            switch (dataKey.GetKeyType())
            {
            case DataKeyType.INTEGER:
                result += EditorGUI.GetPropertyHeight(intEventProp);
                break;

            case DataKeyType.FLOAT:
                result += EditorGUI.GetPropertyHeight(floatEventProp);
                break;

            case DataKeyType.BOOLEAN:
                result += EditorGUI.GetPropertyHeight(boolEventProp);
                break;

            case DataKeyType.STRING:
                result += EditorGUI.GetPropertyHeight(stringEventProp);
                break;

            case DataKeyType.VOID:
                result += EditorGUI.GetPropertyHeight(voidEventProp);
                break;
            }

            return(result);
        }
コード例 #3
0
        public void Dispatch(List <PlotAdditionalData> additionalDataList)
        {
            foreach (PlotAdditionalData data in additionalDataList)
            {
                PlotAdditionalDataKey dataKey = data.dataKey;
                if (m_map.ContainsKey(dataKey))
                {
                    PlotAdditionalDataKeyUnityEvent e = m_map[dataKey];
                    switch (dataKey.GetKeyType())
                    {
                    case DataKeyType.INTEGER:
                        e.Dispatch(data.intValue);
                        break;

                    case DataKeyType.FLOAT:
                        e.Dispatch(data.floatValue);
                        break;

                    case DataKeyType.BOOLEAN:
                        e.Dispatch(data.boolValue);
                        break;

                    case DataKeyType.STRING:
                        e.Dispatch(data.stringValue);
                        break;

                    case DataKeyType.VOID:
                        e.Dispatch();
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            int prevIndentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            EditorGUI.BeginProperty(position, label, property);

            SerializedProperty    dataKeyProp = property.FindPropertyRelative("m_dataKey");
            PlotAdditionalDataKey dataKey     = (PlotAdditionalDataKey)dataKeyProp.objectReferenceValue;

            Rect dataKeyRect;

            if (dataKey == null || dataKey.GetKeyType() == DataKeyType.VOID)
            {
                dataKeyRect = new Rect(position.x + 75, position.y, position.width - 75, position.height);
            }
            else
            {
                dataKeyRect = new Rect(position.x + 75, position.y, 110, position.height);
            }

            Rect typeRect      = new Rect(position.x, position.y, 75, position.height);
            Rect valueRect     = new Rect(dataKeyRect.xMax + 5, position.y, position.xMax - dataKeyRect.xMax - 5, position.height);
            Rect boolValueRect = new Rect(dataKeyRect.xMax + 5, position.y, EditorGUIUtility.singleLineHeight, position.height);

            EditorGUI.PropertyField(dataKeyRect, dataKeyProp, GUIContent.none);

            if (dataKey == null)
            {
                if (GUI.Button(typeRect, "New", EditorStyles.miniButtonLeft))
                {
                    GenericMenu newKeyMenu = new GenericMenu();
                    newKeyMenu.AddItem(new GUIContent("String"), false, () => {
                        PlotAdditionalDataKeyString newStringKey = PromptToCreate <PlotAdditionalDataKeyString>("New String Key", "Name");
                        dataKeyProp.objectReferenceValue         = newStringKey;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                    newKeyMenu.AddItem(new GUIContent("Integer"), false, () => {
                        PlotAdditionalDataKeyInteger newIntegerKey = PromptToCreate <PlotAdditionalDataKeyInteger>("New Integer Key", "Name");
                        dataKeyProp.objectReferenceValue           = newIntegerKey;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                    newKeyMenu.AddItem(new GUIContent("Float"), false, () => {
                        PlotAdditionalDataKeyFloat newFloatKey = PromptToCreate <PlotAdditionalDataKeyFloat>("New Float Key", "Name");
                        dataKeyProp.objectReferenceValue       = newFloatKey;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                    newKeyMenu.AddItem(new GUIContent("Boolean"), false, () => {
                        PlotAdditionalDataKeyBoolean newBooleanKey = PromptToCreate <PlotAdditionalDataKeyBoolean>("New Boolean Key", "Name");
                        dataKeyProp.objectReferenceValue           = newBooleanKey;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                    newKeyMenu.AddItem(new GUIContent("A Data Key"), false, () => {
                        PlotAdditionalDataKeyVoid newVoidKey = PromptToCreate <PlotAdditionalDataKeyVoid>("A Data Key", "Name");
                        dataKeyProp.objectReferenceValue     = newVoidKey;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                    newKeyMenu.DropDown(new Rect(typeRect.x, typeRect.y, 0, typeRect.height));
                }
            }
            else
            {
                switch (dataKey.GetKeyType())
                {
                case DataKeyType.INTEGER:
                {
                    EditorGUI.LabelField(typeRect, dataKey.GetKeyTypeName(), EditorStyles.boldLabel);
                    SerializedProperty intValueProp = property.FindPropertyRelative("m_intValue");
                    EditorGUI.PropertyField(valueRect, intValueProp, GUIContent.none);
                    break;
                }

                case DataKeyType.FLOAT:
                {
                    EditorGUI.LabelField(typeRect, dataKey.GetKeyTypeName(), EditorStyles.boldLabel);
                    SerializedProperty floatValueProp = property.FindPropertyRelative("m_floatValue");
                    EditorGUI.PropertyField(valueRect, floatValueProp, GUIContent.none);
                    break;
                }

                case DataKeyType.BOOLEAN:
                {
                    EditorGUI.LabelField(typeRect, dataKey.GetKeyTypeName(), EditorStyles.boldLabel);
                    SerializedProperty boolValueProp = property.FindPropertyRelative("m_boolValue");
                    EditorGUI.PropertyField(boolValueRect, boolValueProp, GUIContent.none);
                    break;
                }

                case DataKeyType.STRING:
                {
                    EditorGUI.LabelField(typeRect, dataKey.GetKeyTypeName(), EditorStyles.boldLabel);
                    SerializedProperty stringValueProp = property.FindPropertyRelative("m_stringValue");
                    EditorGUI.PropertyField(valueRect, stringValueProp, GUIContent.none);
                    break;
                }

                case DataKeyType.VOID:
                {
                    EditorGUI.LabelField(typeRect, dataKey.GetKeyTypeName(), EditorStyles.boldLabel);
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
            EditorGUI.EndProperty();
            EditorGUI.indentLevel = prevIndentLevel;
        }