Esempio n. 1
0
    private void OnLoadOver(GameObject obj, DiamondVector2 pos, string fullPath)
    {
        //防止拖动过快导致还没加载完就被移除了,所以如果包含,证明已经被卸载了,则直接归入缓存中
        if (earlyRemoveDic.ContainsKey(pos))
        {
            //Debug.Log("earlyRemoveSet==" + fullPath);
            cacheManager.Put(fullPath, obj);
            tile2CacheDic.Remove(pos);
            earlyRemoveDic[pos]--;
            if (earlyRemoveDic[pos] == 0)
            {
                earlyRemoveDic.Remove(pos);
            }
            return;
        }
        //如果这个位置加载过,并且不是同一个物体,则把之前的删除
        if (tile2CacheDic.ContainsKey(pos))
        {
            OnObjectRemove(pos, tile2CacheDic[pos].fullPath);
        }

        //Debug.Log("OnLoadOver==" + fullPath);
        obj.transform.localEulerAngles = new Vector3(0, 180, 0);
        obj.transform.localScale       = Vector3.one;
        obj.transform.localPosition    = DiamondCoordinates.DiamondToWorld(pos);
        obj.SetActive(true);
        CacheObjectInfo info = new CacheObjectInfo();

        info.obj      = obj;
        info.fullPath = fullPath;
        tile2CacheDic.Add(pos, info);
        //Debug.Log("OnLoadOver==" + obj.transform.localPosition);
    }
Esempio n. 2
0
 public void Get(string fullPath, DiamondVector2 pos, LoadCacheCallBack action)
 {
     //如果缓存中有值则直接从缓存中拿
     if (cacheDic.ContainsKey(fullPath))
     {
         //直接拿第一个节点
         CacheNode node = cacheDic[fullPath];
         DeleteNode(node);
         action(node.value, pos, fullPath);
     }
     else
     {
         //Debug.Log("LoadAssetAsync==" + fullPath);
         //这里直接用lambda做,需要传的参数挺多的
         AssetManager.AssetLoad.LoadAssetAsync <GameObject>(fullPath,
                                                            (loadInfo) =>
         {
             //可能还没加载完就被卸载了,所以这里做个处理
             if (loadInfo.obj != null)
             {
                 GameObject obj       = GameObject.Instantiate(loadInfo.obj) as GameObject;
                 obj.name             = index.ToString();
                 obj.transform.parent = WorldNode.ObjectParent;
                 index++;
                 action(obj, pos, loadInfo.path);
             }
         },
                                                            null);
     }
 }
Esempio n. 3
0
 private void OnMsgOver(List <WorldDataDto> list)
 {
     foreach (var item in list)
     {
         //当前Tile不在激活状态的话,显示层不作处理
         if (GetTileState(item.index) == WorldTileState.None)
         {
             //数据照常同步
             SetObjectType(item.index, item.type);
             SetObjectId(item.index, item.id);
             continue;
         }
         //Debug.Log("item.id==" + item.id + ", item.index==" + item.index + ",objectIdBytes[item.index]==" + objectIds[item.index]);
         //如果当前的id是新增的或者和之前不一样,则走添加逻辑
         //先拿以下旧的数据
         byte           oldId = GetObjectId(item.index);
         DiamondVector2 dPos  = DiamondVector2.GetDiamondPosByIndex(item.index);
         if (item.id > 0 && (oldId == 0 || oldId != item.id))
         {
             //先把之前的移除
             if (oldId > 0)
             {
                 EventDispatcher.Singleton.NotifyListener(EventKey.WorldObjectRemove, dPos, GetObjectResPath(item.type, oldId));
             }
             EventDispatcher.Singleton.NotifyListener(EventKey.WorldObjectAdd, dPos, GetObjectResPath(item.type, item.id));
         }
         //如果之前的数据中有值但是新的数据没值,则走移除逻辑
         else if (item.id == 0 && oldId > 0)
         {
             EventDispatcher.Singleton.NotifyListener(EventKey.WorldObjectRemove, dPos, GetObjectResPath(item.type, oldId));
         }
         SetObjectType(item.index, item.type);
         SetObjectId(item.index, item.id);
     }
 }
Esempio n. 4
0
    private void OnUpdate()
    {
        if (UITools.IsRaycastUI())
        {
            return;
        }

        if (InputManager.GetMouseButtonDown())
        {
            lastTouchPos = InputManager.GetMousePosition();
        }
        if (InputManager.GetMouseButtonUp())
        {
            if (Vector2.Distance(InputManager.GetMousePosition(), lastTouchPos) <= maxDelta)
            {
                Ray ray = camera.ScreenPointToRay(InputManager.GetMousePosition());
                //发个射线
                float enter = 100.0f;
                Plane plane = WorldCreator.Singleton.plane;
                if (plane.Raycast(ray, out enter))
                {
                    DiamondVector2 dPos = DiamondCoordinates.WorldToDiamond(ray.GetPoint(enter));
                    EventDispatcher.Singleton.NotifyListener(EventKey.WorldClickTile, dPos);
                    //暂时没别的需求,直接打开窗口
                    if (DiamondCoordinates.IsValid(dPos))
                    {
                        UIManager.Singleton.OpenWindow <UIWorldPopup>(dPos);
                    }
                }
            }
        }
    }
