Beispiel #1
0
    // drag mini game
    public void FocusMiniGame(DragGameMiniEvent drag)
    {
#if USE_XLUA
        InvokeXLua("FocusMiniGame", drag);
#else
        List <UILayer> layerTemps = layers[UILayer.Position.Middle].Where(a => a.dragMini != null).ToList();

        if (layerTemps.Count > 0)
        {
            if (drag == null)
            {
                layerMiniMask.SetActive(false);
                foreach (var layer in layerTemps)
                {
                    layer.dragMini.canvasGroup.alpha = 1f; // old is 0.6f
                }
            }
            else
            {
                layerMiniMask.SetActive(true);

                foreach (var layer in layerTemps)
                {
                    layer.dragMini.canvasGroup.alpha = 1f;
                }

                layerTemps = layerTemps.OrderBy(a => a.canvas.sortingOrder).ToList();
                UILayer layerTop     = layerTemps.Last();
                UILayer layerCurrent = layerTemps.FirstOrDefault(a => a.dragMini.Equals(drag));

                if (layerCurrent != null && !layerTop.Equals(layerCurrent))
                {
                    int   order      = layerTop.canvas.sortingOrder;
                    int   layerIndex = layerTop.layerIndex;
                    float distance   = layerTop.canvas.planeDistance;

                    layerTop.layerIndex = layerCurrent.layerIndex;
                    layerTop.SetSortOrder(layerCurrent.canvas.sortingOrder);
                    layerTop.canvas.planeDistance = layerCurrent.canvas.planeDistance;

                    layerCurrent.layerIndex = layerIndex;
                    layerCurrent.SetSortOrder(order);
                    layerCurrent.canvas.planeDistance = distance;
                }
                layers[UILayer.Position.Middle] = layers[UILayer.Position.Middle].OrderBy(a => a.canvas.sortingOrder).ToList();
            }
        }
#endif
    }
Beispiel #2
0
    private UILayer CreateLayer(string key, GameObject obj = null)
    {
#if USE_XLUA
        return(InvokeXLua("CreateLayer", new object[] { key, obj })[0] as UILayer);
#else
        UILayer sLayer    = null;
        string  nameLayer = key.ToString();

        // get exists
        bool isCreate = true;
        if (layerCaches.ContainsKey(key) && layerCaches[key].Count > 0)
        {
            isCreate = false;

            sLayer = layerCaches[key][0];
            sLayer.gameObject.SetActive(true);

            layerCaches[key].RemoveAt(0);
        }
        else
        {
            if (obj == null)
            {
                try
                {
                    obj = Resources.Load(path + "/" + nameLayer) as GameObject;
                }
                catch (Exception e)
                {
                    VKDebug.LogError("Layer not found from local");
                    return(null);
                }
            }

            if ((isLandscape && screenRatio > 1.9f) || (!isLandscape && screenRatio > 0.74f))
            {
                if (!obj.GetComponent <UILayer>().lockCanvasScale)
                {
                    CanvasScaler canvasScaler = obj.GetComponent <CanvasScaler>();
                    canvasScaler.matchWidthOrHeight = 1f;
                }
            }
            else
            {
                if (!obj.GetComponent <UILayer>().lockCanvasScale)
                {
                    CanvasScaler canvasScaler = obj.GetComponent <CanvasScaler>();
                    canvasScaler.matchWidthOrHeight = 0f;
                }
            }
            obj    = Instantiate(obj) as GameObject;
            sLayer = obj.GetComponent <UILayer>();

            // seting init
            sLayer.InitLayer(key, screenRatio);

            sLayer.canvas.renderMode  = RenderMode.ScreenSpaceCamera;
            sLayer.canvas.worldCamera = uiCamera;
        }

        List <UILayer> uiLayerTemps = layers[sLayer.position];
        int            countLayer   = uiLayerTemps.Count;

        // set position
        int   sorting  = countLayer == 0 ? deepOrderStarts[(int)sLayer.position] : (uiLayerTemps[countLayer - 1].canvas.sortingOrder + deepOrder);
        float distance = countLayer == 0 ? planeDistanceStarts[(int)sLayer.position] : (uiLayerTemps[countLayer - 1].canvas.planeDistance - deepPlaneDistance);

        sLayer.transform.SetAsLastSibling();
        sLayer.name = nameLayer + "_" + (countLayer + 1);

        sLayer.SetSortOrder(sorting);
        sLayer.canvas.planeDistance = distance;

        // action
        if (isCreate)
        {
            sLayer.StartLayer();
        }
        sLayer.ShowLayer();

        return(sLayer);
#endif
    }