Пример #1
0
    /// <summary>
    /// 添加全屏点击事件
    /// </summary>
    /// <param name="path"></param>
    /// <param name="onclick"></param>
    /// <param name="isAnima"></param>
    /// <returns></returns>
    protected GameObject AddFullClick(string path, EventTriggerListener.VoidDelegate onclick = null, bool isAnima = false)
    {
        GameObject obj = FindGameObject(path);

        TransformUtil.Add <OnlyRaycastPanel>(obj);
        AddClick(obj, onclick, isAnima);
        return(obj);
    }
Пример #2
0
    /// <summary>
    /// //检测是否添加Canvas
    /// </summary>
    /// <param name="go"></param>
    void CheckCanvas(GameObject go)
    {
        TransformUtil.Add <GraphicRaycaster>(go);
        Canvas canvas = TransformUtil.Add <Canvas>(go);

        canvas.renderMode      = RenderMode.ScreenSpaceCamera;
        canvas.overrideSorting = true;
    }
Пример #3
0
 //static RuntimeAnimatorController controller;
 void Start()
 {
     animator             = TransformUtil.Add <Animator>(gameObject);
     animator.logWarnings = false;
     //if (controller == null)
     //{
     //string fileName = ResMgr.GetInstance().F_GetPath(EnResType.Common) + EnResType.Common.ToString() + FieldConfig.ABExtensionName;
     //string name = ResMgr.GetInstance().F_GetPath(EnResType.Common) + "ButtonAnimator" + FieldConfig.AnimaterExtendsName;
     //controller = ResMgr.GetInstance().LoadAsset<RuntimeAnimatorController>(fileName, name);  //Resources.Load("ButtonAnimator");
     //}
     //animator.runtimeAnimatorController = controller;
 }
Пример #4
0
    /// <summary>
    /// 添加继承ViewBase的组件
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="obj"></param>
    /// <returns></returns>
    protected virtual T AddView <T>(GameObject obj) where T : ViewBase
    {
        T view = TransformUtil.Add <T>(obj);

        if (view.m_IsInit == false)
        {
            view.F_OnInit();
            view.m_IsInit = true;
        }
        DicView[FreeViewBaseId] = view;
        return(view);
    }
Пример #5
0
    void LoadRootUIComplete(string sourceName, GameObject Obj)
    {
        RootUI = Obj;
        RootUI.transform.position   = new Vector3(0, 0, -400);
        RootUI.transform.localScale = Vector3.one;
        RootUI.layer     = LayerMask.NameToLayer("UI");
        m_UnderWinListGo = RootUI.transform.FindChild("UnderWinList");
        m_WinListGo      = RootUI.transform.FindChild("WinList");
        m_TiplistGo      = RootUI.transform.FindChild("TipList");
        m_ToplistGo      = RootUI.transform.FindChild("TopList");
        uiCamera         = RootUI.transform.FindChild("UICamera").GetComponent <Camera>();
        uiCamera.gameObject.AddComponent <UICameraRef>();
        TransformUtil.Add <DontDestroyTool>(RootUI);
        uiResolution = RootUI.GetComponent <CanvasScaler>().referenceResolution;

        SetRootPos(m_UnderWinListGo, T_UIConfig.UI_TYPE.UNDER_WIN);
        SetRootPos(m_WinListGo, T_UIConfig.UI_TYPE.WIN);
        SetRootPos(m_TiplistGo, T_UIConfig.UI_TYPE.TIP);
        SetRootPos(m_TiplistGo, T_UIConfig.UI_TYPE.TOP);
    }
Пример #6
0
    /// <summary>
    /// 查找Button
    /// </summary>
    /// <param name="buttonPath">路径</param>
    /// <param name="action">事件</param>
    /// <param name="isAnimator">是否带点击动画</param>
    /// <param name="isSound">是否有音效</param>
    /// <param name="SoundId">音效Id (T_Etc表配置)</param>
    /// <returns></returns>
    public static Button FindButtonByTrans(Transform tf, string buttonPath, UnityAction action = null, bool isAnimator = true, bool isSound = true, T_Etc.ID SoundId = T_Etc.ID.ButtonSound)
    {
        Transform child = tf;

        if (!string.IsNullOrEmpty(buttonPath))
        {
            child = tf.FindChild(buttonPath);
        }

        if (child == null)
        {
            Loger.Error("not find button:" + buttonPath);
            return(null);
        }
        Button btn = child.GetComponent <Button>();

        if (btn == null)
        {
            btn = child.gameObject.AddComponent <Button>();
        }
        //添加事件
        if (action != null)
        {
            btn.onClick.RemoveAllListeners();
            btn.onClick.AddListener(() => {
                if (isSound == true)
                {
                    //音效
                    //SoundManager.GetInstance().F_PlayUISound(ConfigManager.Etc.GetData(SoundId).IntValue);
                }
                action();
            });
        }
        if (isAnimator == true)
        {
            btn.transition = Selectable.Transition.None;
            TransformUtil.Add <ButtonAnimator>(child);
        }
        return(btn);
    }
