Exemplo n.º 1
0
 void BoundsField()
 {
     EditorGUILayout.BeginVertical(GUI.skin.box);
     m_Bounds    = EditorGUILayout.BoundsField("BoundsField", m_Bounds);
     m_BoundsInt = EditorGUILayout.BoundsIntField("BoundsIntField", m_BoundsInt);
     EditorGUILayout.EndVertical();
 }
Exemplo n.º 2
0
        protected override void OnHeaderGUI()
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.inspectorBig);
            Texture2D icon = AssetPreview.GetMiniTypeThumbnail(typeof(Grid));

            GUILayout.Label(icon, GUILayout.Width(iconSize), GUILayout.Height(iconSize));
            EditorGUILayout.BeginVertical();
            GUILayout.Label(Styles.gridSelectionLabel);
            GridSelection.position = EditorGUILayout.BoundsIntField(GUIContent.none, GridSelection.position);
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            DrawHeaderHelpAndSettingsGUI(GUILayoutUtility.GetLastRect());
        }
Exemplo n.º 3
0
 private void OnGUI()
 {
     GUILayout.Label("This is a test panel");
     gridId = GUILayout.SelectionGrid(gridId, new[] { "tab1", "tab2" }, 2);
     if (gridId == 0)
     {
         isToggle = GUILayout.Toggle(isToggle, "Toggle");
     }
     else
     {
         boundsv   = EditorGUILayout.BoundsField("BoundsField", boundsv);
         boundintv = EditorGUILayout.BoundsIntField("BoundsIntField", boundintv);
     }
 }
        public override void OnInspectorGUI()
        {
            // First reload, no label, no extra options
            _target.BoundsIntFirst = EditorGUILayout.BoundsIntField(_target.BoundsIntFirst);

            // Second reload, with a label and a height of 200 pixels
            _target.BoundsIntSecond = EditorGUILayout.BoundsIntField("Bounds Int Second", _target.BoundsIntSecond, GUILayout.Height(200));

            // Third reload, with a label, a tooltip and a size of 400 pixels * 100 pixels
            var guiContent       = new GUIContent("Bounds Int Third", "This is the third int bounds.");
            var guiLayoutOptions = new GUILayoutOption [] {
                GUILayout.Width(400),
                GUILayout.Height(100)
            };

            _target.BoundsIntThird = EditorGUILayout.BoundsIntField(guiContent, _target.BoundsIntThird, guiLayoutOptions);
        }
Exemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            // Fields
            _testClass.aBounds    = EditorGUILayout.BoundsField("aBounds", _testClass.aBounds);
            _testClass.aBoundsInt = EditorGUILayout.BoundsIntField("aBoundsInt", _testClass.aBoundsInt);
            _testClass.aColor     = EditorGUILayout.ColorField("aColor", _testClass.aColor);
            _testClass.aCurve     = EditorGUILayout.CurveField("aCurve", _testClass.aCurve);
            _testClass.aDouble    = EditorGUILayout.DoubleField("aDouble", _testClass.aDouble);
            // Could also use: DelayedDoubleField.
            _testClass.aanEnum = (AnEnum)EditorGUILayout.EnumPopup("aanEnum", _testClass.aanEnum);
            // Also could use EnumFlagsField.
            _testClass.aFloat = EditorGUILayout.FloatField("aFloat", _testClass.aFloat);
            // Could also use: DelayedFloatField.
            EditorGUILayout.PropertyField(_aGameObject, new GUIContent("A Game Object"), true);
            _testClass.aInt = EditorGUILayout.IntField("aInt", _testClass.aInt);
            // Could also use: DelayedIntField; IntPopup, IntSlider.
            _testClass.aLayer = EditorGUILayout.LayerField("aLayer", _testClass.aLayer);
            _testClass.aLong  = EditorGUILayout.LongField("aLong", _testClass.aLong);
            // Omitting aSystemObject from code generation. No applicable entry for System.Object!
            _testClass.aString = EditorGUILayout.TextField("aString", _testClass.aString);
            // Could also use: DelayedTextField.
            _testClass.aBool = EditorGUILayout.Toggle("aBool", _testClass.aBool);
            // Could also use: ToggleLeft.
            EditorGUILayout.PropertyField(_aTransform, new GUIContent("A Transform"), true);
            _testClass.aVector2    = EditorGUILayout.Vector2Field("aVector2", _testClass.aVector2);
            _testClass.aVector2Int = EditorGUILayout.Vector2IntField("aVector2Int", _testClass.aVector2Int);
            _testClass.aVector3    = EditorGUILayout.Vector3Field("aVector3", _testClass.aVector3);
            _testClass.aVector3Int = EditorGUILayout.Vector3IntField("aVector3Int", _testClass.aVector3Int);
            _testClass.aVector4    = EditorGUILayout.Vector4Field("aVector4", _testClass.aVector4);
            // Omitting SomeQuaternion from code generation. No applicable entry for UnityEngine.Quaternion!

            // Properties
            _testClass.aIntProperty = EditorGUILayout.IntField("aIntProperty", _testClass.aIntProperty);
            // Could also use: DelayedIntField; IntPopup, IntSlider.
            _testClass.aStringProperty = EditorGUILayout.TextField("aStringProperty", _testClass.aStringProperty);
            // Could also use: DelayedTextField.

            // Buttons
            if (GUILayout.Button("Do A Thing"))
            {
                _testClass.DoAThing();
            }

            serializedObject.ApplyModifiedProperties();
        }
    override public void OnInspectorGUI()
    {
        LightingTilemapCollider2D script = target as LightingTilemapCollider2D;

        EditorGUI.BeginDisabledGroup(true);
        EditorGUILayout.EnumPopup("Preset", LightingManager2D.Get().preset);
        EditorGUI.EndDisabledGroup();

        script.mapType = (LightingTilemapCollider2D.MapType)EditorGUILayout.EnumPopup("MapType", script.mapType);

        script.dayHeight = EditorGUILayout.Toggle("Day Height", script.dayHeight);
        if (script.dayHeight)
        {
            script.height = EditorGUILayout.FloatField("Height", script.height);
        }

        script.ambientOcclusion = EditorGUILayout.Toggle("Ambient Occlusion", script.ambientOcclusion);
        if (script.ambientOcclusion)
        {
            script.occlusionSize = EditorGUILayout.FloatField("Occlussion Size", script.occlusionSize);
        }

        script.area = EditorGUILayout.BoundsIntField("Area", script.area);
    }
