Ejemplo n.º 1
0
        public void AddBody(ICollider iCollider)
        {
            if (!(iCollider is TSCollider2D))
            {
                Debug.LogError("You have a 3D object but your Physics 3D is disabled.");
                return;
            }

            TSCollider2D tsCollider = (TSCollider2D)iCollider;

            if (tsCollider._body != null)
            {
                //already added
                return;
            }

            tsCollider.Initialize(world);
            gameObjectMap[tsCollider._body] = tsCollider.gameObject;

            if (tsCollider.gameObject.transform.parent != null && tsCollider.gameObject.transform.parent.GetComponentInParent <TSCollider2D>() != null)
            {
                TSCollider2D   parentCollider = tsCollider.gameObject.transform.parent.GetComponentInParent <TSCollider2D>();
                Physics2D.Body childBody      = tsCollider._body;

                childBody.bodyConstraints.Add(new ConstraintHierarchy2D(((Physics2D.Body)parentCollider.Body), tsCollider._body, (tsCollider.GetComponent <TSTransform2D>().position + tsCollider.ScaledCenter) - (parentCollider.GetComponent <TSTransform2D>().position + parentCollider.ScaledCenter)));
            }

            world.ProcessAddedBodies();
        }
Ejemplo n.º 2
0
        public void AddBody(ICollider iCollider)
        {
            if (!(iCollider is TSCollider2D))
            {
                Debug.LogError("You have a 3D object but your Physics 3D is disabled.");
                return;
            }

            TSCollider2D tsCollider = (TSCollider2D)iCollider;

            if (tsCollider._body != null)
            {
                //already added
                return;
            }

            tsCollider.Initialize(world);
            GameObject gameObject = tsCollider.gameObject;

            gameObjectMap[tsCollider._body] = gameObject;

            HashList <TrueSyncBehaviour> behaviours = new HashList <TrueSyncBehaviour>();

            TrueSyncBehaviour[] behavioursArray = gameObject.GetComponents <TrueSyncBehaviour>();
            for (int i = 0, count = behavioursArray.Length; i < count; i++)
            {
                behaviours.Add(behavioursArray[i]);
            }
            behavioursMap[tsCollider._body] = behaviours;

            if (tsCollider.gameObject.transform.parent != null && tsCollider.gameObject.transform.parent.GetComponentInParent <TSCollider2D>() != null)
            {
                TSCollider2D   parentCollider = tsCollider.gameObject.transform.parent.GetComponentInParent <TSCollider2D>();
                Physics2D.Body childBody      = tsCollider._body;

                childBody.bodyConstraints.Add(new ConstraintHierarchy2D(((Physics2D.Body)parentCollider.Body), tsCollider._body, (tsCollider.GetComponent <TSTransform2D>().position + tsCollider.ScaledCenter) - (parentCollider.GetComponent <TSTransform2D>().position + parentCollider.ScaledCenter)));
            }

            world.ProcessAddedBodies();
        }