Example #1
0
 private void OnMouseDown()
 {
     SFXEventHandler.SendClickPart();
     startPos = transform.position;
     if (snappedTo == null)
     {
         return;
     }
     startSnappedTo    = snappedTo;
     prevsnappingPoint = snappedTo.GetComponent <SnappingPoint>();
     prevsnappingPoint.UnSnap();
     snappedTo = null;
 }
Example #2
0
    private void OnMouseUp()
    {
        audioSource.Stop();

        SnappingPoint[] snaps = GameObject.FindObjectsOfType <SnappingPoint>();
        var             rslt  = GetDistanceToClosestSnappingPoint(snaps);

        if (rslt.distance < snappingDistance)
        {
            Debug.DrawLine(transform.position, rslt.target.transform.position, Color.green, 0, false);

            transform.position = rslt.target.transform.position;

            prevsnappingPoint = null;
            if (snappedTo != null)
            {
                prevsnappingPoint = snappedTo.GetComponent <SnappingPoint>();
            }


            snappedTo = rslt.target.gameObject;

            SnappingPoint snappingPoint = snappedTo.GetComponent <SnappingPoint>();

            if (snappingPoint != null)
            {
                SFXEventHandler.SendAttachPart(snappingPoint.gameObject);
                if (prevsnappingPoint != null)
                {
                    prevsnappingPoint.UnSnap();
                }
                snappingPoint.UnSnap();
                snappingPoint.AssignGameObject(gameObject);

                var bodyPartComp = GetComponent <BodyPartVisual>();
                if (bodyPartComp != null)
                {
                    bodyPartComp.ResetRotationsAndTranslations(snappingPoint.IsBody, snappedTo.transform);
                }
            }

            //this.transform.SetParent(snappedTo.transform);
        }
        else
        {
            transform.position = startPos;
            snappedTo          = startSnappedTo;
            SFXEventHandler.SendAttachPart(null);
        }
    }