Esempio n. 1
0
        public override void OnInspectorGUI()
        {
            Initialize();

            var mapRenderer = (MapRenderer)target;

            serializedObject.UpdateIfRequiredOrScript();

            RenderBanner();

            // Setup and key.
            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.LabelField("API Settings", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;
            _bingMapsKeyProperty.stringValue = EditorGUILayout.PasswordField("Bing Maps Key", _bingMapsKeyProperty.stringValue);
            if (string.IsNullOrWhiteSpace(_bingMapsKeyProperty.stringValue))
            {
                Help(
                    "Provide a Bing Maps developer key to enable the map.",
                    "Sign up for a key at the Bing Maps Dev Center.",
                    "https://www.bingmapsportal.com/");
            }

            _showMapDataInEditorProperty.boolValue =
                EditorGUILayout.Toggle(
                    new GUIContent(
                        "Show Map Data in Editor",
                        "Map data usage in the editor will apply the specified Bing Maps key."),
                    _showMapDataInEditorProperty.boolValue);
            EditorGUILayout.EndVertical();

            // Location Section
            EditorGUILayout.BeginVertical(_boxStyle);
            _showMapLocationOptions = EditorGUILayout.Foldout(_showMapLocationOptions, "Location", true, _foldoutTitleStyle);
            if (_showMapLocationOptions)
            {
                var latitudeProperty = _centerProperty.FindPropertyRelative("Latitude");
                latitudeProperty.doubleValue = EditorGUILayout.DoubleField("Latitude", latitudeProperty.doubleValue);
                var longitudeProperty = _centerProperty.FindPropertyRelative("Longitude");
                longitudeProperty.doubleValue = EditorGUILayout.DoubleField("Longitude", longitudeProperty.doubleValue);

                EditorGUILayout.Slider(_zoomLevelProperty, MapConstants.MinimumZoomLevel, MapConstants.MaximumZoomLevel);
                // Get the zoomlevel values
                var minZoomLevel = _minZoomLevelProperty.floatValue;
                var maxZoomLevel = _maxZoomLevelProperty.floatValue;

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Zoom Level Range");
                EditorGUI.indentLevel--;
                minZoomLevel = EditorGUILayout.FloatField((float)Math.Round(minZoomLevel, 2), _minMaxLabelsLayoutOptions);
                EditorGUILayout.MinMaxSlider(ref minZoomLevel, ref maxZoomLevel, MapConstants.MinimumZoomLevel, MapConstants.MaximumZoomLevel);
                maxZoomLevel = EditorGUILayout.FloatField((float)Math.Round(maxZoomLevel, 2), _minMaxLabelsLayoutOptions);
                EditorGUI.indentLevel++;
                EditorGUILayout.EndHorizontal();

                // Update it back
                _minZoomLevelProperty.floatValue = minZoomLevel;
                _maxZoomLevelProperty.floatValue = maxZoomLevel;
                GUILayout.Space(4);
            }
            EditorGUILayout.EndVertical();

            // Map Layout Section
            EditorGUILayout.BeginVertical(_boxStyle);
            _showMapSizingOptions = EditorGUILayout.Foldout(_showMapSizingOptions, "Map Layout", true, _foldoutTitleStyle);
            if (_showMapSizingOptions)
            {
                // Map Shape Controls
                GUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Map Shape");
                _mapShapeProperty.enumValueIndex = GUILayout.Toolbar(_mapShapeProperty.enumValueIndex, _shapeOptions);
                GUILayout.EndHorizontal();

                GUILayout.Space(6f);

                if (_mapShapeProperty.enumValueIndex == (int)MapShape.Block)
                {
                    EditorGUILayout.PropertyField(_localMapDimensionProperty);
                    EditorGUILayout.LabelField(" ", "Scaled Map Dimension: " + ((MapRenderer)target).MapDimension.ToString());
                    GUILayout.Space(6f);
                    EditorGUILayout.PropertyField(_localMapHeightProperty);
                    EditorGUILayout.LabelField(" ", "Scaled Map Height: " + ((MapRenderer)target).MapHeight.ToString());
                }
                else if (_mapShapeProperty.enumValueIndex == (int)MapShape.Cylinder)
                {
                    EditorGUILayout.PropertyField(_localMapRadiusProperty);
                    EditorGUILayout.LabelField(" ", "Scaled Map Radius: " + (((MapRenderer)target).MapDimension.x / 2.0f).ToString());
                    GUILayout.Space(6f);
                    EditorGUILayout.PropertyField(_localMapHeightProperty);
                    EditorGUILayout.LabelField(" ", "Scaled Map Height: " + ((MapRenderer)target).MapHeight.ToString());
                }
                GUILayout.Space(6f);

                // Map Collider Type Controls
                GUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Map Collider Type");
                _mapColliderTypeProperty.enumValueIndex = GUILayout.Toolbar(_mapColliderTypeProperty.enumValueIndex, _colliderOptions);
                GUILayout.EndHorizontal();

                GUILayout.Space(6f);
            }
            EditorGUILayout.EndVertical();

            // Render Settings Section
            EditorGUILayout.BeginVertical(_boxStyle);
            _terrainOptions = EditorGUILayout.Foldout(_terrainOptions, "Render Settings", true, _foldoutTitleStyle);
            if (_terrainOptions)
            {
                // Map Terrain Type Controls
                GUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Map Terrain Type");
                _mapTerrainType.enumValueIndex = GUILayout.Toolbar(_mapTerrainType.enumValueIndex, _layerOptions);
                GUILayout.EndHorizontal();

                EditorGUILayout.PropertyField(_elevationScaleProperty);
                EditorGUILayout.PropertyField(_castShadowsProperty, new GUIContent("Cast Shadows"));
                EditorGUILayout.PropertyField(_receiveShadowsProperty, new GUIContent("Receive Shadows"));
                EditorGUILayout.PropertyField(_enableMrtkMaterialIntegrationProperty, new GUIContent("Enable MRTK Integration"));
                EditorGUILayout.PropertyField(_useCustomTerrainMaterialProperty, new GUIContent("Use Custom Terrain Material"));
                if (_useCustomTerrainMaterialProperty.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(_customTerrainMaterialProperty, new GUIContent("Terrain Material"));
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.PropertyField(_isClippingVolumeWallEnabledProperty, new GUIContent("Render Clipping Volume Wall"));
                if (_isClippingVolumeWallEnabledProperty.boolValue)
                {
                    EditorGUI.indentLevel++;

                    EditorGUILayout.PropertyField(_mapEdgeColorProperty, new GUIContent("Color"));
                    _mapEdgeColorFadeDistanceProperty.floatValue =
                        EditorGUILayout.Slider(new GUIContent("Edge Fade"), _mapEdgeColorFadeDistanceProperty.floatValue, 0, 1);

                    EditorGUILayout.PropertyField(
                        _useCustomClippingVolumeMaterialProperty,
                        new GUIContent("Use Custom Clipping Volume Material"));
                    if (_useCustomClippingVolumeMaterialProperty.boolValue)
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(_customClippingVolumeMaterialProperty, new GUIContent("Clipping Volume Material"));
                        EditorGUI.indentLevel--;
                    }

                    // Texture Camera Resolution
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Clipping Edge Resolution");
                    _clippingVolumeDistanceTextureResolution.enumValueIndex = GUILayout.Toolbar(
                        _clippingVolumeDistanceTextureResolution.enumValueIndex, _clippingVolumeDistanceTextureResolutionOptions);
                    GUILayout.EndHorizontal();

                    EditorGUI.indentLevel--;
                }
            }
            GUILayout.Space(6f);
            EditorGUILayout.EndVertical();

            // Quality options.
            EditorGUILayout.BeginVertical(_boxStyle);
            _showQualityOptions = EditorGUILayout.Foldout(_showQualityOptions, "Quality", true, _foldoutTitleStyle);
            if (_showQualityOptions)
            {
                EditorGUI.BeginDisabledGroup(Application.isPlaying);
                _maxCacheSizeInBytesProperty.longValue =
                    1024 *
                    1024 *
                    EditorGUILayout.LongField(
                        new GUIContent("Max Cache Size (MB)"),
                        _maxCacheSizeInBytesProperty.longValue / 1024 / 1024);
                EditorGUI.EndDisabledGroup();

                var position = EditorGUILayout.GetControlRect(false, 2 * EditorGUIUtility.singleLineHeight);
                position.height = EditorGUIUtility.singleLineHeight;

                position = EditorGUI.PrefixLabel(position, new GUIContent("Detail Offset"));
                EditorGUI.indentLevel--;

                _detailOffsetProperty.floatValue = EditorGUI.Slider(position, _detailOffsetProperty.floatValue, -1f, 1f);
                float labelWidth = position.width;

                // Render the sub-text labels.
                {
                    position.y     += EditorGUIUtility.singleLineHeight;
                    position.width -= EditorGUIUtility.fieldWidth;

                    var color = GUI.color;
                    GUI.color = color * new Color(1f, 1f, 1f, 0.5f);

                    GUIStyle style =
                        new GUIStyle(GUI.skin.label)
                    {
                        alignment = TextAnchor.UpperLeft
                    };

                    EditorGUI.LabelField(position, "Low", style);

                    style.alignment = TextAnchor.UpperCenter;
                    EditorGUI.LabelField(position, "Default", style);

                    style.alignment = TextAnchor.UpperRight;
                    EditorGUI.LabelField(position, "High", style);

                    GUI.color = color;
                }

                EditorGUI.indentLevel++;
            }
            EditorGUILayout.EndVertical();

            // Texture Tile Providers
            EditorGUILayout.BeginVertical(_boxStyle);
            _showTileLayers = EditorGUILayout.Foldout(_showTileLayers, "Tile Layers", true, _foldoutTitleStyle);
            if (_showTileLayers)
            {
                EditorGUILayout.PropertyField(_textureTileLayersProperty, true);
                EditorGUILayout.PropertyField(_elevationTileLayersProperty, true);
                EditorGUILayout.PropertyField(_hideTileLayerComponentsProperty);
                GUILayout.Space(12f);
            }
            EditorGUILayout.EndVertical();

            // Localization
            EditorGUILayout.BeginVertical(_boxStyle);
            _showLocalizationOptions = EditorGUILayout.Foldout(_showTileLayers, "Localization", true, _foldoutTitleStyle);
            if (_showLocalizationOptions)
            {
                var previousIsLanguageAutoDetected = _languageOverrideProperty.intValue == (int)SystemLanguage.Unknown;
                var newIsLanguageAutoDetected      = EditorGUILayout.Toggle("Autodetect Language", previousIsLanguageAutoDetected);

                // If we are switching from autodetected to override, initialize override property with the current system language.
                if (!newIsLanguageAutoDetected && previousIsLanguageAutoDetected)
                {
                    _languageOverrideProperty.intValue = (int)Application.systemLanguage;
                }

                // If we are switching from overridden to autodetected, clear the override property to unknown.
                if (newIsLanguageAutoDetected && !previousIsLanguageAutoDetected)
                {
                    _languageOverrideProperty.intValue = (int)SystemLanguage.Unknown;
                }

                if (newIsLanguageAutoDetected)
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.EnumPopup("Language", Application.systemLanguage);
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    EditorGUILayout.PropertyField(_languageOverrideProperty, new GUIContent("Language"));
                }
            }
            EditorGUILayout.EndVertical();


            GUILayout.Space(4);
            serializedObject.ApplyModifiedProperties();
        }
    /// <summary>
    /// 绘制object
    /// </summary>
    /// <param name="showName"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    public static object DrawBaseValue(GUIContent content, object data)
    {
        if (data == null)
        {
            return(data);
        }

        Type type = data.GetType();

        content.text = richTextSupport ? GetFormatName(content.text, type, "yellow", data) : GetFormatName(content.text, type, "", data);

        object obj = data;

        if (CanEdit)
        {
            if (type == typeof(int))
            {
                obj = EditorGUILayout.IntField(content, (int)data);
            }
            else if (type == typeof(short))
            {
                obj = EditorGUILayout.IntField(content, (short)data);
            }
            else if (type == typeof(long))
            {
                obj = EditorGUILayout.LongField(content, (long)data);
            }
            else if (type == typeof(double))
            {
                obj = EditorGUILayout.DoubleField(content, (double)data);
            }
            else if (type == typeof(float))
            {
                obj = EditorGUILayout.FloatField(content, (float)data);
            }
            else if (type == typeof(bool))
            {
                obj = EditorGUILayout.Toggle(content, (bool)data);
            }
            else if (type == typeof(string))
            {
                GUIStyle style = "TextArea";
                style.wordWrap = true;
                GUILayout.BeginHorizontal();
                GUILayout.Label(content, GUILayout.MaxWidth(Screen.width / 2));

                obj = EditorGUILayout.TextArea(data.ToString(), style, GUILayout.MaxWidth(Screen.width / 2));
                GUILayout.EndHorizontal();
            }
            else if (type.BaseType.FullName == typeof(UnityEngine.Object).FullName || type.BaseType.FullName == typeof(Component).FullName || type.BaseType.FullName == typeof(MonoBehaviour).FullName)
            {
                obj = EditorGUILayout.ObjectField(content, (UnityEngine.Object)data, type, true);
            }
            else if (type.BaseType == typeof(Enum))
            {
                obj = EditorGUILayout.EnumPopup(content, (Enum)Enum.Parse(type, data.ToString()));
            }
            else if (type == typeof(Vector3))
            {
                obj = EditorGUILayout.Vector3Field(content, (Vector3)data);
            }
            else if (type == typeof(Vector2))
            {
                obj = EditorGUILayout.Vector2Field(content, (Vector2)data);
            }
            else if (type == typeof(Vector3Int))
            {
                obj = EditorGUILayout.Vector3IntField(content, (Vector3Int)data);
            }
            else if (type == typeof(Vector2Int))
            {
                obj = EditorGUILayout.Vector2IntField(content, (Vector2Int)data);
            }
            else if (type == typeof(Vector4))
            {
                obj = EditorGUILayout.Vector4Field(content, (Vector4)data);
            }
            else if (type == typeof(Color))
            {
                obj = EditorGUILayout.ColorField(content, (Color)data);
            }
            else if (type.Name == typeof(List <>).Name)
            {
                DrawFoldout(data, content, () =>
                {
                    obj = DrawList("", data, null, null);
                });
            }
            else if (type.Name == typeof(Dictionary <,>).Name)
            {
                DrawFoldout(data, content, () =>
                {
                    obj = DrawDictionary("", data);
                });
            }
            else if (type.IsArray)
            {
                obj = DrawArray(content, data, null, null);
            }
            else if ((type.IsClass && type != typeof(string)) || type.IsValueType)
            {
                DrawFoldout(data, content, () =>
                {
                    obj = DrawClassData("", type.FullName, data);
                });
            }
        }
        else
        {
            if (type.IsPrimitive ||
                type == typeof(string) ||
                type.IsEnum ||
                type == typeof(Vector2) ||
                type == typeof(Vector3) ||
                type == typeof(Vector2Int) ||
                type == typeof(Vector3Int) ||
                type == typeof(Vector4) ||
                type.FullName == typeof(Color).FullName)
            {
                string showStr = data.ToString();

                DrawLableString(content, showStr);
            }
            else if (type.BaseType == typeof(UnityEngine.Object) || type.BaseType == typeof(Component) || type.BaseType == typeof(MonoBehaviour))
            {
                EditorGUILayout.ObjectField(content, (UnityEngine.Object)data, type, true);
            }
            else if (type.Name == typeof(List <>).Name)
            {
                DrawFoldout(data, content, () =>
                {
                    obj = DrawList("", data, null, null);
                });
            }
            else if (type.Name == typeof(Dictionary <,>).Name)
            {
                DrawFoldout(data, content, () =>
                {
                    obj = DrawDictionary("", data);
                });
            }
            else if (type.IsArray)
            {
                DrawArray(content, data, null, null);
            }
            else if (type.IsClass && type != typeof(string) || type.IsValueType)
            {
                DrawFoldout(data, content, () =>
                {
                    obj = DrawClassData("", type.FullName, data);
                });
            }
        }
        return(obj);
    }
