<feat> 스플래쉬 화면전환 및 프로그램 생성
This commit is contained in:
90
Assets/Scripts/Model/ProgramModel.cs
Normal file
90
Assets/Scripts/Model/ProgramModel.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
public class ProgramModel
|
||||
{
|
||||
private List<RobotProgram> allPrograms = new List<RobotProgram>();
|
||||
private string savePath;
|
||||
|
||||
public RobotProgram CurrentProgram { get; private set; }
|
||||
|
||||
public ProgramModel()
|
||||
{
|
||||
savePath = Path.Combine(Application.persistentDataPath, "programs");
|
||||
Directory.CreateDirectory(savePath); // 저장 폴더가 없으면 생성
|
||||
LoadAllPrograms();
|
||||
}
|
||||
|
||||
public bool CreateNewProgram(string userInputId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userInputId)) return false;
|
||||
|
||||
string newProgramId = $"{userInputId}.job";
|
||||
Debug.Log($"{userInputId}.job 생성");
|
||||
|
||||
// ID가 이미 존재하는지 확인
|
||||
if (GetAllProgramIds().Contains(newProgramId))
|
||||
{
|
||||
Debug.LogError($"프로그램 ID '{newProgramId}'가 이미 존재합니다.");
|
||||
return false;
|
||||
}
|
||||
|
||||
CurrentProgram = new RobotProgram(newProgramId); // 메모리에 새 프로그램 생성
|
||||
|
||||
SaveCurrentProgram();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool LoadProgram(string programId)
|
||||
{
|
||||
string filePath = Path.Combine(savePath, programId + ".job");
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
string json = File.ReadAllText(filePath);
|
||||
CurrentProgram = JsonUtility.FromJson<RobotProgram>(json);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SaveCurrentProgram()
|
||||
{
|
||||
if (CurrentProgram == null) return;
|
||||
|
||||
string json = JsonUtility.ToJson(CurrentProgram, true);
|
||||
string filePath = Path.Combine(savePath, CurrentProgram.programId + ".job");
|
||||
File.WriteAllText(filePath, json);
|
||||
|
||||
// 전체 프로그램 목록 갱신
|
||||
LoadAllPrograms();
|
||||
}
|
||||
|
||||
public void AddPointToCurrentProgram(Vector3 point)
|
||||
{
|
||||
CurrentProgram.endpointPositions.Add(point);
|
||||
}
|
||||
|
||||
public List<string> GetAllProgramIds()
|
||||
{
|
||||
List<string> ids = new List<string>();
|
||||
foreach (var program in allPrograms)
|
||||
{
|
||||
ids.Add(program.programId);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
private void LoadAllPrograms()
|
||||
{
|
||||
allPrograms.Clear();
|
||||
string[] files = Directory.GetFiles(savePath, "*.job");
|
||||
foreach (string file in files)
|
||||
{
|
||||
string programId = Path.GetFileNameWithoutExtension(file);
|
||||
allPrograms.Add(new RobotProgram(programId));
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Model/ProgramModel.cs.meta
Normal file
2
Assets/Scripts/Model/ProgramModel.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e37314a624106794ea72b7ebc3658733
|
||||
16
Assets/Scripts/Model/RobotProgram.cs
Normal file
16
Assets/Scripts/Model/RobotProgram.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class RobotProgram
|
||||
{
|
||||
public string programId;
|
||||
public List<Vector3> endpointPositions;
|
||||
|
||||
public RobotProgram(string id)
|
||||
{
|
||||
programId = id;
|
||||
endpointPositions = new List<Vector3>();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Model/RobotProgram.cs.meta
Normal file
2
Assets/Scripts/Model/RobotProgram.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdb018458d048134d934db15cd1d1989
|
||||
Reference in New Issue
Block a user