Example #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="asset"></param>
    private void DestroyAsset(AssetWrapper asset)
    {
        string assetPath = asset.GetAssetPath();

        string[] dps        = asset.GetDps();
        string   mainBundle = asset.GetBundleName();

        if (m_bundleCache.ContainsKey(mainBundle))
        {
            m_bundleCache[mainBundle].DecRefAsset(assetPath);
            if (dps != null)
            {
                for (int i = 0; i < dps.Length; ++i)
                {
                    string dep_name = dps[i];
                    if (m_bundleCache.ContainsKey(dep_name))
                    {
                        m_bundleCache[dep_name].DecRefAsset(assetPath);
                    }
                }
            }
        }
        else
        {
            Debugger.LogWarning("AssetWrapper :" + assetPath + " has no bundle:" + mainBundle + " in m_bundleCache");
        }
    }
Example #2
0
    // 閿€姣佽祫婧徧
    void DestroyAsset(AssetWrapper asset)
    {
        string assetPath = asset.GetAssetPath();

        string[] dps        = asset.GetDps();
        string   mainBundle = asset.GetBundleName();

        if (m_bundleCache.ContainsKey(mainBundle))
        {
            m_bundleCache[mainBundle].DecRefAsset(assetPath);
            if (dps != null)
            {
                for (int i = 0; i < dps.Length; i++)
                {
                    string dep_name = dps[i];
                    if (m_bundleCache.ContainsKey(dep_name))
                    {
                        m_bundleCache[dep_name].DecRefAsset(assetPath);
                    }
                }
            }
        }
        else
        {
            Debug.LogWarning("AssetWrapper :" + assetPath + " has no bundle:" + mainBundle + " in m_bundleCache");
        }
        //鑰冭檻姣忚繃涓€娈垫椂闂村垽鏂?繖浜汢undles鏄?惁宸茬粡娌℃湁琚?娇鐢?紝鐒跺悗鐩存帴閲婃斁
        //m_bundleCache.Remove();
    }
Example #3
0
    /// <summary>
    /// 加载资源
    /// </summary>
    /// <param name="assetPath"></param>
    /// <param name="assetType"></param>
    /// <returns></returns>
    public AssetWrapper LoadAsset(string fileName, System.Type assetType)
    {
        // 找不到指定的AssetBundle配置信息
        if (!fileMap.ContainsKey(fileName))
        {
            Debugger.LogError("fileMap.ContainsKey(" + fileName + ") == false");
            return(null);
        }

        AssetBundleInfo info       = fileMap[fileName];
        string          assetPath  = info.assetName;
        string          bundleName = info.bundleName;

        // 从缓存中获取AssetWrapper
        if (m_assetWrapperCache.ContainsKey(assetPath))
        {
            m_assetWrapperCache[assetPath].AddRef();
            return(m_assetWrapperCache[assetPath]);
        }

        // 从bundle缓存中实例化一个AssetWrapper
        if (m_bundleCache.ContainsKey(bundleName))
        {
            UnityEngine.Object obj = m_bundleCache[bundleName].GetBundle().LoadAsset(bundleName, assetType);
            AssetWrapper       ret = new AssetWrapper(obj, assetPath, assetType, bundleName, IsSceneBundle(bundleName));
            m_assetWrapperCache.Add(bundleName, ret);
            m_bundleCache[bundleName].AddRefAsset(bundleName);
            return(ret);
        }

        SetLocalization(false);
        return(LoadRes(info, assetType));
    }
Example #4
0
 void Awake()
 {
     //Get the Collider component on this gameObject.
     collider = this.GetComponent <Collider>();
     rbody    = this.GetComponent <Rigidbody>();
     wrapper  = this.GetComponent <AssetWrapper>();
 }
Example #5
0
 /// <summary>
 /// 释放指定资源
 /// </summary>
 /// <param name="asset"></param>
 public void ReleaseAsset(AssetWrapper asset)
 {
     asset.Release();
     if (asset.GetRefCount() < 1)
     {
         // Destroy
         DestroyAsset(asset);
     }
 }
