public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            position.height = lineHeight;

            var sourceTypeProperty = property.FindPropertyRelative("sourceType");
            var sourceTypeValue    = (ElevationSourceType)sourceTypeProperty.enumValueIndex;

            var displayNames = sourceTypeProperty.enumDisplayNames;
            int count        = sourceTypeProperty.enumDisplayNames.Length;

            if (!isGUIContentSet)
            {
                sourceTypeContent = new GUIContent[count];
                for (int extIdx = 0; extIdx < count; extIdx++)
                {
                    sourceTypeContent[extIdx] = new GUIContent
                    {
                        text    = displayNames[extIdx],
                        tooltip = ((ElevationSourceType)extIdx).Description(),
                    };
                }
                isGUIContentSet = true;
            }
            var typePosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent {
                text = "Data Source", tooltip = "Source tileset for Terrain."
            });

            sourceTypeProperty.enumValueIndex = EditorGUI.Popup(typePosition, sourceTypeProperty.enumValueIndex, sourceTypeContent);
            sourceTypeValue = (ElevationSourceType)sourceTypeProperty.enumValueIndex;

            position.y += lineHeight;

            var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions");
            var layerSourceProperty   = sourceOptionsProperty.FindPropertyRelative("layerSource");
            var layerSourceId         = layerSourceProperty.FindPropertyRelative("Id");

            switch (sourceTypeValue)
            {
            case ElevationSourceType.MapboxTerrain:
                var sourcePropertyValue = MapboxDefaultElevation.GetParameters(sourceTypeValue);
                layerSourceId.stringValue = sourcePropertyValue.Id;
                GUI.enabled = false;
                EditorGUI.PropertyField(position, sourceOptionsProperty, _mapIdGui);
                GUI.enabled = true;
                break;

            case ElevationSourceType.Custom:
                layerSourceId.stringValue = CustomSourceMapId;
                EditorGUI.PropertyField(position, sourceOptionsProperty, _mapIdGui);
                CustomSourceMapId = layerSourceId.stringValue;
                break;

            default:
                break;
            }


            //EditorGUI.PropertyField(position, property.FindPropertyRelative("sourceOptions"), true);
            if (sourceTypeValue != ElevationSourceType.None)
            {
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("sourceOptions"));
            }
            if (sourceTypeValue == ElevationSourceType.None)
            {
                GUI.enabled = false;
            }
            var elevationLayerType = property.FindPropertyRelative("elevationLayerType");

            EditorGUI.PropertyField(position, elevationLayerType, new GUIContent {
                text = elevationLayerType.displayName, tooltip = ((ElevationLayerType)elevationLayerType.enumValueIndex).Description()
            });
            position.y += lineHeight;
            if (sourceTypeValue == ElevationSourceType.None)
            {
                GUI.enabled = true;
            }

            EditorGUI.PropertyField(position, property.FindPropertyRelative("requiredOptions"), true);
            position.y  += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("requiredOptions"));
            ShowPosition = EditorGUI.Foldout(position, ShowPosition, "Others");
            if (ShowPosition)
            {
                position.y += lineHeight;
                EditorGUI.PropertyField(position, property.FindPropertyRelative("modificationOptions"), true);
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("modificationOptions"));
                EditorGUI.PropertyField(position, property.FindPropertyRelative("sideWallOptions"), true);
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("sideWallOptions"));
                EditorGUI.PropertyField(position, property.FindPropertyRelative("unityLayerOptions"), true);
            }

            EditorGUI.EndProperty();
        }
