Exemple #1
0
    /// <summary>
    /// 创建UI
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="uiName"></param>
    /// <returns></returns>
    public T CreateUI <T>(string uiName, int layer = -1) where T : BaseUIComponent
    {
        //GameObject uiModel = LoadAssetUtil.SyncLoadAsset<GameObject>("ui/ui", uiName);
        BaseUIComponent uiModel = LoadResourcesUtil.SyncLoadData <BaseUIComponent>($"UI/{uiName}");

        if (uiModel)
        {
            Transform  tfContainer    = GetUITypeContainer(UITypeEnum.UIBase);
            GameObject objUIComponent = Instantiate(tfContainer.gameObject, uiModel.gameObject);
            objUIComponent.SetActive(false);
            objUIComponent.name = objUIComponent.name.Replace("(Clone)", "");
            if (layer >= 0)
            {
                //设置层级
                objUIComponent.transform.SetSiblingIndex(layer);
            }
            T uiComponent = objUIComponent.GetComponent <T>();
            uiList.Add(uiComponent);
            return(uiComponent);
        }
        else
        {
            LogUtil.LogError("没有找到指定UI:" + "UI/" + uiName);
            return(null);
        }
    }
    /// <summary>
    /// 获取区域类型模型
    /// </summary>
    /// <param name="areaType"></param>
    /// <param name="modelName"></param>
    /// <returns></returns>
    public GameObject GetAreaTypeModel(AreaTypeEnum areaType, string modelName)
    {
        //根据不同的地块生成不同的资源
        if (dicModel.TryGetValue(modelName, out GameObject value))
        {
            return(value);
        }
        string path = "";

        switch (areaType)
        {
        case AreaTypeEnum.Base:
            path = Path_AreaType_Base;
            break;

        case AreaTypeEnum.Null:
        case AreaTypeEnum.BaseInit:
            path = Path_AreaType_Null;
            break;

        case AreaTypeEnum.Building:
            path = Path_AreaType_Building;
            break;

        case AreaTypeEnum.Gold:
            path = Path_AreaType_Gold;
            break;
        }
        GameObject objModel = LoadResourcesUtil.SyncLoadData <GameObject>(path + "/" + modelName);

        dicModel.Add(modelName, objModel);
        return(objModel);
    }
    /// <summary>
    /// 通过UI的名字开启UI
    /// </summary>
    /// <param name="uiName"></param>
    public BaseUIComponent OpenUIByName(string uiName)
    {
        BaseUIComponent uiComponent = null;

        if (uiList == null || CheckUtil.StringIsNull(uiName))
        {
            return(uiComponent);
        }
        bool hasData = false;

        for (int i = 0; i < uiList.Count; i++)
        {
            BaseUIComponent itemUI = uiList[i];
            if (itemUI.name.Contains(uiName))
            {
                itemUI.OpenUI();
                hasData = true;
            }
        }
        if (!hasData)
        {
            BaseUIComponent uiModel = LoadResourcesUtil.SyncLoadData <BaseUIComponent>("UI/" + uiName);
            if (uiModel)
            {
                GameObject objUIComponent = Instantiate(objUIContainer, uiModel.gameObject);
                uiComponent = objUIComponent.GetComponent <BaseUIComponent>();
                uiList.Add(uiComponent);
            }
            else
            {
                LogUtil.LogError("没有找到指定UI:" + "Resources/UI/" + uiName);
            }
        }
        return(uiComponent);
    }
Exemple #4
0
    /// <summary>
    ///  读取控件
    /// </summary>
    /// <param name="itemName"></param>
    /// <returns></returns>
    protected GameObject LoadItem(string itemName)
    {
        GameObject objItemModel = LoadResourcesUtil.SyncLoadData <GameObject>($"UI/GameSetting/{itemName}");
        GameObject objItem      = UIHandler.Instance.Instantiate(objListContainer, objItemModel);

        return(objItem);
    }
Exemple #5
0
    /// <summary>
    /// 加载toast容器
    /// </summary>
    public void LoadToastListContainer()
    {
        //加载Toast容器
        GameObject toastListModel = LoadResourcesUtil.SyncLoadData <GameObject>("UI/ToastList");
        GameObject objToastList   = Instantiate(gameObject, toastListModel);

        objToastContainer = CptUtil.GetCptInChildrenByName <Transform>(objToastList, "Container").gameObject;
    }
    /// <summary>
    /// 初始化UI
    /// </summary>
    public void InitUI()
    {
        GameObject uiContainerModel = LoadResourcesUtil.SyncLoadData <GameObject>("UI/Base/UIContainer");

        //实例化UI容器
        objUIContainer = Instantiate(gameObject, uiContainerModel);
        //初始化所有UI容器
        InitUIType();
        //修改一些摄像机
        InitCanvasCamera();
    }
Exemple #7
0
    public override void Awake()
    {
        base.Awake();
        //获取渲染摄像头
        GameObject objRenderModel = LoadResourcesUtil.SyncLoadData <GameObject>("UI/Render/RenderCharacterUI");

        //实例化渲染
        objRender = Instantiate(UIHandler.Instance.manager.GetUITypeContainer(UITypeEnum.Model3D).gameObject, objRenderModel);
        //获取展示的角色
        showCharacter = objRender.GetComponentInChildren <CreatureCptCharacter>();

        ui_RotateLeft.AddLongClickListener(OnLongClickForRoateR);
        ui_RotateRight.AddLongClickListener(OnLongClickForRoateL);
    }
    /// <summary>
    /// 基础-读取列表数据
    /// </summary>
    /// <param name="fileName"></param>
    /// <returns></returns>
    public List <T> BaseLoadDataForList(string fileName)
    {
        if (fileName == null)
        {
            LogUtil.Log("读取文件失败-没有文件名称");
            return(null);
        }
        TextAsset textAsset = LoadResourcesUtil.SyncLoadData <TextAsset>($"JsonText/{fileName}");

        //string strData = FileUtil.LoadTextFile(dataStoragePath + "/" + fileName);
        if (textAsset == null || textAsset.text == null)
        {
            return(null);
        }
        List <T> listData = JsonUtil.FromJsonByNet <List <T> >(textAsset.text);

        return(listData);
    }
Exemple #9
0
    protected T GetModelForResources <T>(Dictionary <string, T> listModel, string resPath) where T : UnityEngine.Object
    {
        if (name == null)
        {
            return(null);
        }
        if (listModel.TryGetValue(name, out T value))
        {
            return(value);
        }

        T model = LoadResourcesUtil.SyncLoadData <T>(resPath);

        if (model != null)
        {
            listModel.Add(name, model);
        }
        return(model);
    }