Esempio n. 3
0
        private void SerializeObj(FieldInfo value, object Comp, object obj)
        {
            Type objtype = value.FieldType;

            object[] attributes = value.GetCustomAttributes(typeof(MFWModel_SerializeAttribute), true);
            if (attributes == null || attributes.Length == 0)
            {
                return;
            }
            object SerializeAttribute = attributes[0];
            bool   IsWirte            = (bool)SerializeAttribute.GetType().GetField("IsWrite").GetValue(SerializeAttribute);
            string Name = SerializeAttribute is MFWModel_SerializeNameAttribute ? (string)SerializeAttribute.GetType().GetField("Name").GetValue(SerializeAttribute) : value.Name;

            if (objtype == typeof(string))
            {
                if (IsWirte)
                {
                    value.SetValue(Comp, EditorGUILayout.TextField(Name, (string)obj));
                }
                else
                {
                    EditorGUILayout.LabelField(Name, (string)obj);
                }
            }
            else if (objtype == typeof(bool))
            {
                if (IsWirte)
                {
                    value.SetValue(Comp, EditorGUILayout.Toggle(Name, (bool)obj));
                }
                else
                {
                    EditorGUILayout.Toggle(Name, (bool)obj);
                }
            }
            else if (objtype.IsEnum)
            {
                if (IsWirte)
                {
                    value.SetValue(Comp, EditorGUILayout.EnumPopup(Name, (Enum)obj));
                }
                else
                {
                    EditorGUILayout.EnumPopup(Name, (Enum)obj);
                }
            }
            else if (objtype == typeof(byte) || objtype == typeof(int))
            {
                if (IsWirte)
                {
                    value.SetValue(Comp, EditorGUILayout.IntField(Name, (int)obj));
                }
                else
                {
                    EditorGUILayout.IntField(Name, (int)obj);
                }
            }
            else if (objtype == typeof(long))
            {
                if (IsWirte)
                {
                    value.SetValue(Comp, EditorGUILayout.LongField(Name, (long)obj));
                }
                else
                {
                    EditorGUILayout.LongField(Name, (long)obj);
                }
            }
            else if (objtype == typeof(float) || objtype == typeof(double))
            {
                if (IsWirte)
                {
                    value.SetValue(Comp, EditorGUILayout.FloatField(Name, (float)obj));
                }
                else
                {
                    EditorGUILayout.FloatField(Name, (float)obj);
                }
            }
            else if (objtype == typeof(Vector2))
            {
                if (IsWirte)
                {
                    value.SetValue(Comp, EditorGUILayout.Vector2Field(Name, (Vector2)obj));
                }
                else
                {
                    EditorGUILayout.Vector2Field(Name, (Vector2)obj);
                }
            }
            else if (objtype == typeof(Vector3))
            {
                if (IsWirte)
                {
                    value.SetValue(Comp, EditorGUILayout.Vector2Field(Name, (Vector3)obj));
                }
                else
                {
                    EditorGUILayout.Vector2Field(Name, (Vector3)obj);
                }
            }
            else if (objtype == typeof(Color32))
            {
                if (IsWirte)
                {
                    value.SetValue(Comp, EditorGUILayout.ColorField(Name, (Color32)obj));
                }
                else
                {
                    EditorGUILayout.ColorField(Name, (Color32)obj);
                }
            }
            else if (objtype.IsGenericType && objtype.GetGenericTypeDefinition() == typeof(Dictionary <,>))
            {
                EditorGUILayout.LabelField(Name + ": 字典列表");
            }
            else if (objtype.IsGenericType && objtype.GetGenericTypeDefinition() == typeof(List <>))
            {
                EditorGUILayout.LabelField(Name + ": 对象列表");
            }
            else
            {
                GUILayout.Label(Name + ": 对象没有序列化");
            }
        }
