Ejemplo n.º 1
0
    /// <summary>
    /// 添加进grid
    /// </summary>
    void AddItemInGrid(int id, bool tail = true)
    {
        //添加到最后一个
        GameObject newGO = ResourcesMgr.Instance().PopPool(PrefabDefine.RECORD);

        newGO.transform.SetParent(contentTrans);
        newGO.transform.localScale = Vector3.one;
        if (tail)
        {
            //Debug.Log("添加到尾部:" + id);
            newGO.transform.localPosition = curPool[curPool.Count - 1].transform.localPosition - new Vector3(0, cellSize.y, 0);
            curHead++;
            curPool.Add(newGO);
        }
        else
        {
            //Debug.Log("添加到头部:" + id);
            newGO.transform.localPosition = curPool[0].transform.localPosition + new Vector3(0, cellSize.y, 0);
            curTail--;
            curPool.Insert(0, newGO);
        }
        newGO.name = "record_" + id;
        newGO.transform.Find("Text").GetComponent <Text>().text = Recyle.Instance().pathList[id];
        beginPos = contentTrans.localPosition;
    }
Ejemplo n.º 2
0
 /// <summary>
 /// 清空,放入资源池
 /// </summary>
 public void Clear()
 {
     for (int i = 0; i < curPool.Count; i++)
     {
         ResourcesMgr.Instance().PushPool(PrefabDefine.RECORD, curPool[i]);
     }
 }
Ejemplo n.º 3
0
    public override void Display()
    {
        this.gameObject.SetActive(true);
        int y     = 0;
        int yNode = 0;

        if (MainManager.Instance().curMouseHero)
        {
            y              = (int)MainManager.Instance().Idx2ListPos(MainManager.Instance().curMouseHero.mID).y;
            yNode          = MainManager.Instance().GetYNode();
            bgImage.sprite = ResourcesMgr.Instance().LoadResource <Sprite>(HERO_BG, true);
        }
        else if (MainManager.Instance().curMouseEnemy)
        {
            y              = (int)MainManager.Instance().Idx2ListPos(MainManager.Instance().curMouseEnemy.mID).y;
            yNode          = MainManager.Instance().GetYNode();
            bgImage.sprite = ResourcesMgr.Instance().LoadResource <Sprite>(ENEMY_BG, true);
        }

        if (y < yNode / 2)
        {
            mTransform.position = hidePos1;
            this.transform.DOMove(showPos1, 0.5f);
        }
        else
        {
            mTransform.position = hidePos2;
            this.transform.DOMove(showPos2, 0.5f);
        }
    }
Ejemplo n.º 4
0
        /// <summary>
        /// 加载指定名称的“UI窗体”
        /// 功能:
        ///    1:根据“UI窗体名称”,加载预设克隆体。
        ///    2:根据不同预设克隆体中带的脚本中不同的“位置信息”,加载到“根窗体”下不同的节点。
        ///    3:隐藏刚创建的UI克隆体。
        ///    4:把克隆体,加入到“所有UI窗体”(缓存)集合中。
        /// </summary>
        private UIBase LoadUIForm(string uiFormName)
        {
            string     strUIFormPaths   = null;           //UI窗体路径
            GameObject goCloneUIPrefabs = null;           //创建的UI克隆体预设
            UIBase     baseUiForm       = null;           //窗体基类


            //根据UI窗体名称,得到对应的加载路径
            _DicFormsPaths.TryGetValue(uiFormName, out strUIFormPaths);

            Debug.Log(strUIFormPaths);

            //根据“UI窗体名称”,加载“预设克隆体”
            if (!string.IsNullOrEmpty(strUIFormPaths))
            {
                goCloneUIPrefabs = ResourcesMgr.Instance().LoadAsset(strUIFormPaths, false);
            }

            //设置“UI克隆体”的父节点(根据克隆体中带的脚本中不同的“位置信息”)
            if (_TraCanvasTransfrom != null && goCloneUIPrefabs != null)
            {
                baseUiForm = goCloneUIPrefabs.GetComponent <UIBase>();
                if (baseUiForm == null)
                {
                    Debug.Log("baseUiForm==null! ,请先确认窗体预设对象上是否加载了baseUIForm的子类脚本! 参数 uiFormName=" + uiFormName);
                    return(null);
                }
                switch (baseUiForm.CurrentUIType.UIForms_Type)
                {
                case UIFormType.Normal:     //普通窗体节点
                    goCloneUIPrefabs.transform.SetParent(_TraNormal, false);
                    break;

                case UIFormType.Fixed:     //固定窗体节点
                    goCloneUIPrefabs.transform.SetParent(_TraFixed, false);
                    break;

                case UIFormType.PopUp:     //弹出窗体节点
                    goCloneUIPrefabs.transform.SetParent(_TraPopUp, false);
                    break;

                default:
                    break;
                }

                //设置隐藏
                goCloneUIPrefabs.SetActive(false);
                //把克隆体,加入到“所有UI窗体”(缓存)集合中。
                _DicALLUIForms.Add(uiFormName, baseUiForm);

                return(baseUiForm);
            }
            else
            {
                Debug.Log("_TraCanvasTransfrom==null Or goCloneUIPrefabs==null!! ,Plese Check!, 参数uiFormName=" + uiFormName);
            }

            Debug.Log("出现不可以预估的错误,请检查,参数 uiFormName=" + uiFormName);
            return(null);
        }//Mehtod_end
