using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SnapNScale : MonoBehaviour {

	[HideInInspector]
	public float[] unitFloats = { 0.1f, 0.25f, 0.5f, 1f, 2f, 5f, 10f }, rotFloats = { 5, 15f, 30f, 45f, 90f, 180f };

	[Header("Position Snap Values")]
	[Incrementor("unitFloats", "X Position", false)]
	public float xPos = 0f;
	[Incrementor("unitFloats", "Y Position", false)]
	public float yPos = 0f;
	[Incrementor("unitFloats", "Z Position", false)]
	public float zPos = 0f;

	[Header("Rotation Snap Values")]
	[Incrementor("rotFloats", "X Rotation", true)]
	public float xRot = 0f;
	[Incrementor("rotFloats", "Y Rotation", true)]
	public float yRot = 0f;
	[Incrementor("rotFloats", "Z Rotation", true)]
	public float zRot = 0f;

	[Header("Uniform Scale Values")]
	public bool scaleWholeObject;
	[Incrementor("unitFloats", "Uniform Scale", false)]
	public float uniformScale = 1f;

	[Header("Scale Snap Values")]
	[Incrementor("unitFloats", "X Scale", false)]
	public float xScale = 1f;
	[Incrementor("unitFloats", "Y Scale", false)]
	public float yScale = 1f;
	[Incrementor("unitFloats", "Z Scale", false)]
	public float zScale = 1f;


	private void OnDrawGizmos () {
		xPos = transform.position.x;
		yPos = transform.position.y;
		zPos = transform.position.z;

		xRot = transform.eulerAngles.x;
		yRot = transform.eulerAngles.y;
		zRot = transform.eulerAngles.z;

		xScale = transform.localScale.x;
		yScale = transform.localScale.y;
		zScale = transform.localScale.z;
		uniformScale = (transform.localScale.x + transform.localScale.y + transform.localScale.z) / 3f;
	}

	void OnValidate () {
		transform.position = new Vector3 (xPos, yPos, zPos);
		transform.eulerAngles = new Vector3 (xRot, yRot, zRot);
		if (scaleWholeObject)
			transform.localScale = new Vector3 (uniformScale, uniformScale, uniformScale);
		else
			transform.localScale = new Vector3 (xScale, yScale, zScale);
	}
}
