Exemple #1
0
        public void ReplaceAsset(string rFilename, bool rCanInstance)
        {
            //TODO: unload textures/shaders?
            if (this.HasBones)
            {
                Agk.DeleteObjectWithChildren(this.ResourceNumber);
            }
            else
            {
                Agk.DeleteObject(this.ResourceNumber);
            }

            if (System.IO.File.Exists(rFilename))
            {
                this.File = rFilename;

                var sourceObject = Media.ObjectList.FirstOrDefault(o => o.File == rFilename && o.InstanceType == 0);
                if (sourceObject != null)
                {
                    if (Agk.IsObjectExists(sourceObject.ResourceNumber))
                    {
                        if (rCanInstance)
                        {
                            this.ResourceNumber = Agk.InstanceObject(sourceObject.ResourceNumber);
                            this.InstanceType   = 2;
                        }
                        else
                        {
                            this.ResourceNumber = Agk.CloneObject(sourceObject.ResourceNumber);
                            this.InstanceType   = 1;
                        }
                    }
                    else
                    {
                        if (this.HasBones)
                        {
                            Agk.LoadObjectWithChildren(sourceObject.ResourceNumber, rFilename);
                        }
                        else
                        {
                            Agk.LoadObject(sourceObject.ResourceNumber, rFilename);
                        }
                        sourceObject.Id = this.Id;
                    }
                }
                else
                {
                    if (this.HasBones)
                    {
                        this.ResourceNumber = Agk.LoadObjectWithChildren(rFilename);
                    }
                    else
                    {
                        this.ResourceNumber = Agk.LoadObject(rFilename);
                    }
                    this.InstanceType = 0;
                }
            }
            else
            {
                App.Log("Media", 4, "error", "ERROR: File not found: " + rFilename + " during Media_LoadObject.");
                App.StopRunning(true);
            }
        }
Exemple #2
0
        public static ObjectAsset LoadObjectAsset(string rFilename, bool rCanInstance, bool rHasBones, string rID)
        {
            App.Log("Media.cs", 2, "media", "Requested load object: " + rFilename + " " + rCanInstance.ToString() + " " + rID);

            if (System.IO.File.Exists(rFilename))
            {
                var tObj = new ObjectAsset();
                tObj.File     = rFilename;
                tObj.HasBones = rHasBones;
                tObj.Id       = String.IsNullOrEmpty(rID) ? Guid.NewGuid().ToString() : rID;

                var sourceObject = Media.ObjectList.FirstOrDefault(o => o.File == rFilename && o.InstanceType == 0);
                if (sourceObject != null)
                {
                    if (Agk.IsObjectExists(sourceObject.ResourceNumber))
                    {
                        if (rCanInstance)
                        {
                            tObj.ResourceNumber = Agk.InstanceObject(sourceObject.ResourceNumber);
                            tObj.InstanceType   = 2;
                        }
                        else
                        {
                            tObj.ResourceNumber = Agk.CloneObject(sourceObject.ResourceNumber);
                            tObj.InstanceType   = 1;
                        }
                    }
                    else
                    {
                        if (rHasBones)
                        {
                            Agk.LoadObjectWithChildren(sourceObject.ResourceNumber, rFilename);
                        }
                        else
                        {
                            Agk.LoadObject(sourceObject.ResourceNumber, rFilename);
                        }
                        sourceObject.Id = tObj.Id;
                        return(sourceObject);
                    }
                }
                else
                {
                    if (rHasBones)
                    {
                        tObj.ResourceNumber = Agk.LoadObjectWithChildren(rFilename);
                    }
                    else
                    {
                        tObj.ResourceNumber = Agk.LoadObject(rFilename);
                    }

                    tObj.InstanceType = 0;
                }

                Media.ObjectList.Add(tObj);
                return(tObj);
            }
            else
            {
                App.Log("Media", 4, "error", "ERROR: File not found: " + rFilename + " during Media_LoadObject.");
                App.StopRunning(true);
                return(null);
            }
        }