Пример #7
0
    /// <summary>
    /// 重新设置UI的层级
    /// </summary>
    /// <param name="type"></param>
    void ResetDepth(T_UIConfig.UI_TYPE currentType)
    {
        int undercount = 0;
        int wincount   = 0;
        int tipcount   = 0;
        int topcount   = 0;
        int id;

        WindowBase tmpTop = null;

        for (int i = 0; i < m_IdPosList.Count; i++)
        {
            id = m_IdPosList[i];
            if (m_UIList.ContainsKey(id))
            {
                WindowBase winbs = m_UIList[id];
                if (winbs == null)
                {
                    continue;
                }
                CheckTop(winbs, ref tmpTop);
                Vector3            localPos = winbs.transform.localPosition;
                T_UIConfig.UI_TYPE type     = winbs.F_GetUIType();
                if (type != currentType)
                {
                    continue;
                }
                Canvas canvas = TransformUtil.Add <Canvas>(winbs.gameObject);
                switch (type)
                {
                case T_UIConfig.UI_TYPE.UNDER_WIN:
                    undercount++;
                    winbs.transform.SetSiblingIndex(undercount * 2);
                    localPos.z = m_StartDepth - undercount * m_depth;
                    winbs.transform.localPosition = localPos;
                    canvas.sortingOrder           = m_StartDepth * (int)type + undercount * m_depth;
                    winbs.V_SortingOrder          = canvas.sortingOrder;
                    break;

                case T_UIConfig.UI_TYPE.WIN:
                    wincount++;
                    winbs.transform.SetSiblingIndex(wincount * 2);
                    localPos.z = m_StartDepth - wincount * m_depth;
                    winbs.transform.localPosition = localPos;
                    canvas.sortingOrder           = m_StartDepth * (int)type + wincount * m_depth;
                    winbs.V_SortingOrder          = canvas.sortingOrder;
                    break;

                case T_UIConfig.UI_TYPE.TIP:
                    tipcount++;
                    winbs.transform.SetSiblingIndex(tipcount * 2);
                    localPos.z = m_StartDepth - tipcount * m_depth;
                    winbs.transform.localPosition = localPos;
                    canvas.sortingOrder           = m_StartDepth * (int)type + tipcount * m_depth;
                    winbs.V_SortingOrder          = canvas.sortingOrder;
                    break;

                case T_UIConfig.UI_TYPE.TOP:
                    topcount++;
                    winbs.transform.SetSiblingIndex(topcount * 2);
                    localPos.z = m_StartDepth - topcount * m_depth;
                    winbs.transform.localPosition = localPos;
                    canvas.sortingOrder           = m_StartDepth * (int)type + topcount * m_depth;
                    winbs.V_SortingOrder          = canvas.sortingOrder;
                    break;
                }
            }
        }

        if (currentType == T_UIConfig.UI_TYPE.WIN)
        {
            CheckHidenWin();
        }
        //设置最上层WIN
        OnTopWin(tmpTop);
    }
Пример #8
0
    /// <summary>
    /// 背景模糊;
    /// </summary>
    public void F_BlurScreenShot()
    {
        if (null != m_BlurTexture)
        {
            m_BlurTexture.gameObject.SetActive(false);
        }
        if (UICamera != null)
        {
            float   scale    = 0.4f; //比例越小,速度越快,但越模糊
            Vector2 v2Screen = new Vector2(Screen.width, Screen.height);

            float UIScreenWidth  = 1280;
            float UIScreenHeight = UIScreenWidth * v2Screen.y / v2Screen.x;
            v2Screen.x = UIScreenWidth;
            v2Screen.y = UIScreenHeight;

            float         width  = v2Screen.x * scale;
            float         height = v2Screen.y * scale;
            RenderTexture rt     = new RenderTexture((int)width, (int)height, 24);
            if (null == SceneCamera)
            {
                if (SceneCameraObj == null)
                {
                    SceneCameraObj = GameObject.Find("WorldCamera");
                }
                if (null != SceneCameraObj)
                {
                    SceneCamera = SceneCameraObj.GetComponent <Camera>();
                }
            }

            if (null != SceneCamera)
            {
                SceneCamera.targetTexture = rt;
                SceneCamera.Render();
                SceneCamera.targetTexture = null;
            }

            UICamera.targetTexture = rt;
            UICamera.Render();
            UICamera.targetTexture = null;
            RenderTexture.active   = rt;

            Texture2D thumb2d = new Texture2D((int)width, (int)height, TextureFormat.RGB24, false);
            thumb2d.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            //Color32[] thumbPixels = thumb2d.GetPixels32();
            //thumb2d.SetPixels32(thumbPixels);
            thumb2d.Apply();

            if (m_BlurTexture == null)
            {
                GameObject go = new GameObject("ScreenBG");
                go.layer                   = LayerMask.NameToLayer("UI");
                go.transform.parent        = m_WinListGo.transform;
                go.transform.localPosition = Vector3.zero;
                go.transform.localScale    = Vector3.one;
                m_BlurTexture              = go.AddComponent <RawImage>();
                m_BlurTexture.color        = new Color32(84, 84, 84, 255);
                Canvas canvas = TransformUtil.Add <Canvas>(go);
                canvas.overrideSorting = true;
                TransformUtil.Add <GraphicRaycaster>(go);
                m_BlurTexture.gameObject.SetActive(false);
            }


            //处理图片;
            m_BlurTexture.texture = UITextureBlurTool.GetInstance().F_HandleImage(thumb2d);
            m_BlurTexture.gameObject.SetActive(true);
            //Color color = m_BlurTexture.color;
            //color.a = 0;
            //m_BlurTexture.color = color;
            GameObject.Destroy(thumb2d);
        }
        else
        {
            Loger.Error("CatureScreenShot Fail, UICamera is NULL!");
        }

        #endregion
    }
Пример #9
0
    /// <summary>
    /// 子节点添加组件
    /// </summary>
    /// <typeparam name="T">组件类型</typeparam>
    /// <param name="path">子节点 path</param>
    /// <returns>组件实例</returns>
    protected T AddComponent <T>(string path) where T : Component
    {
        GameObject obj = FindGameObject(path);

        return(TransformUtil.Add <T>(obj));
    }
Пример #10
0
 /// <summary>
 /// 添加动画
 /// </summary>
 /// <param name="obj"></param>
 protected void AddAnimator(GameObject obj)
 {
     TransformUtil.Add <ButtonAnimator>(obj);
 }