Exemplo n.º 7
0
        public void Draw(float totalWidth)
        {
            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            GUILayout.Space(3);
            this._property.IsSelected = EditorGUILayout.Toggle(this._property.IsSelected);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Space(4);

            GUILayoutOption nameWidth       = GUILayout.Width(totalWidth * 1 / 4 - 10);
            GUILayoutOption typeWidth       = GUILayout.Width(totalWidth / 5 - 10);
            GUILayoutOption defaultValWidth = GUILayout.Width(totalWidth * 2 / 5 - 10);
            GUILayoutOption buttonWidth     = GUILayout.Width(totalWidth / 16 - 5);

            // Property name
            this._property.LastName = EditorGUILayout.TextField(this._property.LastName, nameWidth);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Space(4.5f);

            // Property type
            var rect = EditorGUILayout.GetControlRect(typeWidth);

            Popup(this.selectedType, this.observableTypes, rect, OnSelectType);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Space(4);

            var type = this._property.LastPropertyType;

            // Default value
            if (type == typeof(bool))
            {
                this._property.SetLastValueAs(EditorGUILayout.Toggle(this._property.GetLastValueAs <bool>(), defaultValWidth));
            }
            else if (type == typeof(byte))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <byte>(), defaultValWidth));
            }
            else if (type == typeof(sbyte))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <sbyte>(), defaultValWidth));
            }
            else if (type == typeof(short))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <short>(), defaultValWidth));
            }
            else if (type == typeof(ushort))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <ushort>(), defaultValWidth));
            }
            else if (type == typeof(int))
            {
                this._property.SetLastValueAs(EditorGUILayout.IntField(this._property.GetLastValueAs <int>(), defaultValWidth));
            }
            else if (type == typeof(uint))
            {
                this._property.SetLastValueAs(EditorGUILayout.LongField(this._property.GetLastValueAs <uint>(), defaultValWidth));
            }
            else if (type == typeof(long))
            {
                this._property.SetLastValueAs(EditorGUILayout.LongField(this._property.GetLastValueAs <long>(), defaultValWidth));
            }
            else if (type == typeof(float))
            {
                this._property.SetLastValueAs(EditorGUILayout.FloatField(this._property.GetLastValueAs <float>(), defaultValWidth));
            }
            else if (type == typeof(double))
            {
                this._property.SetLastValueAs(EditorGUILayout.DoubleField(this._property.GetLastValueAs <double>(), defaultValWidth));
            }
            else if (type == typeof(char))
            {
                if (this._property.DefaltValue == null)
                {
                    this._property.DefaltValue = string.Empty;
                    this._property.LastValue   = string.Empty;
                }

                var val = EditorGUILayout.TextField(this._property.GetLastValueAs <char>().ToString(), defaultValWidth);
                this._property.SetLastValueAs(string.IsNullOrEmpty(val) ? (char)0 : val[0]);
            }
            else if (type == typeof(string))
            {
                if (this._property.DefaltValue == null)
                {
                    this._property.DefaltValue = string.Empty;
                    this._property.LastValue   = string.Empty;
                }

                this._property.SetLastValueAs(EditorGUILayout.TextField(this._property.GetLastValueAs <string>(), defaultValWidth));
            }
            else if (type.IsEnum)
            {
                var mask  = type.GetCustomAttribute <FlagsAttribute>();
                var value = this._property.GetLastValueAs <Enum>();

                if (value == null)
                {
                    value = type.GetEnumValues().GetValue(0) as Enum;
                }

                if (mask == null)
                {
                    this._property.SetLastValueAs(EditorGUILayout.EnumPopup(value, defaultValWidth));
                }
                else
                {
                    this._property.SetLastValueAs(EditorGUILayout.EnumFlagsField(value, defaultValWidth));
                }
            }
            else if (type == typeof(Color))
            {
                this._property.SetLastValueAs(EditorGUILayout.ColorField(this._property.GetLastValueAs <Color>(), defaultValWidth));
            }
            else if (type == typeof(Vector2))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector2Field(string.Empty, this._property.GetLastValueAs <Vector2>(), defaultValWidth));
            }
            else if (type == typeof(Vector2Int))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector2IntField(string.Empty, this._property.GetLastValueAs <Vector2Int>(), defaultValWidth));
            }
            else if (type == typeof(Vector3))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector3Field(string.Empty, this._property.GetLastValueAs <Vector3>(), defaultValWidth));
            }
            else if (type == typeof(Vector3Int))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector3IntField(string.Empty, this._property.GetLastValueAs <Vector3Int>(), defaultValWidth));
            }
            else if (type == typeof(Vector4))
            {
                this._property.SetLastValueAs(EditorGUILayout.Vector4Field(string.Empty, this._property.GetLastValueAs <Vector4>(), defaultValWidth));
            }
            else if (type == typeof(Bounds))
            {
                this._property.SetLastValueAs(EditorGUILayout.BoundsField(this._property.GetLastValueAs <Bounds>(), defaultValWidth));
            }
            else if (type == typeof(BoundsInt))
            {
                this._property.SetLastValueAs(EditorGUILayout.BoundsIntField(this._property.GetLastValueAs <BoundsInt>(), defaultValWidth));
            }
            else if (type == typeof(Rect))
            {
                this._property.SetLastValueAs(EditorGUILayout.RectField(this._property.GetLastValueAs <Rect>(), defaultValWidth));
            }
            else if (type == typeof(RectInt))
            {
                this._property.SetLastValueAs(EditorGUILayout.RectIntField(this._property.GetLastValueAs <RectInt>(), defaultValWidth));
            }
            else if (type == typeof(LayerMask))
            {
                EditorGUI.BeginChangeCheck();
                var maskField = EditorGUILayout.MaskField(LayerMaskToField(this._property.GetLastValueAs <LayerMask>()), InternalEditorUtility.layers, defaultValWidth);

                if (EditorGUI.EndChangeCheck())
                {
                    this._property.SetLastValueAs(FieldToLayerMask(maskField));
                }
            }
            else if (type.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                this._property.SetLastValueAs(EditorGUILayout.ObjectField(this._property.GetLastValueAs <UnityEngine.Object>(), type, false, defaultValWidth));
            }
            else
            {
                GUILayout.Label("Undefined!", defaultValWidth);
            }

            GUILayout.EndVertical();

            Color textColor = Color.gray;

            if (this._property.HasChange)
            {
                textColor = Color.black;
            }

            if (ColorButton.Draw("S", CommonColor.LightGreen, textColor, buttonWidth))
            {
                if (this._property.HasChange)
                {
                    this._property.CommitChange();
                    this._onPropertyChanged?.Invoke(this._property);
                }
            }

            if (ColorButton.Draw("X", CommonColor.LightRed, buttonWidth))
            {
                this._onPropertyDelete?.Invoke(this._property);
            }

            GUILayout.EndHorizontal();
        }
        /// <summary>
        /// 绘制单行字段(这也是单纯的画画而已)(只读状态)
        /// </summary>
        /// <param name="value"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        static public 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(Vector2Int))
            {
                EditorGUILayout.Vector2IntField(label, (Vector2Int)value);
            }
            else if (valueType == typeof(Vector3Int))
            {
                EditorGUILayout.Vector3IntField(label, (Vector3Int)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(BoundsInt))
            {
                EditorGUILayout.BoundsIntField(label, (BoundsInt)value);
            }
            else if (valueType == typeof(Rect))
            {
                EditorGUILayout.RectField(label, (Rect)value);
            }
            else if (valueType == typeof(RectInt))
            {
                EditorGUILayout.RectIntField(label, (RectInt)value);
            }
            else if (typeof(UnityEngine.Object).IsAssignableFrom(valueType))
            {
                EditorGUILayout.ObjectField(label, (UnityEngine.Object)value, valueType, true);
            }
            //还有什么类型的字段,来补充啊!!!
            else
            {
                //玛德,我画不出来
                isDrawn = false;
            }

            //打开这行字段的显示
            //不起作用?
            GUI.enabled = true;

            return(isDrawn);
        }
Exemplo n.º 9
0
        public static object PropertyField(Type type, GUIContent label, object value, params GUILayoutOption[] options)
        {
            // generic
            // object
            //layermask
            //enum
            //array



            if (type.IsArray)
            {
            }

            if (type == typeof(int))
            {
                return(EditorGUILayout.IntField(label, (int)value, options));
            }
            if (type == typeof(bool))
            {
                return(EditorGUILayout.Toggle(label, (bool)value, options));
            }
            if (type == typeof(string))
            {
                return(EditorGUILayout.TextField(label, (string)value, options));
            }
            if (type == typeof(float))
            {
                return(EditorGUILayout.FloatField(label, (float)value, options));
            }
            if (type == typeof(char))
            {
                return(EditorGUILayout.IntField(label, (int)value, options));
            }
            if (type == typeof(Color))
            {
                return(EditorGUILayout.ColorField(label, (Color)value, options));
            }

            if (type == typeof(Vector2))
            {
                return(EditorGUILayout.Vector2Field(label, (Vector2)value, options));
            }
            if (type == typeof(Vector3))
            {
                return(EditorGUILayout.Vector3Field(label, (Vector3)value, options));
            }
            if (type == typeof(Vector4))
            {
                return(EditorGUILayout.Vector4Field(label, (Vector4)value, options));
            }

            if (type == typeof(Vector2Int))
            {
                return(EditorGUILayout.Vector2IntField(label, (Vector2Int)value, options));
            }
            if (type == typeof(Vector3Int))
            {
                return(EditorGUILayout.Vector3IntField(label, (Vector3Int)value, options));
            }

            if (type == typeof(Rect))
            {
                return(EditorGUILayout.RectField(label, (Rect)value, options));
            }
            if (type == typeof(RectInt))
            {
                return(EditorGUILayout.RectIntField(label, (RectInt)value, options));
            }

            if (type == typeof(Bounds))
            {
                return(EditorGUILayout.BoundsField(label, (Bounds)value, options));
            }
            if (type == typeof(BoundsInt))
            {
                return(EditorGUILayout.BoundsIntField(label, (BoundsInt)value, options));
            }

            if (type == typeof(AnimationCurve))
            {
                return(EditorGUILayout.CurveField(label, (AnimationCurve)value, options));
            }
            if (type == typeof(Gradient))
            {
                return(EditorGUILayout.GradientField(label, (Gradient)value, options));
            }
            if (type == typeof(Quaternion))
            {
                return(QuaternionField(label, (Quaternion)value, options));
            }


            return(null);
        }
