Beispiel #1
0
    private string OnGenericSerializedProperty(SerializedProperty property, Type type, string label)
    {
        string value = property.stringValue;

        try
        {
            if (type.IsEquivalentTo(typeof(string)) || type.IsEquivalentTo(typeof(Resource)))
            {
                value = EditorGUILayout.TextField(label, value);
            }
            if (type.IsEnum)
            {
                value = EditorGUILayout.EnumPopup(label, StringConversion.FromString(value, type) as Enum).ToString();
            }
            if (type.IsEquivalentTo(typeof(int)))
            {
                value = EditorGUILayout.IntField(label, int.Parse(value)).ToString();
            }
            if (type.IsEquivalentTo(typeof(float)) || type.IsEquivalentTo(typeof(ModProperty)))
            {
                value = EditorGUILayout.FloatField(label, float.Parse(value)).ToString();
            }
            if (type.IsEquivalentTo(typeof(bool)))
            {
                value = EditorGUILayout.Toggle(label, bool.Parse(value)).ToString();
            }
        } catch (Exception)
        {
            value = Activator.CreateInstance(type).ToString();
        }

        return(value);
    }
Beispiel #2
0
        public override Mod GetMod()
        {
            Mod mod = Activator.CreateInstance(Type.GetType(ModType)) as Mod;

            Type type = mod.GetType();

            FieldInfo[] fields = type.GetFields().Where(x => x.IsDefined(typeof(ExposedPropertyAttribute))).ToArray();

            if (Properties.Length != fields.Length)
            {
                throw new Exception("Properties array size is not the same as property fields in type " + type.Name);
            }

            for (int i = 0; i < Properties.Length; i++)
            {
                if (fields[i].FieldType == typeof(ModProperty))
                {
                    (fields[i].GetValue(mod) as ModProperty).Set((float)StringConversion.FromString(Properties[i], typeof(float)));
                }
                else
                {
                    fields[i].SetValue(mod, StringConversion.FromString(Properties[i], fields[i].FieldType));
                }
            }

            return(mod);
        }