manageRecycleBin() public static method

tells TrashMan to start managing the recycle bin at runtime
public static manageRecycleBin ( TrashManRecycleBin, recycleBin ) : void
recycleBin TrashManRecycleBin, Recycle bin.
return void
コード例 #1
0
    public void createTree()
    {
        TrashManRecycleBin bin = new TrashManRecycleBin();

        bin.instancesToPreallocate = 20;
        bin.prefab     = ballPrefab.gameObject;
        ballPrefab.tag = ObjectType.Player;
        TrashMan.manageRecycleBin(bin);
        Rectangle bound = new Rectangle(0, 0, 800, 480);

        quardTree = new QuardTree(bound, 0);
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                ObjectView objectView = TrashMan.spawn(ballPrefab.gameObject).GetComponent <ObjectView>();
                Rectangle  rect       = new Rectangle(200 + i * 50, 120 + j * 50, 20, 20);
                //Rectangle rect = new Rectangle(i * 50, j * 50, 20, 20);
                objectView.setCollisionHandler(rect);
                //objectView.transform.SetParent(this.transform, false);
                Vector3 localPotion = new Vector3(objectView.rect.center.x, objectView.rect.center.y, 0);
                objectView.transform.localPosition = localPotion;
                quardTree.Insert(objectView.rect);
            }
        }
        drawQuardTree(quardTree);
    }
コード例 #2
0
ファイル: DemoUI.cs プロジェクト: zsombornagy/RecyclerKit
    void CreateCanvas()
    {
        if (!_didCreateUiStuff)
        {
            _didCreateUiStuff = true;
            //Create the UI canvas game object
            canvasRoot = new GameObject("Canvas");
            var canvas = canvasRoot.AddComponent <Canvas>();
            canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            var cs = canvasRoot.AddComponent <CanvasScaler>();
            cs.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            cs.screenMatchMode     = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
            cs.referenceResolution = new Vector2(800, 600);

            //create our ui prefab
            uiPrefab = new GameObject("UItxt");
            uiPrefab.transform.position = new Vector3(1000, 10000);
            var txt = uiPrefab.AddComponent <Text>();
            txt.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
            txt.text = "Some text";
            txt.horizontalOverflow = HorizontalWrapMode.Overflow;
            txt.color = Color.white;
            txt.resizeTextForBestFit = true;

            //Make a recycle bin for it
            var recycleBin = new TrashManRecycleBin()
            {
                prefab = uiPrefab
            };
            TrashMan.manageRecycleBin(recycleBin);
        }
    }
コード例 #3
0
ファイル: DemoUI.cs プロジェクト: githysm/RecyclerKit
    void OnGUI()
    {
        if (GUILayout.Button("Spawn Cube"))
        {
            var newObj = TrashMan.spawn(cubePrefab, Random.onUnitSphere * 5f, Random.rotation);
            TrashMan.despawnAfterDelay(newObj, Random.Range(1f, 2f));
        }


        if (GUILayout.Button("Spawn Sphere"))
        {
            var newObj = TrashMan.spawn(spherePrefab, Random.onUnitSphere * 3f);

            // spheres have a hardLimit set so we need to null check before using them
            if (newObj)
            {
                newObj.transform.parent = transform;
                TrashMan.despawnAfterDelay(newObj, Random.Range(5f, 8f));
            }
        }


        if (GUILayout.Button("Spawn Light from Scene"))
        {
            var newObj = TrashMan.spawn("light", Random.onUnitSphere * 10f);

            if (newObj)
            {
                newObj.transform.parent = transform;
                TrashMan.despawnAfterDelay(newObj, Random.Range(5f, 8f));
            }
        }


        if (GUILayout.Button("Spawn Particles by GameObject Name"))
        {
            TrashMan.spawn("Particles", Random.onUnitSphere * 3f);
        }


        if (GUILayout.Button("Create Recycle Bin at Runtime"))
        {
            _didCreateCapsuleRecycleBin = true;
            var recycleBin = new TrashManRecycleBin()
            {
                prefab = capsulePrefab
            };
            TrashMan.manageRecycleBin(recycleBin);
        }


        if (_didCreateCapsuleRecycleBin && GUILayout.Button("Spawn Capsule"))
        {
            var newObj = TrashMan.spawn(capsulePrefab, Random.onUnitSphere * 5f, Random.rotation);
            TrashMan.despawnAfterDelay(newObj, Random.Range(1f, 5f));
        }
    }
