160 lines
3.4 KiB
C#
160 lines
3.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class ToolEditVector
|
|
{
|
|
[HideInInspector]
|
|
public Vector3 cursorPos;
|
|
[HideInInspector]
|
|
public bool selecting, moving;
|
|
[HideInInspector]
|
|
public Vector3 fromCorner, toCorner;
|
|
[HideInInspector]
|
|
public List<int> selected = new List<int>();
|
|
|
|
Vector3 moveFrom, oldCursorPos;
|
|
|
|
public void Reset()
|
|
{
|
|
// for resetting the tool (when swapping around, initializing, etc)
|
|
selecting = false;
|
|
moving = false;
|
|
selected.Clear();
|
|
}
|
|
|
|
public void Frame(Input input, Pixelgon pixelgon)
|
|
{
|
|
Vector3 rawCursorPos = cursorPos = input.dragCursor;
|
|
|
|
if (!selecting)
|
|
{
|
|
if (!moving && input.mainCon.trigger.down)
|
|
{
|
|
// box select from corner anchor
|
|
fromCorner = toCorner = cursorPos;
|
|
selecting = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// box select opposite corner drag
|
|
toCorner = cursorPos;
|
|
|
|
if (input.mainCon.two.down)
|
|
{
|
|
// cancel
|
|
selecting = false;
|
|
}
|
|
else if (input.mainCon.trigger.up)
|
|
{
|
|
int selCount = 0;
|
|
for (int i = 0; i < pixelgon.vectors.Count; i++)
|
|
{
|
|
if (pixelgon.vectors[i] != Vector3.zero)
|
|
{
|
|
if (
|
|
StaticMethods.Inside(fromCorner.x, toCorner.x, pixelgon.vectors[i].x) &&
|
|
StaticMethods.Inside(fromCorner.y, toCorner.y, pixelgon.vectors[i].y) &&
|
|
StaticMethods.Inside(fromCorner.z, toCorner.z, pixelgon.vectors[i].z)
|
|
)
|
|
{
|
|
if (!selected.Contains(i))
|
|
{
|
|
selected.Add(i);
|
|
}
|
|
selCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (selCount == 0)
|
|
{
|
|
selected.Clear();
|
|
}
|
|
|
|
selecting = false;
|
|
}
|
|
}
|
|
|
|
|
|
// do some housekeeping ^-^
|
|
|
|
// pixelgon undo for move back
|
|
// how to remove?
|
|
// ToolEraser (handles joint, vector and quad removal)
|
|
// put these and more into quire
|
|
|
|
|
|
if (selected.Count > 0)
|
|
{
|
|
if (!moving)
|
|
{
|
|
if (!selecting && input.mainCon.one.down)
|
|
{
|
|
moveFrom = oldCursorPos = cursorPos;
|
|
moving = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Vector3 move = cursorPos - oldCursorPos;
|
|
oldCursorPos = cursorPos;
|
|
|
|
for (int i = 0; i < selected.Count; i++)
|
|
{
|
|
pixelgon.vectors[selected[i]] += move;
|
|
}
|
|
|
|
if (input.mainCon.two.down)
|
|
{
|
|
Vector3 delta = cursorPos - moveFrom;
|
|
for (int i = 0; i < selected.Count; i++)
|
|
{
|
|
pixelgon.vectors[selected[i]] -= delta;
|
|
}
|
|
|
|
moving = false;
|
|
}
|
|
else if (input.mainCon.one.up)
|
|
{
|
|
moving = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// use just the selected[0] for snapping
|
|
|
|
// int length = 0;
|
|
// for (int i = 0; i < pixelgon.vectors.Count; i++)
|
|
// {
|
|
// if (pixelgon.vectors[i] == Vector3.zero)
|
|
// {
|
|
// length = 0;
|
|
// }
|
|
// else
|
|
// {
|
|
// if (length > 0)
|
|
// {
|
|
// cursorPos = StaticMethods.EdgeSnap(
|
|
// pixelgon.vectors[i - 1],
|
|
// pixelgon.vectors[i],
|
|
// input.twistCursor
|
|
// );
|
|
// if (cursorPos != input.twistCursor)
|
|
// {
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
// length++;
|
|
// }
|
|
// }
|
|
}
|
|
}
|