Documentation – SnapIT

Getting Started


  1. Create a new Unity project (or use an existing)
  2. Import the package
  3. Run the included SampleScene

Commands (in-game)


Press tab to switch current object.
Press to preview the selected prefab

CODE COMMENTS


All functions is described in the code following best practice doxygen standard. Look how the magnets is placed on the included prefabs.
The included example is created for in-game mode, not just editor.

SimpleSnapManager.cs


This class must be instantiated as a singleton since there should only be one instance of the SimpleSnapManager.  This is done in background using Instace()

Selecting an item

SimpleSnapManager.Instance().Select(CurrentSelectedElement);

Update the SimpleSnapManager

SimpleSnapManager.Instance().Update(GetReferencePoint());

SimpleSnapInstance.cs

Each item that should snap requires this component added.

Set point where distance to magnets will be measured from

protected UnityEngine.Vector3 GetReferencePoint() { }

Preview (display) snap points

public void SnapPreview(UnityEngine.GameObject SourceObject)
{
    if (SourceObject.GetInstanceID() == this.gameObject.GetInstanceID())
    {
        return;
    }

    this.CreateGhostObjects(SourceObject);
}

SimpleSnapExample.cs

inherits SimpleSnapInstance

Override start point from where the distance to magnets will be measured from

protected new Vector3 GetReferencePoint()
{
    Vector3 screenPoint = Camera.main.WorldToScreenPoint(CurrentSelectedElement.transform.position);
    Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
    return Camera.main.ScreenToWorldPoint(curScreenPoint);
}