Example #6
0
        //// GET api/<APIController>/5
        //[HttpGet("{id}")]
        //public string Get(int id)
        //{
        //    return "value";
        //}

        //// POST api/<APIController>
        //[HttpPost]
        //public void Post([FromBody] string value)
        //{
        //}

        //// PUT api/<APIController>/5
        //[HttpPut("{id}")]
        //public void Put(int id, [FromBody] string value)
        //{
        //}

        //// DELETE api/<APIController>/5
        //[HttpDelete("{id}")]
        //public void Delete(int id)
        //{
        //}

        public async Task <String> getContent()
        {
            string preamble = prot + "://" + host; //this data is only known on cotroller level. A little dirty, sry :-(

            List <Asset> rawAssets = await _database.GetCollection <Asset>("Assets").Find(f => true).ToListAsync();

            IMongoCollection <Creator> creators = _database.GetCollection <Creator>("Creators");
            IMongoCollection <Course>  courses  = _database.GetCollection <Course>("Courses");

            List <AssetWrapper> assets = new List <AssetWrapper>();

            //create operator for this!
            foreach (Asset asset in rawAssets)
            {
                AssetWrapper wrappedAsset = new AssetWrapper
                {
                    _id               = asset._id,
                    AssetName         = asset.AssetName,
                    AssetType         = asset.AssetType,
                    AssetFilename     = asset.AssetFilename,
                    AssetLink         = asset.AssetLink,
                    AssetLinkUSDZ     = asset.AssetLink,
                    ExternalLink      = asset.ExternalLink,
                    ThumbnailFilename = asset.ThumbnailFilename,
                    ThumbnailLink     = asset.ThumbnailLink,
                    CreationDate      = asset.CreationDate,
                    Deleted           = asset.Deleted,
                    Creator           = creators.AsQueryable().FirstOrDefault(c => c._id == asset.Creator),
                    Course            = courses.AsQueryable().FirstOrDefault(co => co._id == asset.Course)
                };

                assets.Add(wrappedAsset);
            }

            Content content = new Content
            {
                Assets  = assets,
                Anchors = await _database.GetCollection <Anchor>("Anchors").Find(f => true).ToListAsync(),
                Scenes  = await _database.GetCollection <Scene>("Scenes").Find(f => true).ToListAsync()
            };

            //generate link on request time
            foreach (AssetWrapper asset in content.Assets)
            {
                asset.AssetLink     = Backend.MapFilenameToDownloadLink(Backend.ContentType.Asset, preamble, asset.AssetFilename);
                asset.AssetLinkUSDZ = Backend.MapFilenameToUSDZDownloadLink(Backend.ContentType.Asset, preamble, asset.AssetFilename);
                asset.ThumbnailLink = Backend.MapFilenameToDownloadLink(Backend.ContentType.Thumbnail, preamble, asset.ThumbnailFilename);
            }

            foreach (Scene scene in content.Scenes)
            {
                scene.WorldMapFileLink = Backend.MapFilenameToDownloadLink(Backend.ContentType.WorldMap, preamble, scene.WorldMapFileName);
                scene.MarkerFileLink   = Backend.MapFilenameToDownloadLink(Backend.ContentType.Marker, preamble, scene.MarkerFileName);
            }

            return(JsonConvert.SerializeObject(content, Formatting.Indented));
        }
Example #7
0
    // 鍚屾?鍔犺浇
    public AssetWrapper LoadAsset(string assetPath, System.Type assetType)
    {//鍦╡ditor涓?紝鍏堝湪鐩?綍璧勬簮涓?姞杞斤紝鍔犺浇涓嶅埌鍐嶈繘鍏ョ洰褰曚腑杩涜?
     //string realPath = assetPath.Replace("\\", "/");
#if UNITY_EDITOR
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            Object asset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, assetType);
            if (asset != null)
            {//濡傛灉鏄疎ditor涓?殑璧勬簮灏变笉鍋氳繃澶氬?鐞嗕簡.
                AssetWrapper ret = new AssetWrapper(asset, assetPath, assetType, "", false);
                return(ret);
            }
        }
#endif
#if UNITY_IPHONE
        Debugger.Log("IOS loadRes:" + assetPath);