Esempio n. 4
0
        object ShowInternalItem(string key, System.Type type, object value, Descriptor[] descriptors)
        {
            object ret           = null;
            bool   endHorizontal = IsShowKey(type);

            key = GetPrefixKey(key);

            if (endHorizontal)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(key);
            }

            if (type == typeof(float))
            {
                if (descriptors != null && descriptors[0] is MinMaxDescriptor)
                {
                    var minMaxDescriptor = descriptors[0] as MinMaxDescriptor;
                    ret = EditorGUILayout.Slider((float)value, minMaxDescriptor.min, minMaxDescriptor.max);
                }
                else
                {
                    ret = EditorGUILayout.FloatField((float)value);
                }
            }
            else if (type == typeof(string))
            {
                ret = EditorGUILayout.TextField(value as string);
            }
            else if (type == typeof(bool))
            {
                ret = EditorGUILayout.Toggle((bool)value);
            }
            else if (type == typeof(System.Int32))
            {
                ret = EditorGUILayout.IntField(System.Convert.ToInt32(value));
            }
            else if (type == typeof(System.Int64))
            {
                ret = EditorGUILayout.LongField(System.Convert.ToInt64(value));
            }
            else if (type == typeof(System.Double))
            {
                ret = EditorGUILayout.DoubleField(System.Convert.ToDouble(value));
            }
            else if (type == typeof(System.Single))
            {
                ret = EditorGUILayout.FloatField(System.Convert.ToSingle(value));
            }
            else if (type == typeof(Vector2))
            {
                ret = EditorGUILayout.Vector2Field(key, (Vector2)value);
            }
            else if (type == typeof(Vector3))
            {
                ret = EditorGUILayout.Vector3Field(key, (Vector3)value);
            }
            else if (type == typeof(Vector4))
            {
                ret = EditorGUILayout.Vector4Field(key, (Vector4)value);
            }
            else if (type == typeof(Color))
            {
                ret = EditorGUILayout.ColorField(key, (Color)value);
            }
            else if (type == typeof(Rect))
            {
                ret = EditorGUILayout.RectField(key, (Rect)value);
            }
            else if (type == typeof(Bounds))
            {
                ret = EditorGUILayout.BoundsField(key, (Bounds)value);
            }
            else if (type == typeof(UnityEngine.Object) || type.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                ret = EditorGUILayout.ObjectField(key, value as UnityEngine.Object, type, true);
            }
            else if (type.IsSubclassOf(typeof(System.Enum)))
            {
                ret = EditorGUILayout.EnumPopup(value as System.Enum);
            }

            if (endHorizontal)
            {
                EditorGUILayout.EndHorizontal();
            }

            return(ret);
        }
