From 99c6a0f6f1f0c86e97ac133e561b9a2a54edbe2a Mon Sep 17 00:00:00 2001 From: geondo55 <102933884+geondo55@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:01:53 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Camera,=20Gizmo,=20Project=20Command=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/0.22.7.unity | 55 +++- .../Studio/AssetTool/FBXFileManager.cs | 239 ++++-------------- .../Studio/AssetTool/RenderObjectHandler.cs | 16 +- .../Scripts/Studio/Command/CameraCommand.meta | 8 + .../CameraCommand/MoveToTargetCommand.cs | 35 +++ .../CameraCommand/MoveToTargetCommand.cs.meta | 2 + .../Scripts/Studio/Command/GizmoCommand.meta | 8 + .../GizmoCommand/ActivateMoveGizmoCommand.cs | 26 ++ .../ActivateMoveGizmoCommand.cs.meta | 2 + .../ActivateRotateGizmoCommand.cs | 26 ++ .../ActivateRotateGizmoCommand.cs.meta | 2 + .../GizmoCommand/ActivateScaleGizmoCommand.cs | 26 ++ .../ActivateScaleGizmoCommand.cs.meta | 2 + .../Command/GizmoCommand/ResetGizmoCommand.cs | 26 ++ .../GizmoCommand/ResetGizmoCommand.cs.meta | 2 + .../Studio/Command/ProjectCommand.meta | 8 + .../ProjectCommand/LoadProjectCommand.cs | 62 +++++ .../ProjectCommand/LoadProjectCommand.cs.meta | 2 + .../ProjectCommand/NewProjectCommand.cs | 27 ++ .../ProjectCommand/NewProjectCommand.cs.meta | 2 + .../ProjectCommand/SaveProjectCommand.cs | 36 +++ .../ProjectCommand/SaveProjectCommand.cs.meta | 2 + .../Scripts/Studio/Managers/CameraManager.cs | 17 +- .../Scripts/Studio/Managers/ProjectManager.cs | 72 +----- .../Scripts/Studio/UI/Canvas/Canvas_Popup.cs | 9 +- .../Scripts/Studio/UI/Canvas/Canvas_Static.cs | 2 +- 26 files changed, 450 insertions(+), 264 deletions(-) create mode 100644 Assets/Scripts/Studio/Command/CameraCommand.meta create mode 100644 Assets/Scripts/Studio/Command/CameraCommand/MoveToTargetCommand.cs create mode 100644 Assets/Scripts/Studio/Command/CameraCommand/MoveToTargetCommand.cs.meta create mode 100644 Assets/Scripts/Studio/Command/GizmoCommand.meta create mode 100644 Assets/Scripts/Studio/Command/GizmoCommand/ActivateMoveGizmoCommand.cs create mode 100644 Assets/Scripts/Studio/Command/GizmoCommand/ActivateMoveGizmoCommand.cs.meta create mode 100644 Assets/Scripts/Studio/Command/GizmoCommand/ActivateRotateGizmoCommand.cs create mode 100644 Assets/Scripts/Studio/Command/GizmoCommand/ActivateRotateGizmoCommand.cs.meta create mode 100644 Assets/Scripts/Studio/Command/GizmoCommand/ActivateScaleGizmoCommand.cs create mode 100644 Assets/Scripts/Studio/Command/GizmoCommand/ActivateScaleGizmoCommand.cs.meta create mode 100644 Assets/Scripts/Studio/Command/GizmoCommand/ResetGizmoCommand.cs create mode 100644 Assets/Scripts/Studio/Command/GizmoCommand/ResetGizmoCommand.cs.meta create mode 100644 Assets/Scripts/Studio/Command/ProjectCommand.meta create mode 100644 Assets/Scripts/Studio/Command/ProjectCommand/LoadProjectCommand.cs create mode 100644 Assets/Scripts/Studio/Command/ProjectCommand/LoadProjectCommand.cs.meta create mode 100644 Assets/Scripts/Studio/Command/ProjectCommand/NewProjectCommand.cs create mode 100644 Assets/Scripts/Studio/Command/ProjectCommand/NewProjectCommand.cs.meta create mode 100644 Assets/Scripts/Studio/Command/ProjectCommand/SaveProjectCommand.cs create mode 100644 Assets/Scripts/Studio/Command/ProjectCommand/SaveProjectCommand.cs.meta diff --git a/Assets/Scenes/0.22.7.unity b/Assets/Scenes/0.22.7.unity index 5e83c639..a82809f4 100644 --- a/Assets/Scenes/0.22.7.unity +++ b/Assets/Scenes/0.22.7.unity @@ -255,6 +255,52 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 88186217} m_CullTransparentMesh: 0 +--- !u!1 &121134311 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 121134312} + - component: {fileID: 121134313} + m_Layer: 0 + m_Name: LinkDataUIManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &121134312 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 121134311} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1093055756} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &121134313 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 121134311} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: beaea798e37c61142a62ba5cecd426f2, type: 3} + m_Name: + m_EditorClassIdentifier: + prf_LinkDataUI: {fileID: 3588877776299194241, guid: 9f62a52c6a3d48947b57fdd4f941a260, type: 3} + body: {fileID: 1617081465} --- !u!1 &157533902 GameObject: m_ObjectHideFlags: 0 @@ -965,7 +1011,8 @@ PrefabInstance: propertyPath: m_SizeDelta.x value: 0 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 7997719753715833387, guid: 82511e73cbe6181438fd98254170e476, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] m_AddedComponents: [] @@ -4272,6 +4319,7 @@ Transform: - {fileID: 749092880} - {fileID: 671739451} - {fileID: 391151068} + - {fileID: 121134312} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1093055757 @@ -9591,6 +9639,11 @@ RectTransform: m_CorrespondingSourceObject: {fileID: 2186512387788540450, guid: 985020025db5cc04da0f50eaa5351616, type: 3} m_PrefabInstance: {fileID: 1615364366} m_PrefabAsset: {fileID: 0} +--- !u!224 &1617081465 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 940260026812176822, guid: 82511e73cbe6181438fd98254170e476, type: 3} + m_PrefabInstance: {fileID: 297039007} + m_PrefabAsset: {fileID: 0} --- !u!1 &1647579088 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Studio/AssetTool/FBXFileManager.cs b/Assets/Scripts/Studio/AssetTool/FBXFileManager.cs index bde91dab..67315e63 100644 --- a/Assets/Scripts/Studio/AssetTool/FBXFileManager.cs +++ b/Assets/Scripts/Studio/AssetTool/FBXFileManager.cs @@ -52,23 +52,23 @@ namespace XED.Manage private void OnLoadLocalFBXDirectory(IList list) { - for (int i = 0; i < list.Count; i++) - { - if (!list[i].HasData) - continue; + //for (int i = 0; i < list.Count; i++) + //{ + // if (!list[i].HasData) + // continue; - var path = list[i].Name; - Debug.Log("path " + path); - var files = Directory.GetFiles(path, "*.fbx", SearchOption.AllDirectories); + // var path = list[i].Name; + // Debug.Log("path " + path); + // var files = Directory.GetFiles(path, "*.fbx", SearchOption.AllDirectories); - if (dataRepo.TryGetDataFromPath(path, out var p)) - return; + // if (dataRepo.TryGetDataFromPath(path, out var p)) + // return; - foreach (var file in files) - { - loadFilePath.Enqueue(file); - } - } + // foreach (var file in files) + // { + // loadFilePath.Enqueue(file); + // } + //} } public void SaveToLocalData(List assetDatas, string path = "") @@ -87,7 +87,15 @@ namespace XED.Manage } string path = Application.streamingAssetsPath + "/baseAssetData"; - CoroutineRunner.instance.StartCoroutine(CoroutineLoadFromLocalData(path)); + string filePath = GetLocalPath(path); + + if (!CheckFilePathExists(filePath)) + { + isLoadTaskComplete = true; + return; + } + + CoroutineRunner.instance.StartCoroutine(CoroutineLoadFromLocalData(filePath)); } public CustomAssetData GetCustomAssetData(string name) @@ -96,126 +104,6 @@ namespace XED.Manage //return listAssets.FirstOrDefault(x => x.name == name); } - IEnumerator CoroutineLoadLocalFiles() - { - while (true) - { - yield return new WaitUntil(() => loadFilePath.Count > 0); - string path = loadFilePath.Dequeue(); - string name = System.IO.Path.GetFileNameWithoutExtension(path); - - //if (listAssets.Find(x => x.name == name) != null) - //{ - // yield return null; - // continue; - //} - - if (dataRepo.TryGetDataFromName(name, out var p)) - { - yield return null; - continue; - } - - string directoryPath = Path.GetDirectoryName(path); - string lastFolderName = Path.GetFileName(directoryPath); - string createDate = File.GetCreationTime(path).ToShortDateString(); - string lastRevisionDate = File.GetLastAccessTime(path).ToShortDateString(); - string uploadDate = DateTime.Now.ToShortDateString(); - - GameObject newObject = new GameObject(name); - newObject.transform.parent = fbxAnchor; - CustomAssetData assetData = newObject.AddComponent(); - assetData.assetName = name; - assetData.folderName = lastFolderName; - assetData.createDate = createDate; - assetData.LastRevisionDate = lastRevisionDate; - assetData.UploadDate = uploadDate; - assetData.Creator = "xr@uvc.co.kr"; - assetData.Manager = "xr@uvc.co.kr"; - assetData.LoadLocalFBX(path); - dataRepo.Add(assetData); - //onLoadFbxFile?.Invoke(name, lastFolderName, assetData); - yield return new WaitUntil(() => (assetData.isLoadComplete == true && assetData.progress == 1) || assetData.isLoadError == true); - if (assetData.isLoadError) - { - dataRepo.Remove(assetData); - ManagerHub.instance.Get().assetDataHandler.OnRemoveFbxFile(name); - //onRemoveFbxFile?.Invoke(name); - } - yield return null; - } - } - IEnumerator CoroutineSaveToLocalData(List assetDatas, string path) - { - //if (assetDatas == null || assetDatas.Count == 0) - //{ - // assetDatas = listAssets; - //} - //if (assetDatas.Count == 0) - //{ - // Debug.Log("No AssetDatas to Save"); - // isSaveTaskComplete = true; - // yield break; - //} - - if (dataRepo.isEmpty) - { - dataRepo.AddRange(assetDatas); - } - - if (dataRepo.isEmpty) - { - Debug.Log("No AssetDatas to Save"); - isSaveTaskComplete = true; - yield break; - } - - isSaveTaskComplete = false; - List savedModels = new List(); - List thumbnails = new List(); - RuntimePreviewGenerator.BackgroundColor = Color.clear; - RuntimePreviewGenerator.OrthographicMode = true; - - for (int i = 0; i < assetDatas.Count; i++) - { - var modelData = ConvertToSaveData(assetDatas[i]); - Texture2D thumbnail = RuntimePreviewGenerator.GenerateModelPreview(assetDatas[i].loadedObject.transform, 320, 200); - thumbnail = thumbnail.MakeReadableTexture(); - thumbnails.Add(new ThumbnailData(thumbnail.EncodeToPNG())); - savedModels.Add(modelData); - } - saveData.modelDatas = savedModels.ToArray(); - saveData.textureDatas = sharedMaterial.textureDatas.ToArray(); - saveData.thumbnailDatas = thumbnails.ToArray(); - yield return null; - - //Task task = SaveAsync(identifier, saveData); - - string filePath = string.IsNullOrEmpty(path) ? Path.Combine(Application.persistentDataPath, identifier) : path; - Task task = Task.Run(() => messagePacker.SaveAsync(filePath, saveData)); - - yield return new WaitUntil(() => task.IsCompleted); - isSaveTaskComplete = true; - yield return null; - } - - SavedModelData ConvertToSaveData(CustomAssetData assetData) - { - SavedModelData modelData = new SavedModelData(); - modelData.SaveData(assetData.loadedObject, sharedMaterial); - //°¹¼ö Á¦ÇÑ ¾øÀ½ ¿øÇÏ´Â ¸¸Å­ Á¶Àý °¡´É. Å×½ºÆ®·Î 10°³¸¸ ÁöÁ¤ - modelData.attributes = new string[7][]; - modelData.attributes[0] = new string[] { "assetName", assetData.assetName }; - modelData.attributes[1] = new string[] { "folderName", assetData.folderName }; - - modelData.attributes[2] = new string[] { "createDate", assetData.createDate }; - modelData.attributes[3] = new string[] { "LastRevisionDate", assetData.LastRevisionDate }; - modelData.attributes[4] = new string[] { "UploadDate", assetData.UploadDate }; - modelData.attributes[5] = new string[] { "Creator", assetData.createDate }; - modelData.attributes[6] = new string[] { "Manager", assetData.Manager }; - return modelData; - } - string GetLocalPath(string path) { if (string.IsNullOrEmpty(path)) @@ -237,26 +125,11 @@ namespace XED.Manage return true; } - IEnumerator CoroutineLoadFromLocalData(string path) + IEnumerator CoroutineLoadFromLocalData(string filePath) { isLoadTaskComplete = false; float loadTime = 0; - //string filePath = string.IsNullOrEmpty(path) ? Path.Combine(Application.persistentDataPath, identifier) : path; - string filePath = GetLocalPath(path); - - if (!CheckFilePathExists(filePath)) - { - isLoadTaskComplete = true; - yield break; - } - //if (!System.IO.File.Exists(filePath)) - //{ - // Debug.Log("No File Found At : " + filePath); - // isLoadTaskComplete = true; - // yield break; - //} - Task task = Task.Run(() => messagePacker.LoadAsync(filePath)); yield return new WaitUntil(() => task.IsCompleted); @@ -268,6 +141,7 @@ namespace XED.Manage yield break; } saveData = task.Result; + for (int i = 0; i < saveData.textureDatas.Length; i++) { TextureData texData = saveData.textureDatas[i]; @@ -296,43 +170,42 @@ namespace XED.Manage yield return null; } - bool LoadSaveData(SaveData saveData, int index) - { - var modelData = saveData.modelDatas[index]; - string assetName = modelData.attributes.FirstOrDefault(x => x[0].Equals("assetName"))?[1]; + bool LoadSaveData(SaveData saveData, int index) + { + var modelData = saveData.modelDatas[index]; + string assetName = modelData.attributes.FirstOrDefault(x => x[0].Equals("assetName"))?[1]; - if (dataRepo.TryGetDataFromName(assetName, out var p)) - return false; + if (dataRepo.TryGetDataFromName(assetName, out var p)) + return false; - string folderName = modelData.attributes.FirstOrDefault(x => x[0].Equals("folderName"))?[1]; - string createDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("createDate"))?[1]; - string lastRevisionDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("lastRevisionDate"))?[1]; - string uploadDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("uploadDate"))?[1]; - string creator = modelData.attributes.FirstOrDefault(x => x[0].Equals("creator"))?[1]; - string manager = modelData.attributes.FirstOrDefault(x => x[0].Equals("manager"))?[1]; + string folderName = modelData.attributes.FirstOrDefault(x => x[0].Equals("folderName"))?[1]; + string createDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("createDate"))?[1]; + string lastRevisionDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("lastRevisionDate"))?[1]; + string uploadDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("uploadDate"))?[1]; + string creator = modelData.attributes.FirstOrDefault(x => x[0].Equals("creator"))?[1]; + string manager = modelData.attributes.FirstOrDefault(x => x[0].Equals("manager"))?[1]; - Texture2D thumbnail = new Texture2D(1, 1); - thumbnail.LoadImage(saveData.thumbnailDatas[index].data); - GameObject newObject = new GameObject(assetName); - newObject.transform.parent = fbxAnchor; - CustomAssetData assetData = newObject.AddComponent(); - assetData.assetName = assetName; - assetData.folderName = folderName; - assetData.createDate = createDate; - assetData.LastRevisionDate = lastRevisionDate; - assetData.UploadDate = uploadDate; - assetData.Creator = creator; - assetData.Manager = manager; - assetData.loadedObject = modelData.LoadModelData(sharedMaterial); - assetData.thumbnail = thumbnail; - assetData.OnLoadComplete(); + Texture2D thumbnail = new Texture2D(1, 1); + thumbnail.LoadImage(saveData.thumbnailDatas[index].data); + GameObject newObject = new GameObject(assetName); + newObject.transform.parent = fbxAnchor; + CustomAssetData assetData = newObject.AddComponent(); + assetData.assetName = assetName; + assetData.folderName = folderName; + assetData.createDate = createDate; + assetData.LastRevisionDate = lastRevisionDate; + assetData.UploadDate = uploadDate; + assetData.Creator = creator; + assetData.Manager = manager; + assetData.loadedObject = modelData.LoadModelData(sharedMaterial); + assetData.thumbnail = thumbnail; + assetData.OnLoadComplete(); - dataRepo.Add(assetData); + dataRepo.Add(assetData); //listAssets.Add(assetData); - ManagerHub.instance.Get().assetDataHandler.OnLoadFbxFile(assetData.assetName, assetData.folderName, assetData); - - return true; - } + ManagerHub.instance.Get().assetDataHandler.OnLoadFbxFile(assetData.assetName, assetData.folderName, assetData); + return true; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Studio/AssetTool/RenderObjectHandler.cs b/Assets/Scripts/Studio/AssetTool/RenderObjectHandler.cs index 10ff258a..4205325d 100644 --- a/Assets/Scripts/Studio/AssetTool/RenderObjectHandler.cs +++ b/Assets/Scripts/Studio/AssetTool/RenderObjectHandler.cs @@ -3,15 +3,13 @@ using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEngine; -using UnityEngine.Events; using UnityEngine.EventSystems; using XED.Asset; using XED.Command; -using XED.Core; using XED.DataStructures; using XED.Interfaces; using XED.Manage; -using XED.RuntimeGizmo; +using XED.RuntimeGizmo; namespace XED.Util { @@ -218,19 +216,23 @@ namespace XED.Util } public void ResetRTG() { - rtgController.SetWorkGizmoId(RTGController.GizmoId.None); + var command = new ResetGizmoCommand(rtgController); + CommandInvoker.instance.Invoke(command); } public void SetRTGMove() { - rtgController.SetWorkGizmoId(RTGController.GizmoId.Move); + var command = new ActivateMoveGizmoCommand(rtgController); + CommandInvoker.instance.Invoke(command); } public void SetRTGScale() { - rtgController.SetWorkGizmoId(RTGController.GizmoId.Scale); + var command = new ActivateScaleGizmoCommand(rtgController); + CommandInvoker.instance.Invoke(command); } public void SetRTGRotate() { - rtgController.SetWorkGizmoId(RTGController.GizmoId.Rotate); + var command = new ActivateRotateGizmoCommand(rtgController); + CommandInvoker.instance.Invoke(command); } public void OnTransformBegin() { diff --git a/Assets/Scripts/Studio/Command/CameraCommand.meta b/Assets/Scripts/Studio/Command/CameraCommand.meta new file mode 100644 index 00000000..b0d123c2 --- /dev/null +++ b/Assets/Scripts/Studio/Command/CameraCommand.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 553a24c445d45734e93db3694688a065 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Studio/Command/CameraCommand/MoveToTargetCommand.cs b/Assets/Scripts/Studio/Command/CameraCommand/MoveToTargetCommand.cs new file mode 100644 index 00000000..14c5333b --- /dev/null +++ b/Assets/Scripts/Studio/Command/CameraCommand/MoveToTargetCommand.cs @@ -0,0 +1,35 @@ +using System.IO; +using UnityEngine; +using XED.Command; + +namespace XED +{ + public class MoveToTargetCommand : IIrreversibleCommand + { + private Transform target; + private Vector3 viewAngle; + private float cameraDistance; + + public MoveToTargetCommand(Transform target, Vector3 viewAngle, float cameraDistance) + { + this.target = target; + this.viewAngle = viewAngle; + this.cameraDistance = cameraDistance; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + Camera.main.transform.rotation = Quaternion.Euler(viewAngle); + + Camera.main.transform.position = target.position; + Camera.main.transform.position += -Camera.main.transform.forward * cameraDistance; + } + } +} diff --git a/Assets/Scripts/Studio/Command/CameraCommand/MoveToTargetCommand.cs.meta b/Assets/Scripts/Studio/Command/CameraCommand/MoveToTargetCommand.cs.meta new file mode 100644 index 00000000..3ce01565 --- /dev/null +++ b/Assets/Scripts/Studio/Command/CameraCommand/MoveToTargetCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: af71595b728196a4391585fa1be345c8 \ No newline at end of file diff --git a/Assets/Scripts/Studio/Command/GizmoCommand.meta b/Assets/Scripts/Studio/Command/GizmoCommand.meta new file mode 100644 index 00000000..3978e628 --- /dev/null +++ b/Assets/Scripts/Studio/Command/GizmoCommand.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 58c7bd081b97acf42a09b5b4ef1d3fad +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Studio/Command/GizmoCommand/ActivateMoveGizmoCommand.cs b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateMoveGizmoCommand.cs new file mode 100644 index 00000000..8a828a0b --- /dev/null +++ b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateMoveGizmoCommand.cs @@ -0,0 +1,26 @@ +using XED.RuntimeGizmo; + +namespace XED.Command +{ + public class ActivateMoveGizmoCommand : IIrreversibleCommand + { + private RTGController rtgController; + + public ActivateMoveGizmoCommand(RTGController rtgController) + { + this.rtgController = rtgController; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + rtgController.SetWorkGizmoId(RTGController.GizmoId.Move); + } + } +} diff --git a/Assets/Scripts/Studio/Command/GizmoCommand/ActivateMoveGizmoCommand.cs.meta b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateMoveGizmoCommand.cs.meta new file mode 100644 index 00000000..2fc25dd7 --- /dev/null +++ b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateMoveGizmoCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 96806282dbad1954fb33e13354823e92 \ No newline at end of file diff --git a/Assets/Scripts/Studio/Command/GizmoCommand/ActivateRotateGizmoCommand.cs b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateRotateGizmoCommand.cs new file mode 100644 index 00000000..bca446f4 --- /dev/null +++ b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateRotateGizmoCommand.cs @@ -0,0 +1,26 @@ +using XED.RuntimeGizmo; + +namespace XED.Command +{ + public class ActivateRotateGizmoCommand : IIrreversibleCommand + { + private RTGController rtgController; + + public ActivateRotateGizmoCommand(RTGController rtgController) + { + this.rtgController = rtgController; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + rtgController.SetWorkGizmoId(RTGController.GizmoId.Rotate); + } + } +} diff --git a/Assets/Scripts/Studio/Command/GizmoCommand/ActivateRotateGizmoCommand.cs.meta b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateRotateGizmoCommand.cs.meta new file mode 100644 index 00000000..a32b6219 --- /dev/null +++ b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateRotateGizmoCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: b70e099d374f64847834ff12c191bd91 \ No newline at end of file diff --git a/Assets/Scripts/Studio/Command/GizmoCommand/ActivateScaleGizmoCommand.cs b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateScaleGizmoCommand.cs new file mode 100644 index 00000000..616014c2 --- /dev/null +++ b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateScaleGizmoCommand.cs @@ -0,0 +1,26 @@ +using XED.RuntimeGizmo; + +namespace XED.Command +{ + public class ActivateScaleGizmoCommand : IIrreversibleCommand + { + private RTGController rtgController; + + public ActivateScaleGizmoCommand(RTGController rtgController) + { + this.rtgController = rtgController; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + rtgController.SetWorkGizmoId(RTGController.GizmoId.Scale); + } + } +} diff --git a/Assets/Scripts/Studio/Command/GizmoCommand/ActivateScaleGizmoCommand.cs.meta b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateScaleGizmoCommand.cs.meta new file mode 100644 index 00000000..dd0ec109 --- /dev/null +++ b/Assets/Scripts/Studio/Command/GizmoCommand/ActivateScaleGizmoCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 8959657a6330abd448297620191164d5 \ No newline at end of file diff --git a/Assets/Scripts/Studio/Command/GizmoCommand/ResetGizmoCommand.cs b/Assets/Scripts/Studio/Command/GizmoCommand/ResetGizmoCommand.cs new file mode 100644 index 00000000..022d4f9b --- /dev/null +++ b/Assets/Scripts/Studio/Command/GizmoCommand/ResetGizmoCommand.cs @@ -0,0 +1,26 @@ +using XED.RuntimeGizmo; + +namespace XED.Command +{ + public class ResetGizmoCommand : IIrreversibleCommand + { + private RTGController rtgController; + + public ResetGizmoCommand(RTGController rtgController) + { + this.rtgController = rtgController; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + rtgController.SetWorkGizmoId(RTGController.GizmoId.None); + } + } +} diff --git a/Assets/Scripts/Studio/Command/GizmoCommand/ResetGizmoCommand.cs.meta b/Assets/Scripts/Studio/Command/GizmoCommand/ResetGizmoCommand.cs.meta new file mode 100644 index 00000000..3147d271 --- /dev/null +++ b/Assets/Scripts/Studio/Command/GizmoCommand/ResetGizmoCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 6d2c3f6f335592d4e888a96dbd9903d3 \ No newline at end of file diff --git a/Assets/Scripts/Studio/Command/ProjectCommand.meta b/Assets/Scripts/Studio/Command/ProjectCommand.meta new file mode 100644 index 00000000..65188e79 --- /dev/null +++ b/Assets/Scripts/Studio/Command/ProjectCommand.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cee17c4be8819da47a5eb95110ec3455 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Studio/Command/ProjectCommand/LoadProjectCommand.cs b/Assets/Scripts/Studio/Command/ProjectCommand/LoadProjectCommand.cs new file mode 100644 index 00000000..4748e17e --- /dev/null +++ b/Assets/Scripts/Studio/Command/ProjectCommand/LoadProjectCommand.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; +using System.Linq; +using XED.Asset; +using XED.HierarchyTree; +using XED.Util; + +namespace XED.Command +{ + public class LoadProjectCommand : IIrreversibleCommand + { + private List assets; + private CustomAssetConnector connector; + + Dictionary itemDict = new Dictionary(); + + public LoadProjectCommand(List assets, CustomAssetConnector connector) + { + this.assets = assets; + this.connector = connector; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + foreach (AssetData asset in assets) + { + LoadAsset(asset); + } + + foreach (AssetData asset in assets) + { + RestoreHierarchy(asset); + } + } + + private void LoadAsset(AssetData asset) + { + connector.OnLoadAsset(asset); + itemDict.Add(asset.id, connector.connectedAssets.Last().hierarchyItem); + } + + private void RestoreHierarchy(AssetData asset) + { + foreach (int id in asset.children) + { + HierarchyItem parent = itemDict[asset.id]; + HierarchyItem child = itemDict[id]; + + if (parent == null || child == null) + continue; + + connector.OnRestoreHierarchy(parent, child); + } + } + } +} diff --git a/Assets/Scripts/Studio/Command/ProjectCommand/LoadProjectCommand.cs.meta b/Assets/Scripts/Studio/Command/ProjectCommand/LoadProjectCommand.cs.meta new file mode 100644 index 00000000..280541e7 --- /dev/null +++ b/Assets/Scripts/Studio/Command/ProjectCommand/LoadProjectCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 58dff3fed88a2eb4fab1bc8116f0c170 \ No newline at end of file diff --git a/Assets/Scripts/Studio/Command/ProjectCommand/NewProjectCommand.cs b/Assets/Scripts/Studio/Command/ProjectCommand/NewProjectCommand.cs new file mode 100644 index 00000000..250d0293 --- /dev/null +++ b/Assets/Scripts/Studio/Command/ProjectCommand/NewProjectCommand.cs @@ -0,0 +1,27 @@ +using XED.Asset; + +namespace XED.Command +{ + public class NewProjectCommand : IIrreversibleCommand + { + CustomAssetConnector connector; + + public NewProjectCommand(CustomAssetConnector connector) + { + this.connector = connector; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + connector.ClearObjects(); + } + + } +} diff --git a/Assets/Scripts/Studio/Command/ProjectCommand/NewProjectCommand.cs.meta b/Assets/Scripts/Studio/Command/ProjectCommand/NewProjectCommand.cs.meta new file mode 100644 index 00000000..e2e23d12 --- /dev/null +++ b/Assets/Scripts/Studio/Command/ProjectCommand/NewProjectCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 16f7564790f59584283a83911585ada8 \ No newline at end of file diff --git a/Assets/Scripts/Studio/Command/ProjectCommand/SaveProjectCommand.cs b/Assets/Scripts/Studio/Command/ProjectCommand/SaveProjectCommand.cs new file mode 100644 index 00000000..bea2f34d --- /dev/null +++ b/Assets/Scripts/Studio/Command/ProjectCommand/SaveProjectCommand.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json; +using System.IO; +using XED.Command; +using XED.Util; + +namespace XED +{ + public class SaveProjectCommand : IIrreversibleCommand + { + private string projectPath; + private ProjectData projectData; + + + public SaveProjectCommand(string projectPath, ProjectData projectData) + { + this.projectPath = projectPath; + this.projectData = projectData; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + string json = JsonConvert.SerializeObject(projectData); + FileStream fs = new FileStream(projectPath, FileMode.Create, FileAccess.Write); + StreamWriter writer = new StreamWriter(fs, System.Text.Encoding.Unicode); + writer.Write(json); + writer.Close(); + } + } +} diff --git a/Assets/Scripts/Studio/Command/ProjectCommand/SaveProjectCommand.cs.meta b/Assets/Scripts/Studio/Command/ProjectCommand/SaveProjectCommand.cs.meta new file mode 100644 index 00000000..602b87fd --- /dev/null +++ b/Assets/Scripts/Studio/Command/ProjectCommand/SaveProjectCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 91703b89f5f43354d9d896c2f4b8dcde \ No newline at end of file diff --git a/Assets/Scripts/Studio/Managers/CameraManager.cs b/Assets/Scripts/Studio/Managers/CameraManager.cs index 6dc368ce..5d2fbddd 100644 --- a/Assets/Scripts/Studio/Managers/CameraManager.cs +++ b/Assets/Scripts/Studio/Managers/CameraManager.cs @@ -1,24 +1,23 @@ using UnityEngine; +using XED.Command; namespace XED.Manage { public class CameraManager : Manager { - private float objectViewDistance; - private Vector3 objectViewRotation; + private float cameraDistance; + private Vector3 viewAngle; public override void Init() { - objectViewDistance = 25f; - objectViewRotation = new Vector3(45, 145, 0); + cameraDistance = 25f; + viewAngle = new Vector3(45, 145, 0); } - public void MoveToTwinObjectPos(TwinObject twinObject) + public void MoveToTwinObjectPos(TwinObject target) { - Camera.main.transform.rotation = Quaternion.Euler(objectViewRotation); - - Camera.main.transform.position = twinObject.transform.position; - Camera.main.transform.position += -Camera.main.transform.forward * objectViewDistance; + var command = new MoveToTargetCommand(target.transform, viewAngle, cameraDistance); + CommandInvoker.instance.Invoke(command); } } } diff --git a/Assets/Scripts/Studio/Managers/ProjectManager.cs b/Assets/Scripts/Studio/Managers/ProjectManager.cs index 70caa0d8..1a7c99aa 100644 --- a/Assets/Scripts/Studio/Managers/ProjectManager.cs +++ b/Assets/Scripts/Studio/Managers/ProjectManager.cs @@ -3,9 +3,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using TriLibCore.Dae.Schema; using TriLibCore.SFB; using UnityEditor; using XED.Asset; +using XED.Command; using XED.HierarchyTree; using XED.Service; using XED.Util; @@ -16,23 +18,23 @@ namespace XED.Manage public class ProjectManager : Manager { private AssetDataService assetDataService; + private CustomAssetConnector connector; private string curProjectPath; private ProjectData curProjectData; - Dictionary itemDict = new Dictionary(); - public ProjectManager() { assetDataService = new AssetDataService(); - + connector = ManagerHub.instance.Get(); } + public override void Init() { curProjectPath = string.Empty; curProjectData = null; - itemDict.Clear(); } + public void SaveProject() { bool isNewProject = string.IsNullOrEmpty(curProjectPath); @@ -42,14 +44,14 @@ namespace XED.Manage if (string.IsNullOrEmpty(path)) return; - var connector = ManagerHub.instance.Get(); List assetDatas = assetDataService.SortAssetDatas(connector.connectedAssets); ProjectData projectData = CreateProjectData(path, assetDatas); curProjectPath = path; curProjectData = projectData; - SaveFile(); + var command = new SaveProjectCommand(curProjectPath, curProjectData); + CommandInvoker.instance.Invoke(command); } public void LoadProject() @@ -67,24 +69,23 @@ namespace XED.Manage if (projectData == null) return; - var connector = ManagerHub.instance.Get(); connector.ClearObjects(); Init(); - LoadAssets(projectData.assetDatas); - RestoreHierarchys(projectData.assetDatas); - curProjectPath = path; curProjectData = projectData; + + var command = new LoadProjectCommand(curProjectData.assetDatas, connector); + CommandInvoker.instance.Invoke(command); } public void NewProject() { - var connector = ManagerHub.instance.Get(); - connector.ClearObjects(); - Init(); + + var command = new NewProjectCommand(connector); + CommandInvoker.instance.Invoke(command); } private ProjectData CreateProjectData(string path, List assetDatas) @@ -97,43 +98,6 @@ namespace XED.Manage }; } - private void LoadAssets(List assets) - { - foreach (AssetData asset in assets) - { - LoadAsset(asset); - } - } - - private void LoadAsset(AssetData asset) - { - var connector = ManagerHub.instance.Get(); - connector.OnLoadAsset(asset); - itemDict.Add(asset.id, connector.connectedAssets.Last().hierarchyItem); - } - - private void RestoreHierarchys(List assets) - { - foreach (AssetData asset in assets) - { - RestoreHierarchy(asset); - } - } - - private void RestoreHierarchy(AssetData asset) - { - foreach (int id in asset.children) - { - HierarchyItem parent = itemDict[asset.id]; - HierarchyItem child = itemDict[id]; - - if (parent == null || child == null) - continue; - - ManagerHub.instance.Get().OnRestoreHierarchy(parent, child); - } - } - private string GetSaveFilePath() { var data = StandaloneFileBrowser.SaveFilePanel("SaveProject", "", "", "json"); @@ -146,14 +110,6 @@ namespace XED.Manage return data.Count >= 1 ? data[0].Name : ""; } - private void SaveFile() - { - string json = JsonConvert.SerializeObject(curProjectData); - FileStream fs = new FileStream(curProjectPath, FileMode.Create, FileAccess.Write); - StreamWriter writer = new StreamWriter(fs, System.Text.Encoding.Unicode); - writer.Write(json); - writer.Close(); - } private ProjectData GetFileData(string path) { diff --git a/Assets/Scripts/Studio/UI/Canvas/Canvas_Popup.cs b/Assets/Scripts/Studio/UI/Canvas/Canvas_Popup.cs index 97b1856c..b824a6cd 100644 --- a/Assets/Scripts/Studio/UI/Canvas/Canvas_Popup.cs +++ b/Assets/Scripts/Studio/UI/Canvas/Canvas_Popup.cs @@ -1,11 +1,10 @@ using UnityEngine; -using UnityEngine.EventSystems; +using XED.Manage; +using XED.UI; +using XED.Util; +using XED.VirtualFactory; using XRLib; using XRLib.UI; -using XED.UI; -using XED.VirtualFactory; -using XED.Manage; -using XED.Util; namespace XED { diff --git a/Assets/Scripts/Studio/UI/Canvas/Canvas_Static.cs b/Assets/Scripts/Studio/UI/Canvas/Canvas_Static.cs index 68fc785e..09c55a5b 100644 --- a/Assets/Scripts/Studio/UI/Canvas/Canvas_Static.cs +++ b/Assets/Scripts/Studio/UI/Canvas/Canvas_Static.cs @@ -36,7 +36,7 @@ namespace XED.UI panel_topbar.onClickSaveProject += projectManager.SaveProject; panel_topbar.onClickLoadProject += projectManager.LoadProject; panel_topbar.onClickNewProject += projectManager.NewProject; - panel_topbar.onClickLoadAssets += fbxFileManager.LoadLocalFBXDirectory; + //panel_topbar.onClickLoadAssets += fbxFileManager.LoadLocalFBXDirectory; panel_topbar.onClickAssetWindow += fbxFileManager.LoadLocalData; panel_toolbar.onClickMove += renderObjectHandler.SetRTGMove; -- 2.48.1.windows.1 From cef08df8e04a46fd5b99ec17e5c00b1c6696df6c Mon Sep 17 00:00:00 2001 From: geondo55 <102933884+geondo55@users.noreply.github.com> Date: Mon, 21 Apr 2025 15:26:04 +0900 Subject: [PATCH 2/2] =?UTF-8?q?LoadFile=20Command=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Studio/AssetTool/FBXFileManager.cs | 81 ++++------------ .../Scripts/Studio/Command/FileCommand.meta | 8 ++ .../FileCommand/LoadLocalModelDataCommand.cs | 94 +++++++++++++++++++ .../LoadLocalModelDataCommand.cs.meta | 2 + .../LoadLocalTextureDataCommand.cs | 50 ++++++++++ .../LoadLocalTextureDataCommand.cs.meta | 2 + 6 files changed, 172 insertions(+), 65 deletions(-) create mode 100644 Assets/Scripts/Studio/Command/FileCommand.meta create mode 100644 Assets/Scripts/Studio/Command/FileCommand/LoadLocalModelDataCommand.cs create mode 100644 Assets/Scripts/Studio/Command/FileCommand/LoadLocalModelDataCommand.cs.meta create mode 100644 Assets/Scripts/Studio/Command/FileCommand/LoadLocalTextureDataCommand.cs create mode 100644 Assets/Scripts/Studio/Command/FileCommand/LoadLocalTextureDataCommand.cs.meta diff --git a/Assets/Scripts/Studio/AssetTool/FBXFileManager.cs b/Assets/Scripts/Studio/AssetTool/FBXFileManager.cs index 67315e63..c2f11fcf 100644 --- a/Assets/Scripts/Studio/AssetTool/FBXFileManager.cs +++ b/Assets/Scripts/Studio/AssetTool/FBXFileManager.cs @@ -10,6 +10,8 @@ using System; using System.Linq; using XED.Repositories; using XED.Asset; +using Ookii.Dialogs; +using XED.Command; namespace XED.Manage { @@ -94,7 +96,10 @@ namespace XED.Manage isLoadTaskComplete = true; return; } - + + // var command = new ActivateMoveGizmoCommand(rtgController); + //CommandInvoker.instance.Invoke(command); + CoroutineRunner.instance.StartCoroutine(CoroutineLoadFromLocalData(filePath)); } @@ -128,7 +133,6 @@ namespace XED.Manage IEnumerator CoroutineLoadFromLocalData(string filePath) { isLoadTaskComplete = false; - float loadTime = 0; Task task = Task.Run(() => messagePacker.LoadAsync(filePath)); yield return new WaitUntil(() => task.IsCompleted); @@ -140,72 +144,19 @@ namespace XED.Manage isLoadTaskComplete = true; yield break; } + saveData = task.Result; + // float loadTime = 0f; + + + var command = new LoadLocalTextureDataCommand(sharedMaterial, saveData.textureDatas); + CommandInvoker.instance.Invoke(command); + + + var command2 = new LoadLocalModelDataCommand(saveData, dataRepo, fbxAnchor, sharedMaterial); + CommandInvoker.instance.Invoke(command2); - for (int i = 0; i < saveData.textureDatas.Length; i++) - { - TextureData texData = saveData.textureDatas[i]; - sharedMaterial.AddTextureData(texData); - loadTime += Time.deltaTime; - if (loadTime > 1.0f / 30.0f) - { - loadTime = 0; - yield return null; - } - } - for (int i = 0; i < saveData.modelDatas.Length; i++) - { - if (!LoadSaveData(saveData, i)) - { - continue; - } - loadTime += Time.deltaTime; - if (loadTime > 1.0f / 30.0f) - { - loadTime = 0; - yield return null; - } - } isLoadTaskComplete = true; - yield return null; - } - - bool LoadSaveData(SaveData saveData, int index) - { - var modelData = saveData.modelDatas[index]; - string assetName = modelData.attributes.FirstOrDefault(x => x[0].Equals("assetName"))?[1]; - - if (dataRepo.TryGetDataFromName(assetName, out var p)) - return false; - - string folderName = modelData.attributes.FirstOrDefault(x => x[0].Equals("folderName"))?[1]; - string createDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("createDate"))?[1]; - string lastRevisionDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("lastRevisionDate"))?[1]; - string uploadDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("uploadDate"))?[1]; - string creator = modelData.attributes.FirstOrDefault(x => x[0].Equals("creator"))?[1]; - string manager = modelData.attributes.FirstOrDefault(x => x[0].Equals("manager"))?[1]; - - Texture2D thumbnail = new Texture2D(1, 1); - thumbnail.LoadImage(saveData.thumbnailDatas[index].data); - GameObject newObject = new GameObject(assetName); - newObject.transform.parent = fbxAnchor; - CustomAssetData assetData = newObject.AddComponent(); - assetData.assetName = assetName; - assetData.folderName = folderName; - assetData.createDate = createDate; - assetData.LastRevisionDate = lastRevisionDate; - assetData.UploadDate = uploadDate; - assetData.Creator = creator; - assetData.Manager = manager; - assetData.loadedObject = modelData.LoadModelData(sharedMaterial); - assetData.thumbnail = thumbnail; - assetData.OnLoadComplete(); - - dataRepo.Add(assetData); - //listAssets.Add(assetData); - ManagerHub.instance.Get().assetDataHandler.OnLoadFbxFile(assetData.assetName, assetData.folderName, assetData); - - return true; } } } \ No newline at end of file diff --git a/Assets/Scripts/Studio/Command/FileCommand.meta b/Assets/Scripts/Studio/Command/FileCommand.meta new file mode 100644 index 00000000..6aef0191 --- /dev/null +++ b/Assets/Scripts/Studio/Command/FileCommand.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0344068c97e98f2499c3ef328e804d1c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Studio/Command/FileCommand/LoadLocalModelDataCommand.cs b/Assets/Scripts/Studio/Command/FileCommand/LoadLocalModelDataCommand.cs new file mode 100644 index 00000000..446c4ebc --- /dev/null +++ b/Assets/Scripts/Studio/Command/FileCommand/LoadLocalModelDataCommand.cs @@ -0,0 +1,94 @@ +using System.Collections; +using System.Linq; +using UnityEngine; +using XED.Asset; +using XED.Manage; +using XED.Repositories; +using XED.Util; + +namespace XED.Command +{ + public class LoadLocalModelDataCommand : IIrreversibleCommand + { + private SaveData saveData; + private CustomAssetDataRepository dataRepo; + private Transform fbxAnchor; + private SharedMaterial sharedMaterial; + + float loadTime = 0f; + + public LoadLocalModelDataCommand(SaveData saveData, CustomAssetDataRepository dataRepo, Transform fbxAnchor, SharedMaterial sharedMaterial) + { + this.saveData = saveData; + this.dataRepo = dataRepo; + this.fbxAnchor = fbxAnchor; + this.sharedMaterial = sharedMaterial; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + for (int i = 0; i < saveData.modelDatas.Length; i++) + { + CoroutineRunner.instance.StartCoroutine(LoadModelData(i)); + } + } + + IEnumerator LoadModelData(int index) + { + if (!LoadSaveData(saveData, index)) + yield break; + + loadTime += Time.deltaTime; + if (loadTime > 1f / 30f) + { + loadTime = 0f; + yield return null; + } + } + + bool LoadSaveData(SaveData saveData, int index) + { + var modelData = saveData.modelDatas[index]; + string assetName = modelData.attributes.FirstOrDefault(x => x[0].Equals("assetName"))?[1]; + + if (dataRepo.TryGetDataFromName(assetName, out var p)) + return false; + + string folderName = modelData.attributes.FirstOrDefault(x => x[0].Equals("folderName"))?[1]; + string createDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("createDate"))?[1]; + string lastRevisionDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("lastRevisionDate"))?[1]; + string uploadDate = modelData.attributes.FirstOrDefault(x => x[0].Equals("uploadDate"))?[1]; + string creator = modelData.attributes.FirstOrDefault(x => x[0].Equals("creator"))?[1]; + string manager = modelData.attributes.FirstOrDefault(x => x[0].Equals("manager"))?[1]; + + Texture2D thumbnail = new Texture2D(1, 1); + thumbnail.LoadImage(saveData.thumbnailDatas[index].data); + GameObject newObject = new GameObject(assetName); + newObject.transform.parent = fbxAnchor; + CustomAssetData assetData = newObject.AddComponent(); + assetData.assetName = assetName; + assetData.folderName = folderName; + assetData.createDate = createDate; + assetData.LastRevisionDate = lastRevisionDate; + assetData.UploadDate = uploadDate; + assetData.Creator = creator; + assetData.Manager = manager; + assetData.loadedObject = modelData.LoadModelData(sharedMaterial); + assetData.thumbnail = thumbnail; + assetData.OnLoadComplete(); + + dataRepo.Add(assetData); + //listAssets.Add(assetData); + ManagerHub.instance.Get().assetDataHandler.OnLoadFbxFile(assetData.assetName, assetData.folderName, assetData); + + return true; + } + } +} diff --git a/Assets/Scripts/Studio/Command/FileCommand/LoadLocalModelDataCommand.cs.meta b/Assets/Scripts/Studio/Command/FileCommand/LoadLocalModelDataCommand.cs.meta new file mode 100644 index 00000000..099bf9d8 --- /dev/null +++ b/Assets/Scripts/Studio/Command/FileCommand/LoadLocalModelDataCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 34c7091e151c4654f80f16448c43f36d \ No newline at end of file diff --git a/Assets/Scripts/Studio/Command/FileCommand/LoadLocalTextureDataCommand.cs b/Assets/Scripts/Studio/Command/FileCommand/LoadLocalTextureDataCommand.cs new file mode 100644 index 00000000..f78c894b --- /dev/null +++ b/Assets/Scripts/Studio/Command/FileCommand/LoadLocalTextureDataCommand.cs @@ -0,0 +1,50 @@ +using System.Collections; +using UnityEngine; +using XED.Manage; + +namespace XED.Command +{ + public class LoadLocalTextureDataCommand : IIrreversibleCommand + { + private SharedMaterial sharedMaterial; + private TextureData[] textureData; + + float loadTime = 0f; + + public LoadLocalTextureDataCommand(SharedMaterial sharedMaterial, TextureData[] textureData) + { + this.sharedMaterial = sharedMaterial; + this.textureData = textureData; + } + + public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public bool CanExecute() + { + throw new System.NotImplementedException(); + } + + public void Execute() + { + foreach (var tex in textureData) + { + CoroutineRunner.instance.StartCoroutine(LoadTextureData(tex)); + } + + } + + IEnumerator LoadTextureData(TextureData texData) + { + sharedMaterial.AddTextureData(texData); + + loadTime += Time.deltaTime; + if (loadTime > 1f / 30f) + { + loadTime = 0f; + yield return null; + } + + // yield return null; + } + } +} diff --git a/Assets/Scripts/Studio/Command/FileCommand/LoadLocalTextureDataCommand.cs.meta b/Assets/Scripts/Studio/Command/FileCommand/LoadLocalTextureDataCommand.cs.meta new file mode 100644 index 00000000..457925d2 --- /dev/null +++ b/Assets/Scripts/Studio/Command/FileCommand/LoadLocalTextureDataCommand.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 243104ea078b0364e811f6803ef3b3b2 \ No newline at end of file -- 2.48.1.windows.1