Hi Folks,
I'm really new to both Unity and 2D Toolkit and have started out on a first simple project to more or less replicate a PIXI benchmark here :-
http://www.goodboydigital.com/pixijs/bunnymark/I have my scene setup, 2D Toolkit camera in place, a simple sprite collection made with one sprite (the wabbit
, an empty game object which is responsible for instantiating a prefab I have made out of a simple 2D Toolkit sprite & C# script that controls the bunnies behavior, here's the script attached to the prefab :-
using UnityEngine;
using System.Collections;
public class myBunny : MonoBehaviour {
private float minX = 0.0f;
private float maxX = 9.6f;
private float minY = 0.0f;
private float maxY = 6.4f;
private float speedX = 0;
private float speedY = 0;
tk2dSprite mySprite;
public float gravity = 0.09f;
// Use this for initialization
void Start () {
mySprite = (tk2dSprite)gameObject.GetComponent ("tk2dSprite");
speedX = Random.Range (0.0f, 8.0f);
speedY = Random.Range (-4.0f, 1.5f);
transform.position = new Vector2 (0.0f, 6.4f - mySprite.GetUntrimmedBounds().size.y);
maxX -= mySprite.GetUntrimmedBounds().size.x;
}
// Update is called once per frame
void Update () {
speedY -= gravity;
transform.Translate (speedX * Time.deltaTime, (speedY * Time.deltaTime), 0);
if ((transform.position.x < minX) || transform.position.x > maxX) {
speedX *= -1;
transform.position = new Vector2(Mathf.Clamp(transform.position.x, minX, maxX),transform.position.y);
}
if (transform.position.y < minY) {
speedY = Random.Range (3.0f, 7.6f);
transform.position = new Vector2(transform.position.x, Mathf.Clamp(transform.position.y, minY, maxY));
}
}
}
...an heres the code in the simple script on the empty game object...
using UnityEngine;
using System.Collections;
public class myBunnyMarkController : MonoBehaviour {
// Starting number of bunnies to create
public int startBunnyCount = 2;
// Use this for initialization
void Start () {
for (int i = 1; i <= startBunnyCount; i++) {
Instantiate(Resources.Load("myPrefabs/myWabbitPreFab"));
}
((tk2dTextMesh)GameObject.FindGameObjectWithTag ("TextMesh").GetComponent("tk2dTextMesh")).text = "Number of bunnies : " + startBunnyCount.ToString();
((tk2dTextMesh)GameObject.FindGameObjectWithTag ("TextMesh").GetComponent("tk2dTextMesh")).Commit();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0)) {
for (int i = 1; i <= 50; i++) {
Instantiate(Resources.Load("myPrefabs/myWabbitPreFab"));
}
startBunnyCount += 50;
((tk2dTextMesh)GameObject.FindGameObjectWithTag ("TextMesh").GetComponent("tk2dTextMesh")).text = "Number of bunnies : " + startBunnyCount.ToString();
((tk2dTextMesh)GameObject.FindGameObjectWithTag ("TextMesh").GetComponent("tk2dTextMesh")).Commit();
}
}
}
The codes a bit messy in the empty game object 'controller' but its only fired when starting up or if the mouse is down, I wanted to come back to it once everything else was ok. When I run this I hit about 5000 sprites onscreen in both the Unity player and a standalone build before things start to dip below 60fps, I was hoping for a lot lot more based upon the PIXI benchmark I got the idea from as I'm seeing 10,000's running through their HTML5 renderer, any ideas folks?
Happy to post up the project in full etc but I have 2D Toolkit in use and suspect it would have to go in the private board?
Thanks all