Пример #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            objectId = property.serializedObject.targetObject.GetInstanceID().ToString();

            var sourceTypeProperty = property.FindPropertyRelative("sourceType");

            var displayNames = sourceTypeProperty.enumDisplayNames;
            int count        = sourceTypeProperty.enumDisplayNames.Length;

            if (!isGUIContentSet)
            {
                sourceTypeContent = new GUIContent[count];
                for (int extIdx = 0; extIdx < count; extIdx++)
                {
                    sourceTypeContent[extIdx] = new GUIContent
                    {
                        text    = displayNames[extIdx],
                        tooltip = ((ElevationSourceType)extIdx).Description(),
                    };
                }
                isGUIContentSet = true;
            }
            var sourceTypeLabel = new GUIContent {
                text = "Data Source", tooltip = "Source tileset for Terrain."
            };

            EditorGUI.BeginChangeCheck();
            sourceTypeProperty.enumValueIndex = EditorGUILayout.Popup(sourceTypeLabel, sourceTypeProperty.enumValueIndex, sourceTypeContent);
            if (EditorGUI.EndChangeCheck())
            {
                EditorHelper.CheckForModifiedProperty(property);
            }

            var sourceTypeValue = (ElevationSourceType)sourceTypeProperty.enumValueIndex;

            var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions");
            var layerSourceProperty   = sourceOptionsProperty.FindPropertyRelative("layerSource");
            var layerSourceId         = layerSourceProperty.FindPropertyRelative("Id");

            EditorGUI.BeginChangeCheck();

            switch (sourceTypeValue)
            {
            case ElevationSourceType.MapboxTerrain:
                var sourcePropertyValue = MapboxDefaultElevation.GetParameters(sourceTypeValue);
                layerSourceId.stringValue = sourcePropertyValue.Id;
                GUI.enabled = false;
                EditorGUILayout.PropertyField(sourceOptionsProperty, _mapIdGui);
                GUI.enabled = true;
                break;

            case ElevationSourceType.Custom:
                layerSourceId.stringValue = string.IsNullOrEmpty(CustomSourceMapId) ? MapboxDefaultElevation.GetParameters(ElevationSourceType.MapboxTerrain).Id : CustomSourceMapId;
                EditorGUILayout.PropertyField(sourceOptionsProperty, _mapIdGui);
                CustomSourceMapId = layerSourceId.stringValue;
                break;

            default:
                break;
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorHelper.CheckForModifiedProperty(property);
            }

            var elevationLayerType = property.FindPropertyRelative("elevationLayerType");

            if (sourceTypeValue == ElevationSourceType.None)
            {
                GUI.enabled = false;
                elevationLayerType.enumValueIndex = (int)ElevationLayerType.FlatTerrain;
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(property.FindPropertyRelative("elevationLayerType"), new GUIContent {
                text = elevationLayerType.displayName, tooltip = ((ElevationLayerType)elevationLayerType.enumValueIndex).Description()
            });
            if (EditorGUI.EndChangeCheck())
            {
                EditorHelper.CheckForModifiedProperty(property);
            }

            if (sourceTypeValue == ElevationSourceType.None)
            {
                GUI.enabled = true;
            }

            GUILayout.Space(-lineHeight);
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(property.FindPropertyRelative("colliderOptions"), true);
            if (EditorGUI.EndChangeCheck())
            {
                EditorHelper.CheckForModifiedProperty(property.FindPropertyRelative("colliderOptions"));
            }
            GUILayout.Space(2 * -lineHeight);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(property.FindPropertyRelative("requiredOptions"), true);
            GUILayout.Space(-lineHeight);
            if (EditorGUI.EndChangeCheck())
            {
                EditorHelper.CheckForModifiedProperty(property);
            }

            ShowPosition = EditorGUILayout.Foldout(ShowPosition, "Others");

            if (ShowPosition)
            {
                EditorGUI.BeginChangeCheck();

                EditorGUILayout.PropertyField(property.FindPropertyRelative("modificationOptions"), true);

                EditorGUILayout.PropertyField(property.FindPropertyRelative("sideWallOptions"), true);

                EditorGUILayout.PropertyField(property.FindPropertyRelative("unityLayerOptions"), true);

                if (EditorGUI.EndChangeCheck())
                {
                    EditorHelper.CheckForModifiedProperty(property);
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            position.height = lineHeight;

            var sourceTypeProperty = property.FindPropertyRelative("sourceType");
            var sourceTypeValue    = (ElevationSourceType)sourceTypeProperty.enumValueIndex;

            var typePosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent {
                text = "Style Name", tooltip = EnumExtensions.Description(sourceTypeValue)
            });

            sourceTypeProperty.enumValueIndex = EditorGUI.Popup(typePosition, sourceTypeProperty.enumValueIndex, sourceTypeProperty.enumDisplayNames);
            sourceTypeValue = (ElevationSourceType)sourceTypeProperty.enumValueIndex;

            position.y += lineHeight;
            switch (sourceTypeValue)
            {
            case ElevationSourceType.MapboxTerrain:
                var sourcePropertyValue   = MapboxDefaultElevation.GetParameters(sourceTypeValue);
                var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions");
                var layerSourceProperty   = sourceOptionsProperty.FindPropertyRelative("layerSource");
                var layerSourceId         = layerSourceProperty.FindPropertyRelative("Id");
                layerSourceId.stringValue = sourcePropertyValue.Id;
                GUI.enabled = false;
                EditorGUI.PropertyField(position, sourceOptionsProperty, new GUIContent("Source Option"));
                GUI.enabled = true;
                break;

            case ElevationSourceType.Custom:
                EditorGUI.PropertyField(position, property.FindPropertyRelative("sourceOptions"), true);
                break;

            default:
                break;
            }


            //EditorGUI.PropertyField(position, property.FindPropertyRelative("sourceOptions"), true);
            if (sourceTypeValue != ElevationSourceType.None)
            {
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("sourceOptions"));
            }
            if (sourceTypeValue == ElevationSourceType.None)
            {
                GUI.enabled = false;
            }
            var elevationLayerType = property.FindPropertyRelative("elevationLayerType");

            EditorGUI.PropertyField(position, elevationLayerType, new GUIContent {
                text = elevationLayerType.displayName, tooltip = EnumExtensions.Description((ElevationLayerType)elevationLayerType.enumValueIndex)
            });
            position.y += lineHeight;
            if (sourceTypeValue == ElevationSourceType.None)
            {
                GUI.enabled = true;
            }

            EditorGUI.PropertyField(position, property.FindPropertyRelative("requiredOptions"), true);
            position.y  += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("requiredOptions"));
            showPosition = EditorGUI.Foldout(position, showPosition, "Others");
            if (showPosition)
            {
                position.y += lineHeight;
                EditorGUI.PropertyField(position, property.FindPropertyRelative("modificationOptions"), true);
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("modificationOptions"));
                EditorGUI.PropertyField(position, property.FindPropertyRelative("sideWallOptions"), true);
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("sideWallOptions"));
                EditorGUI.PropertyField(position, property.FindPropertyRelative("unityLayerOptions"), true);
            }

            EditorGUI.EndProperty();
        }