Esempio n. 5
0
        public static bool DrawLayoutField(object value, string label)
        {
            GUI.enabled = false;

            bool isDrawn = true;
            Type valueType = value.GetType();

            if (valueType == typeof(bool))
            {
                EditorGUILayout.Toggle(label, (bool)value);
            }
            else if (valueType == typeof(int))
            {
                EditorGUILayout.IntField(label, (int)value);
            }
            else if (valueType == typeof(long))
            {
                EditorGUILayout.LongField(label, (long)value);
            }
            else if (valueType == typeof(float))
            {
                EditorGUILayout.FloatField(label, (float)value);
            }
            else if (valueType == typeof(double))
            {
                EditorGUILayout.DoubleField(label, (double)value);
            }
            else if (valueType == typeof(string))
            {
                EditorGUILayout.TextField(label, (string)value);
            }
            else if (valueType == typeof(Vector2))
            {
                EditorGUILayout.Vector2Field(label, (Vector2)value);
            }
            else if (valueType == typeof(Vector3))
            {
                EditorGUILayout.Vector3Field(label, (Vector3)value);
            }
            else if (valueType == typeof(Vector4))
            {
                EditorGUILayout.Vector4Field(label, (Vector4)value);
            }
            else if (valueType == typeof(Color))
            {
                EditorGUILayout.ColorField(label, (Color)value);
            }
            else if (valueType == typeof(Bounds))
            {
                EditorGUILayout.BoundsField(label, (Bounds)value);
            }
            else if (valueType == typeof(Rect))
            {
                EditorGUILayout.RectField(label, (Rect)value);
            }
            else if (typeof(UnityEngine.Object).IsAssignableFrom(valueType))
            {
                EditorGUILayout.ObjectField(label, (UnityEngine.Object)value, valueType, true);
            }
            else
            {
                isDrawn = false;
            }

            GUI.enabled = true;

            return isDrawn;
        }
        void DrawPropertyOverride(RuntimePrefabPropertyOverride propertyOverride)
        {
            m_ExpandedStates.TryGetValue(propertyOverride, out var expandedState);
            var wasExpanded = expandedState;

            expandedState = EditorGUILayout.Foldout(expandedState, propertyOverride.PropertyPath, true);
            if (expandedState != wasExpanded)
            {
                m_ExpandedStates[propertyOverride] = expandedState;
            }

            if (expandedState)
            {
                using (new EditorGUI.IndentLevelScope())
                {
                    EditorGUILayout.TextField("Property Path", propertyOverride.PropertyPath);
                    EditorGUILayout.TextField("Transform Path", propertyOverride.TransformPath);
                    EditorGUILayout.IntField("Component Index", propertyOverride.ComponentIndex);

                    switch (propertyOverride)
                    {
                    case IRuntimePrefabOverrideUnityObject unityObjectProperty:
                        EditorGUILayout.ObjectField("Value", unityObjectProperty.Value, typeof(UnityObject), true);
                        break;

                    case IRuntimePrefabOverrideUnityObjectReference objectReferenceProperty:
                        var objectReference = objectReferenceProperty.Value;
                        EditorGUILayout.IntField("Scene ID", objectReference.sceneID);
                        EditorGUILayout.TextField("Guid", objectReference.guid);
                        EditorGUILayout.LongField("File ID", objectReference.fileId);
                        break;

                    case IRuntimePrefabOverride <AnimationCurve> animationCurveProperty:
                        EditorGUILayout.CurveField("Value", animationCurveProperty.Value);
                        break;

                    case RuntimePrefabPropertyOverrideList listProperty:
                        foreach (var element in listProperty.List)
                        {
                            DrawPropertyOverride(element);
                        }

                        break;

                    case IRuntimePrefabOverride <bool> boolProperty:
                        EditorGUILayout.Toggle("Value", boolProperty.Value);
                        break;

                    case IRuntimePrefabOverride <char> charProperty:
                        EditorGUILayout.TextField("Value", charProperty.Value.ToString());
                        break;

                    case IRuntimePrefabOverride <float> floatProperty:
                        EditorGUILayout.FloatField("Value", floatProperty.Value);
                        break;

                    case IRuntimePrefabOverride <int> intProperty:
                        EditorGUILayout.IntField("Value", intProperty.Value);
                        break;

                    case IRuntimePrefabOverride <long> longProperty:
                        EditorGUILayout.LongField("Value", longProperty.Value);
                        break;

                    case IRuntimePrefabOverride <string> stringProperty:
                        EditorGUILayout.TextField("Value", stringProperty.Value);
                        break;
                    }
                }
            }
        }
