Esempio n. 1
0
        public static Type GetSystemTypeFromWrappedDataType(DataType dataType, VariableMetaData metaData, VariableAttributes attributes)
        {
            Type elementType = GetSystemTypeFromWrappedDataType(dataType, metaData);

            if (elementType != null)
            {
                if (attributes.HasFlagByte(VariableAttributes.IsArray))
                {
                    return(elementType.MakeArrayType());
                }
                else if (attributes.HasFlagByte(VariableAttributes.IsList))
                {
                    Type listType = typeof(List <>);
                    return(listType.MakeGenericType(elementType));
                }
                else
                {
                    return(elementType);
                }
            }
            else
            {
                // None matched
                return(null);
            }
        }
Esempio n. 2
0
        public static VariableMetaData Create(DataType dataType, Type elementType, object value, VariableAttributes attributes)
        {
            if (dataType == DataType.Enum || dataType == DataType.UnityObjectReference)
            {
                VariableMetaData metaData = new VariableMetaData();

                metaData.typeFullName = elementType.FullName;
                metaData.assemblyName = elementType.Assembly.FullName;

                if (dataType == DataType.Enum)
                {
                    metaData.enumNames  = Enum.GetNames(elementType);
                    metaData.enumValues = new int[metaData.enumNames.Length];
                    Array enumValuesArray = Enum.GetValues(elementType);
                    for (int i = 0; i < metaData.enumNames.Length; i++)
                    {
                        metaData.enumValues[i] = (int)enumValuesArray.GetValue(i);
                    }
                    return(metaData);
                }
                else if (dataType == DataType.UnityObjectReference)
                {
                    if ((value as UnityEngine.Object) != null || (value is UnityEngine.Object == false && value != null))
                    {
                        if (attributes.HasFlagByte(VariableAttributes.IsArray))
                        {
                            metaData.valueDisplayName = "Array Element";
                        }
                        else if (attributes.HasFlagByte(VariableAttributes.IsList))
                        {
                            metaData.valueDisplayName = "List Element";
                        }
                        else
                        {
                            metaData.valueDisplayName = ((UnityEngine.Object)value).name;
                        }
                    }
                    else
                    {
                        metaData.valueDisplayName = "null";
                    }
                    return(metaData);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }