示例#1
0
    public GameObject CreateUI(string _name, RectTransform _parent)
    {
        MyUnityUIGroup group = FindUI(_name);

        if (group != null)
        {
            Debug.LogError("沒有該UI的資料! : " + _name);
            return(group.GameObject);
        }
        //從UI資料夾中取得資料
        GameObject go = LoadFactory.Instance.LoadAndInstantiateGameObject(_name, "UI");

        if (go != null)
        {
            go.SetActive(true);
            MyUnityUIGroup ui = go.GetComponent <MyUnityUIGroup>();
            if (ui != null)
            {
                ui.Transform.SetParent(_parent);
                ui.Transform.sizeDelta     = Vector2.zero;
                ui.Transform.localScale    = new Vector3(1.0f, 1.0f, 1.0f);
                ui.Transform.localPosition = Vector3.zero;

                ui.Transform.anchoredPosition = Vector3.zero;
                uiPool.Add(_name, ui);
            }
        }
        return(go);
    }
示例#2
0
 /// <summary>
 /// 將已經召喚的物件納入物件池中
 /// </summary>
 /// <param name="_ui"></param>
 /// <returns></returns>
 public bool LoginUI(MyUnityUIGroup _ui, CanvasType _type)
 {
     _ui.Transform.SetParent(GetCanvasByFrequence(_type).Transform);
     if (uiPool.ContainsValue(_ui))
     {
         return(false);
     }
     uiPool.Add(_ui.name, _ui);
     return(true);
 }
    /// <summary>
    /// 讀取根UI,可以放在Start函式中
    /// </summary>
    protected virtual void LoadRootUI(string _objectName, UIFactory.CanvasType _type)
    {
        var go = UIFactory.Instance.CreateUI(_objectName, _type);

        myRootUI = go.GetComponent <MyUnityUIGroup>();
    }
示例#4
0
 /// <summary>
 /// 手動新增子物件(根物件)
 /// </summary>
 public void AddUIMember(MyUnityUIGroup _root)
 {
     _root.GameObject.transform.SetParent(Transform);
 }