Esempio n. 7
0
    public static object GUISwitch(string type, object value)
    {
        var tmp = value;

        switch (type)
        {
        case "AnimationCurve":
            return(SetValueGUI(EditorGUILayout.CurveField(GetValue <AnimationCurve>(value)), tmp));

        case "Bounds":
            return(SetValueGUI(EditorGUILayout.BoundsField(GetValue <Bounds>(value)), tmp));

        case "BoundsInt":
            return(SetValueGUI(EditorGUILayout.BoundsIntField(GetValue <BoundsInt>(value)), tmp));

        case "Color":
            return(SetValueGUI(EditorGUILayout.ColorField(GetValue <Color>(value)), tmp));

        case "Color32":
            return(SetValueGUI(EditorGUILayout.ColorField(GetValue <Color32>(value)), tmp));

        case "Double":
            return(SetValueGUI(EditorGUILayout.DoubleField(GetValue <double>(value)), tmp));

        case "Enum":
            return(SetValueGUI(EditorGUILayout.EnumPopup(GetValue <Enum>(value)), tmp));

        case "Single":
            return(SetValueGUI(EditorGUILayout.FloatField(GetValue <float>(value)), tmp));

        case "Gradient":
            return(SetValueGUI(EditorGUILayout.GradientField(GetValue <Gradient>(value)), tmp));

        case "Rect":
            return(SetValueGUI(EditorGUILayout.RectField(GetValue <Rect>(value)), tmp));

        case "RectInt":
            return(SetValueGUI(EditorGUILayout.RectIntField(GetValue <RectInt>(value)), tmp));

        case "String":
            return(SetValueGUI(EditorGUILayout.TextField(GetValue <string>(value)), tmp));

        case "Boolean":
            return(SetValueGUI(EditorGUILayout.Toggle(GetValue <bool>(value)), tmp));

        case "Vector2":
            return(SetValueGUI(EditorGUILayout.Vector2Field("", GetValue <Vector2>(value)), tmp));

        case "Vector2Int":
            return(SetValueGUI(EditorGUILayout.Vector2IntField("", GetValue <Vector2Int>(value)), tmp));

        case "Vector3":
            return(SetValueGUI(EditorGUILayout.Vector3Field("", GetValue <Vector3>(value)), tmp));

        case "Vector3Int":
            return(SetValueGUI(EditorGUILayout.Vector3IntField("", GetValue <Vector3Int>(value)), tmp));

        case "Vector4":
            return(SetValueGUI(EditorGUILayout.Vector4Field("", GetValue <Vector4>(value)), tmp));

        case "Quaternion":
            return(SetValueGUI(EditorGUILayout.Vector4Field("", GetValue <Quaternion>(value).GetVector4()).GetQuaternion(), tmp));

        //All Integer Types
        case "Byte":
        case "Int16":
        case "Int32":
        case "SByte":
        case "UInt16":
        case "UInt32":
            return(SetValueGUI(EditorGUILayout.IntField(GetValue <int>(value)), tmp));

        case "UInt64":
        case "Int64":
            return(SetValueGUI(EditorGUILayout.LongField(GetValue <long>(value)), tmp));

            //
        }
        return(new object());
    }
        ///Draws an Editor field for object of type directly
        public static object DrawEditorFieldDirect(GUIContent content, object value, Type t, object context,
                                                   object field,
                                                   string propName,
                                                   object[] attributes = null)
        {
            if (typeof(UnityObject).IsAssignableFrom(t) == false && t != typeof(Type))
            {
                //Check abstract
                if ((value != null && value.GetType().IsAbstract) || (value == null && t.IsAbstract))
                {
                    EditorGUILayout.LabelField(content,
                                               new GUIContent(string.Format("Abstract ({0})", t.FriendlyName())));
                    return(value);
                }

                //Auto create instance for some types
                if (value == null && t != typeof(object) && !t.IsAbstract && !t.IsInterface)
                {
                    if (t.GetConstructor(Type.EmptyTypes) != null || t.IsArray)
                    {
                        if (t.IsArray)
                        {
                            value = Array.CreateInstance(t.GetElementType(), 0);
                        }
                        else
                        {
                            value = Activator.CreateInstance(t);
                        }
                    }
                }
            }

            //Check the type
            if (typeof(UnityObject).IsAssignableFrom(t))
            {
                if (t == typeof(Component) && (value is Component))
                {
                    return(ComponentField(content, (Component)value, typeof(Component)));
                }

                return(EditorGUILayout.ObjectField(content, (UnityObject)value, t, true));
            }

            if (t == typeof(Type))
            {
                return(Popup <Type>(content, (Type)value, TypePrefs.GetPreferedTypesList(true)));
            }

            if (t == typeof(string))
            {
                return(EditorGUILayout.TextField(content, (string)value));
            }

            if (t == typeof(char))
            {
                var c = (char)value;
                var s = c.ToString();
                s = EditorGUILayout.TextField(content, s);
                return(string.IsNullOrEmpty(s) ? (char)c : (char)s[0]);
            }

            if (t == typeof(bool))
            {
                return(EditorGUILayout.Toggle(content, (bool)value));
            }

            if (t == typeof(int))
            {
                return(EditorGUILayout.IntField(content, (int)value));
            }

            if (t == typeof(float))
            {
                return(EditorGUILayout.FloatField(content, (float)value));
            }

            if (t == typeof(byte))
            {
                return(Convert.ToByte(Mathf.Clamp(EditorGUILayout.IntField(content, (byte)value), 0, 255)));
            }

            if (t == typeof(long))
            {
                return(EditorGUILayout.LongField(content, (long)value));
            }

            if (t == typeof(double))
            {
                return(EditorGUILayout.DoubleField(content, (double)value));
            }

            if (t == typeof(Vector2))
            {
                return(EditorGUILayout.Vector2Field(content, (Vector2)value));
            }

            if (t == typeof(Vector3))
            {
                return(EditorGUILayout.Vector3Field(content, (Vector3)value));
            }

            if (t == typeof(Vector4))
            {
                return(EditorGUILayout.Vector4Field(content, (Vector4)value));
            }

            if (t == typeof(Quaternion))
            {
                var quat = (Quaternion)value;
                var vec4 = new Vector4(quat.x, quat.y, quat.z, quat.w);
                vec4 = EditorGUILayout.Vector4Field(content, vec4);
                return(new Quaternion(vec4.x, vec4.y, vec4.z, vec4.w));
            }


            if (t == typeof(UnityEvent[]))
            {
                var stateNode = (StateNode)context;
                if (stateNode == null)
                {
                    return(null);
                }

                var s = stateNode.stateDelegate;

                if (s == null)
                {
                    return(null);
                }


                SerializedObject serializedObject = new SerializedObject(s.GetComponent <StateNodeDelegate>());
                var property = serializedObject.FindProperty(propName);
                EditorGUILayout.LabelField("Change this on gameobject");
                EditorGUILayout.PropertyField(property, true);
                serializedObject.ApplyModifiedProperties();
                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                return(null);
            }

            if (t == typeof(Color))
            {
                return(EditorGUILayout.ColorField(content, (Color)value));
            }

            if (t == typeof(Rect))
            {
                return(EditorGUILayout.RectField(content, (Rect)value));
            }

            if (t == typeof(AnimationCurve))
            {
                return(EditorGUILayout.CurveField(content, (AnimationCurve)value));
            }

            if (t == typeof(Bounds))
            {
                return(EditorGUILayout.BoundsField(content, (Bounds)value));
            }

            if (t == typeof(LayerMask))
            {
                return(LayerMaskField(content, (LayerMask)value));
            }

            if (t.IsSubclassOf(typeof(System.Enum)))
            {
                if (t.IsDefined(typeof(FlagsAttribute), true))
                {
#if UNITY_2017_3_OR_NEWER
                    return(EditorGUILayout.EnumFlagsField(content, (System.Enum)value));
#else
                    return(EditorGUILayout.EnumMaskPopup(content, (System.Enum)value));
#endif
                }

                return(EditorGUILayout.EnumPopup(content, (System.Enum)value));
            }

            if (typeof(IList).IsAssignableFrom(t))
            {
                return(ListEditor(content, (IList)value, t, (FieldInfo)field, context, attributes));
            }

            if (typeof(IDictionary).IsAssignableFrom(t))
            {
                return(DictionaryEditor(content, (IDictionary)value, t, (FieldInfo)field, context, attributes));
            }

            //show nested class members recursively
            if (value != null && (t.IsClass || t.IsValueType))
            {
                if (EditorGUI.indentLevel <= 8)
                {
                    GUILayout.BeginVertical();
                    EditorGUILayout.LabelField(content, new GUIContent(string.Format("({0})", t.FriendlyName())));
                    EditorGUI.indentLevel++;
                    ReflectedObjectInspector(value);
                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }
            }
            else
            {
                EditorGUILayout.LabelField(content,
                                           new GUIContent(string.Format("NonInspectable ({0})", t.FriendlyName())));
            }

            return(value);
        }