Esempio n. 1
0
    /*
     * @brief 加载资源
     * @param path 资源路径
     * @param callback 回调函数
     */
    public static void LoadAsset(string path, UnityAction <Object, string> callback = null, System.Type type = null)
    {
        // Windows 平台分隔符为 '/', OS 平台 路径分隔符为 '\', 此处是一个大坑
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            path = path.Replace('\\', '/');
        }

#if UNITY_EDITOR
        ZTSceneManager.GetInstance().StartCoroutine(AnsyLoadAsset(path, callback, type));
#else
        string fileName   = System.IO.Path.GetFileName(path);
        string fileNameEx = System.IO.Path.GetFileNameWithoutExtension(path);
        string abName     = path.Replace(fileName, "").Replace('/', '_');
        abName = abName.Substring(0, abName.Length - 1).ToLower();

        ZTAssetBundleManager.GetInstance().LoadAssetInBundleSync(abName, fileNameEx, (Object gameObject) =>
        {
            //加载assetBundleManifest文件
            if (null != gameObject)
            {
                callback(gameObject, path);
                return;
            }
            callback(null, path);
        }, type);
#endif
    }
Esempio n. 2
0
    //刷新地图元素
    public void UpdateElementView(Vector3 pos, int gridX, int gridY)
    {
        LittleElementBlockLoader.SetBlockPos(pos);
        elementBlockLoader.SetBlockPos(pos);

        return;

        Dictionary <string, MapElement> elementDic = new Dictionary <string, MapElement>();
        int    bigMapX   = (int)pos.x / MapDefine.MAPITEMTOTALSIZE;
        int    bigMapY   = (int)pos.z / MapDefine.MAPITEMTOTALSIZE;
        string bigMapKey = bigMapX + "" + bigMapY;
        int    beginX    = (int)gridX - 1;
        int    beginY    = (int)gridY - 1;
        int    endX      = (int)gridX + 1;
        int    endY      = (int)gridY + 1;

        for (int i = beginX; i <= endX; i++)
        {
            if (i < 0)
            {
                continue;
            }
            for (int j = beginY; j <= endY; j++)
            {
                if (j < 0)
                {
                    continue;
                }
                string gridKey = i + "_" + j;
                Dictionary <string, MapElementGrid> tempGridDataDic;
                if (AllMapElementGridDic.TryGetValue(bigMapKey, out tempGridDataDic))
                {
                    MapElementGrid tempGridData;
                    if (tempGridDataDic.TryGetValue(gridKey, out tempGridData))
                    {
                        List <string> tempElementKeyList = tempGridData.elementKeyList;
                        for (int index = 0; index < tempElementKeyList.Count; index++)
                        {
                            MapElement element;
                            Dictionary <string, MapElement> tempElementDic;
                            if (AllMapElementDic.TryGetValue(bigMapKey, out tempElementDic))
                            {
                                if (tempElementDic.TryGetValue(tempElementKeyList[index], out element))
                                {
                                    if (!elementDic.ContainsKey(element.elementKey))
                                    {
                                        elementDic[element.elementKey] = element;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        var needClearElementDic = activeObj.Keys.Except(elementDic.Keys);
        var needLoadElementDic  = elementDic.Keys.Except(activeObj.Keys);

        createElementList.Clear();
        disableElementList.Clear();
        foreach (var key in needLoadElementDic)
        {
            createElementList.Add(key);
        }

        foreach (var key in needClearElementDic)
        {
            disableElementList.Add(key);
        }

        visionElementDic = elementDic;
        // if (disableElementList.Count > 0)
        //    ClearElementInList();
        if (createElementList.Count > 0 || disableElementList.Count > 0)
        {
            if (null == _OnUpdateElementHandler)
            {
                _OnUpdateElementHandler = OnUpdateElement();
                ZTSceneManager.GetInstance().StartCoroutine(_OnUpdateElementHandler);
            }
        }
        if (disabelObj.Count > 100)
        {
            List <GameObject> tempDisableList = disabelObj.GetRange(0, disabelObj.Count / 2);
            disabelObj.RemoveRange(0, disabelObj.Count / 2);
            ZTSceneManager.GetInstance().StartCoroutine(DestroyElementList(tempDisableList));
        }
    }