コード例 #1
0
    //if mouse over on any sub collider
    void OnComponentMouseUpAsButton(CollisionNodeInfo collisionInfo)
    {
        SpriteTransform tmpSprTransform = spriteRenderer.GetSpriteTransform( collisionInfo.hitNode.componentPath);

        //save the last hover component
        if ( tmpSprTransform != null )
        {
            //make the collisioned sub part unvisibile
            tmpSprTransform.visible = false;
            //make the collisioned collider disable
            collisionInfo.hitNode.collider.enabled = false;

            //create a new gameobject in scene
            GameObject tmp = new GameObject();

            //add a rigidbody to gameobject
            tmp.AddComponent<Rigidbody>();
            //set the position and rotation constraint
            tmp.rigidbody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;
            //give a random velocity
            tmp.rigidbody.velocity = Random.insideUnitSphere * 300f;

            //add a boxcollider
            BoxCollider col = tmp.AddComponent<BoxCollider>();

            //set the collider size like the collision sub collider
            Vector3 size = (collisionInfo.hitNode.collider as BoxCollider).size;
            col.size = new Vector3( size.x, size.y, 200f);
            //set the collider ceneter like the collision sub collider
            col.center = (collisionInfo.hitNode.collider as BoxCollider).center;
            //set the collider material
            col.material = phyMat;

            //add a spriterenderer
            SpriteRenderer tmpRenderer = tmp.AddComponent<SpriteRenderer>();
            tmpRenderer.renderMode = spriteRenderer.renderMode;
            tmpRenderer.updateMode = SpriteRendererUpdateMode.LateUpdate;
            tmpRenderer.localRotation = spriteRenderer.localRotation;
            tmpRenderer.localScale = spriteRenderer.localScale;
            tmpRenderer.plane = spriteRenderer.plane;

            //add the collisioned sprite to the spriterenderer
            int i = tmpRenderer.AttachSprite( tmpSprTransform.sprite );
            SpriteTransform tran = tmpRenderer.GetSpriteTransform(i);
            //set the rotation and scale
            tran.rotation = tmpSprTransform.rotation;
            tran.scale = tmpSprTransform.scale;

            //set the new gameobject position as the collsioned sprite's position in world space
            Matrix4x4 l2wMat = spriteRenderer.GetLocalToWorldMatrix();
            tmp.transform.position = l2wMat.MultiplyPoint(tmpSprTransform.position);

            //add it to list
            objects.Add( tmp);
        }
    }
コード例 #2
0
    //if collider is trigger and same other collider exit it
    void OnComponentTriggerExit(CollisionNodeInfo collisionInfo)
    {
        SpriteTransform tmpSprTransform = spriteRenderer.GetSpriteTransform( collisionInfo.hitNode.componentPath);

        //if we can get the component's SpriteTransform, then remove it from list.
        if ( tmpSprTransform != null )
        {
            collisionComponents.Remove( tmpSprTransform );
        }
    }
コード例 #3
0
    //if collider is trigger and same other collider enter it
    void OnComponentTriggerEnter(CollisionNodeInfo collisionInfo)
    {
        SpriteTransform tmpSprTransform = spriteRenderer.GetSpriteTransform( collisionInfo.hitNode.componentPath);

        //if we can get the component's SpriteTransform, then add it to list.
        if ( tmpSprTransform != null )
        {
            collisionComponents.Add( tmpSprTransform );
        }
    }
コード例 #4
0
    //if mouse over on any sub collider
    void OnComponentMouseOverHandle(CollisionNodeInfo collisionInfo)
    {
        SpriteTransform tmpSprTransform = spriteRenderer.GetSpriteTransform( collisionInfo.hitNode.componentPath);

        //save the last hover component
        if ( tmpSprTransform != null )
        {
            lastHoverSprite = tmpSprTransform;
        }
    }
コード例 #5
0
 // Setup an event delegate so other components can listen for when collisions occur on the nodes
 //	of our animation. We pass back the name of the hit object so developers can track the
 //	hit object based on the name of the node.
 static private void dummyHandler(CollisionNodeInfo cni)
 {
 }
コード例 #6
0
 //if mouse exit on any sub collider
 void OnComponentMouseExit(CollisionNodeInfo collisionInfo)
 {
     //clear the last hover component
     lastHoverSprite = null;
 }
コード例 #7
0
 // Setup an event delegate so other components can listen for when collisions occur on the nodes
 //	of our animation. We pass back the name of the hit object so developers can track the
 //	hit object based on the name of the node.
 static private void dummyHandler(CollisionNodeInfo cni)
 {
 }