Ejemplo n.º 1
0
        public static SmartPtr <T> Read(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
        {
            if (owner == null)
            {
                Log.LogErr("WARNING: SmartPtr created without an owner!");
            }
            int fileID = reader.ReadInt32();

            reader.AlignTo(4);
            Int64 pathID = reader.ReadInt64();

            if (fileID == 0 && pathID == 0)
            {
                return(null);
            }

            var objInfo = assetsFile.GetObjectInfo <T>(fileID, pathID);

            if (objInfo == null)
            {
                Log.LogErr($"WARNING: Could not find objectinfo for creating SmartPtr of type {typeof(T).Name} on owner type {owner?.GetType()?.Name ?? "(null owner)"}!  Returned a null pointer instead.");
                return(null);
            }

            SmartPtr <T> ptr = new SmartPtr <T>(owner, assetsFile.GetObjectInfo <T>(fileID, pathID));

            //TODO: not sure this is only ever called by existing objects
            ptr.IsNew = false;

            return(ptr);
        }
Ejemplo n.º 2
0
        public void Parse(AssetsFile file, AssetsObject owner, AssetsReader reader)
        {
            Texture = SmartPtr <Texture2DObject> .Read(file, owner, reader);

            Scale  = new Vector2F(reader);
            Offset = new Vector2F(reader);
        }
Ejemplo n.º 3
0
 private void Init(AssetsObject owner, IObjectInfo <T> target)
 {
     Target = target ?? throw new NullReferenceException("Target cannot be null");
     Owner  = owner ?? throw new NullReferenceException("Owner cannot be null");
     //TODO: not sure this is only ever called by new objects
     IsNew = true;
     Target.ParentFile.AddPtrRef(this);
     Owner.ObjectInfo.ParentFile.AddPtrRef(this);
 }
Ejemplo n.º 4
0
        public void DeleteObject(AssetsObject assetsObject)
        {
            //TODO: implement dispose on these or something?
            var obj = Metadata.ObjectInfos.FirstOrDefault(x => x.Object == assetsObject);

            if (obj == null)
            {
                Log.LogErr("Tried to delete an object that wasn't part of this file");
                return;
            }

            Metadata.ObjectInfos.Remove(assetsObject.ObjectInfo);
            //TODO: IDs need to be shored up at all?  reflection loop through all objects looking for refs?

            CleanupPtrs(assetsObject.ObjectInfo);
        }
Ejemplo n.º 5
0
            public void Parse(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
            {
                Texture = SmartPtr <Texture2DObject> .Read(assetsFile, owner, reader);

                AlphaTexture = SmartPtr <Texture2DObject> .Read(assetsFile, owner, reader);

                SubMeshes   = reader.ReadArrayOf(r => new Submesh(reader));
                IndexBuffer = reader.ReadArray();
                reader.AlignTo(4);
                VertexData          = new VertexData(reader);
                BindPose            = reader.ReadArrayOf(r => r.ReadSingle());
                TextureRect         = new RectF(reader);
                TextureRectOffset   = new Vector2F(reader);
                AtlasRectOffset     = new Vector2F(reader);
                SettingsRaw         = reader.ReadUInt32();
                UVTransform         = new Vector4F(reader);
                DownscaleMultiplier = reader.ReadSingle();
            }
Ejemplo n.º 6
0
        public static SmartPtr <T> Read(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
        {
            int fileID = reader.ReadInt32();

            reader.AlignTo(4);
            Int64 pathID = reader.ReadInt64();

            if (fileID == 0 && pathID == 0)
            {
                return(null);
            }

            SmartPtr <T> ptr = new SmartPtr <T>(owner, assetsFile.GetObjectInfo <T>(fileID, pathID));

            //TODO: not sure this is only ever called by existing objects
            ptr.IsNew = false;

            return(ptr);
        }
Ejemplo n.º 7
0
        public void Parse(AssetsFile file, AssetsObject owner, AssetsReader reader)
        {
            var count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                TexEnvs.Add(new Map <string, TexEnv>(reader.ReadString(), new TexEnv(file, owner, reader)));
            }
            count = reader.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                Floats.Add(new Map <string, Single>(reader.ReadString(), reader.ReadSingle()));
            }

            count = reader.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                Colors.Add(new Map <string, Color>(reader.ReadString(), new Color(reader)));
            }
        }
Ejemplo n.º 8
0
        public void AddObject(AssetsObject assetsObject, bool assignNextObjectID = true)
        {
            if (assetsObject.ObjectInfo == null)
            {
                throw new ArgumentException("ObjectInfo must be set!");
            }

            if (assignNextObjectID)
            {
                assetsObject.ObjectInfo.ObjectID = GetNextObjectID();
            }
            if (assetsObject.ObjectInfo.ObjectID < 1)
            {
                throw new ArgumentException("ObjectInfo.ObjectID must be > 0.");
            }
            if (Metadata.ObjectInfos.Exists(x => x.ObjectID == assetsObject.ObjectInfo.ObjectID))
            {
                throw new ArgumentException("ObjectInfo.ObjectID already exists in this file.");
            }

            Metadata.ObjectInfos.Add(assetsObject.ObjectInfo);
        }
