티스토리 뷰
12년 5월 기준.
ToolManager_bak.cs
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
enum STATE
{
STATE_CREATENOTE,
STATE_MOVENOTE,
STATE_MOVE
};
public class ToolManager : MonoBehaviour {
private STATE m_eState = STATE.STATE_MOVE;
private delegate void ProcessUpdate();
ProcessUpdate UpdateState;
private const int MAX_LINE_COUNT = 500;
private const int DEFAULT_COURSE = 0;
private const int MAX_COURSE = 3;
private const float DEFAULT_SPEED = 0.0f;
private const float MAX_SPEED = 3.0f;
public GameObject OBJ_LINE;
public GameObject LINE_MANAGER;
public GameObject NOTE_MANAGER;
public GameXML gameXML;
public TextMesh txtCourse;
public TextMesh txtSpeed;
private GameObject m_gSelectNote;
private const float HEIGHTVALUE = -50.0f;
private Vector3 POS_START = new Vector3(-140.0f, HEIGHTVALUE, 0.0f);
private Vector3 POS_END = new Vector3(260.0f, HEIGHTVALUE, 0.0f);
private Vector3 POS_HEIGHT = new Vector3(-140.0f, HEIGHTVALUE, 0.0f);
private float HEIGHT = 20.0f;
private int noteCount = 0;
private const float LINE_WIDTH = 100.0f;
private const int MAX_COUNT_BASELINE = 4;
private bool m_bSelectNote;
// Use this for initialization
void Start () {
SetLine();
SetObject();
m_bSelectNote = false;
}
void SetObject()
{
}
#region BaseLine
void SetLine()
{
SetTimeLine();
SetBaseLine();
}
void SetBaseLine()
{
float fHeight = MAX_LINE_COUNT * HEIGHT;
for (int i = 0; i < MAX_COUNT_BASELINE + 1; ++i)
{
GameObject obj_Line = (GameObject)Instantiate(OBJ_LINE);
obj_Line.transform.parent = LINE_MANAGER.transform;
obj_Line.name = "HeightLine" + i.ToString();
Destroy(obj_Line.transform.FindChild("TextTime").gameObject);
LineRenderer line = obj_Line.GetComponent<LineRenderer>();
Vector3 vPosStart = POS_HEIGHT;
vPosStart.x += i * LINE_WIDTH;
line.SetPosition(0, new Vector3(vPosStart.x, fHeight));
line.SetPosition(1, new Vector3(vPosStart.x, POS_HEIGHT.y));
}
}
void SetTimeLine()
{
for (int i = 0; i < MAX_LINE_COUNT; ++i)
{
GameObject obj_Line = (GameObject)Instantiate(OBJ_LINE);
obj_Line.transform.parent = LINE_MANAGER.transform;
obj_Line.name = "Line" + i.ToString();
TextMesh tTime = obj_Line.transform.FindChild("TextTime").GetComponent<TextMesh>();
tTime.text = i.ToString();
LineRenderer line = obj_Line.GetComponent<LineRenderer>();
Vector3 vPosStart = POS_START;
vPosStart.y += i * HEIGHT;
Vector3 vLIne = obj_Line.transform.localPosition;
vLIne.y = POS_START.y + i * HEIGHT;
obj_Line.transform.localPosition = vLIne;
line.SetPosition(0, new Vector3(POS_START.x, vPosStart.y));
line.SetPosition(1, new Vector3(POS_END.x, vPosStart.y));
}
}
#endregion
void Update()
{
UpdateKeyBoard();
UpdateMouse();
}
void UpdateKeyBoard()
{
if (Input.GetKeyDown(KeyCode.Delete))
{
if (m_gSelectNote)
{
m_gSelectNote.SendMessage("Delete");
}
}
}
void UpdateMouse()
{
if (0 < iPhoneToMouse.touchCount)
{
iPhoneToMouse.pos iPos = iPhoneToMouse.GetTouch(0);
if (TouchPhase.Ended == iPos.phase)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(iPos.position);
if (Physics.Raycast(ray, out hit))
{
string str = hit.collider.gameObject.name;
Debug.Log("Hit Object : " + str);
if ("Plane" == str)
{
if (m_bSelectNote)
{
MoveNote(hit.point);
}
else
{
drawNote("Cube" + noteCount, noteCount, hit.point);
}
}
changeCourse(str);
changeSpeed(str);
}
}
iPhoneToMouse.pos iRtPos = iPhoneToMouse.GetTouch(1);
if (TouchPhase.Ended == iRtPos.phase)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(iPos.position);
NotSelect();
m_bSelectNote = false;
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.CompareTag("Note"))
{
m_gSelectNote = hit.collider.gameObject;
GameDebug.show("SelectNote:" + m_gSelectNote.name);
m_bSelectNote = true;
m_gSelectNote.SendMessage("SetSelect", true);
}
}
if (!m_bSelectNote)
{
GameDebug.show("Not Select");
}
}
}
}
void changeCourse(string str)
{
string s = str.Substring(0, 4);
if (string.Compare(s, "txtC", true) == 0)
{
TextMesh txtCourse = GameObject.Find(str).GetComponent<TextMesh>();
string c = txtCourse.text;
c = c.Substring(c.LastIndexOf(" ")+1);
int count = int.Parse(c);
if (count != MAX_SPEED)
txtCourse.text = "Course : " + (count + 1).ToString();
else
txtCourse.text = "Course : " + DEFAULT_COURSE.ToString();
}
}
void changeSpeed(string str)
{
string s = str.Substring(0, 4);
if (string.Compare(s, "txtS", true) == 0)
{
TextMesh txtSpeed = GameObject.Find(str).GetComponent<TextMesh>();
string c = txtSpeed.text;
c = c.Substring(c.LastIndexOf(" ") + 1);
float count = float.Parse(c);
if (count != MAX_SPEED)
txtSpeed.text = "Speed : " + (count + 1).ToString();
else
txtSpeed.text = "Speed : " + DEFAULT_SPEED.ToString();
}
}
void NotSelect()
{
m_gSelectNote = null;
GameObject[] ArrBody = GameObject.FindGameObjectsWithTag("Note") as GameObject[];
foreach (GameObject body in ArrBody)
{
body.SendMessage("SetSelect", false);
}
}
void DestoryNote()
{
GameObject[] ArrBody = GameObject.FindGameObjectsWithTag("Note") as GameObject[];
foreach (GameObject body in ArrBody)
{
Destroy(body);
}
}
void LoadLine()
{
DestoryNote();
gameXML.loadData();
List<SaveStructure.GameItems> _GameItems = new List<SaveStructure.GameItems>();
_GameItems = gameXML._GameItems;
Vector3 vPosStart = POS_HEIGHT;
noteCount = 0;
for (int i = 0; i < _GameItems.Count; ++i)
{
SaveStructure.GameItems itm = _GameItems[i];
GameObject gNote = (GameObject)Instantiate(Resources.Load("Notes/note" + itm.line.ToString()));
gNote.transform.parent = NOTE_MANAGER.transform;
gNote.name = "Cube"+noteCount;
Vector3 vPos = new Vector3();
vPos.x = vPosStart.x + itm.line * LINE_WIDTH + LINE_WIDTH / 2;
vPos.y = TimeToLine(itm.time);
gNote.transform.position = vPos;
NoteScript sNote = gNote.GetComponent<NoteScript>();
sNote.Line = itm.line;
noteCount++;
setCourse(gNote, itm.course);
setSpeed(gNote, itm.speed);
}
}
void SaveLine()
{
GameObject[] ArrBody = GameObject.FindGameObjectsWithTag("Note") as GameObject[];
List<SaveStructure.GameItems> _GameItems = new List<SaveStructure.GameItems>();
SaveStructure.GameItems itm;
int ID = 0;
foreach (GameObject body in ArrBody)
{
itm = new SaveStructure.GameItems();
float fTime = LineToTime(body.transform.position.y);
NoteScript sNote = body.GetComponent<NoteScript>();
TextMesh tCourse = body.transform.FindChild("txtCourse" + ID).GetComponent<TextMesh>();
TextMesh tSpeed = body.transform.FindChild("txtSpeed" + ID).GetComponent<TextMesh>();
itm.id = ID;
itm.line = sNote.Line;
itm.time = fTime;
itm.course = int.Parse(tCourse.text.Substring(tCourse.text.LastIndexOf(" ")));
itm.speed = float.Parse(tSpeed.text.Substring(tSpeed.text.LastIndexOf(" ")));
ID++;
_GameItems.Add(itm);
}
_GameItems.Sort(new CompareEvent());
for (int i = 0; i < _GameItems.Count; ++i)
{
SaveStructure.GameItems titm = _GameItems[i];
titm.id = i;
}
gameXML.saveData(_GameItems);
}
//void DrawBaseLine(string name, int index, int max)
//{
// float fHeight = max * HEIGHT;
// GameObject obj_Line = (GameObject)Instantiate(OBJ_LINE);
// obj_Line.transform.parent = LINE_MANAGER.transform;
// obj_Line.name = "HeightLine" + index.ToString();
// Destroy(obj_Line.transform.FindChild("TextTime").gameObject);
// LineRenderer line = obj_Line.GetComponent<LineRenderer>();
// Vector3 vPosStart = POS_HEIGHT;
// vPosStart.x += index * LINE_WIDTH;
// line.SetPosition(0, new Vector3(vPosStart.x, fHeight));
// line.SetPosition(1, new Vector3(vPosStart.x, POS_HEIGHT.y));
//}
//void drawTimeLine(string name, int index)
//{
// GameObject obj_Line = (GameObject)Instantiate(OBJ_LINE);
// obj_Line.transform.parent = LINE_MANAGER.transform;
// obj_Line.name = name;
// TextMesh tTime = obj_Line.transform.FindChild("TextTime").GetComponent<TextMesh>();
// tTime.text = index.ToString();
// LineRenderer line = obj_Line.GetComponent<LineRenderer>();
// Vector3 vPosStart = POS_START;
// vPosStart.y += index * HEIGHT;
// Vector3 vLIne = obj_Line.transform.localPosition;
// vLIne.y = POS_START.y + index * HEIGHT;
// obj_Line.transform.localPosition = vLIne;
// line.SetPosition(0, new Vector3(POS_START.x, vPosStart.y));
// line.SetPosition(1, new Vector3(POS_END.x, vPosStart.y));
//}
float LineToTime(float fLineHeight)
{
return (fLineHeight - POS_START.y) / HEIGHT;
}
float TimeToLine(float fTime)
{
return POS_START.y + fTime * HEIGHT;
}
void MoveNote(Vector3 vPos)
{
Vector3 vPosStart = POS_HEIGHT;
int iCount = 100;
for (int i = 0; i < MAX_COUNT_BASELINE; ++i)
{
float fPrev = vPosStart.x + (i * LINE_WIDTH);
float fNext = fPrev + LINE_WIDTH;
if (fPrev < vPos.x && fNext > vPos.x)
{
iCount = i;
}
}
if (MAX_COUNT_BASELINE > iCount && vPosStart.y < vPos.y)
{
vPos.x = vPosStart.x + iCount * LINE_WIDTH + LINE_WIDTH / 2;
m_gSelectNote.transform.position = new Vector3(vPos.x, vPos.y, 0);
}
}
void drawNote(string name, int index, Vector3 vPos)
{
Vector3 vPosStart = POS_HEIGHT;
int iCount = 100;
for (int i = 0; i < MAX_COUNT_BASELINE; ++i)
{
float fPrev = vPosStart.x + (i * LINE_WIDTH);
float fNext = fPrev + LINE_WIDTH;
if (fPrev < vPos.x && fNext > vPos.x)
{
iCount = i;
}
}
if (MAX_COUNT_BASELINE > iCount && vPosStart.y < vPos.y)
{
GameObject gNote = (GameObject)Instantiate(Resources.Load("Notes/note" + iCount.ToString()));
gNote.transform.parent = NOTE_MANAGER.transform;
gNote.name = name;
vPos.x = vPosStart.x + iCount * LINE_WIDTH + LINE_WIDTH/2;
gNote.transform.position = new Vector3(vPos.x, vPos.y, 0);
NoteScript sNote = gNote.GetComponent<NoteScript>();
sNote.Line = iCount;
noteCount++;
setCourse(gNote);
setSpeed(gNote);
}
}
void setCourse(GameObject gNote, int index = -1)
{
TextMesh course = (TextMesh)Instantiate(txtCourse);
course.transform.parent = gNote.transform;
course.name = "txtCourse" + (noteCount - 1);
Vector3 vec;
vec = gNote.transform.position;
vec.y = gNote.transform.position.y + gNote.transform.localScale.z;
vec.y = gNote.transform.position.y + 4;
vec.z = -100;
course.transform.position = vec;
if(index != -1)
course.text = "Course : " + index;
else
course.text = "Course : " + DEFAULT_COURSE.ToString();
}
void setSpeed(GameObject gNote, float index = -1)
{
TextMesh speed = (TextMesh)Instantiate(txtSpeed);
speed.transform.parent = gNote.transform;
speed.name = "txtSpeed" + (noteCount - 1);
Vector3 vec;
vec = gNote.transform.position;
vec.y = gNote.transform.position.y + gNote.transform.localScale.z;
vec.x = gNote.transform.position.x + 36;
vec.y = gNote.transform.position.y + 4;
vec.z = -100;
speed.transform.position = vec;
if (index != -1)
speed.text = "Speed : " + index;
else
speed.text = "Speed : " + DEFAULT_SPEED.ToString();
}
//void loadLine()
//{
// // countBaseLine return count
// //int baseCount = countBaseLine();
// //int lineCount = countTimeLine();
// //int noteCount = countNote();
// // load baseLine
// //for (int i = 0; i < baseCount; ++i)
// //{
// // drawBaseLine(gameXML._GameItems[i].Name, i, lineCount);
// //}
// //// load timeLine
// //for (int i = 0; i < lineCount; ++i)
// //{
// // drawTimeLine(gameXML._GameItems[i].Name, i);
// //}
// //// load note
// //for (int i = 0; i < noteCount; ++i)
// //{
// // Vector3 pos;
// // pos.x = gameXML._GameItems[i].posx;
// // pos.y = gameXML._GameItems[i].posy;
// // pos.z = gameXML._GameItems[i].posz;
// // drawNote(gameXML._GameItems[i].Name, i, pos);
// //}
//}
//int countBaseLine()
//{
// int count = 0;
// for (int i = 0; i < gameXML._GameItems.Count; i++)
// {
// string str = gameXML._GameItems[i].Name.Substring(0, 4);
// if (string.Compare(str, "heig", true) == 0)
// {
// count++;
// }
// }
// Debug.Log("baseCount "+count);
// return count;
//}
//int countTimeLine()
//{
// int count = 0;
// for(int i = 0;i < gameXML._GameItems.Count;i++)
// {
// string str = gameXML._GameItems[i].Name.Substring(0, 4);
// if (string.Compare(str, "line", true) == 0)
// {
// count++;
// }
// }
// // lineManager 때문에 lineCount-1
// count = count - 1;
// Debug.Log("timeCount "+count);
// return count;
//}
//int countNote()
//{
// int count = 0;
// for (int i = 0; i < gameXML._GameItems.Count; i++)
// {
// string str = gameXML._GameItems[i].Name.Substring(0, 4);
// if (string.Compare(str, "cube", true) == 0)
// {
// count++;
// }
// }
// Debug.Log("noteCount " + count);
// noteCount = count;
// return count;
//}
}
'Study' 카테고리의 다른 글
Android(안드로이드) 관련 (0) | 2024.02.04 |
---|---|
Developer Interview Call(개발자 전화 면접) (0) | 2024.02.04 |
Visual Studio(비주얼 스튜디오) 관련 (0) | 2024.02.04 |
Windows(윈도우) Server(서버) 관련 (0) | 2024.02.04 |
DBeaver(디비버) Google Bigquery(구글 빅쿼리) Connect(접속) (1) | 2024.02.03 |