Exemple #1
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
    }