#endif
        //鍘籥ssetbundle涓?繘琛屽姞杞茧棣栧厛鎵惧埌璧勬簮瀵瑰簲鐨刟b; Lorry
        if (_asset2Bundle.ContainsKey(assetPath) == false)
        {
            Debug.LogError("_asset2Bundle.ContainsKey(" + assetPath + ") == false");
            return(null);
        }

        //棣栧厛鐪嬭祫婧怉ssetWrapper鐨勭紦瀛樺瓧鍏氟
        if (m_assetWrapperCache.ContainsKey(assetPath))
        {
            m_assetWrapperCache[assetPath].AddRef();
            return(m_assetWrapperCache[assetPath]);
        }

        string abName = _asset2Bundle[assetPath];
        //闇€瑕侀?鍏堝垽鏂?姞杞歼Lorry
        if (m_bundleCache.ContainsKey(abName))
        {//宸茬粡瀛樺湪姝?undle鐨勭紦瀛橈紝浣嗘槸娌℃湁asset缂撳瓨锛岃瘉鏄庤祫婧愬寘宸茬粡鍔犺浇锛屽彧鏄?病鏈塴oad 姝_asset,杩欓噷娌℃湁澶勭悊濂界殑
            Object       obj = m_bundleCache[abName].GetBundle().LoadAsset(assetPath, assetType);
            AssetWrapper ret = new AssetWrapper(obj, assetPath, assetType, abName, IsSceneBundle(abName));
            m_assetWrapperCache.Add(assetPath, ret);
            //TODO:鑰冭檻缁檅undle娣诲姞寮曠敤,浣嗕及璁狓0%涓嶇敤閿€姣?闇€浠旂粏鑰冭檻 Lorry
            m_bundleCache[abName].AddRefAsset(assetPath);
            return(ret);
        }


        //鍒ゆ柇姝よ繖涓猘ssetPath鏄?惁鏈夋湰鍦扮増鏈?
        SetLocalization(true);
        string target_local_path = GetLocalFileUrl(abName);
        if (System.IO.File.Exists(target_local_path))
        {
            return(LoadRes(assetPath, assetType));
        }
        SetLocalization(false);
        return(LoadRes(assetPath, assetType));
    }
Example #8
0
    //Override
    public void SaveObject()
    {
        lock (assetLock)
        {
            AssetWrapper wrap        = new AssetWrapper();
            string       destination = SavePath + "/" + sceneName + ".dat";
            FileStream   file;
            if (File.Exists(destination))
            {
                File.Delete(destination);
                file = File.OpenWrite(destination);
            }
            else
            {
                file = File.OpenWrite(destination);
            }

            foreach (Item item in items)
            {
                wrap.Push(item.state);
            }

            foreach (Enemy item in enemies)
            {
                wrap.Push(item.state);
            }

            foreach (Door item in doors)
            {
                wrap.Push(item.state);
            }

            foreach (CheckPointTrigger check in checkPoints)
            {
                wrap.Push(check.state);
            }

            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(file, wrap);
        }
    }
Example #9
0
    public void LoadObject()
    {
        lock (assetLock)
        {
            string     destination = SavePath + "/" + sceneName + ".dat";
            FileStream file;

            if (File.Exists(destination))
            {
                file = File.OpenRead(destination);
            }
            else
            {
                Debug.Log("File not found. First Time in area");
                return;
            }

            BinaryFormatter bf = new BinaryFormatter();

            AssetWrapper ass = (AssetWrapper)bf.Deserialize(file);
            UnWrap(ass);
        }
    }
