Skip to content

Commit fa82d46

Browse files
[Dynamic Data] Saving your datas in a file and loading other from a file (#227)
* added saving of dynamic data * correction * added loading files * added loading data and improve prefab * fixed build mode * fixed customdataname issue for Vec3 * added Vec3 save and load * prevent adding save data to github with a gitignore modification * added sample scene * modify namespaces and fixed dicrtionnary find * fixed bug in order of finding vec3 sliders * fixed wrong mathf function * replace the example scene * Modifs * added basic forcefield for dynamic data demo * Update Scenes/SofaScenes/caduceus.scn Co-authored-by: erik pernod <erik.pernod@gmail.com> --------- Co-authored-by: erik pernod <erik.pernod@gmail.com>
1 parent b5dbe8b commit fa82d46

13 files changed

Lines changed: 22547 additions & 515 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ License/*
66
*.pyc.*
77
Core/Scripts/Editor/Tests/logs/
88
Tests/logs/
9+
Core/Scripts/UI/DataManager/DynamicDataSaves/*.JSON
10+
Core/Scripts/UI/DataManager/DynamicDataSaves/*.meta

Core/Scripts/UI/DataManager/DynamicDataSaves.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Core/Scripts/UI/DataManager/DynamicSDataManager.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
using SofaUnityAPI;
88
using TMPro;
99

10-
namespace SofaUnityXR
10+
namespace SofaUnity
1111
{
1212
/// <summary>
13-
/// Data types
13+
/// Data types supported
1414
/// </summary>
1515
public enum SofaDataType
1616
{
@@ -48,7 +48,7 @@ public SofaDataReference(SofaBaseComponent sofaComponent, string dataName, SofaD
4848

4949
public class DynamicSDataManager : MonoBehaviour
5050
{
51-
[SerializeField] private List<SofaDataReference> DSDataList = new List<SofaDataReference>();
51+
[SerializeField] public List<SofaDataReference> DSDataList = new List<SofaDataReference>();
5252
public GameObject UIContainer;
5353
public GameObject DSDataprefab;
5454
public GameObject Vec3_DSDataprefab;
@@ -128,6 +128,17 @@ public void CreateUIElement (SofaDataReference data)
128128
components[i].MAX= data.MAX;
129129
components[i].SetDataName(dataName);
130130
components[i].SetDataType(dataType);
131+
132+
133+
if (string.IsNullOrEmpty(data.optionalCustomName))
134+
{
135+
components[i].SetUIName(dataName);//No custom name so default
136+
}
137+
else
138+
{
139+
components[i].SetUIName(data.optionalCustomName);
140+
}
141+
131142
components[i].DynamicSdataSetup(SBcomp);
132143
}
133144

@@ -167,7 +178,7 @@ public void CreateUIElement (SofaDataReference data)
167178
/// <param name="data"></param>
168179
void FindSofaComponentInScene(SofaDataReference data)
169180
{
170-
SofaBaseComponent[] allBaseComponents = FindObjectsOfType<SofaBaseComponent>();
181+
SofaBaseComponent[] allBaseComponents = FindObjectsByType<SofaBaseComponent>(FindObjectsSortMode.None);
171182

172183
bool found = false;
173184

Core/Scripts/UI/DataManager/DynamicSdata.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Collections.Generic;
88

99

10-
namespace SofaUnityXR
10+
namespace SofaUnity
1111
{
1212
public class DynamicSdata : MonoBehaviour
1313
{
@@ -102,7 +102,7 @@ public void DynamicSdataSetup(SofaBaseComponent SofaBaseComp)
102102
mainPropretySlider.onValueChanged.AddListener(SliderFloat);
103103
break;
104104

105-
case SofaDataType.Double:
105+
case SofaDataType.Double: //double
106106

107107

108108

@@ -285,6 +285,21 @@ public void SetDataName( string DataName)
285285
dataName = DataName;
286286
}
287287

288+
public string GetDataName()
289+
{
290+
return dataName;
291+
}
292+
293+
public string GetUIName()
294+
{
295+
return UIName;
296+
}
297+
298+
public Slider GetSlider()
299+
{
300+
return (mainPropretySlider);
301+
}
302+
288303
public void SetUIName(string thisUIName)
289304
{
290305
UIName = thisUIName;
@@ -295,6 +310,11 @@ public void SetDataType(SofaDataType DataType)
295310
dataType = DataType;
296311
}
297312

313+
public SofaDataType GetDataType()
314+
{
315+
return dataType;
316+
}
317+
298318
} // end class
299319
} //end namespace
300320

Core/Scripts/UI/DataManager/DynamicSofaData.prefab

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ RectTransform:
145145
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
146146
m_AnchorMin: {x: 0.5, y: 0.5}
147147
m_AnchorMax: {x: 0.5, y: 0.5}
148-
m_AnchoredPosition: {x: -46, y: 0}
148+
m_AnchoredPosition: {x: -46, y: -1.6}
149149
m_SizeDelta: {x: 200, y: 50}
150150
m_Pivot: {x: 0.5, y: 0.5}
151151
--- !u!222 &4133571076758841288
@@ -176,7 +176,7 @@ MonoBehaviour:
176176
m_OnCullStateChanged:
177177
m_PersistentCalls:
178178
m_Calls: []
179-
m_text: 'Data Name :'
179+
m_text: Default Data Name
180180
m_isRightToLeft: 0
181181
m_fontAsset: {fileID: 11400000, guid: 522c1115e7013564d92c8fe0fd6d554b, type: 2}
182182
m_sharedMaterial: {fileID: 2833549502675358344, guid: 522c1115e7013564d92c8fe0fd6d554b, type: 2}
@@ -203,8 +203,8 @@ MonoBehaviour:
203203
m_faceColor:
204204
serializedVersion: 2
205205
rgba: 4294967295
206-
m_fontSize: 22
207-
m_fontSizeBase: 22
206+
m_fontSize: 18
207+
m_fontSizeBase: 18
208208
m_fontWeight: 400
209209
m_enableAutoSizing: 0
210210
m_fontSizeMin: 18
@@ -241,7 +241,7 @@ MonoBehaviour:
241241
m_VertexBufferAutoSizeReduction: 0
242242
m_useMaxVisibleDescender: 1
243243
m_pageToDisplay: 1
244-
m_margin: {x: 0, y: 0, z: 0, w: 22.125357}
244+
m_margin: {x: 0, y: 0, z: -97.41943, w: 22.125357}
245245
m_isUsingLegacyAnimationComponent: 0
246246
m_isVolumetricText: 0
247247
m_hasFontAssetChanged: 0
@@ -603,6 +603,8 @@ MonoBehaviour:
603603
mainPropretySlider: {fileID: 4087773701116171958}
604604
PropretyName: {fileID: 3080495347422872568}
605605
PropretyValue: {fileID: 5782485129368148144}
606+
MIN: 0
607+
MAX: 0
606608
--- !u!1 &6919628777754564137
607609
GameObject:
608610
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)