示例#1
0
 public void BaseInit(int moduleId, int instanceId, GameObject root)
 {
     m_wiInfo            = WindowInfoMgr.GetWindowInfo(moduleId);
     m_iInstanceID       = instanceId;
     m_objInstanceRoot   = root;
     m_transInstanceRoot = root.GetComponent <RectTransform>();
     m_ticker            = m_objInstanceRoot.AddComponent <Ticker>();
 }
    private void OnWindowOpen(WindowStartUpEvent param)
    {
        if (m_bIsOpeningAWindow)
        {
            // another window is loading, put this one into open queue and return;
            m_qOpenQueue.Enqueue(param);
            return;
        }

        m_bIsOpeningAWindow = true;
        int     moduleId   = param.ModuleID;
        int     instanceId = moduleId;
        IWindow tmpIns;

        // if key moduleId exist in m_dictInstanceMapper,
        // shows that this window is a uniqe window,
        // and it's in the cache;
        if (m_dictInstanceMapper.TryGetValue(instanceId, out tmpIns))
        {
            LinkedListNode <IWindow> node = m_llInstances.Find(tmpIns);
            m_llInstances.Remove(node);
            m_llInstances.AddFirst(node);

            tmpIns.StartListener();
            tmpIns.StartUp(param.Params);
            m_bIsOpeningAWindow = false;
            return;
        }

        // not in the cache, but it's not a uniqe window
        tmpIns = GetWinInstance(moduleId);
        //tmpIns.SetWindowInfo(moduleId);
        //if (!tmpIns.IsUniqeWindow())
        if (!WindowInfoMgr.GetWindowInfo(moduleId).UniqeWindow)
        {
            WinTemplate template;
            // resources is already loaded
            // create a new window immediately
            instanceId = GetInstanceID(moduleId);
            if (m_dictTemplateMapper.TryGetValue(moduleId, out template))
            {
                GameObject root = GameObject.Instantiate(template.Template) as GameObject;
                root.transform.SetParent(m_transWindowRoot, false);
                root.transform.SetAsLastSibling();
                root.SetActive(true);
                template.RefCnt += 1;
                LinkedListNode <WinTemplate> node = m_llWinTemplate.Find(template);
                m_llWinTemplate.Remove(node);
                m_llWinTemplate.AddFirst(template);
                m_dictInstanceMapper.Add(instanceId, tmpIns);
                m_dictTemplateMapper[moduleId] = template;
                tmpIns.BaseInit(moduleId, instanceId, root);
                tmpIns.Init();
                tmpIns.StartListener();
                tmpIns.StartUp(param.Params);
                m_bIsOpeningAWindow = false;
                return;
            }
        }

        IntermediateParams.WinLoadedParam winParam = new IntermediateParams.WinLoadedParam();
        winParam.ModuleID   = moduleId;
        winParam.InstanceID = instanceId;
        winParam.StartParam = param.Params;
        winParam.Instance   = tmpIns;
        string path = Path.GetUIPath(WindowInfoMgr.GetWindowInfo(moduleId).ResName);

        ResLoader.Load(path, OnWindowResLoaded, winParam);
    }