Esempio n. 5
0
    //不加了 容易误解
    //public static bool operator <=(DiamondVector2 a, DiamondVector2 b)
    //{
    //	return a.x <= b.x;
    //}
    //   public static bool operator >=(DiamondVector2 a, DiamondVector2 b)
    //   {
    //       return a.x >= b.x;
    //   }
    //public static bool operator >(DiamondVector2 a, int b)
    //{
    //    return a.x > b && a.y > b;
    //}
    //public static bool operator <(DiamondVector2 a, int b)
    //{
    //    return a.x < b || a.y < b;
    //}
    public override bool Equals(object other)
    {
        if (!(other is DiamondVector2))
        {
            return(false);
        }
        DiamondVector2 vector = (DiamondVector2)other;

        return(x == vector.x && y == vector.y);
    }
Esempio n. 6
0
    public override void OnInit()
    {
        DiamondVector2 pos = (DiamondVector2)arg;
        //坐标
        Transform bgTf = baseObject.transform.Find("Canvas/Bg");

        UITools.SetText(bgTf.Find("Title"), LanguageSet.Tip_1);
        UITools.SetText(bgTf.Find("Text"), pos.ToString());
        UITools.BindOnClick(baseObject.transform.Find("Canvas/Image"), OnClickClose);
    }
Esempio n. 7
0
    public override void OnInit()
    {
        camera   = WorldCreator.Singleton.camera;
        cameraTf = camera.transform;
        ScriptBridge.Singleton.AddUpdate(OnUpdate, this);
        ScriptBridge.Singleton.AddLateUpdate(OnLateUpdate, this);

        //默认lookat中心点
        DiamondVector2 lookAtDPos = new DiamondVector2(DiamondCoordinates.maxX / 2, DiamondCoordinates.maxY / 2);
        Vector3        worldPos   = DiamondCoordinates.DiamondToWorld(lookAtDPos);

        LookAt(worldPos);
    }
Esempio n. 8
0
 private void OnObjectRemove(DiamondVector2 pos, string fullPath)
 {
     //Debug.Log("OnObjectRemove pos==" + pos);
     //如果移除的物体还没被加载完,则加入移除容器中,待加载完后做处理
     if (!tile2CacheDic.ContainsKey(pos))
     {
         //Debug.Log("earlyRemoveSet==" + pos + ", path==" + fullPath);
         if (!earlyRemoveDic.ContainsKey(pos))
         {
             earlyRemoveDic.Add(pos, 0);
         }
         earlyRemoveDic[pos]++;
         return;
     }
     //Debug.Log("OnObjectRemove==" + pos + ", path==" + fullPath);
     //这里要加个判断,因为这里存的东西可能之前就被移除了
     if (tile2CacheDic[pos].obj != null)
     {
         cacheManager.Put(fullPath, tile2CacheDic[pos].obj);
     }
     tile2CacheDic.Remove(pos);
 }
Esempio n. 9
0
    /// <summary>
    /// 根据摄像机四个角对应的世界坐标+偏移,遍历所有包括的菱形格子
    /// </summary>
    /// <param name="posLB">摄像机左下角</param>
    /// <param name="posLT">摄像机左上角</param>
    /// <param name="posRT">摄像机右上角</param>
    /// <param name="extraDis">偏移,因为如果卡死视野范围,周围过度会不平滑,而且会有露馅</param>
    /// <param name="action">事件回调</param>
    public static void ForeachByWorldPos(Vector3 posLB, Vector3 posLT, Vector3 posRT, float extraDis, Action <DiamondVector2> action)
    {
        //从左上角遍历到右下角,由于菱形地图奇数位会有错位的情况,所以这里加了一个Offset去处理偏移
        float offset     = 0;
        float halfWeight = DiamondCoordinates.w / 2;
        float halfHeight = DiamondCoordinates.h / 2;

        for (float y = posLT.z + extraDis; y >= posLB.z - extraDis; y -= halfHeight)
        {
            for (float x = posLT.x - extraDis; x <= posRT.x + extraDis; x += DiamondCoordinates.w)
            {
                DiamondVector2 dPos = DiamondCoordinates.WorldToDiamond(new Vector3(x + offset, 0, y));
                //无效的点不作处理
                if (!DiamondCoordinates.IsValid(dPos))
                {
                    continue;
                }
                //Debug.Log("worldpos==" + new Vector3(x + offset, 0, y));
                action(dPos);
            }
            offset = offset == 0 ? halfWeight : 0;
        }
    }
Esempio n. 10
0
 public static bool IsSameCol(DiamondVector2 a, DiamondVector2 b)
 {
     return((a.x - a.y) == (b.x - b.y));
 }
Esempio n. 11
0
 private void OnObjectAdd(DiamondVector2 pos, string fullPath)
 {
     cacheManager.Get(fullPath, pos, OnLoadOver);
 }
Esempio n. 12
0
 //菱形坐标转AOI index
 public static Vector2 DiamondToAOIIndex(DiamondVector2 pos)
 {
     return(AOICoordinates.WorldToAOI(DiamondToWorld(pos)));
 }
Esempio n. 13
0
 //菱形坐标转世界坐标
 public static Vector3 DiamondToWorld(DiamondVector2 pos)
 {
     return(new Vector3((pos.x - pos.y) * (w / 2), 0, -(pos.x + pos.y) * (h / 2)));
 }
Esempio n. 14
0
 public static bool IsValid(DiamondVector2 pos)
 {
     return(pos.x >= 0 && pos.y >= 0 && pos.x < maxX && pos.y < maxY);
 }
Esempio n. 15
0
 public bool IsSameRow(DiamondVector2 other)
 {
     return((x + y) == (other.x + other.y));
 }
Esempio n. 16
0
 public bool IsSameCol(DiamondVector2 other)
 {
     return((x - y) == (other.x - other.y));
 }
Esempio n. 17
0
 public static bool IsSameRow(DiamondVector2 a, DiamondVector2 b)
 {
     return((a.x + a.y) == (b.x + b.y));
 }