Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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;
        }
    }
Exemplo n.º 4
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());
    }
Exemplo n.º 5
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);
    }
Exemplo n.º 6
0
    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);
    }
Exemplo n.º 7
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();
    }