Beispiel #1
0
    /// <summary>
    /// 自动给Forms层级排序
    /// </summary>
    private int AutoCalculateDepth(UIBaseForms <MonoBehaviour> forms, int curDepth)
    {
        UIPanel parentPanel = forms.GetComponent <UIPanel>();

        if (parentPanel == null)
        {
            NIDebug.LogWarning("=============自动给Forms层级排序========parentPanel是null======");
            return(curDepth);
        }

        UIPanel[] childrenPanel = forms.GetComponentsInChildren <UIPanel>(true); //这里的下标0也是parentPanel

        int parentPanelDepth = parentPanel.depth;
        int maxDis           = 0;

        for (int i = 0; i < childrenPanel.Length; i++)
        {
            int disDepth = childrenPanel[i].depth - parentPanelDepth;
            childrenPanel[i].depth = curDepth + disDepth;
            if (disDepth > maxDis)
            {
                maxDis = disDepth;
            }
        }

        return(curDepth + maxDis + 1);
    }
Beispiel #2
0
    /// <summary>
    /// Dispatchs the service.
    /// </summary>
    /// <returns>The service.</returns>
    /// <param name="i">The index.</param>
    /// <param name="owner">Owner.</param>
    /// <param name="name">Name.</param>
    /// <param name="fixedMode">If set to <c>true</c> fixed coro.</param>
    public static Proxy DispatchService(IEnumerator i, UnityEngine.Object owner, string name, bool fixedMode)
    {
        // mInstance对象不存在
        if (mInstance == null)
        {
            return(null);
        }

        // 没有owner对象
        if (owner == null)
        {
            NIDebug.LogWarning("owner 是空的,i = {0}, name = {1}", i, name);
            return(null);
        }

        Dictionary <string, Proxy> cm = (!fixedMode ? mCoroutionMap : mCoroutionFixedMap);
        List <Proxy> cl = (!fixedMode ? mCoroutionList : mCoroutionFixedList);

#if UNITY_EDITOR
        if (cm.Count > 500)
        {
            NIDebug.LogWarning("Coroutine数量太多!");
        }
#endif

        // 没有名字,自动取一个
        if (string.IsNullOrEmpty(name))
        {
            name = GameUtility.GetUniqueName("AnonymousCoroutine");
        }

        // 如果已经包含了该协程名的协程
        if (cm.ContainsKey(name))
        {
            NIDebug.LogWarning(string.Format("重名Coroutine {0}, 失败!", name));
            return(null);
        }

        Proxy p = new Proxy(name, i, owner, fixedMode);
        cm.Add(name, p);
        cl.Add(p);

        if (!fixedMode)
        {
            mInstance.StartCoroutine(Step(p));
        }
        else
        {
            StepFixed(p);
        }

        return(p);
    }
Beispiel #3
0
 private void PushForms(string formsName)
 {
     if (!mFormsStackName.ContainsKey(formsName))
     {
         mFormsStackName.Add(formsName, mCurStackFormsIndex);
         mFormsStackIndex.Add(mCurStackFormsIndex, formsName);
     }
     else
     {
         NIDebug.LogWarning("**************功能窗口栈已有此窗口*****************");
     }
 }
Beispiel #4
0
 private void PopForms(string formsName)
 {
     if (!mFormsStackIndex[mCurStackFormsIndex].Equals(formsName))
     {
         NIDebug.LogWarning("*************此窗口不是栈顶窗口,无法Pop****************");
         return;
     }
     if (mFormsStackName.ContainsKey(formsName))
     {
         mFormsStackIndex.Remove(mFormsStackName[formsName]);
         mFormsStackName.Remove(formsName);
     }
 }
