Ejemplo n.º 1
0
        private static object DrawField(
            Entity entity,
            Tuple <FieldInfo, PropertyInfoAttribute> field,
            object currentValue)
        {
            object newValue = null;

            switch (field.Item2.Type)
            {
            case Core.PropertyInfoType.Int8:
                newValue = FoxKitUiUtils.SbyteField(field.Item1.Name, (sbyte)currentValue);
                break;

            case Core.PropertyInfoType.UInt8:
                newValue = FoxKitUiUtils.ByteField(field.Item1.Name, (byte)currentValue);
                break;

            case Core.PropertyInfoType.Int16:
                newValue = FoxKitUiUtils.ShortField(field.Item1.Name, (short)currentValue);
                break;

            case Core.PropertyInfoType.UInt16:
                newValue = FoxKitUiUtils.UShortField(field.Item1.Name, (ushort)currentValue);
                break;

            case Core.PropertyInfoType.Int32:
                if (field.Item2.Enum != null)
                {
                    newValue = EditorGUILayout.EnumPopup(field.Item1.Name, (Enum)currentValue);
                }
                else
                {
                    newValue = EditorGUILayout.IntField(field.Item1.Name, (int)currentValue);
                }

                break;

            case Core.PropertyInfoType.UInt32:
                newValue = FoxKitUiUtils.UIntField(field.Item1.Name, (uint)currentValue);
                break;

            case Core.PropertyInfoType.Int64:
                newValue = EditorGUILayout.LongField(field.Item1.Name, (long)currentValue);
                break;

            case Core.PropertyInfoType.UInt64:
                newValue = FoxKitUiUtils.ULongField(field.Item1.Name, (ulong)currentValue);
                break;

            case Core.PropertyInfoType.Float:
                newValue = EditorGUILayout.FloatField(field.Item1.Name, (float)currentValue);
                break;

            case Core.PropertyInfoType.Double:
                newValue = EditorGUILayout.DoubleField(field.Item1.Name, (double)currentValue);
                break;

            case Core.PropertyInfoType.Bool:
                newValue = EditorGUILayout.Toggle(field.Item1.Name, (bool)currentValue);
                break;

            case Core.PropertyInfoType.String:
                newValue = EditorGUILayout.TextField(field.Item1.Name, field.Item1.GetValue(entity) as string);
                break;

            case Core.PropertyInfoType.Path:
                newValue = EditorGUILayout.ObjectField(
                    field.Item1.Name,
                    field.Item1.GetValue(entity) as UnityEngine.Object,
                    typeof(UnityEngine.Object),
                    false);
                break;

            case Core.PropertyInfoType.EntityPtr:
                newValue = FoxKitUiUtils.EntityPtrField(
                    field.Item1.Name,
                    currentValue,
                    field.Item2.PtrType,
                    () => AddEntityWindow.Create(field.Item2.PtrType, true, type => field.Item1.SetValue(entity, CreateEntity(type, entity))),
                    dataElement => DestroyEntity(dataElement, entity));
                break;

            case Core.PropertyInfoType.Vector3:
                newValue = EditorGUILayout.Vector3Field(
                    field.Item1.Name,
                    (UnityEngine.Vector3)field.Item1.GetValue(entity));
                break;

            case Core.PropertyInfoType.Vector4:
                newValue = EditorGUILayout.Vector4Field(
                    field.Item1.Name,
                    (UnityEngine.Vector4)field.Item1.GetValue(entity));
                break;

            case Core.PropertyInfoType.Quat:
                newValue = FoxKitUiUtils.QuaternionField(field.Item1.Name, (UnityEngine.Quaternion)currentValue);
                break;

            case Core.PropertyInfoType.Matrix3:
                Assert.IsTrue(false, "There shouldn't be any Matrix3 properties. Report this.");
                break;

            case Core.PropertyInfoType.Matrix4:
                EditorGUILayout.HelpBox("Matrix4 properties are not currently supported.", MessageType.Error);
                break;

            case Core.PropertyInfoType.Color:
                newValue = EditorGUILayout.ColorField(field.Item1.Name, (Color)field.Item1.GetValue(entity));
                break;

            case Core.PropertyInfoType.FilePtr:
                newValue = EditorGUILayout.ObjectField(
                    field.Item1.Name,
                    field.Item1.GetValue(entity) as UnityEngine.Object,
                    typeof(UnityEngine.Object),
                    false);
                break;

            case Core.PropertyInfoType.EntityHandle:
                newValue = FoxKitUiUtils.EntityHandleField(field.Item1.Name, currentValue, typeof(Entity));
                break;

            case Core.PropertyInfoType.EntityLink:
                var           link             = field.Item1.GetValue(entity) as EntityLink;
                Action <Data> onEntitySelected = selected => link.Entity = selected;
                Action <DataIdentifier, string> onDataIdentifierEntitySelected = (identifier, key) => link.SetDataIdentifier(identifier, key);

                newValue = FoxKitUiUtils.EntityLinkField(field.Item1.Name, link, onEntitySelected, onDataIdentifierEntitySelected);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(newValue);
        }
Ejemplo n.º 2
0
 private void CreateEntity(string key)
 {
     AddEntityWindow.Create(this.ptrType, true, type => this.CreateNewEntityAtKey(type, key));
 }
Ejemplo n.º 3
0
        private static T DrawListItem <T>(
            Rect position,
            T itemValue,
            Core.PropertyInfoType type,
            Type @enum,
            Type ptrType,
            Action <Type> createEntityCallback = null)
        {
            object newValue = null;

            switch (type)
            {
            case Core.PropertyInfoType.Int8:
                newValue = FoxKitUiUtils.SbyteField(position, (sbyte)(object)itemValue);
                break;

            case Core.PropertyInfoType.UInt8:
                newValue = FoxKitUiUtils.ByteField(position, (byte)(object)itemValue);
                break;

            case Core.PropertyInfoType.Int16:
                newValue = FoxKitUiUtils.ShortField(position, (short)(object)itemValue);
                break;

            case Core.PropertyInfoType.UInt16:
                newValue = FoxKitUiUtils.UShortField(position, (ushort)(object)itemValue);
                break;

            case Core.PropertyInfoType.Int32:
                if (@enum != null)
                {
                    // I'm sorry
                    var enumValue = (Enum)Enum.ToObject(@enum, itemValue);
                    newValue = EditorGUI.EnumPopup(position, enumValue);
                }
                else
                {
                    newValue = EditorGUI.IntField(position, (int)(object)itemValue);
                }

                break;

            case Core.PropertyInfoType.UInt32:
                //newValue = FoxKitUiUtils.UIntField(position, (uint)(object)itemValue);
                if (@enum != null)
                {
                    newValue = EditorGUI.EnumPopup(position, (Enum)(object)itemValue);
                }
                else
                {
                    newValue = FoxKitUiUtils.UIntField(position, (uint)(object)itemValue);
                }
                break;

            case Core.PropertyInfoType.Int64:
                newValue = EditorGUI.LongField(position, (long)(object)itemValue);
                break;

            case Core.PropertyInfoType.UInt64:
                newValue = FoxKitUiUtils.ULongField(position, (ulong)(object)itemValue);
                break;

            case Core.PropertyInfoType.Float:
                newValue = EditorGUI.FloatField(position, (float)(object)itemValue);
                break;

            case Core.PropertyInfoType.Double:
                newValue = EditorGUI.DoubleField(position, (double)(object)itemValue);
                break;

            case Core.PropertyInfoType.Bool:
                newValue = EditorGUI.Toggle(position, (bool)(object)itemValue);
                break;

            case Core.PropertyInfoType.String:
                newValue = EditorGUI.TextField(position, (string)(object)itemValue);
                break;

            case Core.PropertyInfoType.Path:
                newValue = EditorGUI.ObjectField(
                    position,
                    itemValue as UnityEngine.Object,
                    typeof(UnityEngine.Object),
                    false);
                break;

            case Core.PropertyInfoType.EntityPtr:
                newValue = FoxKitUiUtils.EntityPtrField(
                    position,
                    itemValue,
                    ptrType,
                    () => AddEntityWindow.Create(ptrType, true, createEntityCallback));
                break;

            case Core.PropertyInfoType.Vector3:
                newValue = EditorGUI.Vector3Field(position, string.Empty, (UnityEngine.Vector3)(object) itemValue);
                break;

            case Core.PropertyInfoType.Vector4:
                newValue = EditorGUI.Vector4Field(position, string.Empty, (UnityEngine.Vector4)(object) itemValue);
                break;

            case Core.PropertyInfoType.Quat:
                newValue = FoxKitUiUtils.QuaternionField(position, (UnityEngine.Quaternion)(object) itemValue);
                break;

            case Core.PropertyInfoType.Matrix3:
                Assert.IsTrue(false, "There shouldn't be any Matrix3 properties. Report this.");
                break;

            case Core.PropertyInfoType.Matrix4:
                // TODO
                //Debug.LogWarning("Matrix4 properties not currently supported.");
                EditorGUI.HelpBox(position, "Matrix4 properties are not currently supported.", MessageType.Error);
                newValue = itemValue;
                break;

            case Core.PropertyInfoType.Color:
                newValue = EditorGUI.ColorField(position, (Color)(object)itemValue);
                break;

            case Core.PropertyInfoType.FilePtr:
                newValue = EditorGUI.ObjectField(
                    position,
                    itemValue as UnityEngine.Object,
                    typeof(UnityEngine.Object),
                    false);
                break;

            case Core.PropertyInfoType.EntityHandle:
                newValue = FoxKitUiUtils.EntityHandleField(position, itemValue, typeof(Entity));
                break;

            case Core.PropertyInfoType.EntityLink:
                var           link           = itemValue as EntityLink;
                Action <Data> entitySelected = selected => link.Entity = selected;
                Action <DataIdentifier, string> dataIdentifierEntitySelected =
                    (identifier, key) => link.SetDataIdentifier(identifier, key);

                newValue = FoxKitUiUtils.EntityLinkField(
                    position,
                    (EntityLink)(object)itemValue,
                    entitySelected,
                    dataIdentifierEntitySelected);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return((T)newValue);
        }
Ejemplo n.º 4
0
 private void CreateEntity(int index)
 {
     AddEntityWindow.Create(this.ptrType, true, type => this.CreateNewEntityAtIndex(type, index));
 }