Inheritance: PropertyAttribute
コード例 #1
0
 public override void OnGUILayout(IGUIProperty property, Attribute attribute)
 {
     UnityEngine.RangeAttribute attr = attribute as UnityEngine.RangeAttribute;
     using (new GUILayout.HorizontalScope())
     {
         GUILayoutx.PrefixLabel(property.DisplayName);
         float value = (float)property.Value;
         value = GUILayout.HorizontalSlider(value, attr.min, attr.max);
         property.SetValue(value);
     }
 }
コード例 #2
0
        protected void RenderFloatField(FieldInfo field, DataField attribute)
        {
            // TODO: add errors check here too
            UnityEngine.RangeAttribute rangeAttr = GetAttribute <UnityEngine.RangeAttribute>(field);

            if (rangeAttr != null)
            {
                field.SetValue(this, EditorGUILayout.Slider(attribute.EditorLabel, float.Parse(field.GetValue(this).ToString()), rangeAttr.min, rangeAttr.max));
            }
            else
            {
                field.SetValue(this, EditorGUILayout.FloatField(attribute.EditorLabel, float.Parse(field.GetValue(this).ToString())));
            }
        }
コード例 #3
0
        protected void RenderArrayField(FieldInfo field, DataField attribute, string[] options = null, int[] values = null, System.Type modelType = null)
        {
            System.Array array            = field.GetValue(this) as System.Array;
            System.Type  arrayElementType = field.FieldType.GetElementType();

            if (array == null)
            {
                array = System.Array.CreateInstance(arrayElementType, 0);
            }

            var   listType = typeof(List <>).MakeGenericType(arrayElementType);
            IList list     = (IList)System.Activator.CreateInstance(listType);

            for (int i = 0; i < array.Length; i++)
            {
                list.Add(array.GetValue(i));
            }

            if (list.Count == 0)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(attribute.EditorLabel + string.Format(" ({0:N0})", list.Count));
            }

            int    indexToRemove = -1;
            string label         = "";

            for (int i = 0; i < list.Count; i++)
            {
                label = string.Format("Element {0:D}", i);
                EditorGUILayout.BeginHorizontal();

                if (i == 0)
                {
                    EditorGUILayout.PrefixLabel(attribute.EditorLabel + string.Format(" ({0:N0})", list.Count));
                }
                else
                {
                    GUILayout.Space(EditorGUIUtility.labelWidth);
                }

                if (arrayElementType == typeof(string))
                {
                    list[i] = EditorGUILayout.TextField(label, list[i] as string);
                }
                else if (arrayElementType == typeof(Color))
                {
                    list[i] = EditorGUILayout.ColorField(label, (Color)list[i]);
                }
                else if (arrayElementType == typeof(int))
                {
                    if (options != null && values != null)
                    {
                        int newValue = EditorGUILayout.IntPopup(label, int.Parse(list[i].ToString()), options, values);
                        list[i] = newValue;

                        MethodInfo method = DataRererence.GetType().GetMethod("GetModels", BindingFlags.Instance | BindingFlags.Public);
                        method = method.MakeGenericMethod(modelType);
                        System.Array models = method.Invoke(DataRererence, new object[] {  }) as System.Array;

                        for (int index = 0; index < models.Length; index++)
                        {
                            IGameDataModel model = models.GetValue(index) as IGameDataModel;
                            if (model != null && model.ID.Equals(newValue))
                            {
                                model.RenderPreviewForForeignKey();
                            }
                        }

                        if (GUILayout.Button("Open", GUILayout.MaxWidth(40)))
                        {
                            method = DataRererence.GetType().GetMethod("RegisterOpenModelRequest", BindingFlags.Instance | BindingFlags.Public);
                            method = method.MakeGenericMethod(modelType);
                            method.Invoke(DataRererence, new object[] { newValue });
                        }
                    }
                    else
                    {
                        UnityEngine.RangeAttribute rangeAttr = GetAttribute <UnityEngine.RangeAttribute>(field);

                        if (rangeAttr != null)
                        {
                            list[i] = EditorGUILayout.IntSlider(label, (int)list[i], Mathf.FloorToInt(rangeAttr.min), Mathf.FloorToInt(rangeAttr.max));
                        }
                        else
                        {
                            list[i] = EditorGUILayout.IntField(label, (int)list[i]);
                        }
                    }
                }
                else if (arrayElementType == typeof(float))
                {
                    UnityEngine.RangeAttribute rangeAttr = GetAttribute <UnityEngine.RangeAttribute>(field);

                    if (rangeAttr != null)
                    {
                        list[i] = EditorGUILayout.Slider(label, (float)list[i], rangeAttr.min, rangeAttr.max);
                    }
                    else
                    {
                        list[i] = EditorGUILayout.FloatField(label, (float)list[i]);
                    }
                }
                else if (arrayElementType == typeof(bool))
                {
                    list[i] = EditorGUILayout.Toggle(label, (bool)list[i]);
                }
                else if (arrayElementType == typeof(AnimationCurve))
                {
                    list[i] = EditorGUILayout.CurveField(label, (AnimationCurve)list[i]);
                }
                else if (arrayElementType.IsEnum)
                {
                    System.Enum newValue = EditorGUILayout.EnumPopup(label, (System.Enum)System.Enum.Parse(list[i].GetType(), list[i].ToString()));
                    list[i] = System.Convert.ChangeType(newValue, System.Enum.GetUnderlyingType(list[i].GetType()));
                }
                else if (arrayElementType.GetInterface(typeof(IGameDataModel).Name) != null)
                {
                    EditorGUILayout.LabelField(label, EditorStyles.boldLabel);

                    IGameDataModel model = list[i] as IGameDataModel;
                    model.SetDataReference(DataRererence);
                    EditorGUILayout.BeginVertical();
                    model.RenderForm(true);
                    EditorGUILayout.EndVertical();
                }
                else
                {
                    EditorGUILayout.LabelField(label, "Field type is not supported");
                }

                if (GUILayout.Button("-", GUILayout.MaxWidth(20)))
                {
                    if (EditorUtility.DisplayDialog("Warning!", "Are you sure?", "Yes", "No"))
                    {
                        indexToRemove = i;
                    }
                }

                EditorGUILayout.EndHorizontal();
            }

            if (indexToRemove >= 0)
            {
                list.RemoveAt(indexToRemove);
            }

            if (list.Count == 0)
            {
                if (GUILayout.Button("+", GUILayout.MaxWidth(20)))
                {
                    list.Add(System.Activator.CreateInstance(arrayElementType));
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();

                if (GUILayout.Button("+", GUILayout.MaxWidth(20)))
                {
                    list.Add(System.Activator.CreateInstance(arrayElementType));
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();

            System.Array newArray = System.Array.CreateInstance(arrayElementType, list.Count);

            for (int i = 0; i < list.Count; i++)
            {
                newArray.SetValue(list[i], i);
            }

            field.SetValue(this, newArray);
        }
コード例 #4
0
 private void InitializeStageMovementRanges()
 {
     _activeLimits = new RangeAttribute(0.0f, 5.0f);
 }