Beispiel #5
0
    /// <summary>
    /// 创建窗口
    /// </summary>
    public T ShowForms <T>(string formsName, string PrefabName, bool IsAutoDepth = true) where T : UIBaseForms <MonoBehaviour>
    {
        if (string.IsNullOrEmpty(formsName) || string.IsNullOrEmpty(PrefabName))
        {
            return(null);
        }

        UIBaseForms <MonoBehaviour> forms = null;

        if (!mFormsDic.TryGetValue(formsName, out forms))
        {
            forms = _CreateForms <T>(formsName, PrefabName);
            if (forms != null)
            {
                forms.Show();
            }
        }
        else
        {
            forms.ReShow();
        }

        if (forms != null)
        {
            switch (forms.formsLayerType)
            {
            case UIFormsLayer.MainUILayer:
                if (IsAutoDepth)
                {
                    AutoCalculateDepth(forms, mCurMainUILayerDepth);
                }
                break;

            case UIFormsLayer.CommonUILayer:
            {
                if (forms.formsType == UIFormsType.Normal)
                {
                    //1.隐藏栈顶forms
                    if (mFormsStackIndex.ContainsKey(mCurStackFormsIndex))
                    {
                        string name = mFormsStackIndex[mCurStackFormsIndex];
                        if (mFormsDic.ContainsKey(name))
                        {
                            mFormsDic[name].Hide();
                        }
                    }

                    //2.如果存在栈中且不是位于栈顶(是否考虑栈顶的话就不做后面的操作),需要"Top"到栈顶
                    if (mFormsStackName.ContainsKey(formsName))
                    {
                        if (mFormsStackName[formsName] != mCurStackFormsIndex)
                        {
                            int tIndex = mFormsStackName[formsName];
                            for (int i = tIndex; i < mCurStackFormsIndex; i++)
                            {
                                mFormsStackIndex[i] = mFormsStackIndex[i + 1];
                                mFormsStackName[mFormsStackIndex[i]] = i;
                            }
                            mFormsStackIndex[mCurStackFormsIndex] = formsName;
                            mFormsStackName[formsName]            = mCurStackFormsIndex;
                        }
                    }
                    else
                    {
                        mCurStackFormsIndex++;
                        PushForms(formsName);
                    }

                    //3.移除Stack类型的窗口
                    if (mPopupFormsStack.Count > 0)
                    {
                        foreach (var item in mPopupFormsStack)
                        {
                            this.DestroyForms(item);
                        }
                        mPopupFormsStack.Clear();
                    }

                    //3.重置depth,
                    //这里可以考虑做成:假栈为空的时候,界面只剩下主界面的时候重置depth
                    //目前是做成:只显示一个normal型窗口,底下normal窗口隐藏,所以这里可以重置depth
                    //mCurFormsDepth = 1;
                }
                else if (forms.formsType == UIFormsType.Popup)
                {
                    if (!mPopupFormsStack.Contains(formsName))
                    {
                        mPopupFormsStack.Push(formsName);
                    }
                    else
                    {
                        NIDebug.LogWarning("*****************栈窗口已经有此窗口*******************");
                    }
                }

                if (IsAutoDepth)
                {
                    mCurCommonUILayerDepth = AutoCalculateDepth(forms, mCurCommonUILayerDepth);
                }
            }
            break;

            case UIFormsLayer.RewardLayer:
                break;

            case UIFormsLayer.TipLayer:
                break;

            case UIFormsLayer.NotifyLayer:
                break;

            case UIFormsLayer.GuideLayer:
                break;

            case UIFormsLayer.LoadingLayer:
                break;

            case UIFormsLayer.ServerLayer:
                break;

            default:
                break;
            }

            return(forms as T);
        }

        return(null);
    }
Beispiel #6
0
    private T _CreateForms <T>(string formsName, string prefabName) where T : UIBaseForms <MonoBehaviour>
    {
        string     path     = PREFABS_PATH + prefabName;
        GameObject prefabGo = Resources.Load(path) as GameObject;

        if (prefabGo == null)
        {
            NIDebug.LogWarning("**********************改路径下没有这个窗体预制体***************************");
            return(null);
        }

        GameObject go = GameObject.Instantiate(prefabGo) as GameObject;

        if (go == null)
        {
            return(null);
        }

        T formsScript = go.GetComponent <T>();

        if (formsScript == null)
        {
            formsScript = go.AddComponent <T>();
        }
        if (formsScript == null)
        {
            NIDebug.LogWarning("**********************不存在此脚本***************************");
            return(null);
        }

        go.name = formsName;
        Transform t = go.transform;

        switch (formsScript.formsLayerType)
        {
        case UIFormsLayer.MainUILayer:
            if (MainUILayerRoot != null)
            {
                t.parent = MainUILayerRoot.transform;
            }
            break;

        case UIFormsLayer.CommonUILayer:
            if (CommonUILayerRoot != null)
            {
                t.parent = CommonUILayerRoot.transform;
            }
            break;

        case UIFormsLayer.RewardLayer:
            break;

        case UIFormsLayer.TipLayer:
            break;

        case UIFormsLayer.NotifyLayer:
            break;

        case UIFormsLayer.GuideLayer:
            break;

        case UIFormsLayer.LoadingLayer:
            break;

        case UIFormsLayer.ServerLayer:
            break;

        default:
            if (mFormsUIRoot != null)
            {
                t.parent = mFormsUIRoot.transform;
            }
            break;
        }
        t.localPosition = Vector3.zero;
        t.localRotation = Quaternion.identity;
        t.localScale    = Vector3.one;

        mFormsDic.Add(formsName, formsScript);

        return(formsScript);
    }
Beispiel #7
0
    /// <summary>
    /// 关闭单个窗口
    /// </summary>
    public void CloseForms(string formsName)
    {
        if (string.IsNullOrEmpty(formsName))
        {
            return;
        }

        UIBaseForms <MonoBehaviour> forms = null;

        if (mFormsDic.TryGetValue(formsName, out forms))
        {
            switch (forms.formsLayerType)
            {
            case UIFormsLayer.MainUILayer:
                NIDebug.LogWarning("============MianUILayer类型的窗口不让关闭===============");
                return;

            case UIFormsLayer.CommonUILayer:
            {
                if (forms.formsType == UIFormsType.Normal)
                {
                    if (forms.formsLifeType == UIFormsLifeType.GoldLife)
                    {
                        forms.Hide();
                    }
                    else if (forms.formsLifeType == UIFormsLifeType.HumanLife)
                    {
                        DestroyForms(formsName);
                    }

                    PopForms(formsName);
                }
                else if (forms.formsType == UIFormsType.Popup)
                {
                    DestroyForms(formsName);
                }
            }
            break;

            case UIFormsLayer.RewardLayer:
                break;

            case UIFormsLayer.TipLayer:
                break;

            case UIFormsLayer.NotifyLayer:
                break;

            case UIFormsLayer.GuideLayer:
                break;

            case UIFormsLayer.LoadingLayer:
                break;

            case UIFormsLayer.ServerLayer:
                break;

            default:
                break;
            }
        }
    }