Example #10
0
    private AssetWrapper LoadRes(AssetBundleInfo info, System.Type assetType)
    {
        string assetPath  = info.assetName;
        string bundleName = info.bundleName;

        if (info.dependencies != null)
        {
            foreach (string dep in info.dependencies)
            {
                if (m_bundleCache.ContainsKey(dep))
                {
                    m_bundleCache[dep].AddRefAsset(bundleName);
                    continue;
                }
                else
                {
                    if (string.IsNullOrEmpty(dep))
                    {
                        Debugger.LogError("AB name " + bundleName + " 依赖名空!");
                        continue;
                    }

                    BundleWrapper loaded_bundle_bw = LoadBundle(dep);
                    loaded_bundle_bw.AddRefAsset(bundleName);
                    UnityEngine.Object temp = loaded_bundle_bw.GetBundle().mainAsset;
                    if (temp != null)
                    {
                        Debugger.Log("dep_bundle mainAsset: " + temp.name);
                    }
                }
            }
        }

        if (m_bundleCache.ContainsKey(bundleName))
        {
            UnityEngine.Object obj = m_bundleCache[bundleName].GetBundle().LoadAsset(assetPath, assetType);
            AssetWrapper       ret = new AssetWrapper(obj, assetPath, assetType, bundleName, IsSceneBundle(bundleName));
            m_assetWrapperCache.Add(assetPath, ret);
            m_bundleCache[bundleName].AddRefAsset(assetPath);
            return(ret);
        }

        // load target bundle
        BundleWrapper target_bundle_bw = LoadBundle(bundleName);

        target_bundle_bw.AddRefAsset(assetPath);
        // load asset
        AssetWrapper ret_aw;

        if (IsSceneBundle(bundleName))
        {
            ret_aw = new AssetWrapper(null, assetPath, assetType, bundleName, true);
        }
        else
        {
            string realPath = assetPath;
            //if (m_isLocalization)
            //{
            //    realPath = Regex.Replace(realPath, "^Assets/", "Assets/L10n/" + Const.L10n + "/");
            //}
            UnityEngine.Object obj = target_bundle_bw.GetBundle().LoadAsset(realPath, assetType);
            if (obj == null)
            {
                Debugger.LogError("targetBundle Wrong!");
                return(null);
            }
            ret_aw = new AssetWrapper(obj, assetPath, assetType, bundleName, false);
        }
        m_assetWrapperCache.Add(assetPath, ret_aw);

        return(ret_aw);
    }
