private static Tuple <Type, Object> GetTypeAndValue(AssetProperty assetProperty, int level)
            {
                Object theValue;
                Type   valueType;

                //For each AssetProperty, it has different type and value
                //must deal with it separately
                try
                {
                    if (assetProperty is AssetPropertyBoolean)
                    {
                        AssetPropertyBoolean property = assetProperty as AssetPropertyBoolean;
                        valueType = typeof(AssetPropertyBoolean);
                        theValue  = property.Value;
                    }
                    else if (assetProperty is AssetPropertyDistance)
                    {
                        AssetPropertyDistance property = assetProperty as AssetPropertyDistance;
                        valueType = typeof(AssetPropertyDistance);
                        theValue  = property.Value;
                    }
                    else if (assetProperty is AssetPropertyDouble)
                    {
                        AssetPropertyDouble property = assetProperty as AssetPropertyDouble;
                        valueType = typeof(AssetPropertyDouble);
                        theValue  = property.Value;
                    }
                    else if (assetProperty is AssetPropertyDoubleArray2d)
                    {
                        //Default, it is supported by PropertyGrid to display Double []
                        //Try to convert DoubleArray to Double []
                        AssetPropertyDoubleArray2d property = assetProperty as AssetPropertyDoubleArray2d;
                        valueType = typeof(AssetPropertyDoubleArray2d);
                        theValue  = GetSystemArrayAsString(property.Value);
                    }
                    else if (assetProperty is AssetPropertyDoubleArray3d)
                    {
                        AssetPropertyDoubleArray3d property = assetProperty as AssetPropertyDoubleArray3d;
                        valueType = typeof(AssetPropertyDoubleArray3d);
                        //theValue = GetSystemArrayAsString( property.Value ); // 2017
                        theValue = Util.DoubleArrayString(property.GetValueAsDoubles()); // 2018
                    }
                    else if (assetProperty is AssetPropertyDoubleArray4d)
                    {
                        AssetPropertyDoubleArray4d property = assetProperty as AssetPropertyDoubleArray4d;
                        valueType = typeof(AssetPropertyDoubleArray4d);
                        //theValue = GetSystemArrayAsString( property.Value ); // 2017
                        theValue = Util.DoubleArrayString(property.GetValueAsDoubles()); // 2018
                    }
                    else if (assetProperty is AssetPropertyDoubleMatrix44)
                    {
                        AssetPropertyDoubleMatrix44 property = assetProperty as AssetPropertyDoubleMatrix44;
                        valueType = typeof(AssetPropertyDoubleMatrix44);
                        theValue  = GetSystemArrayAsString(property.Value);
                    }
                    else if (assetProperty is AssetPropertyEnum)
                    {
                        AssetPropertyEnum property = assetProperty as AssetPropertyEnum;
                        valueType = typeof(AssetPropertyEnum);
                        theValue  = property.Value;
                    }
                    else if (assetProperty is AssetPropertyFloat)
                    {
                        AssetPropertyFloat property = assetProperty as AssetPropertyFloat;
                        valueType = typeof(AssetPropertyFloat);
                        theValue  = property.Value;
                    }
                    else if (assetProperty is AssetPropertyInteger)
                    {
                        AssetPropertyInteger property = assetProperty as AssetPropertyInteger;
                        valueType = typeof(AssetPropertyInteger);
                        theValue  = property.Value;
                    }
                    else if (assetProperty is AssetPropertyReference)
                    {
                        AssetPropertyReference property = assetProperty as AssetPropertyReference;
                        valueType = typeof(AssetPropertyReference);
                        theValue  = "REFERENCE"; //property.Type;
                    }
                    else if (assetProperty is AssetPropertyString)
                    {
                        AssetPropertyString property = assetProperty as AssetPropertyString;
                        valueType = typeof(AssetPropertyString);
                        theValue  = property.Value;
                    }
                    else if (assetProperty is AssetPropertyTime)
                    {
                        AssetPropertyTime property = assetProperty as AssetPropertyTime;
                        valueType = typeof(AssetPropertyTime);
                        theValue  = property.Value;
                    }
                    else
                    {
                        valueType = typeof(String);
                        theValue  = "Unprocessed asset type: " + assetProperty.GetType().Name;
                    }

                    if (assetProperty.NumberOfConnectedProperties > 0)
                    {
                        String result = "";
                        result = theValue.ToString();

                        TaskDialog.Show("Connected properties found", assetProperty.Name + ": " + assetProperty.NumberOfConnectedProperties);
                        IList <AssetProperty> properties = assetProperty.GetAllConnectedProperties();

                        foreach (AssetProperty property in properties)
                        {
                            if (property is Asset)
                            {
                                // Nested?
                                Asset asset = property as Asset;
                                int   size  = asset.Size;
                                for (int i = 0; i < size; i++)
                                {
                                    //AssetProperty subproperty = asset[i]; // 2018
                                    AssetProperty        subproperty  = asset.Get(i); // 2019
                                    Tuple <Type, Object> valueAndType = GetTypeAndValue(subproperty, level + 1);
                                    String indent = "";
                                    if (level > 0)
                                    {
                                        for (int iLevel = 1; iLevel <= level; iLevel++)
                                        {
                                            indent += "   ";
                                        }
                                    }
                                    result += "\n " + indent + "- connected: name: " + subproperty.Name + " | type: " + valueAndType.Item1.Name +
                                              " | value: " + valueAndType.Item2.ToString();
                                }
                            }
                        }

                        theValue = result;
                    }
                }
                catch
                {
                    return(null);
                }
                return(new Tuple <Type, Object>(valueType, theValue));
            }
 /// <summary>
 /// Gets the current value of the property on a component.
 /// </summary>
 /// <param name="component">The component with the property for which to retrieve the value.</param>
 /// <returns>The value of a property for a given component.</returns>
 public override object GetValue(object component)
 {
     //For each AssetProperty, it has different type and value
     //must deal with it separately
     try
     {
         if (m_assetProperty is AssetPropertyBoolean)
         {
             AssetPropertyBoolean property = m_assetProperty as AssetPropertyBoolean;
             m_valueType = typeof(Boolean);
             m_value     = property.Value;
         }
         else if (m_assetProperty is AssetPropertyDistance)
         {
             AssetPropertyDistance property = m_assetProperty as AssetPropertyDistance;
             m_valueType = typeof(Double);
             m_value     = property.Value;
         }
         else if (m_assetProperty is AssetPropertyDouble)
         {
             AssetPropertyDouble property = m_assetProperty as AssetPropertyDouble;
             m_valueType = typeof(Double);
             m_value     = property.Value;
         }
         else if (m_assetProperty is AssetPropertyDoubleArray2d)
         {
             //Default, it is supported by PropertyGrid to display Double []
             //Try to convert DoubleArray to Double []
             AssetPropertyDoubleArray2d property = m_assetProperty as AssetPropertyDoubleArray2d;
             m_valueType = typeof(Double[]);
             m_value     = GetSystemArray(property.Value);
         }
         else if (m_assetProperty is AssetPropertyDoubleArray3d)
         {
             AssetPropertyDoubleArray3d property = m_assetProperty as AssetPropertyDoubleArray3d;
             m_valueType = typeof(Double[]);
             m_value     = GetSystemArray(property.Value);
         }
         else if (m_assetProperty is AssetPropertyDoubleArray4d)
         {
             AssetPropertyDoubleArray4d property = m_assetProperty as AssetPropertyDoubleArray4d;
             m_valueType = typeof(Double[]);
             m_value     = GetSystemArray(property.Value);
         }
         else if (m_assetProperty is AssetPropertyDoubleMatrix44)
         {
             AssetPropertyDoubleMatrix44 property = m_assetProperty as AssetPropertyDoubleMatrix44;
             m_valueType = typeof(Double[]);
             m_value     = GetSystemArray(property.Value);
         }
         else if (m_assetProperty is AssetPropertyEnum)
         {
             AssetPropertyEnum property = m_assetProperty as AssetPropertyEnum;
             m_valueType = typeof(int);
             m_value     = property.Value;
         }
         else if (m_assetProperty is AssetPropertyFloat)
         {
             AssetPropertyFloat property = m_assetProperty as AssetPropertyFloat;
             m_valueType = typeof(float);
             m_value     = property.Value;
         }
         else if (m_assetProperty is AssetPropertyInteger)
         {
             AssetPropertyInteger property = m_assetProperty as AssetPropertyInteger;
             m_valueType = typeof(int);
             m_value     = property.Value;
         }
         else if (m_assetProperty is AssetPropertyReference)
         {
             AssetPropertyReference property = m_assetProperty as AssetPropertyReference;
             m_valueType = typeof(String);
             m_value     = property.Type;
         }
         else if (m_assetProperty is AssetPropertyString)
         {
             AssetPropertyString property = m_assetProperty as AssetPropertyString;
             m_valueType = typeof(String);
             m_value     = property.Value;
         }
         else if (m_assetProperty is AssetPropertyTime)
         {
             AssetPropertyTime property = m_assetProperty as AssetPropertyTime;
             m_valueType = typeof(DateTime);
             m_value     = property.Value;
         }
         else
         {
             return(null);
         }
     }
     catch
     {
         return(null);
     }
     return(m_value);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 读取Asset中的各种属性
        /// </summary>
        /// <param name="prop"></param>
        /// <param name="ttrgb"></param>
        public void ReadAssetProperty(AssetProperty prop, string ttrgb)
        {
            switch (prop.Type)
            {
                 
#if R2016
            case AssetPropertyType.APT_Integer:
#elif R2018
            case AssetPropertyType.Integer:
#endif
                var AssetPropertyInt = prop as AssetPropertyInteger;
                break;

#if R2016
            case AssetPropertyType.APT_Distance:
#elif R2018
            case AssetPropertyType.Distance:
#endif
                var AssetPropertyDistance = prop as AssetPropertyDistance;
                break;

#if R2016
            case AssetPropertyType.APT_Double:
#elif R2018
            case AssetPropertyType.Double1:
#endif
                var AssetPropertyDouble = prop as AssetPropertyDouble;
                break;

#if R2016
            case AssetPropertyType.APT_DoubleArray2d:
#elif R2018
            case AssetPropertyType.Double2:
#endif
                var AssetPropertyDoubleArray2d = prop as AssetPropertyDoubleArray2d;
                break;

#if R2016
            case AssetPropertyType.APT_DoubleArray4d:
#elif R2018
            case AssetPropertyType.Double4:
#endif
                var AssetPropertyDoubleArray4d = prop as AssetPropertyDoubleArray4d;
                break;

#if R2016
            case AssetPropertyType.APT_String:
#elif R2018
            case AssetPropertyType.String:
#endif
                AssetPropertyString val = prop as AssetPropertyString;
                if (val.Name == "unifiedbitmap_Bitmap" && val.Value != "")
                {
                    map.Add(ttrgb);
                    map.Add(val.Value.Trim().Replace("\\", ""));
                }

                break;

#if R2016
            case AssetPropertyType.APT_Boolean:
#elif R2018
            case AssetPropertyType.Boolean:
#endif
                AssetPropertyBoolean boolProp = prop as AssetPropertyBoolean;
                break;

#if R2016
            case AssetPropertyType.APT_Double44:
#elif R2018
            case AssetPropertyType.Double44:
#endif
                AssetPropertyDoubleArray4d transformProp = prop as AssetPropertyDoubleArray4d;
#if R2016
                DoubleArray tranformValue = transformProp.Value;
#elif R2018
                DoubleArray tranformValue = (DoubleArray)transformProp.GetValueAsDoubles();
#endif
                break;

                //APT_Lis包含了一系列的子属性值
#if R2016
            case AssetPropertyType.APT_List:
#elif R2018
            case AssetPropertyType.List:
#endif
                AssetPropertyList     propList = prop as AssetPropertyList;
                IList <AssetProperty> subProps = propList.GetValue();
                if (subProps.Count == 0)
                {
                    break;
                }
                switch (subProps[0].Type)
                {
#if R2016
                case AssetPropertyType.APT_Integer:
#elif R2018
                case AssetPropertyType.Integer:
#endif
                    foreach (AssetProperty subProp in subProps)
                    {
                        AssetPropertyInteger intProp = subProp as AssetPropertyInteger;
                        int intValue = intProp.Value;
                    }
                    break;

#if R2016
                case AssetPropertyType.APT_String:
#elif R2018
                case AssetPropertyType.String:
#endif

                    foreach (AssetProperty subProp in subProps)
                    {
                        AssetPropertyString intProp = subProp as AssetPropertyString;
                        string intValue             = intProp.Value;
                        if (intProp.Name == "unifiedbitmap_Bitmap" && intProp.Value != "")
                        {
                            map.Add(ttrgb);
                            map.Add(intProp.Value.Trim().Replace("\\", ""));
                        }
                    }
                    break;
                }
                break;

#if R2016
            case AssetPropertyType.APT_Asset:
#elif R2018
            case AssetPropertyType.Asset:
#endif
                Asset propAsset = prop as Asset;
                for (int i = 0; i < propAsset.Size; i++)
                {
                    ReadAssetProperty(propAsset[i], ttrgb);
                }
                break;

#if R2016
            case AssetPropertyType.APT_Reference:
#elif R2018
            case AssetPropertyType.Reference:
#endif
                break;

            default:
                break;
            }

                        //遍历连接属性,一般位图信息存储在这里  
                        if (prop.NumberOfConnectedProperties == 0)
            {
                return;
            }
            foreach (AssetProperty connectedProp in prop.GetAllConnectedProperties())
            {
                ReadAssetProperty(connectedProp, ttrgb);
            }
        }
Ejemplo n.º 4
0
        private void LogMaterial(AssetProperty asset, StringBuilder log, string t = null)
        {
            if (asset == null)
            {
                return;
            }
            log.Append(t + "Asset.Type:" + asset.Type.ToString() + "::" + asset.Name + "=");
            switch (asset.Type)
            {
            case AssetPropertyType.APT_Asset:
                Asset a = asset as Asset;
                log.Append("Asset,Size:" + a.Size + "\n");
                for (int i = 0; i < a.Size; i++)
                {
                    LogMaterial(a[i], log, t + "\t");
                }
                break;

            case AssetPropertyType.APT_Boolean:
                AssetPropertyBoolean ab = asset as AssetPropertyBoolean;
                log.Append(ab.Value + "\n");
                break;

            case AssetPropertyType.APT_Distance:
                AssetPropertyDistance ad = asset as AssetPropertyDistance;
                log.Append(ad.Value + "\n");
                break;

            case AssetPropertyType.APT_Double:
                AssetPropertyDouble ado = asset as AssetPropertyDouble;
                log.Append(ado.Value + "\n");
                break;

            case AssetPropertyType.APT_Double44:
                break;

            case AssetPropertyType.APT_DoubleArray2d:
                AssetPropertyDoubleArray2d ado2 = asset as AssetPropertyDoubleArray2d;
                log.Append(ado2.Value.get_Item(0) + "," + ado2.Value.get_Item(1) + "\n");
                break;

            case AssetPropertyType.APT_DoubleArray3d:
                AssetPropertyDoubleArray3d ado3 = asset as AssetPropertyDoubleArray3d;
                log.Append(ado3.Value.get_Item(0) + "," + ado3.Value.get_Item(1) + "," + ado3.Value.get_Item(2) + "\n");
                break;

            case AssetPropertyType.APT_DoubleArray4d:
                AssetPropertyDoubleArray4d ado4 = asset as AssetPropertyDoubleArray4d;
                log.Append(ado4.Value.get_Item(0) + "," + ado4.Value.get_Item(1) + "," + ado4.Value.get_Item(2) + "," + ado4.Value.get_Item(3) + "\n");
                break;

            case AssetPropertyType.APT_Enum:
                AssetPropertyEnum ae = asset as AssetPropertyEnum;
                log.Append(ae.Value + "\n");
                break;

            case AssetPropertyType.APT_Float:
                AssetPropertyFloat af = asset as AssetPropertyFloat;
                log.Append(af.Value + "\n");
                break;

            case AssetPropertyType.APT_FloatArray:
                IList <float> lf = (asset as AssetPropertyFloatArray).GetValue();
                foreach (float f in lf)
                {
                    log.Append(f + ",");
                }
                log.Append("\n");
                break;

            case AssetPropertyType.APT_Int64:
                AssetPropertyInt64 ai6 = asset as AssetPropertyInt64;
                log.Append(ai6.Value + "\n");
                break;

            case AssetPropertyType.APT_Integer:
                AssetPropertyInteger ai = asset as AssetPropertyInteger;
                log.Append(ai.Value + "\n");
                break;

            case AssetPropertyType.APT_List:
                break;

            case AssetPropertyType.APT_Properties:
                AssetProperties ap = asset as AssetProperties;
                log.Append("AssetProperties,Count:" + ap.Size + "\n");
                for (int i = 0; i < ap.Size; i++)
                {
                    LogMaterial(ap[i], log, t + "\t");
                }
                break;

            case AssetPropertyType.APT_Reference:
                break;

            case AssetPropertyType.APT_String:
                AssetPropertyString _as = asset as AssetPropertyString;
                log.Append(_as.Value + "\n");
                break;

            case AssetPropertyType.APT_Time:
                AssetPropertyTime at = asset as AssetPropertyTime;
                log.Append(at.Value + "\n");
                break;

            case AssetPropertyType.APT_UInt64:
                AssetPropertyUInt64 aiu6 = asset as AssetPropertyUInt64;
                log.Append(aiu6.Value + "\n");
                break;

            case AssetPropertyType.APT_Unknown:
                log.Append("\n");
                break;

            default:
                log.Append("\n");
                break;
            }
            foreach (Asset _a in asset.GetAllConnectedProperties())
            {
                log.Append(t + "GetAllConnectedProperties:\n");
                LogMaterial(_a, log, t + "\t");
            }
        }
Ejemplo n.º 5
0
        public void ReadAssetProperty(AssetProperty prop, StreamWriter objWriter)
        {
            switch (prop.Type)
            {
                // Retrieve the value from simple type property is easy.  
                // for example, retrieve bool property value.  
#if R2016
            case AssetPropertyType.APT_Integer:
#elif R2018
            case AssetPropertyType.Integer:
#endif
                var AssetPropertyInt = prop as AssetPropertyInteger;
                objWriter.WriteLine(AssetPropertyInt.Name + "= " + AssetPropertyInt.Value.ToString() + ";" + AssetPropertyInt.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_Distance:
#elif R2018
            case AssetPropertyType.Distance:
#endif
                var AssetPropertyDistance = prop as AssetPropertyDistance;
                objWriter.WriteLine(AssetPropertyDistance.Name + "= " + AssetPropertyDistance.Value + ";" + AssetPropertyDistance.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_Double:
#elif R2018
            case AssetPropertyType.Double1:
#endif
                var AssetPropertyDouble = prop as AssetPropertyDouble;
                objWriter.WriteLine(AssetPropertyDouble.Name + "= " + AssetPropertyDouble.Value.ToString() + ";" + AssetPropertyDouble.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_DoubleArray2d:
#elif R2018
            case AssetPropertyType.Double2:
#endif
                var AssetPropertyDoubleArray2d = prop as AssetPropertyDoubleArray2d;
                objWriter.WriteLine(AssetPropertyDoubleArray2d.Name + "= " + AssetPropertyDoubleArray2d.Value.ToString() + ";" + AssetPropertyDoubleArray2d.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_DoubleArray4d:
#elif R2018
            case AssetPropertyType.Double4:
#endif
                var AssetPropertyDoubleArray4d = prop as AssetPropertyDoubleArray4d;
                objWriter.WriteLine(AssetPropertyDoubleArray4d.Name + "= " + AssetPropertyDoubleArray4d.Value.ToString() + ";" + AssetPropertyDoubleArray4d.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_String:
#elif R2018
            case AssetPropertyType.String:
#endif
                AssetPropertyString val = prop as AssetPropertyString;
                objWriter.WriteLine(val.Name + "= " + val.Value + ";" + val.IsReadOnly.ToString());
                break;

#if R2016
            case AssetPropertyType.APT_Boolean:
#elif R2018
            case AssetPropertyType.Boolean:
#endif
                AssetPropertyBoolean boolProp = prop as AssetPropertyBoolean;
                objWriter.WriteLine(boolProp.Name + "= " + boolProp.Value.ToString() + ";" + boolProp.IsReadOnly.ToString());
                break;

                // When you retrieve the value from the data array property,  
                // you may need to get which value the property stands for.  
                // for example, the APT_Double44 may be a transform data.
#if R2016
            case AssetPropertyType.APT_Double44:
#elif R2018
            case AssetPropertyType.Double44:
#endif
                AssetPropertyDoubleArray4d transformProp = prop as AssetPropertyDoubleArray4d;
                DoubleArray tranformValue = transformProp.Value;
                objWriter.WriteLine(transformProp.Name + "= " + transformProp.Value.ToString() + ";" + tranformValue.IsReadOnly.ToString());
                break;

                // The APT_List contains a list of sub asset properties with same type.
#if R2016
            case AssetPropertyType.APT_List:
#elif R2018
            case AssetPropertyType.List:
#endif
                AssetPropertyList     propList = prop as AssetPropertyList;
                IList <AssetProperty> subProps = propList.GetValue();
                if (subProps.Count == 0)
                {
                    break;
                }
                switch (subProps[0].Type)
                {
#if R2016
                case AssetPropertyType.APT_Integer:
#elif R2018
                case AssetPropertyType.Integer:
#endif
                    foreach (AssetProperty subProp in subProps)
                    {
                        AssetPropertyInteger intProp = subProp as AssetPropertyInteger;
                        int intValue = intProp.Value;
                        objWriter.WriteLine(intProp.Name + "= " + intProp.Value.ToString() + ";" + intProp.IsReadOnly.ToString());
                    }
                    break;

#if R2016
                case AssetPropertyType.APT_String:
#elif R2018
                case AssetPropertyType.String:
#endif
                    foreach (AssetProperty subProp in subProps)
                    {
                        AssetPropertyString intProp = subProp as AssetPropertyString;
                        string intValue             = intProp.Value;
                        objWriter.WriteLine(intProp.Name + "= " + intProp.Value.ToString() + ";" + intProp.IsReadOnly.ToString());
                    }
                    break;
                }
                break;

#if R2016
            case AssetPropertyType.APT_Asset:
#elif R2018
            case AssetPropertyType.Asset:
#endif
                Asset propAsset = prop as Asset;
                for (int i = 0; i < propAsset.Size; i++)
                {
                    ReadAssetProperty(propAsset[i], objWriter);
                }
                break;

#if R2016
            case AssetPropertyType.APT_Reference:
#elif R2018
            case AssetPropertyType.Reference:
#endif
                break;

            default:
                objWriter.WriteLine("居然有啥都不是类型的" + prop.Type.ToString());
                break;
            }
                        // Get the connected properties.  
                        // please notice that the information of many texture stores here.  
                        if (prop.NumberOfConnectedProperties == 0)
            {
                return;
            }
            foreach (AssetProperty connectedProp in prop.GetAllConnectedProperties())
            {
                ReadAssetProperty(connectedProp, objWriter);
            }
        }