Ejemplo n.º 5
0
    /// <summary>
    /// 设置关卡,初始化图块数据
    /// </summary>
    /// <param name="level"></param>
    public void SetLevel(int level)
    {
        curLevel = level;
        string path = MAP_PATH + level;

        curMap = ResourcesMgr.Instance().LoadAsset(path, true);
        TiledMap map = curMap.GetComponent <TiledMap>();

        InitMapNode(map);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// 拖动过程中刷新UI
    /// </summary>
    void RefreshUI()
    {
        int needCount = Recyle.Instance().pathList.Count;

        //判断向上还是向下
        if (curPos.y > beginPos.y)
        {
            //Debug.Log("向下");
            if (curTail >= needCount - 1)
            {
                return;
            }
            int count = curPool.Count;
            int idx   = 0;
            for (int i = 0; i < count; i++)
            {
                if (curPos.y + curPool[idx].transform.localPosition.y >= 0)
                {
                    GameObject go = curPool[idx];
                    curPool.RemoveAt(idx);
                    ResourcesMgr.Instance().PushPool(PrefabDefine.RECORD, go);
                    AddItemInGrid(++curTail);
                }
                else
                {
                    return;
                }
            }
        }
        else if (curPos.y < beginPos.y)
        {
            //Debug.Log("向上");
            if (curHead <= 0)
            {
                return;
            }
            int   count  = curPool.Count;
            int   idx    = count - 1;
            float height = view.GetComponent <RectTransform>().sizeDelta.y;
            for (int i = count - 1; i >= 0; i--)
            {
                if (curPos.y + height + curPool[idx].transform.localPosition.y < cellSize.y)
                {
                    GameObject go = curPool[idx];
                    curPool.RemoveAt(idx);
                    ResourcesMgr.Instance().PushPool(PrefabDefine.RECORD, go);
                    AddItemInGrid(--curHead, false);
                }
                else
                {
                    return;
                }
            }
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// 初始化光标,定义初始位置跟idx,添加到鼠标移动事件
    /// </summary>
    private void InitMouseCursor()
    {
        GameObject prefab = ResourcesMgr.Instance().LoadResource <GameObject>(NORMALCURSOR_PATH, true);

        mouseCursor = Instantiate <GameObject>(prefab);
        //Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //pos.z = 0;
        //mouseCursor.transform.position = pos;
        //cursorIdx = Pos2Idx(pos);
        cursorIdx = HeroManager.Instance().GetHero(0).mID;
        mouseCursor.transform.position = Idx2Pos(cursorIdx);
        cursorAnimator = mouseCursor.GetComponent <Animator>();
    }
Ejemplo n.º 8
0
    /// <summary>
    /// 加载指定名称的“UI窗体”
    /// 功能:
    ///    1:根据“UI窗体名称”,加载预设克隆体。
    ///    2:根据不同预设克隆体中带的脚本中不同的“位置信息”,加载到“根窗体”下不同的节点。
    ///    3:隐藏刚创建的UI克隆体。
    ///    4:把克隆体,加入到“所有UI窗体”(缓存)集合中。
    /// </summary>
    /// <param name="uiFormName">UI窗体名称</param>
    private BaseUiFrame LoadUiForm(string uiFormName)
    {
        GameObject cloneUiPrefabs = null;             //创建的UI克隆体预设
        UiWind     uiWind         = (UiWind)Enum.Parse(typeof(UiWind), uiFormName);

        //根据UI窗体名称,得到对应的加载路径
        _dicFormsPaths.TryGetValue(uiWind, out string strUiFormPaths);
        //根据“UI窗体名称”,加载“预设克隆体”
        if (strUiFormPaths != null)
        {
            cloneUiPrefabs = ResourcesMgr.Instance().LoadAsset(strUiFormPaths, false);
        }
        //设置“UI克隆体”的父节点(根据克隆体中带的脚本中不同的“位置信息”)
        if (CanvasTrans != null && cloneUiPrefabs != null)
        {
            BaseUiFrame baseUiForm = cloneUiPrefabs.GetComponent <BaseUiFrame>();   //窗体基类
            if (baseUiForm == null)
            {
                Debug.Log("baseUiForm==null! ,请先确认窗体预设对象上是否加载了baseUIForm的子类脚本! 参数 uiFormName=" + uiFormName);
                return(null);
            }
            switch (baseUiForm.CurrentUiType.UiWindType)
            {
            case UiWindType.Normal:                     //普通窗体节点
                cloneUiPrefabs.transform.SetParent(_normalTrans, false);
                break;

            case UiWindType.Fixed:                      //固定窗体节点
                cloneUiPrefabs.transform.SetParent(_fixedTrans, false);
                break;

            case UiWindType.PopUp:                      //弹出窗体节点
                cloneUiPrefabs.transform.SetParent(_popUpTrans, false);
                break;
            }
            //设置隐藏
            cloneUiPrefabs.SetActive(false);
            //把克隆体,加入到“所有UI窗体”(缓存)集合中。
            _dicAllUiForms.Add(uiFormName, baseUiForm);
            return(baseUiForm);
        }
        else
        {
            Debug.Log("_TraCanvasTransfrom==null Or goCloneUIPrefabs==null!! ,Plese Check!, 参数uiFormName=" + uiFormName);
        }

        Debug.Log("出现不可以预估的错误,请检查,参数 uiFormName=" + uiFormName);
        return(null);
    }
Ejemplo n.º 9
0
    private void InitUI()
    {
        float viewHeight = view.GetComponent <RectTransform>().sizeDelta.y;

        cellSize = contentTrans.GetComponent <GridLayoutGroup>().cellSize;
        float cellHeight = cellSize.y;
        //view能容纳个数
        float count = viewHeight / cellHeight;
        //根据需要加载个数
        int needCount = Recyle.Instance().pathList.Count;

        //根据需要加载个数初始化contentsize
        contentTrans.GetComponent <RectTransform>().sizeDelta = new Vector2(0, needCount * cellHeight);
        if (count - (int)count > 0)
        {
            count = (int)count + 1;
        }
        //实际需要
        int realCount = 0;

        if (needCount >= (int)count)
        {
            realCount = (int)count;
        }
        else
        {
            realCount = needCount;
        }

        for (int i = 0; i < realCount; i++)
        {
            GameObject go = ResourcesMgr.Instance().PopPool(PrefabDefine.RECORD);
            go.name = "record_" + i;
            go.transform.SetParent(contentTrans);
            go.transform.localScale = Vector3.one;
            go.transform.Find("Text").GetComponent <Text>().text = Recyle.Instance().pathList[i];

            Button btn = go.GetComponent <Button>();
            btn.onClick.AddListener(delegate()
            {
                OnClickRecord(go);
            });
        }
        curHead = 0;
        curTail = (int)count - 1;
    }
Ejemplo n.º 10
0
    public GameObject GetPool(string name, Vector3 pos)
    {
        GameObject obj;

        if (objPool.ContainsKey(name) && objPool[name].Count > 0)
        {
            obj = objPool[name][0];
            objPool[name].RemoveAt(0);
        }
        else if (objPool.ContainsKey(name) && objPool[name].Count == 0)
        {
            //obj = Instantiate(Resources.Load(name)) as GameObject;
            obj = ResourcesMgr.Instance().LoadAsset(name, true);
        }
        else
        {
            obj = ResourcesMgr.Instance().LoadAsset(name, true);
            //obj = Instantiate(Resources.Load(name)) as GameObject;
            objPool.Add(name, new List <GameObject>());
        }
        obj.SetActive(true);
        obj.transform.position = pos;
        return(obj);
    }
Ejemplo n.º 11
0
 //初始化加载(根UI窗体)Canvas预设
 private void InitRootCanvasLoading()
 {
     ResourcesMgr.Instance().LoadAsset("ResUi/Canvas", false);
 }
Ejemplo n.º 12
0
 //初始化加载(根UI窗体)Canvas预设
 private void InitRootCanvasLoading()
 {
     Debug.Log("初始化加载canvas");
     m_Canvas = ResourcesMgr.Instance().LoadAsset(SysDefine.SYS_PATH_CANVAS, false).GetComponent <Canvas>();
 }