Skip to content

Commit

Permalink
Planar Tool Locking Via Modifier Key (Resolves #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawkbat committed Nov 24, 2016
1 parent c6e0749 commit 6d7a0ad
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Assets/Editor.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,16 @@ MonoBehaviour:
ctrl: 0
alt: 0
blockedByUI: 1
bindPlaneLock:
name: Plane Lock
key: 120
btn: -1
axis:
negateAxis: 0
shift: 0
ctrl: 0
alt: 0
blockedByUI: 0
--- !u!114 &1114957955
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class Edit : MonoBehaviour

public Binding bindUseTool;
public Binding bindUseToolAlt;

public Binding bindPlaneLock;

public static int width;
public static int height;
Expand Down
16 changes: 12 additions & 4 deletions Assets/Scripts/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void Awake()
int ny;
int nz;

bool badPlane;
Plane plane;

Dictionary<int, byte> edits = new Dictionary<int, byte>();
Expand All @@ -31,15 +32,18 @@ void Update()
bool toolHeld = Edit.use.bindUseTool.IsHeld() || Edit.use.bindUseToolAlt.IsHeld();
bool toolAlt = Edit.use.bindUseToolAlt.IsHeld();

bool planeLock = Edit.use.bindPlaneLock.IsHeld();

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

if (toolHeld && !editing)
{
editing = true;
PreviewChunk.use.chunk.SetPaletteIndices(GetChunk().GetPaletteIndices());
badPlane = true;
}

if (!toolHeld)
if (!planeLock || badPlane)
{
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 1000f, mask))
Expand Down Expand Up @@ -73,19 +77,17 @@ void Update()
cursor.forward = n;

plane = new Plane(n, p);
badPlane = false;
}
else
{
cursor.gameObject.SetActive(false);
}
}else
{
cursor.gameObject.SetActive(false);

float dist;
if (plane.Raycast(ray, out dist))
{

Vector3 p = ray.GetPoint(dist);
Vector3 n = plane.normal;

Expand All @@ -111,6 +113,12 @@ void Update()

cursor.position = p;
cursor.forward = n;

cursor.gameObject.SetActive(!IsOutOfBounds(px+nx, py+ny, pz+nz));
}
else
{
cursor.gameObject.SetActive(false);
}
}
if (toolHeld)
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ void KeyBindings()
Edit.use.bindToolPlace,
Edit.use.bindToolPaint,
Edit.use.bindUseTool,
Edit.use.bindUseToolAlt
Edit.use.bindUseToolAlt,
Edit.use.bindPlaneLock
};

GUILayout.BeginArea(new Rect(0f, 25f, Screen.width, Screen.height - 25f));
Expand Down

0 comments on commit 6d7a0ad

Please sign in to comment.