Esempio n. 1
0
 /// <summary/>
 public Material()
 {
     Nodes     = new MaterialNodeCollection();
     FinalNode = new FinalNode();
 }
Esempio n. 2
0
            public void Read(BinaryReader propReader)
            {
                var   encode = propReader.ReadInt32();
                short declaringTypeId;
                short propertyTag;

                DecodePropertyTag(encode, out declaringTypeId, out propertyTag);
                EncodeTag       = encode;
                DeclaringTypeId = declaringTypeId;
                PropertyTag     = propertyTag;

                CachedProperty cached;

                if (TypeRecord.Type.TaggedProperties.TryGetValue(encode, out cached))
                {
                    Name         = cached.Name;
                    Property     = cached;
                    PropertyType = cached.PropertyType;
                }

                DataType = (DataType)propReader.ReadByte();

                while (propReader.BaseStream.Position < propReader.BaseStream.Length)
                {
                    switch (DataType)
                    {
                    case DataType.String:
                        Data.Add(propReader.ReadString());
                        break;

                    case DataType.Content:
                        Data.Add(propReader.ReadString());
                        break;

                    case DataType.Boolean:
                        Data.Add(propReader.ReadBoolean());
                        break;

                    case DataType.Int16:
                        Data.Add(propReader.ReadInt16());
                        break;

                    case DataType.Int32:
                        Data.Add(propReader.ReadInt32());
                        break;

                    case DataType.Int64:
                        Data.Add(propReader.ReadInt64());
                        break;

                    case DataType.Single:
                        Data.Add(propReader.ReadSingle());
                        break;

                    case DataType.Double:
                        Data.Add(propReader.ReadDouble());
                        break;

                    case DataType.Enum:
                        Data.Add(propReader.ReadInt16());
                        break;

                    case DataType.FontFamily:
                        Data.Add(new FontFamily(propReader.ReadString()));
                        break;

                    case DataType.Referent:
                        var referent = propReader.ReadInt32();
                        Data.Add(referent == -1 ? Referent.Null : Context.GlobalReferents[referent]);
                        break;

                    case DataType.UserData:
                        if (VisualC.CompareMemory(propReader.ReadBytes(3), _nullChars, 3) == 0)
                        {
                            Data.Add(null);
                        }
                        else
                        {
                            propReader.BaseStream.Position -= 3;     // go back to start
                            var       id = propReader.ReadByte();
                            IDataType userData;

                            switch (id)
                            {
                            case 0:
                                userData = new Vector3();
                                break;

                            case 1:
                                userData = new Vector2();
                                break;

                            case 2:
                                userData = new Vector4();
                                break;

                            case 3:
                                userData = new Colour();
                                break;

                            case 4:
                                userData = new Axes();
                                break;

                            case 5:
                                userData = new CFrame();
                                break;

                            case 6:
                                userData = new UDim2();
                                break;

                            case 7:
                                userData = new ColourSequence();
                                break;

                            case 8:
                                userData = new NumberSequence();
                                break;

                            case 9:
                                userData = new NumberRange();
                                break;

                            case 10:
                                userData = new Faces();
                                break;

                            case 11:
                                userData = new Matrix3();
                                break;

                            case 12:
                                userData = new PhysicalProperties();
                                break;

                            case 13:
                                userData = new Plane();
                                break;

                            case 15:
                                userData = new Ray();
                                break;

                            case 16:
                                userData = new Region3();
                                break;

                            case 17:
                                userData = new Vector3int16();
                                break;

                            case 18:
                                userData = new Region3int16();
                                break;

                            case 19:
                                userData = new DateTime();
                                break;

                            case 20:
                                userData = new TimeSpan();
                                break;

                            case 21:
                                userData = new BinaryData();
                                break;

                            case 22:
                                userData = new MaterialNodeCollection();
                                break;

                            case 23:
                                userData = new InstanceId();
                                break;

                            case 24:
                                userData = new FontFamily();
                                break;

                            default:
                                throw new IndexOutOfRangeException($"No DataType with data ID \"{id}\" found.");
                            }

                            userData.Load(propReader);
                            Data.Add(userData);
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }