Beispiel #1
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽列表项相关∽-★-∽--------∽-★-∽------∽-★-∽--------//

        //创建列表项
        protected GameObject CreateItem(int index_)
        {
            if (m_index2item.ContainsKey(index_))
            {
                return(m_index2item[index_]);
            }

            GameObject item;

            if (m_itemPool.Count > 0)
            {
                item = ListUtil.Pop(m_itemPool);  //先从池里拿
            }
            else
            {
                item = GameObjUtil.Instantiate(m_itemTemp);
                GameObjUtil.ChangeParent(item, m_contentGo);
            }

            m_index2item[index_] = item;
            item.SetActive(true);
            item.name = "item(" + index_ + ")";

            LayItem(index_, item);
            return(item);
        }
Beispiel #2
0
        void Initialize()
        {
            base.onValueChanged.AddListener(OnValueChanged);

            m_checkmarkGo = GameObjUtil.FuzzySearchChild(this.gameObject, "checkmark");
            m_backGo      = GameObjUtil.FuzzySearchChild(this.gameObject, "back");
        }
Beispiel #3
0
    void OnKeyPress(object evt_)
    {
        KeyCode key = (KeyCode)evt_;

        switch (key)
        {
        case KeyCode.Keypad1:
            m_listView.JumpToIndex(11, KListViewScroll.JumpPosType.BOTTOM);
            break;

        case KeyCode.Keypad2:
            m_listView.JumpToIndex(5, KListViewScroll.JumpPosType.CENTER);
            break;

        case KeyCode.Keypad3:
            m_listView.JumpToIndex(14, KListViewScroll.JumpPosType.TOP);
            break;

        case KeyCode.Keypad4:

            GameObjUtil.RemoveFromParent(m_btnOk.gameObject);

            break;

        case KeyCode.Keypad5:

            GameObjUtil.ChangeParent(m_btnOk.gameObject, m_panel);

            break;

        default:
            break;
        }
    }
Beispiel #4
0
    public TestPop4()
    {
        m_popId    = POP_ID.TEST_POP_4;
        m_layerIdx = POP_LAYER_IDX.LAYER_POP_1;

        ShowGameObject();

        //
        m_btnOk    = GetChildByName <KButton>("Button_Ok", true);
        m_btnClose = GetChildByName <KButton>("Button_Close", true);

        m_panel = GameObjUtil.GetParent(m_btnOk.gameObject);

        //
        m_inputName      = GetChildByName <KInputField>("Input_name", true);
        m_labelTestInput = GetChildByName <KText>("Label_testInput", true);
        //
        m_tgl_1      = GetChildByName <KToggle>("Toggle_position1", true);
        m_labelTgl_1 = GetChildByName <KText>(m_tgl_1.gameObject, "Label_Text", true);
        m_tglGroup_1 = GetChildByName <KToggleGroup>("ToggleGroup_a1", true);
        //
        m_sliderSchedule = GetChildByName <KSlider>("Slider_Schedule1", true);
        m_labelSchedule  = GetChildByName <KText>("Label_testSilder", true);
        //
        m_barLoading = GetChildByName <KProgressBar>("ProgressBar_loading", true);
        //
        m_icon = GetChildByName <KImage>("Image_sharedAnchor", true);
        //
        m_scrollView = GetChildByName <KScrollView>("ScrollView_GuildList", true);
        m_listView   = ComponentUtil.EnsureComponent <KListViewScroll>(m_scrollView.gameObject);
    }
Beispiel #5
0
    //-------∽-★-∽------∽-★-∽--------∽-★-∽ListView∽-★-∽--------∽-★-∽------∽-★-∽--------//


    void ShowListView()
    {
        GameObject container = GameObjUtil.FindChild(m_scrollViewItemList.gameObject, "Image_mask/Container_content");

        List <int> datas = new List <int>();
        int        num   = 10;

        for (int i = 0; i < num; ++i)
        {
            datas.Add(i);
        }

        m_listView = ComponentUtil.EnsureComponent <KListView>(container);
        m_listView.itemViewType = typeof(Item1);
        m_listView.onDataChanged.AddListener(UpdateListItem);


        LayoutParam param = m_listView.layoutParam;

        //param.padding = new Padding(20, 20, 20, 20);
        param.itemGap = new Vector2(10, 50);
        //param.divNum = 2;


        m_listView.ShowList(datas);
    }
Beispiel #6
0
    //-------∽-★-∽------∽-★-∽--------∽-★-∽Layout∽-★-∽--------∽-★-∽------∽-★-∽--------//

    void ShowLayout()
    {
        LayoutParam param = new LayoutParam {
        };

        param.padding = new Padding(20, 20, 20, 20);
        param.itemGap = new Vector2(50, 50);
        param.divNum  = 2;

        GameObject itemGo    = GameObjUtil.FindChild(m_scrollViewItemList.gameObject, "Image_mask/Container_content/Container_Item");
        GameObject container = GameObjUtil.GetParent(itemGo);

        itemGo.SetActive(false);

        for (var i = 0; i < 10; ++i)
        {
            GameObject item = GameObjUtil.Instantiate(itemGo);

            item.SetActive(true);
            GameObjUtil.ChangeParent(item, container);

            LayoutUtil.LayItem(param, i, item);

            m_idx2item[i] = item;
        }
    }
Beispiel #7
0
        protected override void __Initialize()
        {
            m_scrollable = true;

            m_maskTrans = GetChildComponent <RectTransform>("Image_mask");    //遮罩

            GameObject contentGo = GameObjUtil.FuzzySearchChild(m_maskTrans.gameObject, "content");

            m_contentTrans = contentGo.GetComponent <RectTransform>();
            m_contentTrans.anchoredPosition = Vector2.zero;
            m_contentTrans.sizeDelta        = new Vector2(m_maskTrans.rect.width, m_maskTrans.rect.height);

            m_scrollRect = ComponentUtil.EnsureComponent <ScrollRect>(this.gameObject);
            RefreshScrollRectSetting();
            m_scrollRect.viewport = m_maskTrans;
            m_scrollRect.content  = m_contentTrans;

            if (GetChild("Container_arrow") != null)
            {
                //有箭头
                m_scrollArrow = AddChildComponent <KScrollViewArrow>("Container_arrow");
            }

            m_scrollRect.onValueChanged.AddListener(OnInternalValueChanged);
        }
Beispiel #8
0
        protected void AddItemAt(Type itemType, object data, int index, bool doLayoutImmediately = true)
        {
            if (m_isExecutingCoroutine == true)
            {
                Log.Error("有尚未执行完毕的协程~~", this);
                return;
            }

            //要改成循环利用

            GameObject go = GameObjUtil.Instantiate(m_itemTemplate);

            go.transform.SetParent(this.transform);
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = Vector3.zero;
            go.SetActive(true);


            //BuildItem(go);
            KListItem item = ComponentUtil.EnsureComponent(go, itemType) as KListItem;

            item.Index = index;
            item.name  = GenerateItemName(index);
            AddItemEventListener(item);
            m_itemList.Insert(index, item);

            item.SetData(data);   //设置数据

            if (doLayoutImmediately)
            {
                RefreshAllItemLayout();
            }
        }
Beispiel #9
0
    void ClearLayout()
    {
        foreach (var kvp in m_idx2item)
        {
            GameObjUtil.Delete(kvp.Value);
        }

        m_idx2item.Clear();
    }
Beispiel #10
0
 public void Despawn()
 {
     while (spawnedList.Count > 0)
     {
         GameObjectContainer toDespawn = spawnedList[0];
         spawnedList.RemoveAt(0);
         GameObjUtil.Destroy(toDespawn.gameObject);
     }
 }
Beispiel #11
0
    int m_clickCntMax = 3;  //关闭需要的点击次数

    public PopErrorReport()
    {
        m_popId    = POP_ID.ERROR_REPORT;
        m_layerIdx = POP_LAYER_IDX.LAYER_TOP;

        ShowGameObject();


        m_btn  = GetChildByName <KButton>("Container_ErrorReport/Container_Panel/Button_Center");
        m_text = GameObjUtil.FindChlid <KText>(m_btn.gameObject, "Label_Text");
    }
Beispiel #12
0
        protected override void __Initialize()
        {
            m_contentGo = gameObject;

            m_itemTemp = GameObjUtil.FuzzySearchChild(m_contentGo, "item"); //只查找一层
            m_itemTemp.SetActive(false);                                    //隐藏掉模板

            RectTransform rectTrans = m_itemTemp.GetComponent <RectTransform>();

            m_layoutParam.itemSize = rectTrans.sizeDelta;
            m_layoutParam.pivot    = rectTrans.pivot;
        }
 public virtual void despawnAll()
 {
     foreach (string s in spawned.Keys)
     {
         if (spawned[s] != null)
         {
             GameObjUtil.Destroy(spawned[s]);
         }
     }
     spawned.Clear();
     count = 0;
 }
Beispiel #14
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (collisionState.colliderStatus[starPickup])
     {
         Collider2D[] collArr = collisionState.collidingMembers[starPickup];
         foreach (Collider2D coll in collArr)
         {
             GameObjUtil.Destroy(coll.gameObject);
             currentCollected++;
         }
     }
 }
Beispiel #15
0
        protected override void __ShowGameObject()
        {
            base.__ShowGameObject();

            GameObjUtil.ChangeParent(m_gameObject, KUIApp.UILayer);
            m_gameObject.SetActive(true);

            m_canvas                  = m_gameObject.GetComponent <Canvas>();
            m_canvas.worldCamera      = KUIApp.UICamera;
            m_canvas.sortingLayerName = m_sortingLayer.ToString();
            m_canvas.sortingOrder     = m_sortingOrder;
            m_canvas.planeDistance    = m_planeDistance;
        }
Beispiel #16
0
 public void Despawn(string name)
 {
     for (int i = 0; i < spawnedList.Count; i++)
     {
         GameObjectContainer goc = spawnedList[i];
         if (string.Compare(goc.name, name) == 0)
         {
             spawnedList.RemoveAt(i);
             GameObjUtil.Destroy(goc.gameObject);
             i--;
         }
     }
 }
Beispiel #17
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽KList∽-★-∽--------∽-★-∽------∽-★-∽--------//



        override protected void __Initialize()
        {
            m_itemList        = new List <KListItem>();
            m_isSupportSingle = true;

            m_itemTemplate = GameObjUtil.FuzzySearchChild(gameObject, "item"); //只查找一层
            m_itemTemplate.SetActive(false);                                   //隐藏掉魔板

            if (m_itemSize == Vector2.zero)
            {
                m_itemSize = m_itemTemplate.GetComponent <RectTransform>().sizeDelta;
            }
        }
 public virtual bool despawn(string objstr)
 {
     Debug.Log(objstr);
     if (spawned.ContainsKey(objstr))
     {
         if (spawned[objstr] != null)
         {
             GameObjUtil.Destroy(spawned[objstr]);
         }
         spawned.Remove(objstr);
         count--;
         return(true);
     }
     return(false);
 }
Beispiel #19
0
    // Update is called once per frame
    IEnumerator EnemyGenerator()
    {
        yield return(new WaitForSeconds(delay));

        if (active)
        {
            var newTransform = transform;
            var perfab       = prefabs[Random.Range(0, prefabs.Length)];
            if (perfab.gameObject.CompareTag("ObstacleStone"))
            {
                stoneNum++;
            }
            GameObjUtil.Instantiate(perfab, newTransform.position);
            ResetDelay();
        }
        StartCoroutine(EnemyGenerator());
    }
Beispiel #20
0
    public void Despawn(GameObject go)
    {
        int removeIndex = -1;

        for (int i = 0; i < spawnedList.Count; i++)
        {
            GameObjectContainer goc = spawnedList[i];
            if (go == goc.gameObject)
            {
                removeIndex = i;
            }
        }
        if (removeIndex >= 0)
        {
            GameObjectContainer toRemove = spawnedList[removeIndex];
            spawnedList.RemoveAt(removeIndex);
            GameObjUtil.Destroy(toRemove.gameObject);
        }
    }
Beispiel #21
0
    public GameObject Spawn(string name, Vector3 position)
    {
        GameObject toSpawn = null;

        foreach (PrefabContainer prefab in prefabs)
        {
            if (string.Compare(name, prefab.name) == 0)
            {
                toSpawn = prefab.prefab;
            }
        }
        if (toSpawn != null)
        {
            GameObject          go  = GameObjUtil.Instantiate(toSpawn, position);
            GameObjectContainer goc = new GameObjectContainer(name, go);
            spawnedList.Add(goc);
            return(go);
        }
        return(null);
    }
Beispiel #22
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽Prefab∽-★-∽--------∽-★-∽------∽-★-∽--------//

        //生成预制
        static void GenPrefabs(GameObject root, bool isBuildAssetBundle)
        {
            Dictionary <GameObject, GameObject> go2parent = null;    //记录父节点,方便还原

            //List<GameObject> toGenerate = GetPrefabList(root, jsonName);
            List <GameObject> toGenerate = GetPrefabList(root, root.name);

            for (int i = toGenerate.Count - 1; i >= 0; --i)
            {
                GameObject go = toGenerate[i];
                if (go.transform.parent)
                {
                    //需要export
                    GameObject parent = go.transform.parent.gameObject;

                    if (go2parent == null)
                    {
                        go2parent = new Dictionary <GameObject, GameObject>();
                    }
                    go2parent[go] = parent;

                    var pos = go.GetComponent <RectTransform>().anchoredPosition3D;
                    go.transform.parent = null; //放到根目录
                    go.GetComponent <RectTransform>().anchoredPosition3D = pos;
                }

                //保存预制文件
                CreatePrefabFile(go, isBuildAssetBundle);
            }

            if (go2parent != null)
            {
                List <KeyValuePair <GameObject, GameObject> > list = new List <KeyValuePair <GameObject, GameObject> >(go2parent);
                list.Reverse();
                foreach (var kvp in list)
                {
                    //移回原来的地方,这样比较方便写界面逻辑
                    GameObjUtil.ChangeParent(kvp.Key, kvp.Value);
                }
            }
        }
Beispiel #23
0
        static List <int> __delList = new List <int>();    //需要删除的序号



        protected override void __Initialize()
        {
            m_scrollView = ComponentUtil.EnsureComponent <KScrollView>(this.gameObject);

            m_maskTrans = m_scrollView.maskTrans;

            m_contentTrans       = m_scrollView.contentTrans;
            m_contentSizeDefault = m_contentTrans.sizeDelta;      //content的默认尺寸(实际size不能比这个小)
            m_contentGo          = m_contentTrans.gameObject;

            m_itemTemp = GameObjUtil.FuzzySearchChild(m_contentGo, "item"); //只查找一层
            m_itemTemp.SetActive(false);                                    //隐藏掉模板

            //KListView a1 = gameObject.GetComponent<KListView>();
            //Component a2 = gameObject.GetComponent("mg.org.KUI.KListView");

            RectTransform rectTrans = m_itemTemp.GetComponent <RectTransform>();

            m_layoutParam.itemSize = rectTrans.sizeDelta;
            m_layoutParam.pivot    = rectTrans.pivot;
        }
Beispiel #24
0
        override protected void __Initialize()
        {
            GameObject arrowGo = GameObjUtil.FuzzySearchChild(gameObject, "arrow");

            if (arrowGo != null)
            {
                m_pageArrow = ComponentUtil.EnsureComponent <KScrollPageArrow> (arrowGo);
            }

            GameObject displayer = GameObjUtil.FuzzySearchChild(gameObject, "pager");

            if (displayer != null)
            {
                m_pageDisplayer = ComponentUtil.EnsureComponent <KScrollPageDisplayer>(displayer);
            }

            m_pageTrans = GetChildComponent <RectTransform>("Image_mask");

            GameObject contentGo = GameObjUtil.FuzzySearchChild(m_pageTrans.gameObject, "content");

            m_contentTrans = contentGo.GetComponent <RectTransform>();
        }
Beispiel #25
0
        //获取ui实际输出的预制列表(有export标记的独立输出)
        static List <GameObject> GetPrefabList(GameObject root, string parentPanelName)
        {
            string export_flag = "export";

            List <GameObject> ret = new List <GameObject>();

            ret.Add(root);  //默认添加根对象

            List <GameObject> toExport = new List <GameObject>();

            GameObjUtil.FuzzySearchChildren(root, export_flag, ref toExport);  //名称有export就是额外导出
            //toExport.Clear();
            foreach (GameObject go in toExport)
            {
                int start = go.name.IndexOf(export_flag);  //Container_exportPart2

                //string name = go.name.Substring(0, start) + go.name.Substring(start + 6) + "__" + parentPanelName;
                string name = parentPanelName + "__" + go.name.Substring(0, start) + go.name.Substring(start + export_flag.Length);  //Canvas_Bag__Container_Part2
                go.name = name;
                ret.Add(go);
            }
            return(ret);
        }
    public virtual GameObject spawn(int i)
    {
        GameObject thisPrefab = prefabs[i];
        string     prefabName = thisPrefab.name;
        float      spawnprob  = prefabProb[i];
        GameObject spawngo    = null;
        float      floatroll  = Random.Range(0f, 1f);

        if (floatroll < spawnprob)
        {
            thisPrefab.name = prefabName + count.ToString();
            spawngo         = GameObjUtil.Instantiate(thisPrefab, this.transform.position);
        }
        if (spawngo != null)
        {
            if (!spawned.ContainsKey(spawngo.name))
            {
                spawned.Add(spawngo.name, spawngo);
                count++;
            }
        }
        thisPrefab.name = prefabName;
        return(spawngo);
    }
Beispiel #27
0
    //-------∽-★-∽------∽-★-∽--------∽-★-∽数据操作∽-★-∽--------∽-★-∽------∽-★-∽--------//

    private void Test_LoadBundle()
    {
        string[] dependPaths = new string[] {
            "StreamingAssets/depend.j",
        };

        string[] bundlePaths = new string[] {
            "StreamingAssets/canvas_bag.j",
            "StreamingAssets/canvas_test3.j",
        };

        List <AssetBundle> bundleList = new List <AssetBundle>();

        foreach (string path in dependPaths)
        {
            AssetBundle b = AssetBundle.LoadFromFile(Application.dataPath + "/" + path);
            bundleList.Add(b);
        }

        AssetBundle bundle1 = AssetBundle.LoadFromFile(Application.dataPath + "/" + bundlePaths[1]);

        bundleList.Add(bundle1);

        GameObject prefab = bundle1.LoadAsset("canvas_test3") as GameObject;

        GameObject go = GameObjUtil.Instantiate(prefab);

        GameObjUtil.ChangeParent(go, KUIApp.UILayer);

        //需要全部卸载掉才能重新加载, 不然会报错
        foreach (var b in bundleList)
        {
            b.Unload(false);
        }
        Resources.UnloadUnusedAssets();
    }
Beispiel #28
0
 public void OutofBounds()
 {
     outofBound = false;
     GameObjUtil.Destory(gameObject);
 }
Beispiel #29
0
    void OnKeyPress(object evt_)
    {
        KeyCode key = (KeyCode)evt_;

        switch (key)
        {
        case KeyCode.RightArrow:

            //m_inputName.GainFocus();
            AppExp(5);
            SprAtlasCache.me.UnloadSprite("npc1026");

            break;

        case KeyCode.LeftArrow:

            SubExp(5);
            SprAtlasCache.me.LoadSprite(this, m_icon1, "npc1026", "npc1026_mini", true);

            break;

        case KeyCode.UpArrow:

            Log.Debug(m_icon1 != null ? "还活着" : "挂了");

            break;

        case KeyCode.DownArrow:

            GameObjUtil.Delete(m_icon1.gameObject);

            break;

        case KeyCode.Keypad1:

            m_listViewScroll.JumpToIndex(4, KListViewScroll.JumpPosType.TOP);

            break;

        case KeyCode.Keypad2:

            m_listViewScroll.JumpToIndex(4, KListViewScroll.JumpPosType.CENTER);

            break;

        case KeyCode.Keypad3:

            //m_listViewScroll.JumpToIndex(4, KListViewScroll.JumpPosType.BOTTOM);
            m_listViewScroll.JumpToTop();
            break;

        case KeyCode.Keypad4:

            List <int> datas = new List <int>();
            int        num   = 5;
            for (int i = 0; i < num; ++i)
            {
                datas.Add(i);
            }

            m_listViewScroll.ShowList(datas);

            break;
        }
    }