Example #11
0
    private AssetWrapper LoadRes(string assetPath, System.Type assetType)
    {
        //寮€濮嬪姞杞藉?搴旂殑璧勬簮鍖勭.assetbundle)
        string abName = _asset2Bundle[assetPath];

        string[] dps;
        if (m_isLocalization)
        {
            dps = m_manifestL10n.GetAllDependencies(abName);
        }
        else
        {
            dps = m_manifest.GetAllDependencies(abName);
        }

        for (int i = 0; i < dps.Length; i++)
        {
            string dep_name = dps[i];
            if (m_bundleCache.ContainsKey(dep_name))
            {
                m_bundleCache[dep_name].AddRefAsset(assetPath);
                continue;
            }
            else
            {
                if (string.IsNullOrEmpty(dep_name))
                {
                    Log.PrintMsg("鏌ヤ竴涓娺" + abName + " 鐨刴anifest鏂囦欢锛屾湁渚濊禆鏄?┖鐨勩€佱");
                    continue;
                }
                //string local_path = GetLocalFileUrl(dep_name);
                //byte[] dep_content = System.IO.File.ReadAllBytes(local_path);
                //AssetBundle dep_bundle = AssetBundle.CreateFromMemoryImmediate(dep_content);
                ////AssetBundle dep_bundle = AssetBundle.CreateFromFile(local_path); //鍦ㄦ煇浜涘钩鍙颁笂璇诲彇鍘嬬缉鏂囦欢浼氬穿婧冨緟鏂皏ersion瑙e喅
                //Assert.IsNotNull<AssetBundle>(dep_bundle, "渚濊禆鎵撳寘璧勬簮鏈夐棶棰楖" + dep_name);
                //Object temp = dep_bundle.mainAsset;
                //if(temp!= null)
                //    Debugger.Log("dep_bundle mainAsset:" + temp.name);
                //BundleWrapper loaded_bundle_bw = new BundleWrapper(dep_name, dep_bundle);
                //loaded_bundle_bw.AddRefAsset(assetPath);
                //m_bundleCache.Add(dep_name, loaded_bundle_bw); // keep in bundle cache
                BundleWrapper loaded_bundle_bw = LoadBundle(dep_name);
                loaded_bundle_bw.AddRefAsset(assetPath);
                Object temp = loaded_bundle_bw.GetBundle().mainAsset;
                if (temp != null)
                {
                    Debugger.Log("dep_bundle mainAsset:" + temp.name);
                }
            }
        }//渚濊禆璧勬簮鍔犺浇瀹屾瘯; Lorry


        if (m_bundleCache.ContainsKey(abName))
        {//宸茬粡瀛樺湪姝?undle鐨勭紦瀛橈紝浣嗘槸娌℃湁asset缂撳瓨锛岃瘉鏄庤祫婧愬寘宸茬粡鍔犺浇锛屽彧鏄?病鏈塴oad 姝_asset,鍦ㄧ壒娈婃儏鍐典笅鍑虹幇bug
            Object       obj = m_bundleCache[abName].GetBundle().LoadAsset(assetPath, assetType);
            AssetWrapper ret = new AssetWrapper(obj, assetPath, assetType, abName, IsSceneBundle(abName));
            m_assetWrapperCache.Add(assetPath, ret);
            //TODO:鑰冭檻缁檅undle娣诲姞寮曠敤,浣嗕及璁狓0%涓嶇敤閿€姣?闇€浠旂粏鑰冭檻 Lorry
            m_bundleCache[abName].AddRefAsset(assetPath);
            return(ret);
        }

        // load target bundle
        BundleWrapper target_bundle_bw = LoadBundle(abName);

        target_bundle_bw.AddRefAsset(assetPath);
        // load asset
        AssetWrapper ret_aw;

        if (IsSceneBundle(abName))
        {//濡傛灉鏄?満鏅?紝assetBundle杞藉叆鍚庯紝閫氳繃loadlevel杩涘叆;
            ret_aw = new AssetWrapper(null, assetPath, assetType, abName, true);
        }
        else
        {
            // 璇诲彇鏈?湴鍖栬祫婧愭椂锛屽皢瀹為檯璺?緞涓?殑/L10n/xxx/琛ヤ笂; ly0464
            string realPath = assetPath;
            if (m_isLocalization)
            {
                realPath = Regex.Replace(realPath, "^Assets/", "Assets/L10n/" + Const.L10n + "/");
            }
            Object obj = target_bundle_bw.GetBundle().LoadAsset(realPath, assetType);
            if (obj == null)
            {
                Debugger.LogError("targetBundle Wrong!");
                return(null);
            }
            ret_aw = new AssetWrapper(obj, assetPath, assetType, abName, false);
            // add bundle refs
            //AddBundleRefAsset(abName, assetPath);
        }
        m_assetWrapperCache.Add(assetPath, ret_aw);

        return(ret_aw);
    }
Example #12
0
    void UnWrap(AssetWrapper ass)
    {
        for (int i = 0; i < ass.items.Length; i++)
        {
            Debug.Log("ItemState");
            if (ass.items[i] != null)
            {
                foreach (Item item in items)
                {
                    if (item.MatchID(ass.items[i].m_ItemID))
                    {
                        item.ChangeState(ass.items[i]);
                        break;
                    }
                }
            }
            else
            {
                break;
            }
        }
        Debug.Log("EnemyState");

        for (int i = 0; i < ass.enemies.Length; i++)
        {
            if (ass.enemies[i] != null)
            {
                foreach (Enemy e in enemies)
                {
                    if (e.MatchID(ass.enemies[i].m_EnemyID))
                    {
                        e.ChangeState(ass.enemies[i]);
                        break;
                    }
                }
            }
            else
            {
                break;
            }
        }

        Debug.Log("DoorState");

        for (int i = 0; i < ass.doors.Length; i++)
        {
            if (ass.doors[i] != null)
            {
                foreach (Door d in doors)
                {
                    if (d.MatchID(ass.doors[i].m_DoorID))
                    {
                        d.ChangeState(ass.doors[i]);
                        break;
                    }
                }
            }
            else
            {
                break;
            }
        }

        for (int i = 0; i < ass.doors.Length; i++)
        {
            if (ass.checkPoints[i] != null)
            {
                foreach (CheckPointTrigger c in checkPoints)
                {
                    if (c.MatchID(ass.checkPoints[i].m_CheckID))
                    {
                        c.ChangeState(ass.checkPoints[i]);
                        break;
                    }
                }
            }
            else
            {
                break;
            }
        }
    }