Exemplo n.º 10
0
    public static object DrawIndividualVariable(ObjectPickerContext objectPickerContext, WrappedVariable variable, string fieldName, object fieldValue, OpenPickerCallback onObjectPicker, int index = 0)
    {
        object newValue;

        if (variable.DataType == DataType.Enum)
        {
            //Type underlyingType = variable.MetaData.GetTypeFromMetaData();
            int enumValueIndex = Array.IndexOf(variable.MetaData.EnumValues, fieldValue);
            enumValueIndex = EditorGUILayout.Popup(fieldName, enumValueIndex, variable.MetaData.EnumNames);

            newValue = variable.MetaData.EnumValues[enumValueIndex];
        }
        else if (variable.DataType == DataType.UnityObjectReference)
        {
            if (fieldValue is Guid)
            {
                EditorGUILayout.BeginHorizontal();
                Guid fieldValueGuid = (Guid)fieldValue;

                if (fieldValueGuid != Guid.Empty && variable.ValueDisplayNames.Length > index)
                {
                    EditorGUILayout.TextField(fieldName, variable.ValueDisplayNames[index]);
                }
                else
                {
                    EditorGUILayout.TextField(fieldName, "None (" + variable.MetaData.TypeFullName + ")");
                }

                if (objectPickerContext != null)
                {
                    if (GUILayout.Button("...", GUILayout.Width(30)))
                    {
                        onObjectPicker(objectPickerContext, variable);
                    }
                }

                bool guiEnabled = GUI.enabled;
                // Force GUI enabled on for this control
                GUI.enabled = (fieldValueGuid != Guid.Empty);
                if (GUILayout.Button("-->", GUILayout.Width(30)))
                {
                    APIManager       apiManager = BridgingContext.Instance.container.APIManager;
                    SidekickSettings settings   = BridgingContext.Instance.container.Settings;
                    apiManager.SendToPlayers(new GetObjectRequest((Guid)fieldValue, (InfoFlags)settings.GetGameObjectFlags));
                    Debug.Log(fieldValue);
                }

                GUI.enabled = guiEnabled;
                EditorGUILayout.EndHorizontal();

                newValue = fieldValue;
            }
            else
            {
                newValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, variable.MetaData.GetTypeFromMetaData(), true);
            }
        }
        else if (variable.DataType == DataType.Integer)
        {
            newValue = EditorGUILayout.IntField(fieldName, (int)fieldValue);
        }
        else if (variable.DataType == DataType.Long)
        {
            newValue = EditorGUILayout.LongField(fieldName, (long)fieldValue);
        }
        else if (variable.DataType == DataType.String)
        {
            newValue = EditorGUILayout.TextField(fieldName, (string)fieldValue);
        }
        else if (variable.DataType == DataType.Char)
        {
            string newString = EditorGUILayout.TextField(fieldName, new string((char)fieldValue, 1));
            if (newString.Length == 1)
            {
                newValue = newString[0];
            }
            else
            {
                newValue = fieldValue;
            }
        }
        else if (variable.DataType == DataType.Float)
        {
            newValue = EditorGUILayout.FloatField(fieldName, (float)fieldValue);
        }
        else if (variable.DataType == DataType.Double)
        {
            newValue = EditorGUILayout.DoubleField(fieldName, (double)fieldValue);
        }
        else if (variable.DataType == DataType.Boolean)
        {
            newValue = EditorGUILayout.Toggle(fieldName, (bool)fieldValue);
        }
        else if (variable.DataType == DataType.Vector2)
        {
            newValue = EditorGUILayout.Vector2Field(fieldName, (Vector2)fieldValue);
        }
        else if (variable.DataType == DataType.Vector3)
        {
            newValue = EditorGUILayout.Vector3Field(fieldName, (Vector3)fieldValue);
        }
        else if (variable.DataType == DataType.Vector4)
        {
            newValue = EditorGUILayout.Vector4Field(fieldName, (Vector4)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.Vector2Int)
        {
            newValue = EditorGUILayout.Vector2IntField(fieldName, (Vector2Int)fieldValue);
        }
        else if (variable.DataType == DataType.Vector3Int)
        {
            newValue = EditorGUILayout.Vector3IntField(fieldName, (Vector3Int)fieldValue);
        }
#endif
        else if (variable.DataType == DataType.Quaternion)
        {
            //if(InspectorSidekick.Current.Settings.RotationsAsEuler)
            //{
            //  Quaternion quaternion = (Quaternion)fieldValue;
            //  Vector3 eulerAngles = quaternion.eulerAngles;
            //  eulerAngles = EditorGUILayout.Vector3Field(fieldName, eulerAngles);
            //  newValue = Quaternion.Euler(eulerAngles);
            //}
            //else
            {
                Quaternion quaternion = (Quaternion)fieldValue;
                Vector4    vector     = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                vector   = EditorGUILayout.Vector4Field(fieldName, vector);
                newValue = new Quaternion(vector.x, vector.y, vector.z, vector.z);
            }
        }
        else if (variable.DataType == DataType.Bounds)
        {
            newValue = EditorGUILayout.BoundsField(fieldName, (Bounds)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.BoundsInt)
        {
            newValue = EditorGUILayout.BoundsIntField(fieldName, (BoundsInt)fieldValue);
        }
#endif
        else if (variable.DataType == DataType.Color)
        {
            newValue = EditorGUILayout.ColorField(fieldName, (Color)fieldValue);
        }
        else if (variable.DataType == DataType.Color32)
        {
            newValue = (Color32)EditorGUILayout.ColorField(fieldName, (Color32)fieldValue);
        }
        else if (variable.DataType == DataType.Gradient)
        {
            newValue = InternalEditorGUILayout.GradientField(new GUIContent(fieldName), (Gradient)fieldValue);
        }
        else if (variable.DataType == DataType.AnimationCurve)
        {
            newValue = EditorGUILayout.CurveField(fieldName, (AnimationCurve)fieldValue);
        }
        else if (variable.DataType == DataType.Rect)
        {
            newValue = EditorGUILayout.RectField(fieldName, (Rect)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.RectInt)
        {
            newValue = EditorGUILayout.RectIntField(fieldName, (RectInt)fieldValue);
        }
#endif
        else
        {
            GUILayout.Label(fieldName);
            newValue = fieldValue;
        }

        return(newValue);
    }
        private void DrawNpc()
        {
            EditorGUILayout.BeginVertical("Box");

            #region NpcId Property
            GUILayout.Space(5);
            //获得Npc类中的_npcId属性
            SerializedProperty npcId = _spNpc.FindPropertyRelative("_npcId");
            EditorGUILayout.PropertyField(npcId, new GUIContent("NpcID"));
            #endregion

            #region NameId
            GUILayout.Space(5);
            //获得Npc类中的_nameId属性
            SerializedProperty nameId = _spNpc.FindPropertyRelative("_nameId");
            EditorGUILayout.PropertyField(nameId, new GUIContent("NameID"));
            #endregion

            #region Speed
            GUILayout.Space(5);
            SerializedProperty speed = _spNpc.FindPropertyRelative("_speed");
            EditorGUILayout.PropertyField(speed, new GUIContent("Speed"));
            #endregion

            #region Life
            GUILayout.Space(5);
            SerializedProperty life = _spNpc.FindPropertyRelative("_life");
            EditorGUILayout.PropertyField(life, new GUIContent("Life"));
            #endregion

            #region Button
            GUILayout.Space(5);
            Rect        rc   = GUILayoutUtility.GetRect(_debugButton, GUI.skin.button);
            const float with = 150f;
            rc.x     = rc.x + (rc.width - with) / 2;
            rc.width = with;
            if (GUI.Button(rc, _debugButton))
            {
                Debug.Log("npcId :" + npcId.intValue);
                Debug.Log("nameId :" + nameId.intValue);
                Debug.Log("speed :" + speed.floatValue);
                Debug.Log("life :" + life.floatValue);
            }
            #endregion


            GUILayout.Space(10);
            // target控制动画开始播放
            _fadeGroup.target = EditorGUILayout.Foldout(_fadeGroup.target, "BeginFadeGroup", true);

            // 系统使用tween渐变faded数值
            if (EditorGUILayout.BeginFadeGroup(_fadeGroup.faded))
            {
                SerializedProperty npcId2 = _spNpc.FindPropertyRelative("_npcId");
                EditorGUILayout.PropertyField(npcId2, new GUIContent("NpcID"));

                EditorGUILayout.BoundsField("BoundsField", new Bounds());
                EditorGUILayout.BoundsIntField("BoundsIntField", new BoundsInt());
            }
            // begin - end 之间元素会进行动画
            EditorGUILayout.EndFadeGroup();
            // 又一种风格的空格
            GUILayout.Space(10);

            EditorGUILayout.EndVertical();
        }
Exemplo n.º 12
0
    protected override void OnGUI()
    {
        base.OnGUI();

        pos = EditorGUILayout.BeginScrollView(pos);

        if (GUILayout.Button("这是一个按钮"))
        {
            Debug.Log("Click Button");
        }
        EditorGUILayout.LabelField("空格");
        EditorGUILayout.Separator();
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("这是一个默认Lable");
        EditorGUILayout.LabelField("这是高300,宽50的Label", GUILayout.Width(300), GUILayout.Height(50));
        EditorGUILayout.LabelField("这是一个拾色器");
        EditorGUILayout.ColorField(Color.white);
        EditorGUILayout.LabelField("Bounds");
        bounds = EditorGUILayout.BoundsField(bounds);
        EditorGUILayout.LabelField("BoundsInt");
        boundsInt = EditorGUILayout.BoundsIntField(boundsInt);
        EditorGUILayout.LabelField("AnimationCurve");
        curve = EditorGUILayout.CurveField(curve);

        EditorGUILayout.LabelField("<color=#ff0000>注意比对延迟设置和直接设置的区别</color>", Style);
        EditorGUILayout.Space();

        toggle     = EditorGUILayout.Toggle("Toggle", toggle);
        toggleLeft = EditorGUILayout.ToggleLeft("ToggleLeft", toggleLeft);

        //double
        EditorGUILayout.LabelField("延迟设置" + delayedDou.ToString());
        delayedDou = EditorGUILayout.DelayedDoubleField("DelayedDouble", delayedDou);
        EditorGUILayout.LabelField("直接设置" + dou.ToString());
        dou        = EditorGUILayout.DoubleField("Double", dou);
        delayedInt = EditorGUILayout.DelayedIntField("DelayedInt", delayedInt);
        //int
        i         = EditorGUILayout.IntField("Int", i);
        sliderInt = EditorGUILayout.IntSlider(sliderInt, 0, 100);

        //text
        delayedText = EditorGUILayout.DelayedTextField("DelayedText", delayedText);
        text        = EditorGUILayout.TextField("Text", text);
        password    = EditorGUILayout.PasswordField("Password", password);
        EditorGUILayout.LabelField("TextArea");
        textArea = EditorGUILayout.TextArea(textArea);
        //float
        delayedFloat = EditorGUILayout.DelayedFloatField("DelayedFloat", delayedFloat);
        f            = EditorGUILayout.FloatField("Float", f);
        fSlider      = EditorGUILayout.Slider("FloatSlider", fSlider, 0, 10);
        fKnob        = EditorGUILayout.Knob(new Vector2(100, 100), fKnob, 0, 10, "Knob", Color.blue, Color.red, true);
        longvalue    = EditorGUILayout.LongField("Long", longvalue);

        //vector
        v2    = EditorGUILayout.Vector2Field("Vector2", v2);
        v2Int = EditorGUILayout.Vector2IntField("Vector2Int", v2Int);

        v3    = EditorGUILayout.Vector3Field("Vector3", v3);
        v3Int = EditorGUILayout.Vector3IntField("Vector3Int", v3Int);

        v4 = EditorGUILayout.Vector4Field("Vector4", v4);

        EditorGUILayout.LabelField("枚举Field");
        m_Flags = (ExampleFlagsEnum)EditorGUILayout.EnumFlagsField(m_Flags);

        EditorGUILayout.LabelField("注意两者的区别");
        m_Flags = (ExampleFlagsEnum)EditorGUILayout.EnumPopup(m_Flags);

        gradient = EditorGUILayout.GradientField("Gradient", gradient);

        go   = (GameObject)EditorGUILayout.ObjectField("GameObject", go, typeof(GameObject), true);
        clip = (AnimationClip)EditorGUILayout.ObjectField("Clip", clip, typeof(AnimationClip), true);

        EditorGUILayout.LabelField("Rect");
        rect = EditorGUILayout.RectField(rect);
        EditorGUILayout.LabelField("RectInt");
        rectInt = EditorGUILayout.RectIntField(rectInt);


        EditorGUILayout.HelpBox("这是一个信息Box", MessageType.Info);
        EditorGUILayout.HelpBox("这是一个警告Box", MessageType.Warning);
        EditorGUILayout.HelpBox("这是一个错误Box", MessageType.Error);

        EditorGUILayout.SelectableLabel("SelectableLabel");


        EditorGUILayout.EndScrollView();
    }
Exemplo n.º 13
0
    public static object DrawIndividualVariable(ComponentDescription componentDescription, WrappedVariable variable, string fieldName, Type fieldType, object fieldValue, Action <Guid, WrappedVariable> onObjectPicker)
    {
        object newValue;

        if (variable.DataType == DataType.Enum)
        {
            newValue = EditorGUILayout.IntPopup(fieldName, (int)fieldValue, variable.MetaData.EnumNames, variable.MetaData.EnumValues);
        }
        else if (variable.DataType == DataType.UnityObjectReference)
        {
            if (fieldValue is Guid)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(fieldName);
                if ((Guid)fieldValue != Guid.Empty)
                {
                    EditorGUILayout.TextField(variable.MetaData.ValueDisplayName);
                }
                else
                {
                    EditorGUILayout.TextField("None (" + variable.MetaData.TypeFullName + ")");
                }
                if (componentDescription != null)
                {
                    if (GUILayout.Button("...", GUILayout.Width(30)))
                    {
                        onObjectPicker(componentDescription.Guid, variable);
                    }
                }
                EditorGUILayout.EndHorizontal();

                newValue = fieldValue;
            }
            else if (typeof(UnityEngine.Object).IsAssignableFrom(fieldType))
            {
                newValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, variable.MetaData.GetTypeFromMetaData(), true);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
        else if (fieldType == typeof(int) ||
                 (fieldType.IsSubclassOf(typeof(Enum)) && OldInspectorSidekick.Current.Settings.TreatEnumsAsInts))
        {
            newValue = EditorGUILayout.IntField(fieldName, (int)fieldValue);
        }
        else if (fieldType == typeof(long))
        {
            newValue = EditorGUILayout.LongField(fieldName, (long)fieldValue);
        }
        else if (fieldType == typeof(string))
        {
            newValue = EditorGUILayout.TextField(fieldName, (string)fieldValue);
        }
        else if (fieldType == typeof(char))
        {
            string newString = EditorGUILayout.TextField(fieldName, new string((char)fieldValue, 1));
            if (newString.Length == 1)
            {
                newValue = newString[0];
            }
            else
            {
                newValue = fieldValue;
            }
        }
        else if (fieldType == typeof(float))
        {
            newValue = EditorGUILayout.FloatField(fieldName, (float)fieldValue);
        }
        else if (fieldType == typeof(double))
        {
            newValue = EditorGUILayout.DoubleField(fieldName, (double)fieldValue);
        }
        else if (fieldType == typeof(bool))
        {
            newValue = EditorGUILayout.Toggle(fieldName, (bool)fieldValue);
        }
        else if (fieldType == typeof(Vector2))
        {
            newValue = EditorGUILayout.Vector2Field(fieldName, (Vector2)fieldValue);
        }
        else if (fieldType == typeof(Vector3))
        {
            newValue = EditorGUILayout.Vector3Field(fieldName, (Vector3)fieldValue);
        }
        else if (fieldType == typeof(Vector4))
        {
            newValue = EditorGUILayout.Vector4Field(fieldName, (Vector4)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (fieldType == typeof(Vector2Int))
        {
            newValue = EditorGUILayout.Vector2IntField(fieldName, (Vector2Int)fieldValue);
        }
        else if (fieldType == typeof(Vector3Int))
        {
            newValue = EditorGUILayout.Vector3IntField(fieldName, (Vector3Int)fieldValue);
        }
#endif
        else if (fieldType == typeof(Quaternion))
        {
            //if(InspectorSidekick.Current.Settings.RotationsAsEuler)
            //{
            //  Quaternion quaternion = (Quaternion)fieldValue;
            //  Vector3 eulerAngles = quaternion.eulerAngles;
            //  eulerAngles = EditorGUILayout.Vector3Field(fieldName, eulerAngles);
            //  newValue = Quaternion.Euler(eulerAngles);
            //}
            //else
            {
                Quaternion quaternion = (Quaternion)fieldValue;
                Vector4    vector     = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                vector   = EditorGUILayout.Vector4Field(fieldName, vector);
                newValue = new Quaternion(vector.x, vector.y, vector.z, vector.z);
            }
        }
        else if (fieldType == typeof(Bounds))
        {
            newValue = EditorGUILayout.BoundsField(fieldName, (Bounds)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (fieldType == typeof(BoundsInt))
        {
            newValue = EditorGUILayout.BoundsIntField(fieldName, (BoundsInt)fieldValue);
        }
#endif
        else if (fieldType == typeof(Color))
        {
            newValue = EditorGUILayout.ColorField(fieldName, (Color)fieldValue);
        }
        else if (fieldType == typeof(Color32))
        {
            newValue = (Color32)EditorGUILayout.ColorField(fieldName, (Color32)fieldValue);
        }
        else if (fieldType == typeof(Gradient))
        {
            newValue = InternalEditorGUILayout.GradientField(new GUIContent(fieldName), (Gradient)fieldValue);
        }
        else if (fieldType == typeof(AnimationCurve))
        {
            newValue = EditorGUILayout.CurveField(fieldName, (AnimationCurve)fieldValue);
        }
        else if (fieldType.IsSubclassOf(typeof(Enum)))
        {
            newValue = EditorGUILayout.EnumPopup(fieldName, (Enum)fieldValue);
        }
        else if (fieldType == typeof(Rect))
        {
            newValue = EditorGUILayout.RectField(fieldName, (Rect)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (fieldType == typeof(RectInt))
        {
            newValue = EditorGUILayout.RectIntField(fieldName, (RectInt)fieldValue);
        }
#endif
        else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)))
        {
            newValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, fieldType, true);
        }
        else
        {
            GUILayout.Label(fieldType + " " + fieldName);
            newValue = fieldValue;
        }



        //          EditorGUILayout.BoundsField()
        //          EditorGUILayout.ColorField
        //          EditorGUILayout.CurveField
        //          EditorGUILayout.EnumPopup
        //          EditorGUILayout.EnumMaskField
        //          EditorGUILayout.IntSlider // If there's a range attribute maybe?
        //          EditorGUILayout.LabelField // what's this?
        //          EditorGUILayout.ObjectField
        //          EditorGUILayout.RectField
        //          EditorGUILayout.TextArea
        //          EditorGUILayout.TextField

        // What's this? public static void HelpBox (string message, MessageType type, bool wide)
        // What's this?         public static bool InspectorTitlebar (bool foldout, Object targetObj)

        return(newValue);
    }
Exemplo n.º 14
0
    public static object DrawIndividualVariable(ObjectPickerContext objectPickerContext, WrappedVariable variable, string fieldName, object fieldValue, OpenPickerCallback onObjectPicker, int index = 0)
    {
        object newValue;

        if (variable.DataType == DataType.Enum)
        {
            newValue = EditorGUILayout.IntPopup(fieldName, (int)fieldValue, variable.MetaData.EnumNames, variable.MetaData.EnumValues);
        }
        else if (variable.DataType == DataType.UnityObjectReference)
        {
            if (fieldValue is Guid)
            {
                EditorGUILayout.BeginHorizontal();
                if ((Guid)fieldValue != Guid.Empty && variable.ValueDisplayNames.Length > index)
                {
                    EditorGUILayout.TextField(fieldName, variable.ValueDisplayNames[index]);
                }
                else
                {
                    EditorGUILayout.TextField(fieldName, "None (" + variable.MetaData.TypeFullName + ")");
                }
                if (objectPickerContext != null)
                {
                    if (GUILayout.Button("...", GUILayout.Width(30)))
                    {
                        onObjectPicker(objectPickerContext, variable);
                    }
                }
                EditorGUILayout.EndHorizontal();

                newValue = fieldValue;
            }
            else
            {
                newValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, variable.MetaData.GetTypeFromMetaData(), true);
            }
        }
        else if (variable.DataType == DataType.Integer)
        {
            newValue = EditorGUILayout.IntField(fieldName, (int)fieldValue);
        }
        else if (variable.DataType == DataType.Long)
        {
            newValue = EditorGUILayout.LongField(fieldName, (long)fieldValue);
        }
        else if (variable.DataType == DataType.String)
        {
            newValue = EditorGUILayout.TextField(fieldName, (string)fieldValue);
        }
        else if (variable.DataType == DataType.Char)
        {
            string newString = EditorGUILayout.TextField(fieldName, new string((char)fieldValue, 1));
            if (newString.Length == 1)
            {
                newValue = newString[0];
            }
            else
            {
                newValue = fieldValue;
            }
        }
        else if (variable.DataType == DataType.Float)
        {
            newValue = EditorGUILayout.FloatField(fieldName, (float)fieldValue);
        }
        else if (variable.DataType == DataType.Double)
        {
            newValue = EditorGUILayout.DoubleField(fieldName, (double)fieldValue);
        }
        else if (variable.DataType == DataType.Boolean)
        {
            newValue = EditorGUILayout.Toggle(fieldName, (bool)fieldValue);
        }
        else if (variable.DataType == DataType.Vector2)
        {
            newValue = EditorGUILayout.Vector2Field(fieldName, (Vector2)fieldValue);
        }
        else if (variable.DataType == DataType.Vector3)
        {
            newValue = EditorGUILayout.Vector3Field(fieldName, (Vector3)fieldValue);
        }
        else if (variable.DataType == DataType.Vector4)
        {
            newValue = EditorGUILayout.Vector4Field(fieldName, (Vector4)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.Vector2Int)
        {
            newValue = EditorGUILayout.Vector2IntField(fieldName, (Vector2Int)fieldValue);
        }
        else if (variable.DataType == DataType.Vector3Int)
        {
            newValue = EditorGUILayout.Vector3IntField(fieldName, (Vector3Int)fieldValue);
        }
#endif
        else if (variable.DataType == DataType.Quaternion)
        {
            //if(InspectorSidekick.Current.Settings.RotationsAsEuler)
            //{
            //  Quaternion quaternion = (Quaternion)fieldValue;
            //  Vector3 eulerAngles = quaternion.eulerAngles;
            //  eulerAngles = EditorGUILayout.Vector3Field(fieldName, eulerAngles);
            //  newValue = Quaternion.Euler(eulerAngles);
            //}
            //else
            {
                Quaternion quaternion = (Quaternion)fieldValue;
                Vector4    vector     = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                vector   = EditorGUILayout.Vector4Field(fieldName, vector);
                newValue = new Quaternion(vector.x, vector.y, vector.z, vector.z);
            }
        }
        else if (variable.DataType == DataType.Bounds)
        {
            newValue = EditorGUILayout.BoundsField(fieldName, (Bounds)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.BoundsInt)
        {
            newValue = EditorGUILayout.BoundsIntField(fieldName, (BoundsInt)fieldValue);
        }
#endif
        else if (variable.DataType == DataType.Color)
        {
            newValue = EditorGUILayout.ColorField(fieldName, (Color)fieldValue);
        }
        else if (variable.DataType == DataType.Color32)
        {
            newValue = (Color32)EditorGUILayout.ColorField(fieldName, (Color32)fieldValue);
        }
        else if (variable.DataType == DataType.Gradient)
        {
            newValue = InternalEditorGUILayout.GradientField(new GUIContent(fieldName), (Gradient)fieldValue);
        }
        else if (variable.DataType == DataType.AnimationCurve)
        {
            newValue = EditorGUILayout.CurveField(fieldName, (AnimationCurve)fieldValue);
        }
        else if (variable.DataType == DataType.Rect)
        {
            newValue = EditorGUILayout.RectField(fieldName, (Rect)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.RectInt)
        {
            newValue = EditorGUILayout.RectIntField(fieldName, (RectInt)fieldValue);
        }
#endif
        else
        {
            GUILayout.Label(fieldName);
            newValue = fieldValue;
        }

        return(newValue);
    }
Exemplo n.º 15
0
        private void _drawValue(ValueS valueS)
        {
            //todo draw Value
            if (valueS.IsUnity)
            {
                Object obj;
                EditorGUI.BeginChangeCheck();
                {
                    obj = EditorGUILayout.ObjectField(valueS.UValue, valueS.ValueType, false);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    valueS.SetValue(obj);
                    _save();
                }
            }
            else
            {
                //todo non Unity Type

                var value = valueS.GetValue();

                if (value == null)
                {
                    valueS.SetValue(Activator.CreateInstance(valueS.ValueType));
                    _save();
                }


                _drawNonUnityValue <int>(valueS, x => EditorGUILayout.DelayedIntField((int)x.GetValue()));
                _drawNonUnityValue <float>(valueS, x => EditorGUILayout.DelayedFloatField((float)x.GetValue()));
                _drawNonUnityValue <double>(valueS, x => EditorGUILayout.DelayedDoubleField((double)x.GetValue()));
                _drawNonUnityValue <long>(valueS, x => EditorGUILayout.LongField((long)x.GetValue()));
                _drawNonUnityValue <string>(valueS, x => EditorGUILayout.DelayedTextField((string)x.GetValue()));
                _drawNonUnityValue <Vector2>(valueS, x => EditorGUILayout.Vector2Field("", (Vector2)x.GetValue()));
                _drawNonUnityValue <Vector2Int>(valueS, x => EditorGUILayout.Vector2IntField("", (Vector2Int)x.GetValue()));
                _drawNonUnityValue <Vector3>(valueS, x => EditorGUILayout.Vector3Field("", (Vector3)x.GetValue()));
                _drawNonUnityValue <Vector3Int>(valueS, x => EditorGUILayout.Vector3IntField("", (Vector3Int)x.GetValue()));
                _drawNonUnityValue <Vector4>(valueS, x => EditorGUILayout.Vector4Field("", (Vector4)x.GetValue()));
                _drawNonUnityValue <Color>(valueS, x => EditorGUILayout.ColorField((Color)x.GetValue()));
                _drawNonUnityValue <AnimationCurve>(valueS, x => EditorGUILayout.CurveField((AnimationCurve)x.GetValue()));
                _drawNonUnityValue <Bounds>(valueS, x => EditorGUILayout.BoundsField((Bounds)x.GetValue()));
                _drawNonUnityValue <BoundsInt>(valueS, x => EditorGUILayout.BoundsIntField((BoundsInt)x.GetValue()));
                _drawNonUnityValue <Rect>(valueS, x => EditorGUILayout.RectField((Rect)x.GetValue()));
                _drawNonUnityValue <RectInt>(valueS, x => EditorGUILayout.RectIntField((RectInt)x.GetValue()));
                _drawNonUnityValue <Enum>(valueS, x => EditorGUILayout.EnumFlagsField((Enum)x.GetValue()));
                _drawNonUnityValue <Gradient>(valueS, x => EditorGUILayout.GradientField((Gradient)x.GetValue()));

                if (GUILayout.Button("Edit Value"))
                {
                    var size = 250;

                    _ValueEditPopup.ValueS = valueS;

                    PopupWindow.Show(
                        new Rect(new Vector2(Event.current.mousePosition.x - size / 2, -(_rect.height - size - (Event.current.mousePosition.y + 60)))
                                 , new Vector2(size, size)),
                        _ValueEditPopup);
                }
            }
        }
        static public object DrawPropertyLayoutField(object value, string label, out Type type)
        {
            //先关闭这行字段的显示
            GUI.enabled = true;

            Type valueType = value.GetType();

            type = valueType;

            if (valueType == typeof(int))
            {
                return(EditorGUILayout.IntField(label, (int)value));
            }
            else if (valueType == typeof(long))
            {
                return(EditorGUILayout.LongField(label, (long)value));
            }
            else if (valueType == typeof(float))
            {
                return(EditorGUILayout.FloatField(label, (float)value));
            }
            else if (valueType == typeof(double))
            {
                return(EditorGUILayout.DoubleField(label, (double)value));
            }
            else if (valueType == typeof(string))
            {
                return(EditorGUILayout.TextField(label, (string)value));
            }
            else if (valueType == typeof(Vector2))
            {
                return(EditorGUILayout.Vector2Field(label, (Vector2)value));
            }
            else if (valueType == typeof(Vector3))
            {
                return(EditorGUILayout.Vector3Field(label, (Vector3)value));
            }
            else if (valueType == typeof(Vector4))
            {
                return(EditorGUILayout.Vector4Field(label, (Vector4)value));
            }
            else if (valueType == typeof(Vector2Int))
            {
                return(EditorGUILayout.Vector2IntField(label, (Vector2Int)value));
            }
            else if (valueType == typeof(Vector3Int))
            {
                return(EditorGUILayout.Vector3IntField(label, (Vector3Int)value));
            }
            else if (valueType == typeof(Color))
            {
                return(EditorGUILayout.ColorField(label, (Color)value));
            }
            else if (valueType == typeof(Bounds))
            {
                return(EditorGUILayout.BoundsField(label, (Bounds)value));
            }
            else if (valueType == typeof(BoundsInt))
            {
                return(EditorGUILayout.BoundsIntField(label, (BoundsInt)value));
            }
            else if (valueType == typeof(Rect))
            {
                return(EditorGUILayout.RectField(label, (Rect)value));
            }
            else if (valueType == typeof(RectInt))
            {
                return(EditorGUILayout.RectIntField(label, (RectInt)value));
            }
            else if (typeof(UnityEngine.Object).IsAssignableFrom(valueType))
            {
                return(EditorGUILayout.ObjectField(label, (UnityEngine.Object)value, valueType, true));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 17
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();

        // draw disabled MonoScript

        EditorGUI.BeginDisabledGroup(true);
        EditorGUILayout.ObjectField("Script", this.monoScript, typeof(MonoScript), false);
        EditorGUI.EndDisabledGroup();

//----------------------------------------------------------------------------------------------------------------------

        // draw intValue and boolValue, and boolValue has custom label display

        EditorGUILayout.PropertyField(this.serializedObject.FindProperty("intValue"));
        EditorGUILayout.PropertyField(this.serializedObject.FindProperty("boolValue"), this.boolValueContent);
        var v2Property = this.serializedObject.FindProperty("v2");

        EditorGUILayout.PropertyField(v2Property);
        v2Property.FindPropertyRelative("x").floatValue = 999.0f;

        EditorGUILayout.Separator();

//----------------------------------------------------------------------------------------------------------------------

        // draw array of elements

        var elements = this.serializedObject.FindProperty("floatArray");

        if (EditorGUILayout.PropertyField(elements))
        {
            EditorGUI.indentLevel++;
            elements.arraySize = EditorGUILayout.DelayedIntField("Size", elements.arraySize);

            for (int i = 0, size = elements.arraySize; i < size; i++)
            {
                var element = elements.GetArrayElementAtIndex(i);
                EditorGUILayout.PropertyField(element);
            }

            EditorGUI.indentLevel--;
        }

        EditorGUILayout.Space();

//----------------------------------------------------------------------------------------------------------------------

        this.fadeGroup.target = EditorGUILayout.Foldout(this.fadeGroup.target, "BeginFadeGroup", true);

        if (EditorGUILayout.BeginFadeGroup(this.fadeGroup.faded))
        {
            EditorGUILayout.BoundsField("BoundsField", new Bounds());
            EditorGUILayout.BoundsIntField("BoundsIntField", new BoundsInt());
        }

        EditorGUILayout.EndFadeGroup();

        GUILayout.Space(10);

//----------------------------------------------------------------------------------------------------------------------

        EditorGUILayout.BeginHorizontal(GUI.skin.box);

        EditorGUILayout.LabelField("This is BeginHorizontal", GUILayout.MaxWidth(150.0f));
        EditorGUILayout.DelayedDoubleField(11.1f);
        EditorGUILayout.DelayedTextField("DelayedTextField");
        EditorGUILayout.DropdownButton(GUIContent.none, FocusType.Passive);

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();

//----------------------------------------------------------------------------------------------------------------------

        EditorGUILayout.BeginVertical(GUI.skin.box);

        GUILayout.Box("This is BeginVertical");
        EditorGUILayout.ColorField("ColorField", Color.yellow);
        EditorGUILayout.CurveField("CurveField", new AnimationCurve(), GUILayout.MaxWidth(400.0f));
        EditorGUILayout.HelpBox("HelpBox", MessageType.Info);
        EditorGUILayout.EnumFlagsField("EnumFlagsField", this.types);
        EditorGUILayout.EnumPopup("EnumPopup", this.types);

        this.selectOption = EditorGUILayout.IntPopup("IntPopup", (int)this.selectOption, new[] { "0", "1", "2" }, new[] { 0, 1, 2 });
        this.selectOption = EditorGUILayout.IntSlider("IntSlider", (int)this.selectOption, 0, 2);
        this.selectOption = EditorGUILayout.MaskField("MaskField", (int)this.selectOption, new[] { "mask1", "mask2", "mask3" });
        this.selectOption = EditorGUILayout.Popup("Popup", (int)this.selectOption, new[] { "s1", "s2", "s3" });

        EditorGUILayout.EndVertical();

        EditorGUILayout.Separator();

//----------------------------------------------------------------------------------------------------------------------

        this.scrollPos = EditorGUILayout.BeginScrollView(this.scrollPos, GUI.skin.box);

        GUILayout.Box("this is BeginScrollView");
        EditorGUILayout.TextArea("this is TextArea");
        EditorGUILayout.RectField("RectField", new Rect());
        this.toggle      = EditorGUILayout.Toggle("Toggle", this.toggle);
        this.toggleGroup = EditorGUILayout.BeginToggleGroup("BeginToggleGroup", this.toggleGroup);

        GUILayout.Button("Btn1");
        GUILayout.Button("Btn2");
        GUILayout.Button("Btn3");

        EditorGUILayout.EndToggleGroup();

        EditorGUILayout.EndScrollView();

        this.serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 18
0
 public override void OnGUILayout(ReflectedProperty property, GUIContent label = null)
 {
     property.Value = EditorGUILayout.BoundsIntField(label, (BoundsInt)property.Value);
 }
Exemplo n.º 19
0
        private static void DrawIndividualVariable(GUIContent label, Type fieldType, object fieldValue, IEnumerable <Attribute> customAttributes, out bool handled, Action <object> changeCallback)
        {
            EditorGUI.BeginChangeCheck();
            handled = true;
            object newValue;

            RangeAttribute rangeAttribute = null;

            if (customAttributes != null)
            {
                foreach (var customAttribute in customAttributes)
                {
                    if (customAttribute is RangeAttribute attribute)
                    {
                        rangeAttribute = attribute;
                    }
                }
            }

            if (fieldType == typeof(int))
            {
                if (SidekickSettings.PreferUnityAttributes && rangeAttribute != null)
                {
                    newValue = EditorGUILayout.IntSlider(label, (int)fieldValue, (int)rangeAttribute.min, (int)rangeAttribute.max);
                }
                else
                {
                    newValue = EditorGUILayout.IntField(label, (int)fieldValue);
                }
            }
            else if (fieldType == typeof(uint))
            {
                long newLong = EditorGUILayout.LongField(label, (uint)fieldValue);
                // Replicate Unity's built in behaviour
                newValue = (uint)Mathf.Clamp(newLong, uint.MinValue, uint.MaxValue);
            }
            else if (fieldType == typeof(long))
            {
                newValue = EditorGUILayout.LongField(label, (long)fieldValue);
            }
            else if (fieldType == typeof(ulong))
            {
                // Note that Unity doesn't have a built in way to handle larger values than long.MaxValue (its inspector
                // doesn't work correctly with ulong in fact), so display it as a validated text field
                string newString = EditorGUILayout.TextField(label, ((ulong)fieldValue).ToString());
                if (ulong.TryParse(newString, out ulong newULong))
                {
                    newValue = newULong;
                }
                else
                {
                    newValue = fieldValue;
                }
            }
            else if (fieldType == typeof(byte))
            {
                int newInt = EditorGUILayout.IntField(label, (byte)fieldValue);
                // Replicate Unity's built in behaviour
                newValue = (byte)Mathf.Clamp(newInt, byte.MinValue, byte.MaxValue);
            }
            else if (fieldType == typeof(sbyte))
            {
                int newInt = EditorGUILayout.IntField(label, (sbyte)fieldValue);
                // Replicate Unity's built in behaviour
                newValue = (sbyte)Mathf.Clamp(newInt, sbyte.MinValue, sbyte.MaxValue);
            }
            else if (fieldType == typeof(ushort))
            {
                int newInt = EditorGUILayout.IntField(label, (ushort)fieldValue);
                // Replicate Unity's built in behaviour
                newValue = (ushort)Mathf.Clamp(newInt, ushort.MinValue, ushort.MaxValue);
            }
            else if (fieldType == typeof(short))
            {
                int newInt = EditorGUILayout.IntField(label, (short)fieldValue);
                // Replicate Unity's built in behaviour
                newValue = (short)Mathf.Clamp(newInt, short.MinValue, short.MaxValue);
            }
            else if (fieldType == typeof(string))
            {
                newValue = EditorGUILayout.TextField(label, (string)fieldValue);
            }
            else if (fieldType == typeof(char))
            {
                string newString = EditorGUILayout.TextField(label, new string((char)fieldValue, 1));
                // Replicate Unity's built in behaviour
                if (newString.Length == 1)
                {
                    newValue = newString[0];
                }
                else
                {
                    newValue = fieldValue;
                }
            }
            else if (fieldType == typeof(float))
            {
                if (SidekickSettings.PreferUnityAttributes && rangeAttribute != null)
                {
                    newValue = EditorGUILayout.Slider(label, (float)fieldValue, rangeAttribute.min, rangeAttribute.max);
                }
                else
                {
                    newValue = EditorGUILayout.FloatField(label, (float)fieldValue);
                }
            }
            else if (fieldType == typeof(double))
            {
                newValue = EditorGUILayout.DoubleField(label, (double)fieldValue);
            }
            else if (fieldType == typeof(bool))
            {
                newValue = EditorGUILayout.Toggle(label, (bool)fieldValue);
            }
            else if (fieldType == typeof(Vector2))
            {
                newValue = EditorGUILayout.Vector2Field(label, (Vector2)fieldValue);
            }
            else if (fieldType == typeof(Vector3))
            {
                newValue = EditorGUILayout.Vector3Field(label, (Vector3)fieldValue);
            }
            else if (fieldType == typeof(Vector4))
            {
                newValue = EditorGUILayout.Vector4Field(label, (Vector4)fieldValue);
            }
            else if (fieldType == typeof(Vector2Int))
            {
                newValue = EditorGUILayout.Vector2IntField(label, (Vector2Int)fieldValue);
            }
            else if (fieldType == typeof(Vector3Int))
            {
                newValue = EditorGUILayout.Vector3IntField(label, (Vector3Int)fieldValue);
            }
            else if (fieldType == typeof(Quaternion))
            {
                Quaternion quaternion = (Quaternion)fieldValue;
                Vector4    vector     = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                vector   = EditorGUILayout.Vector4Field(label, vector);
                newValue = new Quaternion(vector.x, vector.y, vector.z, vector.z);
            }
#if UNITY_MATH_EXISTS
            else if (fieldType == typeof(float2))
            {
                newValue = (float2)EditorGUILayout.Vector2Field(label, (float2)fieldValue);
            }
            else if (fieldType == typeof(float3))
            {
                newValue = (float3)EditorGUILayout.Vector3Field(label, (float3)fieldValue);
            }
            else if (fieldType == typeof(float4))
            {
                newValue = (float4)EditorGUILayout.Vector4Field(label, (float4)fieldValue);
            }
#endif
            else if (fieldType == typeof(Bounds))
            {
                newValue = EditorGUILayout.BoundsField(label, (Bounds)fieldValue);
            }
            else if (fieldType == typeof(BoundsInt))
            {
                newValue = EditorGUILayout.BoundsIntField(label, (BoundsInt)fieldValue);
            }
            else if (fieldType == typeof(Color))
            {
                newValue = EditorGUILayout.ColorField(label, (Color)fieldValue);
            }
            else if (fieldType == typeof(Color32))
            {
                newValue = (Color32)EditorGUILayout.ColorField(label, (Color32)fieldValue);
            }
            else if (fieldType == typeof(Gradient))
            {
                newValue = EditorGUILayout.GradientField(new GUIContent(label), (Gradient)fieldValue);
            }
            else if (fieldType == typeof(AnimationCurve))
            {
                newValue = EditorGUILayout.CurveField(label, (AnimationCurve)fieldValue);
            }
            else if (fieldType.IsSubclassOf(typeof(Enum)))
            {
                newValue = EditorGUILayout.EnumPopup(label, (Enum)fieldValue);
                Type underlyingType = Enum.GetUnderlyingType(fieldValue.GetType());
                // Cast from the enum to the underlying type (e.g. byte) then to int
                object cast = Convert.ChangeType(newValue, underlyingType);
                cast = Convert.ChangeType(cast, typeof(int));
                // Allow them to edit as an int then cast back
                newValue = Convert.ChangeType(EditorGUILayout.IntField((int)cast), underlyingType);
            }
            else if (fieldType == typeof(Rect))
            {
                newValue = EditorGUILayout.RectField(label, (Rect)fieldValue);
            }
            else if (fieldType == typeof(RectInt))
            {
                newValue = EditorGUILayout.RectIntField(label, (RectInt)fieldValue);
            }
            else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                newValue = EditorGUILayout.ObjectField(label, (UnityEngine.Object)fieldValue, fieldType, true);
            }
            else if (fieldType == typeof(Type))
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(label, new GUIContent(TypeUtility.NameForType((Type)fieldValue)));
                var popupRect = GUILayoutUtility.GetLastRect();
                popupRect.width = EditorGUIUtility.currentViewWidth;

                var selectTypeButtonLabel = new GUIContent("Select");
                if (GUILayout.Button(selectTypeButtonLabel, EditorStyles.miniButton))
                {
                    TypeSelectDropdown dropdown = new TypeSelectDropdown(new AdvancedDropdownState(), type =>
                    {
                        // Async apply
                        changeCallback?.Invoke(type);
                    });
                    dropdown.Show(popupRect);
                }

                EditorGUILayout.EndHorizontal();
                newValue = fieldValue;
            }
            else
            {
                handled  = false;
                newValue = fieldValue;
            }

            if (EditorGUI.EndChangeCheck())
            {
                changeCallback?.Invoke(newValue);
            }
        }
Exemplo n.º 20
0
        public static object AnyTypeField(string label, object value, string messageOnFail = null)
        {
            switch (value)
            {
            case int intValue:
                return(EditorGUILayout.IntField(label, intValue));

            case bool boolValue:
                return(EditorGUILayout.Toggle(label, boolValue));

            case long longValue:
                return(EditorGUILayout.LongField(label, longValue));

            case float floatValue:
                return(EditorGUILayout.FloatField(label, floatValue));

            case double doubleValue:
                return(EditorGUILayout.DoubleField(label, doubleValue));

            case string stringValue:
                return(EditorGUILayout.TextField(label, stringValue));

            case Vector2 vector2Value:
                return(EditorGUILayout.Vector2Field(label, vector2Value));

            case Vector3 vector3Value:
                return(EditorGUILayout.Vector3Field(label, vector3Value));

            case Vector4 vector4Value:
                return(EditorGUILayout.Vector4Field(label, vector4Value));

            case Vector2Int vector2IntValue:
                return(EditorGUILayout.Vector2IntField(label, vector2IntValue));

            case Vector3Int vector3IntValue:
                return(EditorGUILayout.Vector3IntField(label, vector3IntValue));

            case Rect rectValue:
                return(EditorGUILayout.RectField(label, rectValue));

            case RectInt rectIntValue:
                return(EditorGUILayout.RectIntField(label, rectIntValue));

            case Bounds boundsValue:
                return(EditorGUILayout.BoundsField(label, boundsValue));

            case BoundsInt boundsIntValue:
                return(EditorGUILayout.BoundsIntField(label, boundsIntValue));

            case Color colorValue:
                return(EditorGUILayout.ColorField(label, colorValue));

            case Gradient gradientValue:
                return(EditorGUILayout.GradientField(label, gradientValue));

            case AnimationCurve animationCurveValue:
                return(EditorGUILayout.CurveField(label, animationCurveValue));

            default:
                break;
            }

            if (value.GetType().BaseType == typeof(Enum))
            {
                return(EditorGUILayout.EnumPopup(label, (Enum)value));
            }

            if (typeof(UnityEngine.Object).IsAssignableFrom(value.GetType()))
            {
                return(EditorGUILayout.ObjectField(label, (UnityEngine.Object)value, value.GetType(), true));
            }

            if (string.IsNullOrEmpty(messageOnFail))
            {
                messageOnFail = $"{value.GetType()} is not supported by method {nameof(AnyTypeField)}";
            }

            EditorGUILayout.HelpBox(messageOnFail, MessageType.Warning);

            return(value);
        }
Exemplo n.º 21
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());
    }