From 675589de2b93971b1cf0f0825518c10edaca4723 Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Mon, 25 Jul 2022 09:20:17 +0800 Subject: [PATCH] fix: little work around on saving data --- Scenes/SampleScene.unity | 84 ------------------- TNodeCore/Components.meta | 3 + TNodeCore/Components/RuntimeDataSaver.cs | 46 ++++++++++ TNodeCore/Components/RuntimeDataSaver.cs.meta | 3 + .../{Runtime => Components}/RuntimeGraph.cs | 12 ++- .../RuntimeGraph.cs.meta | 0 .../NodeGraphView/IBaseDataGraphView.cs | 1 + .../Editor/NodeGraphView/DataGraphView.cs | 1 + 8 files changed, 64 insertions(+), 86 deletions(-) create mode 100644 TNodeCore/Components.meta create mode 100644 TNodeCore/Components/RuntimeDataSaver.cs create mode 100644 TNodeCore/Components/RuntimeDataSaver.cs.meta rename TNodeCore/{Runtime => Components}/RuntimeGraph.cs (96%) rename TNodeCore/{Runtime => Components}/RuntimeGraph.cs.meta (100%) diff --git a/Scenes/SampleScene.unity b/Scenes/SampleScene.unity index 7c49f30..1b726a3 100644 --- a/Scenes/SampleScene.unity +++ b/Scenes/SampleScene.unity @@ -625,90 +625,6 @@ Transform: m_Father: {fileID: 507038910} m_RootOrder: -1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1648230696 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1648230698} - - component: {fileID: 1648230697} - m_Layer: 0 - m_Name: Square - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!212 &1648230697 -SpriteRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1648230696} - m_Enabled: 1 - m_CastShadows: 0 - m_ReceiveShadows: 0 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 0 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_FlipX: 0 - m_FlipY: 0 - m_DrawMode: 0 - m_Size: {x: 1, y: 1} - m_AdaptiveModeThreshold: 0.5 - m_SpriteTileMode: 0 - m_WasSpriteAssigned: 1 - m_MaskInteraction: 0 - m_SpriteSortPoint: 0 ---- !u!4 &1648230698 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1648230696} - 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: 0} - m_RootOrder: 3 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1701140682 GameObject: m_ObjectHideFlags: 0 diff --git a/TNodeCore/Components.meta b/TNodeCore/Components.meta new file mode 100644 index 0000000..9f7628b --- /dev/null +++ b/TNodeCore/Components.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 732046b8ee564bd5be9be4ce908a011b +timeCreated: 1658710679 \ No newline at end of file diff --git a/TNodeCore/Components/RuntimeDataSaver.cs b/TNodeCore/Components/RuntimeDataSaver.cs new file mode 100644 index 0000000..399907b --- /dev/null +++ b/TNodeCore/Components/RuntimeDataSaver.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +namespace TNodeCore.Components{ + public class RuntimeDataSaver:MonoBehaviour{ + public string saveName; + public string saveExtension = "tng"; + public Dictionary savedData = new(); + public void Load(){ + string path = Application.persistentDataPath + "/"+ saveName + "." + saveExtension; + if(!File.Exists(path)){ + Debug.LogWarning("File not found: " + path); + return; + } + string json = File.ReadAllText(path); + savedData = JsonUtility.FromJson>(json); + } + public void Save(){ + string path = Application.persistentDataPath + "/" + saveName + "." + saveExtension; + string json = JsonUtility.ToJson(savedData); + File.WriteAllText(path, json); + } + + public void Write(string id,object o){ + if (savedData.ContainsKey(id)){ + savedData[id] = o; + } + else{ + savedData.Add(id,o); + } + } + + public object Read(string id){ + return savedData.ContainsKey(id) ? savedData[id] : null; + } + public bool Has(string id){ + return savedData.ContainsKey(id); + } + public void Remove(string id){ + if (savedData.ContainsKey(id)){ + savedData.Remove(id); + } + } + } +} \ No newline at end of file diff --git a/TNodeCore/Components/RuntimeDataSaver.cs.meta b/TNodeCore/Components/RuntimeDataSaver.cs.meta new file mode 100644 index 0000000..cad9fa5 --- /dev/null +++ b/TNodeCore/Components/RuntimeDataSaver.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c4a377b7b5444bf08d3cf68b5a54daf5 +timeCreated: 1658710701 \ No newline at end of file diff --git a/TNodeCore/Runtime/RuntimeGraph.cs b/TNodeCore/Components/RuntimeGraph.cs similarity index 96% rename from TNodeCore/Runtime/RuntimeGraph.cs rename to TNodeCore/Components/RuntimeGraph.cs index ddc6415..0cdd8ea 100644 --- a/TNodeCore/Runtime/RuntimeGraph.cs +++ b/TNodeCore/Components/RuntimeGraph.cs @@ -2,14 +2,15 @@ using System.Collections.Generic; using System.Linq; using TNodeCore.Models; +using TNodeCore.Runtime; using UnityEngine; -namespace TNodeCore.Runtime{ +namespace TNodeCore.Components{ public class RuntimeGraph:MonoBehaviour{ public GraphData graphData; + public List sceneNodes; public readonly Dictionary RuntimeNodes = new Dictionary(); - private GraphTool _graphTool; private class GraphTool{ @@ -182,6 +183,13 @@ namespace TNodeCore.Runtime{ RuntimeNodes.Clear(); _build = false; } + + public void Start(){ + Build(); + } + public virtual void RuntimeExecute(){ + _graphTool.DirectlyTraversal(); + } } diff --git a/TNodeCore/Runtime/RuntimeGraph.cs.meta b/TNodeCore/Components/RuntimeGraph.cs.meta similarity index 100% rename from TNodeCore/Runtime/RuntimeGraph.cs.meta rename to TNodeCore/Components/RuntimeGraph.cs.meta diff --git a/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs b/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs index 7db65a6..0208be5 100644 --- a/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs +++ b/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs @@ -1,4 +1,5 @@ using System; +using TNodeCore.Components; using TNodeCore.Models; using TNodeCore.Runtime; using UnityEngine; diff --git a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index 9836559..c16e838 100644 --- a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs +++ b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; using TNode.Editor.Inspector; +using TNodeCore.Components; using TNodeCore.Editor.Blackboard; using TNodeCore.Editor.EditorPersistence; using TNodeCore.Editor.NodeGraphView;