
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Editor_Node : MonoBehaviour
{
public Vector3 vIn_Max;
public Vector3 vIn_Min;
private Vector3 vIn_MaxStart;
private Vector3 vIn_MinStart;
public Slider scale_Slide;
private float scale_Slide_last = 1f;
public MD_Scale_Cube md_Scale_Cube;
private Image bkg_ImagePlate;
public enum EditState
{
SELECTED,
EDITING,
EDITED,
INACTIVE,
}
public bool bBlinking = false;
public float blink_Time = 0f;
public EditState editState;
void Awake ()
{
bkg_ImagePlate = GetComponent<Image>();
editState = EditState.INACTIVE;
setState(editState);
vIn_MaxStart = new Vector3(15, 15, 15);
vIn_MinStart = new Vector3(-15, -15, -15);
}
public void setState(EditState edit_State)
{
editState = edit_State;
bBlinking = false;
if(editState == EditState.SELECTED)
{
if (hasBeenEdited())
{
bkg_ImagePlate.color = new Color(0.4f, 0.05f, 0.8f, 0.9f);
}
else
{
bkg_ImagePlate.color = new Color(0.7f, 0.05f, 0.05f, 0.9f);
}
}
else if(editState == EditState.EDITING)
{
bBlinking = true;
scale_Slide.value = 1;
}
else if(editState == EditState.EDITED)
{
bkg_ImagePlate.color = new Color(0.6f, 0.05f, 0.6f, 0.7f);
}
else if(editState == EditState.INACTIVE)
{
bkg_ImagePlate.color = new Color(0, 0, 0, 0);
}
}
public bool Scale_Slider_Changed()
{
bool bChanged = false;
if (scale_Slide.value != scale_Slide_last)
{
bChanged = true;
}
scale_Slide_last = scale_Slide.value;
return bChanged;
}
public void setMinMax(Vector3 min, Vector3 max)
{
vIn_Min = min;
vIn_Max = max;
}
public void setDone_Editing()
{
if(hasBeenEdited())
{
setState(EditState.EDITED);
}
else
{
setState(EditState.INACTIVE);
}
}
public void onReset()
{
vIn_Max = vIn_MaxStart;
vIn_Min = vIn_MinStart;
//if(editState == EditState.EDITING)
//{
md_Scale_Cube.resetScaleCube();
//}
//UnEdited / Cleared
bkg_ImagePlate.color = new Color(0.7f, 0.05f, 0.05f, 0.7f);
if(editState != EditState.EDITING)
{
Color col = bkg_ImagePlate.color;
col.a = 0;
bkg_ImagePlate.color = col;
}
}
public bool hasBeenEdited()
{
if(vIn_Max == vIn_MaxStart && vIn_Min == vIn_MinStart)
{
return false;
}
else
{
return true;
}
}
void Update ()
{
if(bBlinking)
{
blink_Time += 3f*Time.deltaTime;
Color col = bkg_ImagePlate.color;
col.a = Mathf.Abs(0.4f * Mathf.Sin(blink_Time / 2f * Mathf.PI));
bkg_ImagePlate.color = col;
}
}
}
