Example #1
0
    private void Start()
    {
        _quadTree = new QuadTree(new Rect(0, 0, WorldSize.x, WorldSize.y), BodiesPerNode, MaxSplits);
        _csQuad   = new CollisionSystemQuadTree(_quadTree);

        for (int i = 0; i < MaxBodies; i++)
        {
            //InstantiateObj();
            var body = GameObject.Instantiate <DemoPhysicsBody>(DemoPhysicsBody);
            body.gameObject.tag     = "instantiated";
            body.health             = 5;
            body.transform.position = new Vector3(Random.Range(0, WorldSize.x), 0, Random.Range(0, WorldSize.y));
            _csBrute.AddBody(body);    // add body to CollisionSystemBrute
            _csQuad.AddBody(body);
            _quadTree.AddBody(body);   // add body to QuadTree
            _quadTreeBodies.Add(body); // cache bodies so we can refresh the tree in update
        }
    }
Example #2
0
    /// <summary>
    /// Instantiate Method
    /// </summary>
    public void InstantiateObj()
    {
        if (DemoPhysicsBody == null)
        {
            DemoPhysicsBody = Resources.Load <DemoPhysicsBody>("Prefabs/DemoPhysicsBody") as DemoPhysicsBody;
        }
        var body = GameObject.Instantiate <DemoPhysicsBody>(DemoPhysicsBody);

        body.gameObject.tag     = "instantiated";
        body.health             = 5;
        body.transform.position = new Vector3(Random.Range(0, WorldSize.x), 0, Random.Range(0, WorldSize.y));
        _csBrute.AddBody(body);  // add body to CollisionSystemBrute
        _csQuad.AddBody(body);
        _quadTree.AddBody(body); // add body to QuadTree
        _quadTreeBodies.Add(body);
    }