Ejemplo n.º 1
0
        public void Disconnect()
        {
            if (ConnectedJoint)
            {
                ConnectedJoint.ConnectedJoint = null;
            }

            ConnectedJoint = null;
        }
Ejemplo n.º 2
0
        public Vector3 GetPositionOfClosestFreeJoint(Vector3 position)
        {
            var        joints               = baseBlocks.SelectMany(b => b.GetFreeJoints()).ToList();
            BlockJoint closestJoint         = null;
            var        closestBlockDistance = -1f;

            foreach (var joint in joints)
            {
                var distance = Vector3.Distance(joint.GetCenterPosition(), position);
                if (distance < closestBlockDistance || closestBlockDistance < 0)
                {
                    closestJoint         = joint;
                    closestBlockDistance = distance;
                }
            }

            return(closestJoint.GetCenterPosition());
        }
Ejemplo n.º 3
0
        public ClosestJointsPair GetClosestTwoJoints(IEnumerable <BlockJoint> blockJoints,
                                                     IEnumerable <BlockJoint> baseJoints)
        {
            BlockJoint closestBlockJoint        = null;
            BlockJoint closestBaseJoint         = null;
            float      closestBaseJointDistance = -1;
            var        blockJointsList          = blockJoints.ToList();

            foreach (var baseJoint in baseJoints)
            {
                var        direction = baseJoint.GetDirection();
                RaycastHit objectHit;
                Debug.DrawRay(baseJoint.transform.position, direction, Color.green, 1000);
                if (Physics.Raycast(baseJoint.transform.position, direction, out objectHit, .5f))
                {
                    var hitBlock = objectHit.collider.GetComponent <Block>();
                    if (hitBlock != null)
                    {
                        continue;
                    }
                }

                foreach (var blockJoint in blockJointsList)
                {
                    var distance = Vector3.Distance(blockJoint.GetJointPosition(),
                                                    baseJoint.GetJointPosition());
                    if (distance < closestBaseJointDistance || closestBaseJointDistance < 0)
                    {
                        closestBaseJoint         = baseJoint;
                        closestBlockJoint        = blockJoint;
                        closestBaseJointDistance = distance;
                    }
                }
            }

            return(new ClosestJointsPair
            {
                BlockJoint = closestBlockJoint,
                BaseJoint = closestBaseJoint
            });
        }
Ejemplo n.º 4
0
 public void Join(BlockJoint other)
 {
     ConnectedJoint       = other;
     other.ConnectedJoint = this;
 }