コード例 #4
0
    public void Start()
    {
        createTree();


        TrashManRecycleBin bin = new TrashManRecycleBin();

        bin.instancesToPreallocate = 20;
        bin.prefab     = textPrefab.gameObject;
        ballPrefab.tag = ObjectType.Player;
        TrashMan.manageRecycleBin(bin);
    }
コード例 #5
0
        IEnumerator _testPool()
        {
            TrashManRecycleBin data   = new TrashManRecycleBin();
            GameObject         prefab = new GameObject();

            data.prefab = prefab;
            TrashMan.manageRecycleBin(data);
            for (int i = 0; i < 66; ++i)
            {
                var newObj = TrashMan.spawn(prefab);
                TrashMan.despawnAfterDelay(newObj, 2f);
                yield return(new WaitForSeconds(3f));
            }
        }
コード例 #6
0
ファイル: ModelFactory.cs プロジェクト: harryqk/Newbie
    public void init()
    {
        TrashManRecycleBin bin = new TrashManRecycleBin();

        bin.instancesToPreallocate = 20;
        bin.prefab     = this.transform.Find("Ball").gameObject;
        bin.prefab.tag = ObjectType.Player;
        TrashMan.manageRecycleBin(bin);

        TrashManRecycleBin binBullet = new TrashManRecycleBin();

        binBullet.instancesToPreallocate = 200;
        binBullet.prefab = this.transform.Find("Bullet").gameObject;
        TrashMan.manageRecycleBin(binBullet);

        TrashManRecycleBin enemy = new TrashManRecycleBin();

        enemy.instancesToPreallocate = 20;
        enemy.prefab     = this.transform.Find("EnemyBall").gameObject;
        enemy.prefab.tag = ObjectType.Enemy;
        TrashMan.manageRecycleBin(enemy);
    }
コード例 #7
0
ファイル: DemoUI.cs プロジェクト: zsombornagy/RecyclerKit
    void OnGUI()
    {
        if (GUILayout.Button("Spawn Cube"))
        {
            var newObj = TrashMan.spawn(cubePrefab, Random.onUnitSphere * 5f, Random.rotation);
            TrashMan.despawnAfterDelay(newObj, Random.Range(1f, 2f));
        }


        if (GUILayout.Button("Spawn Sphere"))
        {
            var newObj = TrashMan.spawn(spherePrefab, Random.onUnitSphere * 3f);

            // spheres have a hardLimit set so we need to null check before using them
            if (newObj)
            {
                newObj.transform.parent = transform;
                TrashMan.despawnAfterDelay(newObj, Random.Range(5f, 8f));
            }
        }


        if (GUILayout.Button("Spawn Light from Scene"))
        {
            var newObj = TrashMan.spawn("light", Random.onUnitSphere * 10f);

            if (newObj)
            {
                newObj.transform.parent = transform;
                TrashMan.despawnAfterDelay(newObj, Random.Range(5f, 8f));
            }
        }


        if (GUILayout.Button("Spawn Particles by GameObject Name"))
        {
            TrashMan.spawn("Particles", Random.onUnitSphere * 3f);
        }

#if UNITY_4_6 || UNITY_5_0
        if (GUILayout.Button("Spawn UI element"))
        {
            CreateCanvas();
            var go = TrashMan.spawn(uiPrefab, Vector2.zero);
            go.transform.SetParent(canvasRoot.transform, true);
            var rt = go.transform as RectTransform;
            rt.anchoredPosition = new Vector2(Random.Range(-380, 380), Random.Range(-280, 280));
            TrashMan.despawnAfterDelay(go, Random.Range(1f, 5f));
        }
#endif
        if (GUILayout.Button("Create Recycle Bin at Runtime"))
        {
            _didCreateCapsuleRecycleBin = true;
            var recycleBin = new TrashManRecycleBin()
            {
                prefab = capsulePrefab
            };
            TrashMan.manageRecycleBin(recycleBin);
        }


        if (_didCreateCapsuleRecycleBin && GUILayout.Button("Spawn Capsule"))
        {
            var newObj = TrashMan.spawn(capsulePrefab, Random.onUnitSphere * 5f, Random.rotation);
            TrashMan.despawnAfterDelay(newObj, Random.Range(1f, 5f));
        }
    }