Ejemplo n.º 1
0
    /// <summary>
    /// 直接加载这个窗口
    /// </summary>
    /// <param name="path">Path.</param>
    public static void DirectShowPrefab(string path)
    {
        GameObject prefab   = Resources.Load(path) as GameObject;
        GameObject uicamera = GameObject.Find("UI Root/Camera");

        prefab = UnityTools.AddChild(uicamera, prefab);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 显示窗口
    /// tips:检查是否是隐藏
    /// </summary>
    /// <param name="name">Name.</param>
    public void ShowWindow(string name)
    {
        // 判断是否是隐藏,如果隐藏,则设置显示,如果已经显示,则不操作
        BaseWindow bw = GetWindow(name);

        if (bw != null)
        {
            if (!IsWindowVisible(bw))
            {
                bw.gameObject.SetActive(true);
                bw.OnShow();
                PushShowingStack(bw);
            }
            return;
        }

        // 获得外部配置数据
        UIWindowData config = UIWindowDataProvider.Instance.GetData(name);

        if (config == null || string.IsNullOrEmpty(config.mPrefabPath))
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0}'s prefab config is null!", name);
            return;
        }

        // 加载prefab,实例化,挂载至root点
        GameObject prefab = Resources.Load(config.mPrefabPath) as GameObject;

        if (null == prefab)
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0}'s prefab cannot Load!", name);
            return;
        }

        prefab = UnityTools.AddChild(UISystem.Instance.GetUICamera(), prefab);

        // 获得BaseWindow对象,调用Init
        bw = prefab.GetComponent <BaseWindow>();
        if (bw == null)
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0} can't get BaseWindow component from prefab!", name);
            return;
        }
        bw.SetConfigData(config);
        if (!bw.Init())
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0}'s BaseWindow init failed!", name);
            return;
        }

        // 加入管理队列和栈
        bw.OnShow();
        mManagedWindows.Add(bw);
        PushShowingStack(bw);

        Resources.UnloadUnusedAssets();
        System.GC.Collect();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 显示窗口
    /// tips:检查是否是隐藏
    /// </summary>
    /// <param name="name">Name.</param>
    public void ShowWindow(string name)
    {
                #if !SERVER
        // 判断是否是隐藏,如果隐藏,则设置显示,如果已经显示,则不操作
        BaseWindow bw = GetWindow(name);
        if (bw != null)
        {
            if (!IsWindowVisible(bw))
            {
                bw.gameObject.SetActive(true);
                bw.OnShow();
                PushShowingStack(bw);
            }

            // cancel 掉fade流程
            //TweenAlpha ta = bw.gameObject.GetComponent<TweenAlpha>();
            //if (ta != null)
            //{
            //    ta.ResetToBeginning();
            //    ta.value = 1.0f;
            //    ta.enabled = false;
            //}

            TweenAlpha ta = bw.gameObject.GetComponent <TweenAlpha>();
            if (ta == null)
            {
                ta = bw.gameObject.AddComponent <TweenAlpha>();
            }
            ta.enabled = true;
            ta.ResetToBeginning();
            ta.from     = 0;
            ta.to       = 1;
            ta.duration = 0.5f;
            ta.SetOnFinished(() =>
            {
                ta.value   = 1.0f;
                ta.enabled = false;
            });
            ta.Play(true);
            return;
        }

        // 获得外部配置数据
        UIWindowConfig config = UIWindowConfigProvider.Instance.GetData(name);
        if (config == null || string.IsNullOrEmpty(config.mPrefabPath))
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0}'s prefab config is null!", name);
            return;
        }

        // 加载prefab,实例化,挂载至root点
        //GameObject prefab = Resources.Load(config.mPrefabPath) as GameObject;
        GameObject prefab = AssetManager.Get().LoadResource(config.mPrefabPath) as GameObject;
        if (null == prefab)
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0}'s prefab cannot Load!", name);
            return;
        }

        prefab = UnityTools.AddChild(mUICamera.gameObject, prefab);

        // 获得BaseWindow对象,调用Init
        bw = prefab.GetComponent <BaseWindow>();
        if (bw == null)
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0} can't get BaseWindow component from prefab!", name);
            return;
        }
        bw.SetConfigData(config);
        if (!bw.Init())
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0}'s BaseWindow init failed!", name);
            return;
        }

        {
            TweenAlpha ta = bw.gameObject.GetComponent <TweenAlpha>();
            if (ta == null)
            {
                ta = bw.gameObject.AddComponent <TweenAlpha>();
            }
            ta.enabled = true;
            ta.ResetToBeginning();
            ta.from     = 0;
            ta.to       = 1;
            ta.duration = 0.5f;
            ta.SetOnFinished(() =>
            {
                ta.value   = 1.0f;
                ta.enabled = false;
            });
            ta.Play(true);
        }


        // 加入管理队列和栈
        mManagedWindows.Add(bw);
        bw.OnShow();
        PushShowingStack(bw);

        //Resources.UnloadUnusedAssets ();
        //System.GC.Collect ();
                #endif
    }