Ejemplo n.º 9
0
 public SmartPtr(AssetsObject owner, IObjectInfo <T> target)
 {
     Init(owner, target);
 }
Ejemplo n.º 10
0
        public static IObjectInfo <AssetsObject> FromTypeIndex(AssetsFile assetsFile, int typeIndex, AssetsObject assetsObject)
        {
            var type            = GetObjectType(assetsFile, typeIndex);
            var genericInfoType = typeof(ObjectInfo <>).MakeGenericType(type);
            var constructor     = genericInfoType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Int64), typeof(int), typeof(int), typeof(int), typeof(AssetsFile), type }, null);

            var genericOI = (IObjectInfo <AssetsObject>)constructor.Invoke(new object[] { (Int64)(-1), (int)-1, (int)-1, typeIndex, assetsFile, assetsObject });

            return(genericOI);
        }
Ejemplo n.º 11
0
        public static IObjectInfo <AssetsObject> FromClassID(AssetsFile assetsFile, int classID, AssetsObject assetsObject)
        {
            var typeIndex = assetsFile.Metadata.Types.IndexOf(assetsFile.Metadata.Types.First(x => x.ClassID == classID));

            return(FromTypeIndex(assetsFile, typeIndex, assetsObject));
        }
Ejemplo n.º 12
0
        public static IObjectInfo <AssetsObject> FromTypeHash(AssetsFile assetsFile, Guid typeHash, AssetsObject assetsObject)
        {
            var typeIndex = assetsFile.Metadata.Types.IndexOf(assetsFile.Metadata.Types.First(x => x.TypeHash == typeHash));

            return(FromTypeIndex(assetsFile, typeIndex, assetsObject));
        }
Ejemplo n.º 13
0
 public AssetInfo(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
 {
     Parse(assetsFile, owner, reader);
 }
Ejemplo n.º 14
0
 private void Parse(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
 {
     PreloadIndex = reader.ReadInt32();
     PreloadSize  = reader.ReadInt32();
     Asset        = SmartPtr <AssetsObject> .Read(assetsFile, owner, reader);
 }
Ejemplo n.º 15
0
 public SpriteRenderData(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
 {
     Parse(assetsFile, owner, reader);
 }
Ejemplo n.º 16
0
 public TexEnv(AssetsFile file, AssetsObject owner, AssetsReader reader)
 {
     Parse(file, owner, reader);
 }
Ejemplo n.º 17
0
 public BundleMap(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
 {
     Parse(assetsFile, owner, reader);
 }
Ejemplo n.º 18
0
 private void Parse(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
 {
     First  = reader.ReadString();
     Second = new AssetInfo(assetsFile, owner, reader);
 }
Ejemplo n.º 19
0
 public PropertySheet(AssetsFile file, AssetsObject owner, AssetsReader reader)
 {
     Parse(file, owner, reader);
 }
Ejemplo n.º 20
0
 public SmartPtr(AssetsObject owner, T target)
 {
     Init(owner, (IObjectInfo <T>)target.ObjectInfo);
 }
Ejemplo n.º 21
0
 public static ISmartPtr <T> PtrFrom <T>(this IObjectInfo <T> objectInfo, AssetsObject owner) where T : AssetsObject
 {
     return(new SmartPtr <T>(owner, objectInfo));
 }
Ejemplo n.º 22
0
 public static ISmartPtr <T> PtrFrom <T>(this T assetObject, AssetsObject owner) where T : AssetsObject
 {
     return(new SmartPtr <T>(owner, assetObject));
 }
Ejemplo n.º 23
0
        public static IObjectInfo <AssetsObject> FromClassID(AssetsFile assetsFile, int classID, AssetsObject assetsObject)
        {
            var foundType = assetsFile.Metadata.Types.FirstOrDefault(x => x.ClassID == classID);

            if (foundType == null)
            {
                Log.LogMsg($"Type with class ID {classID} was not found in file {assetsFile.AssetsFilename}, it will be added.");
                if (classID == AssetsConstants.ClassID.MonoBehaviourScriptType || classID == AssetsConstants.ClassID.MonoScriptType)
                {
                    Log.LogErr("Monoscripts and Monobehaviours can't be created in files that don't already have them by using a class ID.");
                    throw new Exception("Class ID not found in file!");
                }
                assetsFile.Metadata.Types.Add(new AssetsType()
                {
                    ClassID = classID
                });
            }
            var typeIndex = assetsFile.Metadata.Types.IndexOf(assetsFile.Metadata.Types.First(x => x.ClassID == classID));

            return(FromTypeIndex(assetsFile, typeIndex, assetsObject));
        }