Esempio n. 1
0
    public void RefreshMapTile(IntVector2 tileCoord)
    {
        SubMapView subMapView = null;
        int        blockId    = MapDataManager.TileCoordToBlockId(tileCoord);

        if (mSubMapViews.TryGetValue(blockId, out subMapView))
        {
            subMapView.RefreshTile(tileCoord);
        }
    }
Esempio n. 2
0
    SubMapView CreateSubMapView()
    {
        SubMapView ret = null;

        if (mCachedSubMapViews.Count > 0)
        {
            ret = mCachedSubMapViews.Dequeue();
            ret.OnOutRecover();
        }
        else
        {
            ret = GameObject.Instantiate <SubMapView>(subMapViewTemplate);
            ret.OnInit();
            ret.transform.SetParent(transform);
        }
        ret.gameObject.SetActive(true);
        return(ret);
    }
Esempio n. 3
0
    /// <summary>
    /// 刷新可见地块,当可见地块改变时调用
    /// </summary>
    void RefreshVisiableSubMapView()
    {
        HashSet <int> visibleBlockSet = GetVisiableMapBlocks();

        //找到哪些子地块已经变得不可见
        mToRemoveBlockIdList.Clear();
        var subMapViewEnumerator = mSubMapViews.GetEnumerator();

        while (subMapViewEnumerator.MoveNext())
        {
            if (!visibleBlockSet.Contains(subMapViewEnumerator.Current.Key))
            {
                mToRemoveBlockIdList.Add(subMapViewEnumerator.Current.Key);
            }
        }

        //不可见地块删除
        for (int i = 0; i < mToRemoveBlockIdList.Count; ++i)
        {
            int        toRemoveBlockId  = mToRemoveBlockIdList [i];
            SubMapView removeSubMapView = mSubMapViews [toRemoveBlockId];
            mSubMapViews.Remove(toRemoveBlockId);
            RecoverSubMapView(removeSubMapView);
        }

        var visibleBlockSetEnum = visibleBlockSet.GetEnumerator();

        while (visibleBlockSetEnum.MoveNext())
        {
            if (mSubMapViews.ContainsKey(visibleBlockSetEnum.Current))
            {
                continue;
            }
            SubMapView newSubMapView = CreateSubMapView();
            mSubMapViews.Add(visibleBlockSetEnum.Current, newSubMapView);
            newSubMapView.SetBlockId(visibleBlockSetEnum.Current);
        }
    }
Esempio n. 4
0
 void RecoverSubMapView(SubMapView subMapView)
 {
     subMapView.OnEnterRecover();
     subMapView.gameObject.SetActive(false);
     mCachedSubMapViews.Enqueue(subMapView);
 }