예제 #1
0
 public override Bounds BoundsField(GUIContent content, Bounds value, Layout option)
 {
     return(EditorGUILayout.BoundsField(content, value, option));
 }
예제 #2
0
        public static bool DrawLayoutField(object value, string label)
        {
            GUI.enabled = false;

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

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

            GUI.enabled = true;

            return(isDrawn);
        }
예제 #3
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);
    }
예제 #4
0
 public object DrawAndGetNewValue(Type memberType, string memberName, object value, IEntity entity, int index, IComponent component)
 {
     return(EditorGUILayout.BoundsField(memberName, (Bounds)value));
 }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 protected override Bounds DrawAndUpdateValue()
 {
     return(EditorGUILayout.BoundsField(new GUIContent(Label), m_cachedValue, options));
 }
예제 #6
0
        ///Draws an Editor field for object of type directly
        public static object DrawEditorFieldDirect(GUIContent content, object value, Type t, FieldInfo field = null, object context = null, 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, UserTypePrefs.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(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(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))
                {
                    return(EditorGUILayout.EnumMaskPopup(content, (System.Enum)value));
                }
                return(EditorGUILayout.EnumPopup(content, (System.Enum)value));
            }

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

            if (typeof(IDictionary).IsAssignableFrom(t))
            {
                return(DictionaryEditor(content, (IDictionary)value, t, 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);
        }
예제 #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());
    }
    public static object GetUnityEditorInputFieldValue(this Type type, object currentValue)
    {
        if (type.IsSubtypeOrEqualToOneOf(typeof(int), typeof(short), typeof(byte)))
        {
            return(EditorGUILayout.IntField((int)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(long)))
        {
            return(EditorGUILayout.LongField((long)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(float)))
        {
            return(EditorGUILayout.FloatField((float)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(double)))
        {
            return(EditorGUILayout.DoubleField((double)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(string)))
        {
            return(EditorGUILayout.TextField(((string)currentValue) ?? ""));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(char)))
        {
            return(CharField((char)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(bool)))
        {
            return(EditorGUILayout.Toggle((bool)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(Enum)))
        {
            return(EnumField(type, currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(Color)))
        {
            return(EditorGUILayout.ColorField((Color)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(LayerMask)))
        {
            return(LayerMaskField((LayerMask)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(Vector2)))
        {
            return(EditorGUILayout.Vector2Field("", (Vector2)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(Vector3)))
        {
            return(EditorGUILayout.Vector3Field("", (Vector3)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(Vector4)))
        {
            return(EditorGUILayout.Vector4Field("", (Vector4)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(Rect)))
        {
            return(EditorGUILayout.RectField((Rect)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(Bounds)))
        {
            return(EditorGUILayout.BoundsField((Bounds)currentValue));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(AnimationCurve)))
        {
            return(EditorGUILayout.CurveField(((AnimationCurve)currentValue) ?? new AnimationCurve()));
        }
        else if (type.IsSubtypeOrEqualTo(typeof(UnityEngine.Object)))
        {
            return(ObjectField(type, (UnityEngine.Object)currentValue));
        }

        throw new ArgumentException(string.Format("type {0} has no Unity Editor input field", type), "type");
    }
    public void WizardGUI()
    {
        int size = 0;

        try {
            size = Method.Parameters.Count;
        } catch (NullReferenceException) {
            EditorGUILayout.HelpBox("My parent window has lost focus, please close me", MessageType.Error);
            return;
        }

        for (int i = 0; i < size; i++)
        {
            var parameter = Method.Parameters[i];

            switch (parameter.TypeName)
            {
            case "String":
                parameter.StringValue = EditorGUILayout.TextField(parameter.DisplayName, parameter.StringValue);
                break;

            case "Int32":
                parameter.IntValue = EditorGUILayout.IntField(parameter.DisplayName, parameter.IntValue);
                break;

            case "Int64":
                parameter.LongValue = EditorGUILayout.LongField(parameter.DisplayName, parameter.LongValue);
                break;

            case "Single":
                parameter.FloatValue = EditorGUILayout.FloatField(parameter.DisplayName, parameter.FloatValue);
                break;

            case "Double":
                parameter.DoubleValue = EditorGUILayout.DoubleField(parameter.DisplayName, parameter.DoubleValue);
                break;

            case "Boolean":
                parameter.BoolValue = EditorGUILayout.Toggle(parameter.DisplayName, parameter.BoolValue);
                break;

            case "Vector2":
                parameter.Vector2Value = EditorGUILayout.Vector2Field(parameter.DisplayName, parameter.Vector2Value);
                break;

            case "Vector3":
                parameter.Vector3Value = EditorGUILayout.Vector3Field(parameter.DisplayName, parameter.Vector3Value);
                break;

            case "Vector4":
                parameter.Vector4Value = EditorGUILayout.Vector4Field(parameter.DisplayName, parameter.Vector4Value);
                break;

            case "Quaternion":
                var v4 = new Vector4(parameter.QuaternionValue.x, parameter.QuaternionValue.y, parameter.QuaternionValue.z, parameter.QuaternionValue.w);
                v4 = EditorGUILayout.Vector4Field(parameter.DisplayName, v4);
                parameter.QuaternionValue = new Quaternion(v4.x, v4.y, v4.z, v4.w);
                break;

            case "Bounds":
                parameter.BoundsValue = EditorGUILayout.BoundsField(parameter.DisplayName, parameter.BoundsValue);
                break;

            case "Rect":
                parameter.RectValue = EditorGUILayout.RectField(parameter.DisplayName, parameter.RectValue);
                break;

            case "Matrix4x4":
                matrixMode = (MatrixWizard.EMatrixMode)EditorGUILayout.EnumPopup(parameter.DisplayName, matrixMode);
                switch (matrixMode)
                {
                case MatrixWizard.EMatrixMode.Column:
                    parameter.MatrixValue = MatrixWizard.DrawColumns(parameter.MatrixValue);
                    break;

                case MatrixWizard.EMatrixMode.Row:
                    parameter.MatrixValue = MatrixWizard.DrawRows(parameter.MatrixValue);
                    break;
                }
                break;

            case "AnimationCurve":
                parameter.AnimationCurveValue = EditorGUILayout.CurveField(parameter.AnimationCurveValue);
                break;

            case "Object":
            case "GameObject":
                parameter.ObjectValue = EditorGUILayout.ObjectField(parameter.DisplayName, parameter.ObjectValue, parameter.Type, true);
                break;

            case "Enum":
                var enumValue = (Enum)Enum.Parse(parameter.Type, parameter.EnumNames[parameter.EnumValue]);
                enumValue = EditorGUILayout.EnumPopup(parameter.DisplayName, enumValue);
                for (int j = 0; j < parameter.EnumNames.Length; j++)
                {
                    if (parameter.EnumNames[j] == enumValue.ToString())
                    {
                        parameter.EnumValue = j;
                        break;
                    }
                }
                break;

            default:
                EditorGUILayout.HelpBox(string.Format("The type {0} is not supported", parameter.RepresentableType), MessageType.Warning);
                break;
            }
        }
    }
예제 #10
0
        public void ShowInternalItem_Playing(string path, string key, object value, bool showKey = true)
        {
            if (value == null)
            {
                return;
            }

            var  type = value.GetType();
            bool endSingleVertical = false;

            if (showKey)
            {
                if (type.IsValueType || type == typeof(string) || type.IsSubclassOf(typeof(UnityEngine.Object)) || type == typeof(UnityEngine.Object))
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(GetPrefixKey(key));

                    endSingleVertical = true;
                }
            }

            if (type.IsValueType)
            {
                if (type == typeof(double))
                {
                    EditorGUILayout.DoubleField((double)value);
                }
                else if (type == typeof(bool))
                {
                    EditorGUILayout.Toggle((bool)value);
                }
                else if (type == typeof(System.Int32))
                {
                    EditorGUILayout.IntField(System.Convert.ToInt32(value));
                }
                else if (type == typeof(System.Int64))
                {
                    EditorGUILayout.IntField(System.Convert.ToInt32(value));
                }
                else if (type == typeof(System.Double))
                {
                    EditorGUILayout.DoubleField(System.Convert.ToDouble(value));
                }
                else if (type == typeof(System.Single))
                {
                    EditorGUILayout.FloatField(System.Convert.ToSingle(value));
                }
                else if (type == typeof(Vector2))
                {
                    EditorGUILayout.Vector2Field(string.Empty, (Vector2)value);
                }
                else if (type == typeof(Vector3))
                {
                    EditorGUILayout.Vector3Field(string.Empty, (Vector3)value);
                }
                else if (type == typeof(Vector4))
                {
                    EditorGUILayout.Vector4Field(string.Empty, (Vector4)value);
                }
                else if (type == typeof(Color))
                {
                    EditorGUILayout.ColorField((Color)value);
                }
                else if (type == typeof(Rect))
                {
                    EditorGUILayout.RectField((Rect)value);
                }
                else if (type == typeof(Bounds))
                {
                    EditorGUILayout.BoundsField((Bounds)value);
                }
                else if (type.IsSubclassOf(typeof(System.Enum)))
                {
                    EditorGUILayout.EnumPopup(value as System.Enum);
                }
            }
            else
            {
                if (type == typeof(string))
                {
                    EditorGUILayout.TextField(value as string);
                }
                else if (type.IsSubclassOf(typeof(UnityEngine.Object)) || type == typeof(UnityEngine.Object))
                {
                    EditorGUILayout.ObjectField(value as UnityEngine.Object, type, true);
                }
                else if (type.IsArray)
                {
                    bool show = false;

                    string fullpath = path + "." + key;

                    EditorGUILayout.BeginVertical("Box");
                    EditorGUI.indentLevel++;

                    foldout.TryGetValue(fullpath, out show);
                    show = EditorGUILayout.Foldout(show, GetPrefixKey(key));
                    foldout[fullpath] = show;

                    if (show)
                    {
                        var array  = value as System.Array;
                        int length = array.Length;
                        for (int i = 0; i < length; i++)
                        {
                            ShowInternalItem_Playing(fullpath, i.ToString(), array.GetValue(i), false);
                        }
                    }

                    EditorGUI.indentLevel--;
                    EditorGUILayout.EndVertical();
                }
                else if (type == typeof(LuaTable))
                {
                    bool   show     = false;
                    string fullpath = null;
                    if (string.IsNullOrEmpty(key))
                    {
                        show     = true;
                        fullpath = key;
                    }
                    else
                    {
                        fullpath = path + "." + key;

                        EditorGUILayout.BeginVertical("Box");


                        if (!foldout.TryGetValue(fullpath, out show) && string.IsNullOrEmpty(path))
                        {
                            show = true;
                        }

                        show = EditorGUILayout.Foldout(show, GetPrefixKey(key));
                        foldout[fullpath] = show;
                    }

                    if (show)
                    {
                        EditorGUI.indentLevel++;

                        LuaTable realValue = value as LuaTable;
                        realValue.ForEach <string, object>((k, v) =>
                        {
                            ShowInternalItem_Playing(fullpath, k, v);
                        });

                        EditorGUI.indentLevel--;
                    }

                    if (!string.IsNullOrEmpty(key))
                    {
                        EditorGUILayout.EndVertical();
                    }
                }
            }

            if (endSingleVertical)
            {
                EditorGUILayout.EndHorizontal();
            }
        }
        void OnGUIForLeftContainer()
        {
            // the 330 is from Editor.k_WideModeMinWidth, see InspectorWindow.cs for the code doing it for the IMGUI Inspector.
            EditorGUIUtility.wideMode = m_IMGUIContainer.layout.width > 330;
            EditorGUILayout.LabelField("IMGUI Container");

            if (m_ShowLabelOnFields)
            {
                m_IntegerFieldValue        = EditorGUILayout.IntField("IntField", m_IntegerFieldValue);
                m_LongFieldValue           = EditorGUILayout.LongField("LongField", m_LongFieldValue);
                m_FloatFieldValue          = EditorGUILayout.FloatField("FloatField", m_FloatFieldValue);
                m_DoubleFieldValue         = EditorGUILayout.DoubleField("DoubleField", m_DoubleFieldValue);
                m_EnumValuesFieldValue     = (EnumValues)EditorGUILayout.EnumPopup("EnumPopup", m_EnumValuesFieldValue);
                m_EnumFlagValuesFieldValue = (EnumFlagValues)EditorGUILayout.EnumFlagsField("EnumFlagsField", m_EnumFlagValuesFieldValue);

                m_TextFieldValue       = EditorGUILayout.TextField("TextField", m_TextFieldValue);
                m_PasswordFieldValue   = EditorGUILayout.PasswordField("PasswordField", m_PasswordFieldValue);
                m_Vector3FieldValue    = EditorGUILayout.Vector3Field("Vector3Field", m_Vector3FieldValue);
                m_Vector3IntFieldValue = EditorGUILayout.Vector3IntField("Vector3IntField", m_Vector3IntFieldValue);
                m_Vector2FieldValue    = EditorGUILayout.Vector2Field("Vector2Field", m_Vector2FieldValue);

                m_ColorFieldValue        = EditorGUILayout.ColorField("ColorField", m_ColorFieldValue);
                m_CameraObjectFieldValue = EditorGUILayout.ObjectField("ObjectField Camera", m_CameraObjectFieldValue, typeof(Camera), true);
                m_GameObjectFieldValue   = EditorGUILayout.ObjectField("ObjectField GameObj", m_GameObjectFieldValue, typeof(GameObject), true);
                m_CurveXValue            = EditorGUILayout.CurveField("CurveField X", m_CurveXValue);
                m_CurveMeshValue         = EditorGUILayout.CurveField("CurveField Mesh", m_CurveMeshValue);
                m_PopupFieldValue        = EditorGUILayout.Popup("Popup", m_PopupFieldValue, m_PopupFieldOptions);
                m_RectFieldValue         = EditorGUILayout.RectField("RectField", m_RectFieldValue);
                m_BoundsFieldValue       = EditorGUILayout.BoundsField("BoundsField", m_BoundsFieldValue);
                m_ToggleRightValue       = EditorGUILayout.Toggle("Toggle", m_ToggleRightValue);
                m_MaskFieldValue         = EditorGUILayout.MaskField("MaskField", m_MaskFieldValue, m_MaskFieldOptions);
                m_LayerFieldValue        = EditorGUILayout.LayerField("LayerField", m_LayerFieldValue);
                m_TagFieldValue          = EditorGUILayout.TagField("TagField", m_TagFieldValue);
                EditorGUILayout.MinMaxSlider("MinMaxSlider", ref m_MinMaxSliderMinValue, ref m_MinMaxSliderMaxValue, m_MinMaxSliderMinLimit, m_MinMaxSliderMaxLimit);
                m_SliderValue    = EditorGUILayout.Slider("Slider", m_SliderValue, 2, 8);
                m_SliderIntValue = EditorGUILayout.IntSlider("IntSlider", m_SliderIntValue, 11, 23);
            }
            else
            {
                m_IntegerFieldValue        = EditorGUILayout.IntField(m_IntegerFieldValue);
                m_LongFieldValue           = EditorGUILayout.LongField(m_LongFieldValue);
                m_FloatFieldValue          = EditorGUILayout.FloatField(m_FloatFieldValue);
                m_DoubleFieldValue         = EditorGUILayout.DoubleField(m_DoubleFieldValue);
                m_EnumValuesFieldValue     = (EnumValues)EditorGUILayout.EnumPopup(m_EnumValuesFieldValue);
                m_EnumFlagValuesFieldValue = (EnumFlagValues)EditorGUILayout.EnumFlagsField(m_EnumFlagValuesFieldValue);

                m_TextFieldValue       = EditorGUILayout.TextField(m_TextFieldValue);
                m_PasswordFieldValue   = EditorGUILayout.PasswordField(m_PasswordFieldValue);
                m_Vector3FieldValue    = EditorGUILayout.Vector3Field("Vector3Field", m_Vector3FieldValue);
                m_Vector3IntFieldValue = EditorGUILayout.Vector3IntField("Vector3IntField", m_Vector3IntFieldValue);
                m_Vector2FieldValue    = EditorGUILayout.Vector2Field("Vector2Field", m_Vector2FieldValue);

                m_ColorFieldValue        = EditorGUILayout.ColorField(m_ColorFieldValue);
                m_CameraObjectFieldValue = EditorGUILayout.ObjectField(m_CameraObjectFieldValue, typeof(Camera), true);
                m_GameObjectFieldValue   = EditorGUILayout.ObjectField(m_GameObjectFieldValue, typeof(GameObject), true);
                m_CurveXValue            = EditorGUILayout.CurveField(m_CurveXValue);
                m_CurveMeshValue         = EditorGUILayout.CurveField(m_CurveMeshValue);
                m_PopupFieldValue        = EditorGUILayout.Popup(m_PopupFieldValue, m_PopupFieldOptions);
                m_RectFieldValue         = EditorGUILayout.RectField(m_RectFieldValue);
                m_BoundsFieldValue       = EditorGUILayout.BoundsField(m_BoundsFieldValue);
                m_ToggleRightValue       = EditorGUILayout.Toggle(m_ToggleRightValue);
                m_MaskFieldValue         = EditorGUILayout.MaskField(m_MaskFieldValue, m_MaskFieldOptions);
                m_LayerFieldValue        = EditorGUILayout.LayerField(m_LayerFieldValue);
                m_TagFieldValue          = EditorGUILayout.TagField(m_TagFieldValue);
                EditorGUILayout.MinMaxSlider(ref m_MinMaxSliderMinValue, ref m_MinMaxSliderMaxValue, m_MinMaxSliderMinLimit, m_MinMaxSliderMaxLimit);
                m_SliderValue    = EditorGUILayout.Slider(m_SliderValue, 2, 8);
                m_SliderIntValue = EditorGUILayout.IntSlider(m_SliderIntValue, 11, 23);
            }

            GUILayout.BeginHorizontal();
            GUILayout.Button(k_ButtonLeftTitle);
            GUILayout.Button(k_ButtonRightTitle);
            GUILayout.EndHorizontal();
            GUILayout.Button(k_ButtonTopTitle);
            GUILayout.Button(k_ButtonBottomTitle);

            SliderProgressTestSO.Update();

            if (m_ShowLabelOnFields)
            {
                m_ColorFieldValue        = EditorGUILayout.ColorField("ColorField", m_ColorFieldValue);
                m_LayerFieldValue        = EditorGUILayout.LayerField("LayerField", m_LayerFieldValue);
                m_MultiLineTextAreaValue = EditorGUILayout.TextArea(m_MultiLineTextAreaValue);
                EditorGUILayout.IntSlider(SliderProgressTestProperty, 0, 100, new GUIContent("IntSlider"));
                ProgressBar(SliderProgressTestProperty.intValue / 100.0f, "Progress Bar");
                m_ColorFieldValue = EditorGUILayout.ColorField("ColorField", m_ColorFieldValue);
                EditorGUILayout.BeginHorizontal();
                m_scrollViewPosition = EditorGUILayout.BeginScrollView(m_scrollViewPosition, false, false, GUILayout.MaxWidth(100), GUILayout.MaxHeight(100));
                EditorGUILayout.LabelField("ScrollBars", GUILayout.Height(100), GUILayout.Height(200));
                EditorGUILayout.EndScrollView();
                m_verticalSliderValue = GUILayout.VerticalSlider(m_verticalSliderValue, 0, 30, GUILayout.Height(100), GUILayout.Width(50));
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                m_ColorFieldValue        = EditorGUILayout.ColorField(m_ColorFieldValue);
                m_LayerFieldValue        = EditorGUILayout.LayerField(m_LayerFieldValue);
                m_MultiLineTextAreaValue = EditorGUILayout.TextArea(m_MultiLineTextAreaValue);
                EditorGUILayout.IntSlider(SliderProgressTestProperty, 0, 100);
                ProgressBar(SliderProgressTestProperty.intValue / 100.0f, "Progress Bar");
                m_ColorFieldValue = EditorGUILayout.ColorField(m_ColorFieldValue);
                EditorGUILayout.BeginHorizontal();
                m_scrollViewPosition = EditorGUILayout.BeginScrollView(m_scrollViewPosition, false, false, GUILayout.MaxWidth(100), GUILayout.MaxHeight(100));
                EditorGUILayout.LabelField("ScrollBars", GUILayout.Height(100), GUILayout.Height(200));
                EditorGUILayout.EndScrollView();
                m_verticalSliderValue = GUILayout.VerticalSlider(m_verticalSliderValue, 0, 30, GUILayout.Height(100), GUILayout.Width(50));
                EditorGUILayout.EndHorizontal();
            }
            SliderProgressTestSO.ApplyModifiedProperties();
        }
예제 #12
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);
        }
        public static object GenericField(string name, object value, Type t, MemberInfo member = null, object context = null)
        {
            if (t == null)
            {
                GUILayout.Label("NO TYPE PROVIDED!");
                return(value);
            }

            if (typeof(Delegate).IsAssignableFrom(t))
            {
                return(value);
            }

            name = name.SplitCamelCase();

            IEnumerable <Attribute> attributes = new Attribute[0];

            if (member != null)
            {
                if (t.GetCustomAttributes(typeof(HideInInspector), true).FirstOrDefault() != null)
                {
                    return(value);
                }

                attributes = member.GetCustomAttributes(true).Cast <Attribute>();


                if (attributes.Any(a => a is HideInInspector))
                {
                    return(value);
                }
            }

            if (member != null)
            {
                var nameAtt = attributes.FirstOrDefault(a => a is NameAttribute) as NameAttribute;
                if (nameAtt != null)
                {
                    name = nameAtt.name;
                }
            }

            if (typeof(UnityEngine.Object).IsAssignableFrom(t))
            {
                return(EditorGUILayout.ObjectField(name, (UnityEngine.Object)value, t, typeof(Component).IsAssignableFrom(t) || t == typeof(GameObject)));
            }

            if ((value != null && value.GetType().IsAbstract) || (value == null && t.IsAbstract))
            {
                EditorGUILayout.LabelField(name, string.Format("Abstract ({0})", t.FriendlyName()));
                return(value);
            }

            if (value == null && !t.IsAbstract && !t.IsInterface && (t.IsValueType || t.GetConstructor(Type.EmptyTypes) != null || t.IsArray))
            {
                if (t.IsArray)
                {
                    value = Array.CreateInstance(t.GetElementType(), 0);
                }
                else
                {
                    value = Activator.CreateInstance(t);
                }
            }

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

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

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

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

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

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

            if (t == typeof(Vector4))
            {
                return(EditorGUILayout.Vector4Field(name, (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(name, vec4);
                return(new Quaternion(vec4.x, vec4.y, vec4.z, vec4.w));
            }

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

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

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

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

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

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

            if (typeof(IList).IsAssignableFrom(t))
            {
                return(ListEditor(name, (IList)value, t, context));
            }

            if (typeof(IDictionary).IsAssignableFrom(t))
            {
                //目前json序列化只支持以string为key的类型
                var keyType = t.GetGenericArguments()[0];
                if (keyType == typeof(string))
                {
                    return(DictionaryEditor(name, (IDictionary)value, t, context));
                }
            }

            if (t.IsSubclassOf(typeof(System.Enum)))
            {
#if UNITY_5
                if (t.GetCustomAttributes(typeof(FlagsAttribute), true).FirstOrDefault() != null)
                {
                    return(EditorGUILayout.EnumMaskPopup(new GUIContent(name), (System.Enum)value));
                }
#endif
                return(EditorGUILayout.EnumPopup(name, (System.Enum)value));
            }

            //show nested class members recursively
            if (value != null && !t.IsEnum && !t.IsInterface)
            {
                GUILayout.BeginVertical();
                EditorGUILayout.LabelField(name, t.FriendlyName());
                EditorGUI.indentLevel++;
                ShowAutoEditorGUI(value);
                EditorGUI.indentLevel--;
                GUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.LabelField(name, string.Format("({0})", t.FriendlyName()));
            }

            return(value);
        }
예제 #14
0
        public static void DrawDungeonGenerator(DungeonGenerator generator, bool isRuntimeDungeon)
        {
            generator.DungeonFlow = (DungeonFlow)EditorGUILayout.ObjectField("Dungeon Flow", generator.DungeonFlow, typeof(DungeonFlow), false);

            generator.ShouldRandomizeSeed = EditorGUILayout.Toggle(new GUIContent("Randomize Seed", "If checked, a new random seed will be created every time a dungeon is generated. If unchecked, a specific seed will be used each time"), generator.ShouldRandomizeSeed);

            if (!generator.ShouldRandomizeSeed)
            {
                generator.Seed = EditorGUILayout.IntField(new GUIContent("Seed", "The seed used to generate a dungeon layout. Generating a dungoen multiple times with the same seed will produce the exact same results each time"), generator.Seed);
            }

            generator.MaxAttemptCount    = EditorGUILayout.IntField(new GUIContent("Max Failed Attempts", "The maximum number of times DunGen is allowed to fail at generating a dungeon layout before giving up. This only applies in-editor; in a packaged build, DunGen will keep trying indefinitely"), generator.MaxAttemptCount);
            generator.LengthMultiplier   = EditorGUILayout.FloatField(new GUIContent("Length Multiplier", "Used to alter the length of the dungeon without modifying the Dungeon Flow asset. 1 = normal-length, 2 = double-length, 0.5 = half-length, etc."), generator.LengthMultiplier);
            generator.IgnoreSpriteBounds = EditorGUILayout.Toggle(new GUIContent("Ignore Sprite Bounds", "When calculating bounding boxes for tiles, if this is checked, sprited will be ignored"), generator.IgnoreSpriteBounds);
            generator.UpVector           = EditorGUILayout.Vector3Field(new GUIContent("Up Vector", "The up direction of the dungeon. This won't actually rotate your dungeon, but it must match the expected up-vector for your dungeon layout - usually (0, 1, 0) for 3D and (0, 0, -1) for 2D"), generator.UpVector);

            if (generator.LengthMultiplier < 0)
            {
                generator.LengthMultiplier = 0.0f;
            }

            if (isRuntimeDungeon)
            {
                generator.DebugRender = EditorGUILayout.Toggle("Debug Render", generator.DebugRender);
            }

            generator.PlaceTileTriggers = EditorGUILayout.Toggle(new GUIContent("Place Tile Triggers", "Places trigger colliders around Tiles which can be used in conjunction with the DungenCharacter component to receieve events when changing rooms"), generator.PlaceTileTriggers);
            generator.TileTriggerLayer  = EditorGUILayout.LayerField(new GUIContent("Trigger Layer", "The layer to place the tile root objects on if \"Place Tile Triggers\" is checked"), generator.TileTriggerLayer);

            if (isRuntimeDungeon)
            {
                generator.GenerateAsynchronously = EditorGUILayout.Toggle(new GUIContent("Generate Asynchronously", "If checked, DunGen will generate the layout without blocking Unity's main thread, allowing for things like animated loading screens to be shown"), generator.GenerateAsynchronously);

                EditorGUI.BeginDisabledGroup(!generator.GenerateAsynchronously);
                generator.MaxAsyncFrameMilliseconds = EditorGUILayout.Slider(new GUIContent("Max Frame Time", "How many milliseconds the dungeon generation is allowed to take per-frame"), generator.MaxAsyncFrameMilliseconds, 0f, 1000f);
                generator.PauseBetweenRooms         = EditorGUILayout.Slider(new GUIContent("Pause Between Rooms", "If greater than zero, the dungeon generation will pause for the set time (in seconds) after placing a room; useful for visualising the generation process"), generator.PauseBetweenRooms, 0, 5);
                EditorGUI.EndDisabledGroup();
            }

            EditorGUI.BeginChangeCheck();
            generator.RestrictDungeonToBounds = EditorGUILayout.Toggle(new GUIContent("Restrict to Bounds?", "If checked, tiles will only be placed within the specified bounds below. May increase generation times"), generator.RestrictDungeonToBounds);

            EditorGUI.BeginDisabledGroup(!generator.RestrictDungeonToBounds);
            generator.TilePlacementBounds = EditorGUILayout.BoundsField(new GUIContent("Placement Bounds", "Tiles are not allowed to be placed outside of these bounds"), generator.TilePlacementBounds);
            EditorGUI.EndDisabledGroup();

            if (EditorGUI.EndChangeCheck() && isRuntimeDungeon)
            {
                SceneView.RepaintAll();
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.BeginVertical("box");

            EditorGUILayout.LabelField("Global Overrides", EditorStyles.boldLabel);
            EditorGUILayout.Space();


            EditorGUILayout.BeginHorizontal();
            generator.OverrideRepeatMode = EditorGUILayout.Toggle(generator.OverrideRepeatMode, GUILayout.Width(10));
            bool previousEnabled = GUI.enabled;

            GUI.enabled          = generator.OverrideRepeatMode;
            generator.RepeatMode = (TileRepeatMode)EditorGUILayout.EnumPopup("Repeat Mode", generator.RepeatMode);
            GUI.enabled          = previousEnabled;
            EditorGUILayout.EndHorizontal();

            DrawOverride("Allow Tile Rotation", ref generator.OverrideAllowTileRotation, ref generator.AllowTileRotation);

            EditorGUILayout.EndVertical();
        }
        // Update is called once per frame
        protected override void OnTCInspectorGUI()
        {
            var  doSim = GetProperty("_manager.m_noSimulation");
            bool sim   = doSim.hasMultipleDifferentValues || !doSim.boolValue;

            if (m_tabGroup.ToggleArea("Particle Manager", new Color(1.0f, 0.8f, 0.8f)))
            {
                GUI.enabled = !EditorApplication.isPlaying;

                GUILayout.Space(5.0f);

                GUILayout.BeginHorizontal();

                ToolbarToggle("_manager.looping", new GUIContent("Loop", "Looping vs One shot"));
                ToolbarToggle("_manager.playOnAwake", new GUIContent("Play on awake", "Play when instantiated or play on script event"));
                ToolbarToggle("_manager.prewarm", new GUIContent("Prewarm", "Simulate particles on first frame to prevent startup issues"));
                ToolbarToggle("_manager.m_noSimulation", new GUIContent("No Simulation", "Simulation on/off. Useful when driving particles from custom shader to save performance"));

                GUILayout.Space(10.0f);

                GUI.enabled = sim;

                if (GUILayout.Button(new GUIContent("Visualize", "Open visualize window"), EditorStyles.toolbarButton))
                {
                    TCParticlesVisualizeWindow.ShowWindow();
                }

                GUI.enabled = true;

                GUILayout.EndHorizontal();

                GUILayout.Space(5.0f);

                PropField("_manager._duration", new GUIContent("Manager Life", "Seconds that the system is playing / loops"));
                PropField("_manager.delay", new GUIContent("Start Delay", "Seconds before the system starts playing"));

                GUI.enabled = true;

                PropField("_manager._maxParticles", new GUIContent("Max particles", "Maximum amount of particles the system has at any point in time. Keep low to increase performance"));

                Space();

                PropField("_manager._simulationSpace",
                          new GUIContent("Simulation Space",
                                         "The space the particles are simulated in. Local will move particles with the system, global will make them independent"));

                if (sim)
                {
                    PropField("_emitter._inheritVelocity",
                              new GUIContent("Inherit Velocity", "Factor of movement from the system to be inherited for the particles"));
                }
            }

            m_tabGroup.ToggleAreaEnd("Particle Manager");

            if (m_tabGroup.ToggleArea("Emission", new Color(0.8f, 1.0f, 0.8f)))
            {
                PropField("_emitter.emit",
                          new GUIContent("Do Emit", "Determines whether the system should be emitting particles right now"));

                GUILayout.BeginHorizontal();

                PropField("_emitter._emissionRate",
                          new GUIContent("Emission Rate", "Amount of particles to emit per second or unit"));
                PropField("_emitter.m_emissionType",
                          new GUIContent("", "Determines whether particles are emitter per second or per unit"), GUILayout.Width(80.0f));

                GUILayout.EndHorizontal();

                foreach (TCParticleSystem t in targets)
                {
                    t.Emitter.EmissionRate = Mathf.Clamp(t.Emitter.EmissionRate, 0, 5000000);
                }

                SerializedProperty bursts = GetProperty("_emitter.bursts");

                if (!bursts.hasMultipleDifferentValues)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Bursts", GUILayout.Width(80.0f));
                    const float width = 51.0f;
                    GUILayout.Label("Time", GUILayout.Width(width));
                    GUILayout.Label("Particles", GUILayout.Width(width));
                    EditorGUILayout.EndHorizontal();

                    int del = -1;
                    for (int i = 0; i < bursts.arraySize; ++i)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(85.0f);
                        EditorGUILayout.PropertyField(CheckBurstProp("time", i), new GUIContent(""), GUILayout.Width(width));
                        EditorGUILayout.PropertyField(CheckBurstProp("amount", i), new GUIContent(""), GUILayout.Width(width));
                        GUILayout.Space(10.0f);

                        if (GUILayout.Button("", "OL Minus", GUILayout.Width(24.0f)))
                        {
                            del = i;
                        }

                        GUILayout.EndHorizontal();
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(103.0f + 2 * width);
                    if (GUILayout.Button("", "OL Plus", GUILayout.Width(24.0f)))
                    {
                        bursts.InsertArrayElementAtIndex(bursts.arraySize);
                    }

                    GUILayout.EndHorizontal();

                    if (del != -1)
                    {
                        bursts.DeleteArrayElementAtIndex(del);
                    }

                    Space();
                }

                PropField("_emitter.pes", new GUIContent("", "Emitter Shape"));
                GUILayout.Label("Shape emission", EditorStyles.boldLabel);
                PropField("_emitter.m_emitTag", new GUIContent("Emit Tag", "The tag to link with shape emitters"));
            }

            m_tabGroup.ToggleAreaEnd("Emission");

            if (m_tabGroup.ToggleArea("Particles", new Color(0.0f, 0.8f, 1.0f)))
            {
                if (sim)
                {
                    PropField("_emitter._energy", new GUIContent("Lifetime", "Amount of seconds particles can be alive"));

                    GUILayout.Space(10.0f);

                    PropField("_emitter._speed", new GUIContent("Start Speed", "Speed particles start with when emitted"));
                    PropField("_emitter._velocityOverLifetime",
                              new GUIContent("Velocity over lifetime", "Velocity and direction over lifetime. Lifetime is [0...1]"));

                    Space();
                }

                PropField("_emitter._size", new GUIContent("Start Size", "Size in units that particles start with"));

                if (sim)
                {
                    PropField("_emitter._sizeOverLifetime",
                              new GUIContent("Size Over Lifetime",
                                             "A factor [0..1] to multiply the base size with over the lifetime of the particle [0..1]"));
                }

                Space();

                PropField("_emitter._rotation", new GUIContent("Start Rotation", "The rotation a particle starts with"));

                if (sim)
                {
                    PropField("_emitter._angularVelocity",
                              new GUIContent("Angular Velocity", "Degrees per second all particles rotate with"));
                }

                if (sim)
                {
                    GUILayout.Space(10.0f);

                    GUILayout.BeginHorizontal();
                    var mode    = GetProperty("_particleRenderer.colourGradientMode");
                    var colProp = GetProperty("_particleRenderer._colourOverLifetime");

                    switch (mode.enumValueIndex)
                    {
                    case (int)ParticleColourGradientMode.OverLifetime:
                        EditorGUILayout.PropertyField(colProp, new GUIContent("Color over lifetime"));
                        break;

                    default:
                        EditorGUILayout.PropertyField(colProp, new GUIContent("Color over speed"));
                        break;
                    }

                    EnumPopup(mode, (ParticleColourGradientMode)mode.enumValueIndex);

                    GUILayout.EndHorizontal();

                    if (mode.enumValueIndex != (int)ParticleColourGradientMode.OverLifetime)
                    {
                        EditorGUILayout.PropertyField(GetProperty("_particleRenderer.maxSpeed"),
                                                      new GUIContent("Max Speed", "The speed where particles are colored like the end of the gradient"));
                    }
                }
            }

            m_tabGroup.ToggleAreaEnd("Particles");

            if (sim)
            {
                if (m_tabGroup.ToggleArea("Forces", new Color(1.0f, 1.0f, 0.8f)))
                {
                    PropField("_forcesManager._maxForces",
                              new GUIContent("Max Forces", "The maximum number of forces that can affect this system, determined by priority"));

                    var maxProp = GetProperty("_forcesManager._maxForces");

                    if (!maxProp.hasMultipleDifferentValues && maxProp.intValue != 0)
                    {
                        PropField("_manager.gravityMultiplier",
                                  new GUIContent("Gravity Multiplier",
                                                 "The amount of gravity (determined in physics settings) applied to the particles"));
                        PropField("_emitter._constantForce",
                                  new GUIContent("Constant Force",
                                                 "A force that is constantly applied to the particles, accelerating them in one direction"));
                    }

                    EditorGUILayout.BeginHorizontal();
                    PropField("_forcesManager._forceLayers",
                              new GUIContent("Force Layers", "Layers to filter what forces can affect this system"));

                    if (Targets.Length == 1)
                    {
                        if (GUILayout.Button("", "OL Plus", GUILayout.Width(20.0f)))
                        {
                            Targets[0].ForceManager.BaseForces.Add(null);
                        }
                    }

                    EditorGUILayout.EndHorizontal();

                    if (Targets.Length == 1)
                    {
                        var forceManager = Targets[0].ForceManager;

                        int del = -1;

                        for (int i = 0; i < forceManager.BaseForces.Count; ++i)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Space(20.0f);

                            forceManager.BaseForces[i] =
                                EditorGUILayout.ObjectField("Link to ", forceManager.BaseForces[i], typeof(TCForce), true) as TCForce;

                            if (GUILayout.Button("", "OL Minus", GUILayout.Width(20.0f)))
                            {
                                del = i;
                            }

                            GUILayout.EndHorizontal();
                        }

                        if (del != -1)
                        {
                            forceManager.BaseForces.RemoveAt(del);
                        }

                        forceManager.MaxForces = Mathf.Max(forceManager.MaxForces, forceManager.BaseForces.Count);
                    }

                    GUILayout.BeginHorizontal();
                    SerializedProperty curveProp = GetProperty("_manager.dampingIsCurve");
                    EditorGUILayout.PropertyField(
                        curveProp.boolValue ? GetProperty("_manager.dampingCurve") : GetProperty("_manager.damping"),
                        new GUIContent("Damping"));

                    curveProp.boolValue =
                        (DampingPopup)
                        EditorGUILayout.EnumPopup("", curveProp.boolValue ? DampingPopup.Curve : DampingPopup.Constant,
                                                  EditorStyles.toolbarPopup,
                                                  GUILayout.Width(15.0f)) == DampingPopup.Curve;

                    GUILayout.EndHorizontal();

                    PropField("_manager.MaxSpeed", new GUIContent("Max Speed", "The speed particles are clamped to. -1 for infinity"));

                    PropField("_forcesManager.useBoidsFlocking",
                              new GUIContent("Boids Flocking",
                                             "Determines whether the particles should flock. Flocking gives a firefly like behavior to the particles"));

                    if (GetProperty("_forcesManager.useBoidsFlocking").boolValue)
                    {
                        PropField("_forcesManager.boidsPositionStrength",
                                  new GUIContent("Position Strength",
                                                 "The strength at which particles are pushed to the average position of all particles"));
                        PropField("_forcesManager.boidsVelocityStrength",
                                  new GUIContent("Velocity Strength",
                                                 "The strength at which particles are forced to the average velocity of all particles"));
                        PropField("_forcesManager.boidsCenterStrength",
                                  new GUIContent("Center Position Strength",
                                                 "The strength at which particles are pushed to the position of the particle system"));
                    }
                }

                m_tabGroup.ToggleAreaEnd("Forces");

                if (m_tabGroup.ToggleArea("Collision", new Color(1.0f, 0.8f, 1.0f)))
                {
                    PropField("_colliderManager._maxColliders",
                              new GUIContent("Max Colliders",
                                             "The maximum number of colliders that can affect this system, determined by priority"));

                    var maxProp = GetProperty("_colliderManager._maxColliders");

                    if (!maxProp.hasMultipleDifferentValues && maxProp.intValue != 0)
                    {
                        PropField("_colliderManager.overrideBounciness", new GUIContent("Override Bounciness"));

                        if (GetProperty("_colliderManager.overrideBounciness").boolValue)
                        {
                            PropField("_colliderManager._bounciness",
                                      new GUIContent("Bounciness", "Amount that particles bounce back after an collision"));
                        }

                        PropField("_colliderManager.overrideStickiness", new GUIContent("Override stickiness"));

                        if (GetProperty("_colliderManager.overrideStickiness").boolValue)
                        {
                            PropField("_colliderManager._stickiness",
                                      new GUIContent("Bounciness", "Amount that particles stick after an collision"));
                        }

                        PropField("_colliderManager._particleThickness", new GUIContent("Particle Thickness"));
                    }

                    EditorGUILayout.BeginHorizontal();
                    PropField("_colliderManager._colliderLayers",
                              new GUIContent("Collider Layers", "Layers to filter which colliders can affect this system"));

                    if (Targets.Length == 1)
                    {
                        if (GUILayout.Button("", "OL Plus", GUILayout.Width(20.0f)))
                        {
                            Targets[0].ColliderManager.BaseColliders.Add(null);
                        }
                    }

                    EditorGUILayout.EndHorizontal();

                    if (Targets.Length == 1)
                    {
                        var baseColliders = Targets[0].ColliderManager.BaseColliders;

                        int del = -1;
                        for (int i = 0; i < baseColliders.Count; ++i)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Space(20.0f);
                            baseColliders[i] =
                                EditorGUILayout.ObjectField("Link to ", baseColliders[i], typeof(TCCollider), true) as TCCollider;

                            if (GUILayout.Button("", "OL Minus", GUILayout.Width(20.0f)))
                            {
                                del = i;
                            }

                            GUILayout.EndHorizontal();
                        }

                        if (del != -1)
                        {
                            baseColliders.RemoveAt(del);
                        }
                    }

                    foreach (var system in Targets)
                    {
                        system.ColliderManager.MaxColliders = Mathf.Max(system.ColliderManager.MaxColliders,
                                                                        system.ColliderManager.BaseColliders.Count);
                    }
                }

                m_tabGroup.ToggleAreaEnd("Collision");
            }

            if (m_tabGroup.ToggleArea("Renderer", new Color(0.8f, 1.0f, 1.0f)))
            {
                PropField("_particleRenderer._material", new GUIContent("Material"));
                PropField("_particleRenderer._renderMode", new GUIContent("Render Mode"));

                var shapeProp = GetProperty("_emitter.pes.shape");
                if (!shapeProp.hasMultipleDifferentValues && (EmitShapes)shapeProp.enumValueIndex == EmitShapes.PointCloud)
                {
                    PropField("_particleRenderer.pointCloudNormals", new GUIContent("Point Cloud Normals"));
                }

                var renderMode = (GeometryRenderMode)GetProperty("_particleRenderer._renderMode").enumValueIndex;

                switch (renderMode)
                {
                case GeometryRenderMode.Mesh:
                    PropField("_particleRenderer._mesh",
                              new GUIContent("Mesh", "The mesh that is used for the particles to render with. Keep as low poly as possible"));
                    break;

                case GeometryRenderMode.TailStretchBillboard:
                case GeometryRenderMode.StretchedBillboard:
                    PropField("_particleRenderer._lengthScale",
                              new GUIContent("Length Scale", "Factor that determines the length when particles has no velocity"));
                    PropField("_particleRenderer._speedScale",
                              new GUIContent("Speed Scale", "Factor that determines how much a particle should stretch when it has velocity"));
                    if (renderMode == GeometryRenderMode.TailStretchBillboard)
                    {
                        PropField("_particleRenderer.TailUv",
                                  new GUIContent("Tail UV", "The UV Coordinate of the vertex where the particles begins to stretch"));
                    }

                    break;
                }

                if (renderMode == GeometryRenderMode.Billboard || renderMode == GeometryRenderMode.StretchedBillboard ||
                    renderMode == GeometryRenderMode.TailStretchBillboard)
                {
                    PropField("_particleRenderer.isPixelSize",
                              new GUIContent("Is Pixel Size", "Determines whether the particle size is in units or screen pixels"));

                    if (sim)
                    {
                        PropField("_particleRenderer.spriteSheetAnimation",
                                  new GUIContent("Sprite Sheet", "Enables sprite sheet animation"));
                    }
                }

                if (sim)
                {
                    if (GetProperty("_particleRenderer.spriteSheetAnimation").boolValue)
                    {
                        PropField("_particleRenderer.spriteSheetColumns",
                                  new GUIContent("Sheet Columns", "Nr. of columns in the sprite sheet"));
                        PropField("_particleRenderer.spriteSheetRows", new GUIContent("Sheet rows", "Nr. of rows in the sprite sheet"));
                        PropField("_particleRenderer.spriteSheetCycles",
                                  new GUIContent("Sheet cycles", "Amount of cycles a particle should do in it's lifetime"));

                        PropField("_particleRenderer.spriteSheetBasePlaySpeed",
                                  new GUIContent("Base Play Speed", "Base speed sprite sheet animation plays at. Useful for particles that life infinitely"));

                        PropField("_particleRenderer.spriteSheetRandomStart",
                                  new GUIContent("Random Start", "Should the sprite sheet start playing at a random point in the sprite sheet?"));
                    }
                }

                PropField("_particleRenderer.glow", new GUIContent("Glow Strength", "Glow strength of the particles"));
                PropField("_particleRenderer._useFrustumCulling",
                          new GUIContent("Frustum culling", "Determines whether the system should be frustum culled"));

                //If supported...

                PropField("_particleRenderer.CastShadows", new GUIContent("Cast Shadows", "Should this system cast shadows"));
                PropField("_particleRenderer.ReceiveShadows", new GUIContent("Receive Shadows", "Should particles receive shadows"));

                if (GetProperty("_particleRenderer._useFrustumCulling").boolValue)
                {
                    SerializedProperty boundsProp = GetProperty("_particleRenderer._bounds");
                    boundsProp.boundsValue = EditorGUILayout.BoundsField(boundsProp.boundsValue);

                    PropField("_particleRenderer.culledSimulationMode",
                              new GUIContent("Culled Mode", "Determines how particles are treated when they are culled"));

                    if (GetProperty("_particleRenderer.culledSimulationMode").enumValueIndex ==
                        (int)CulledSimulationMode.SlowSimulation)
                    {
                        PropField("_particleRenderer.cullSimulationDelta",
                                  new GUIContent("Culled Delta", "Sets the frequency the particles are update when they are culled"));
                    }
                }
            }

            m_tabGroup.ToggleAreaEnd("Renderer");

            if (sim)
            {
                foreach (var o in targets)
                {
                    var t = (TCParticleSystem)o;
                    t.ParticleRenderer.UpdateColourOverLifetime();
                    t.Emitter.UpdateSizeOverLifetime();
                }
            }

            serializedObject.ApplyModifiedProperties();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(m_tabGroup);
            }
        }
예제 #16
0
 static ExposeProperties()
 {
     propertyDrawerFuncs [SerializedPropertyType.Integer] = (field) => {
         return(EditorGUILayout.IntField(field.Name, ( int )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.Boolean] = (field) => {
         return(EditorGUILayout.Toggle(field.Name, ( bool )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.Float] = (field) => {
         return(EditorGUILayout.FloatField(field.Name, ( float )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.String] = (field) => {
         return(EditorGUILayout.TextField(field.Name, ( string )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.Color] = (field) => {
         return(EditorGUILayout.ColorField(field.Name, ( Color )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.ObjectReference] = (field) => {
         return(EditorGUILayout.ObjectField(field.Name, (UnityEngine.Object)field.Value, field.Type, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.LayerMask] = (field) => {
         // TODO: test it.
         return(EditorGUILayout.LayerField(field.Name, ( int )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.Enum] = (field) => {
         return(EditorGUILayout.EnumPopup(field.Name, ( Enum )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.Vector2] = (field) => {
         return(EditorGUILayout.Vector2Field(field.Name, ( Vector2 )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.Vector3] = (field) => {
         return(EditorGUILayout.Vector3Field(field.Name, ( Vector3 )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.Vector4] = (field) => {
         return(EditorGUILayout.Vector4Field(field.Name, ( Vector4 )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.Rect] = (field) => {
         return(EditorGUILayout.RectField(field.Name, ( Rect )field.Value, new GUILayoutOption [0]));
     };
     // TODO: how to implement it?
     //propertyDrawerFuncs [SerializedPropertyType.ArraySize] = ( field ) => {
     //	return	EditorGUILayout.arr ( field.Name, ( Rect ) field.Value, new GUILayoutOption [0] );
     //};
     // TODO: how to implement it?
     //propertyDrawerFuncs [SerializedPropertyType.Character] = ( field ) => {
     //	return	EditorGUILayout.cha ( field.Name, ( Rect ) field.Value, new GUILayoutOption [0] );
     //};
     propertyDrawerFuncs [SerializedPropertyType.AnimationCurve] = (field) => {
         return(EditorGUILayout.CurveField(field.Name, ( AnimationCurve )field.Value, new GUILayoutOption [0]));
     };
     propertyDrawerFuncs [SerializedPropertyType.Bounds] = (field) => {
         return(EditorGUILayout.BoundsField(field.Name, ( Bounds )field.Value, new GUILayoutOption [0]));
     };
     // TODO: how to implement it?
     //propertyDrawerFuncs [SerializedPropertyType.Gradient] = ( field ) => {
     //	return	EditorGUILayout.gra ( field.Name, ( Bounds ) field.Value, new GUILayoutOption [0] );
     //};
     // TODO: how to implement it?
     //propertyDrawerFuncs [SerializedPropertyType.Quaternion] = ( field ) => {
     //	return	EditorGUILayout.qua ( field.Name, ( Quaternion ) field.Value, new GUILayoutOption [0] );
     //};
 }
        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();
        }
예제 #18
0
        public static object Draw(string propName, object propValue, ref bool foldout)
        {
            if (propValue == null)
            {
                return(null);
            }
            System.Type type = propValue.GetType();
            object      obj2 = null;

            if (type == typeof(float))
            {
                return(EditorGUILayout.FloatField(propName, (float)propValue, new GUILayoutOption[0]));
            }
#if UNITY_5_3_OR_NEWER
            if (type == typeof(double))
            {
                return(EditorGUILayout.DoubleField(propName, (double)propValue, new GUILayoutOption[0]));
            }
#endif
            if (type == typeof(int))
            {
                return(EditorGUILayout.IntField(propName, (int)propValue, new GUILayoutOption[0]));
            }
            if (type == typeof(uint))
            {
                return((uint)EditorGUILayout.IntField(propName, (int)((uint)propValue), new GUILayoutOption[0]));
            }
            if (type == typeof(Vector2))
            {
                return(EditorGUILayout.Vector2Field(propName, (Vector2)propValue, new GUILayoutOption[0]));
            }
            if (type == typeof(Vector3))
            {
                return(EditorGUILayout.Vector3Field(propName, (Vector3)propValue, new GUILayoutOption[0]));
            }
            if (type == typeof(Vector4))
            {
                return(rdtGuiVector4Field.Draw(propName, (Vector4)propValue, ref foldout));
            }
            if (type == typeof(Matrix4x4))
            {
                return(rdtGuiMatrixField.Draw(propName, (Matrix4x4)propValue, ref foldout));
            }
            if (type == typeof(bool))
            {
                return(EditorGUILayout.Toggle(propName, (bool)propValue, new GUILayoutOption[0]));
            }
            if (type.IsEnum)
            {
                return(EditorGUILayout.EnumPopup(propName, (Enum)propValue, new GUILayoutOption[0]));
            }
            if (type == typeof(string))
            {
                return(EditorGUILayout.TextField(propName, (string)propValue, new GUILayoutOption[0]));
            }
            if (type == typeof(Color))
            {
                return(EditorGUILayout.ColorField(propName, (Color)propValue, new GUILayoutOption[0]));
            }
            if (type == typeof(Color32))
            {
                return((Color32)EditorGUILayout.ColorField(propName, (Color)((Color32)propValue), new GUILayoutOption[0]));
            }
            if (type == typeof(Quaternion))
            {
                Quaternion quaternion = (Quaternion)propValue;
                Vector4    vector     = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                obj2         = rdtGuiVector4Field.Draw(propName, vector, ref foldout);
                vector       = (Vector4)obj2;
                quaternion.x = vector.x;
                quaternion.y = vector.y;
                quaternion.z = vector.z;
                quaternion.w = vector.w;
                return(quaternion);
            }
            if (type == typeof(Bounds))
            {
                return(EditorGUILayout.BoundsField(propName, (Bounds)propValue, new GUILayoutOption[0]));
            }
            if (type == typeof(Rect))
            {
                return(EditorGUILayout.RectField(propName, (Rect)propValue, new GUILayoutOption[0]));
            }
            if (type.IsArray)
            {
                Array arr = (Array)propValue;
                return(rdtGuiArrayField.Draw(propName, arr, ref foldout));
            }
            if (type == typeof(rdtSerializerButton))
            {
                return(new rdtSerializerButton(GUILayout.Button(propName, new GUILayoutOption[0])));
            }
            if (type == typeof(rdtSerializerSlider))
            {
                rdtSerializerSlider slider = (rdtSerializerSlider)propValue;
                obj2 = EditorGUILayout.Slider(propName, slider.Value, slider.LimitMin, slider.LimitMax, new GUILayoutOption[0]);
                return(new rdtSerializerSlider((float)obj2, slider.LimitMin, slider.LimitMax));
            }
            rdtDebug.Debug(string.Concat(new object[] { "rdtGuiProperty: Unknown type: ", type.Name, " (name=", propName, ", value=", propValue, ")" }), new object[0]);
            return(obj2);
        }
예제 #19
0
    void Set_Inspector()
    {
        GUI.backgroundColor = new Color(1.0f, 1.0f, 0.5f, 1.0f);
        serializedObject.Update();
        if (EditorApplication.isPlaying == false)
        {
            // Basic settings
            EditorGUILayout.Space(); EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Basic settings", MessageType.None, true);
            EditorGUILayout.Slider(DistanceProp, 0.1f, 10.0f, "Distance");
            EditorGUILayout.Slider(SpacingProp, 0.05f, 1.0f, "Spacing");
            EditorGUILayout.Slider(Track_MassProp, 0.1f, 100.0f, "Mass");
            // Shape settings
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Shape settings", MessageType.None, true);
            SelectedAngleProp.intValue = EditorGUILayout.IntPopup("Angle of Front Arc", SelectedAngleProp.intValue, AngleNames, AngleValues);
            Rear_FlagProp.boolValue    = EditorGUILayout.Toggle("Set Rear Arc", Rear_FlagProp.boolValue);
            if (Rear_FlagProp.boolValue)
            {
                Angle_RearProp.intValue = EditorGUILayout.IntPopup("Angle of Rear Arc", Angle_RearProp.intValue, AngleNames, AngleValues);
            }
            EditorGUILayout.IntSlider(NumberProp, 0, 80, "Number of Straight");
            // Collider settings
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Collider settings", MessageType.None, true);
            Collider_InfoProp.boundsValue = EditorGUILayout.BoundsField("Box Collider", Collider_InfoProp.boundsValue);
            Collider_MaterialProp.objectReferenceValue = EditorGUILayout.ObjectField("Physic Material", Collider_MaterialProp.objectReferenceValue, typeof(PhysicMaterial), false);
            // Mesh settings
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Mesh settings", MessageType.None, true);
            Track_L_MeshProp.objectReferenceValue     = EditorGUILayout.ObjectField("Mesh of Left", Track_L_MeshProp.objectReferenceValue, typeof(Mesh), false);
            Track_R_MeshProp.objectReferenceValue     = EditorGUILayout.ObjectField("Mesh of Right", Track_R_MeshProp.objectReferenceValue, typeof(Mesh), false);
            Track_L_MaterialProp.objectReferenceValue = EditorGUILayout.ObjectField("Material of Left", Track_L_MaterialProp.objectReferenceValue, typeof(Material), false);
            Track_R_MaterialProp.objectReferenceValue = EditorGUILayout.ObjectField("Material of Right", Track_R_MaterialProp.objectReferenceValue, typeof(Material), false);
            // Reinforce settings
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Reinforce settings", MessageType.None, true);
            SubJoint_TypeProp.intValue = EditorGUILayout.Popup("Reinforce Type", SubJoint_TypeProp.intValue, SubJointNames);
            if (SubJoint_TypeProp.intValue != 2)
            {
                EditorGUILayout.Slider(Reinforce_RadiusProp, 0.1f, 10.0f, "Radius of SphereCollider");
            }
            // Interpolation settings
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Interpolation settings", MessageType.None, true);
            Use_InterpolationProp.boolValue = EditorGUILayout.Toggle("Use Interpolation", Use_InterpolationProp.boolValue);
            if (Use_InterpolationProp.boolValue)
            {
                EditorGUILayout.Slider(Joint_OffsetProp, 0.0f, 1.0f, "Joint Offset");
                Interpolation_L_MeshProp.objectReferenceValue     = EditorGUILayout.ObjectField("Mesh of Left", Interpolation_L_MeshProp.objectReferenceValue, typeof(Mesh), false);
                Interpolation_R_MeshProp.objectReferenceValue     = EditorGUILayout.ObjectField("Mesh of Right", Interpolation_R_MeshProp.objectReferenceValue, typeof(Mesh), false);
                Interpolation_L_MaterialProp.objectReferenceValue = EditorGUILayout.ObjectField("Material of Left", Interpolation_L_MaterialProp.objectReferenceValue, typeof(Material), false);
                Interpolation_R_MaterialProp.objectReferenceValue = EditorGUILayout.ObjectField("Material of Right", Interpolation_R_MaterialProp.objectReferenceValue, typeof(Material), false);
            }
            // Special settings
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Specail settings for Unity5", MessageType.None, true);
            EditorGUILayout.Slider(Special_OffsetProp, -0.1f, 0.1f, "Offset for Unity5");
            // Durability settings
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Durability settings", MessageType.None, true);
            EditorGUILayout.Slider(Track_DurabilityProp, 1.0f, 1000000.0f, "Track Durability");
            if (Track_DurabilityProp.floatValue >= 1000000)
            {
                Track_DurabilityProp.floatValue = Mathf.Infinity;
            }
            EditorGUILayout.Slider(BreakForceProp, 10000.0f, 1000000.0f, "HingeJoint BreakForce");
            if (BreakForceProp.floatValue >= 1000000)
            {
                BreakForceProp.floatValue = Mathf.Infinity;
            }
            // for Static Track
            EditorGUILayout.Space(); EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Edit Static Track", MessageType.None, true);
            Static_FlagProp.boolValue = EditorGUILayout.Toggle("for Static Track", Static_FlagProp.boolValue);

            // Update Value
            EditorGUILayout.Space(); EditorGUILayout.Space();
            RealTime_FlagProp.boolValue = EditorGUILayout.Toggle("Real Time Update", RealTime_FlagProp.boolValue);
            if (GUILayout.Button("Update Value"))
            {
                if (RealTime_FlagProp.boolValue == false)
                {
                    Create();
                }
            }
            EditorGUILayout.Space(); EditorGUILayout.Space();
        }
        else             // in PlayMode.
        {
            EditorGUILayout.Space(); EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Edit Static Track", MessageType.None, true);
            if (Static_FlagProp.boolValue)                 // for making Static_Track
            {
                if (!Prefab_FlagProp.boolValue)            // Static_Track is not prepared yet.
                {
                    RealTime_FlagProp.boolValue = false;
                    EditorGUILayout.Space(); EditorGUILayout.Space();
                    if (GUILayout.Button("Change into Static Track"))
                    {
                        Change_Static_Track();
                        Prefab_FlagProp.boolValue = true;
                    }
                    EditorGUILayout.Space(); EditorGUILayout.Space();
                }
                else                     // Static_Track has been prepared.
                {
                    EditorGUILayout.Space(); EditorGUILayout.Space();
                    if (GUILayout.Button("Create Prefab in 'Assets' folder"))
                    {
                        Create_Prefab();
                    }
                    EditorGUILayout.Space(); EditorGUILayout.Space();
                }
            }
        }

        //
        serializedObject.ApplyModifiedProperties();
    }
예제 #20
0
        public static object PropertyField(Type type, GUIContent label, object value, params GUILayoutOption[] options)
        {
            // generic
            // object
            //layermask
            //array


            if (type.IsArray)
            {
            }

            if (type.IsEnum)
            {
                return(EditorGUILayout.EnumPopup(label, (Enum)value, options));
            }

            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);
        }