Persistent Variables & refactor setup (pre break)
This commit is contained in:
parent
96ab7cd8d7
commit
71098561e2
22 changed files with 1457 additions and 22 deletions
BIN
Assets/Data.dat
Normal file
BIN
Assets/Data.dat
Normal file
Binary file not shown.
7
Assets/Data.dat.meta
Normal file
7
Assets/Data.dat.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7823259b9d149ac4a9f207b7b99fba2c
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -12,6 +12,7 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: b37f4483e8f4f3047b5e67b5118cb74d, type: 3}
|
m_Script: {fileID: 11500000, guid: b37f4483e8f4f3047b5e67b5118cb74d, type: 3}
|
||||||
m_Name: Design
|
m_Name: Design
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
queued: 0
|
||||||
headOffset: {x: 0, y: 0, z: -22}
|
headOffset: {x: 0, y: 0, z: -22}
|
||||||
pivotPos: {x: 0, y: 2.8, z: 0}
|
pivotPos: {x: 0, y: 2.8, z: 0}
|
||||||
scale: 60
|
scale: 60
|
||||||
|
|
BIN
Assets/Design.dat
Normal file
BIN
Assets/Design.dat
Normal file
Binary file not shown.
7
Assets/Design.dat.meta
Normal file
7
Assets/Design.dat.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dc92bee0d4022a9479f4d214b67d9a96
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
15
Assets/Remember.asset
Normal file
15
Assets/Remember.asset
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 9979df78c5c6af94ca9d03ad1c89cceb, type: 3}
|
||||||
|
m_Name: Remember
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
queued: 0
|
8
Assets/Remember.asset.meta
Normal file
8
Assets/Remember.asset.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4ba49476e4b08964eb357fe5eb5a4b00
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
File diff suppressed because it is too large
Load diff
|
@ -1,11 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[CreateAssetMenu]
|
[CreateAssetMenu]
|
||||||
public class Design : ScriptableObject
|
public class Design : ScriptableObject
|
||||||
{
|
{
|
||||||
|
public bool queued;
|
||||||
|
|
||||||
[Header("View")]
|
[Header("View")]
|
||||||
public Vector3 headOffset = new Vector3(0, 0, -60);
|
public Vector3 headOffset = new Vector3(0, 0, -60);
|
||||||
public Vector3 pivotPos;
|
public Vector3 pivotPos;
|
||||||
|
|
166
Assets/Scripts/InspectorSetter.cs
Normal file
166
Assets/Scripts/InspectorSetter.cs
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using NaughtyAttributes;
|
||||||
|
|
||||||
|
[ExecuteAlways]
|
||||||
|
public class InspectorSetter : MonoBehaviour
|
||||||
|
{
|
||||||
|
// the gap of data is on quit in the editor
|
||||||
|
// on quit -> save to file and queue editor setter
|
||||||
|
public CustomDic[] customDic = new CustomDic[1024];
|
||||||
|
public string filePath = "C:/dofdev/SnakeInABox/Assets/Data.dat";
|
||||||
|
|
||||||
|
[Header("References")]
|
||||||
|
public Monolith mono;
|
||||||
|
public Remember remember;
|
||||||
|
|
||||||
|
[Button]
|
||||||
|
public void FreshDic()
|
||||||
|
{
|
||||||
|
customDic = new CustomDic[1024];
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Queue()
|
||||||
|
{
|
||||||
|
Serialize();
|
||||||
|
remember.queued = true;
|
||||||
|
EditorUtility.SetDirty(remember);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (remember.queued)
|
||||||
|
{
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
Deserialize();
|
||||||
|
mono.Fetch(this);
|
||||||
|
|
||||||
|
remember.queued = false;
|
||||||
|
EditorUtility.SetDirty(mono);
|
||||||
|
EditorUtility.SetDirty(remember);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Serialize()
|
||||||
|
{
|
||||||
|
FileStream fs = new FileStream(filePath, FileMode.Create);
|
||||||
|
BinaryFormatter formatter = new BinaryFormatter();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
formatter.Serialize(fs, customDic);
|
||||||
|
}
|
||||||
|
catch (SerializationException e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Failed to serialize. Reason: " + e.Message);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
fs.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deserialize()
|
||||||
|
{
|
||||||
|
FileStream fs = new FileStream(filePath, FileMode.Open);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
BinaryFormatter formatter = new BinaryFormatter();
|
||||||
|
customDic = (CustomDic[])formatter.Deserialize(fs);
|
||||||
|
}
|
||||||
|
catch (SerializationException e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Failed to deserialize. Reason: " + e.Message);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
fs.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(string key, dynamic data)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < customDic.Length; i++)
|
||||||
|
{
|
||||||
|
if (customDic[i].key == key)
|
||||||
|
{
|
||||||
|
if (data.GetType() == typeof(Vector3) || data.GetType() == typeof(Vector3Int))
|
||||||
|
{
|
||||||
|
customDic[i + 0].data = data.x;
|
||||||
|
customDic[i + 1].data = data.y;
|
||||||
|
customDic[i + 2].data = data.z;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
customDic[i].data = data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (customDic[i].key == "")
|
||||||
|
{
|
||||||
|
if (data.GetType() == typeof(Vector3) || data.GetType() == typeof(Vector3Int))
|
||||||
|
{
|
||||||
|
customDic[i + 0] = new CustomDic(key, data.x);
|
||||||
|
customDic[i + 1] = new CustomDic(key, data.y);
|
||||||
|
customDic[i + 2] = new CustomDic(key, data.z);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
customDic[i] = new CustomDic(key, data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public dynamic Fetch(string key, dynamic data)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
while (i < customDic.Length)
|
||||||
|
{
|
||||||
|
if (customDic[i].key == key)
|
||||||
|
{
|
||||||
|
if (data.GetType() == typeof(Vector3))
|
||||||
|
{
|
||||||
|
return new Vector3(customDic[i + 0].data, customDic[i + 1].data, customDic[i + 2].data);
|
||||||
|
}
|
||||||
|
else if (data.GetType() == typeof(Vector3Int))
|
||||||
|
{
|
||||||
|
return new Vector3Int(customDic[i + 0].data, customDic[i + 1].data, customDic[i + 2].data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return customDic[i].data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (customDic[i].key == "")
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class CustomDic
|
||||||
|
{
|
||||||
|
public CustomDic(string key, dynamic data)
|
||||||
|
{
|
||||||
|
this.key = key;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string key;
|
||||||
|
public dynamic data;
|
||||||
|
}
|
11
Assets/Scripts/InspectorSetter.cs.meta
Normal file
11
Assets/Scripts/InspectorSetter.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 546049c444196c2449117da7b0117469
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
35
Assets/Scripts/Logic.cs
Normal file
35
Assets/Scripts/Logic.cs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class Logic
|
||||||
|
{
|
||||||
|
[HideInInspector]
|
||||||
|
public Monolith mono;
|
||||||
|
|
||||||
|
// public Rig rig;
|
||||||
|
|
||||||
|
// [Header("Variables")]
|
||||||
|
|
||||||
|
// public World world; Snake snake; public Box box; public
|
||||||
|
|
||||||
|
public void Set(InspectorSetter setter)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fetch(InspectorSetter setter)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start(Monolith mono)
|
||||||
|
{
|
||||||
|
this.mono = mono;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Logic.cs.meta
Normal file
11
Assets/Scripts/Logic.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 03488fca6f559bd40829bbfe2105a22b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
50
Assets/Scripts/Monolith.cs
Normal file
50
Assets/Scripts/Monolith.cs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Monolith : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Logic logic;
|
||||||
|
public Render render;
|
||||||
|
|
||||||
|
[Header("Variables")]
|
||||||
|
public float test;
|
||||||
|
public string words = "";
|
||||||
|
public Vector3 v3;
|
||||||
|
|
||||||
|
[Header("References")]
|
||||||
|
public InspectorSetter setter;
|
||||||
|
|
||||||
|
void OnDisable()
|
||||||
|
{
|
||||||
|
setter.Set("Monolith.test", test);
|
||||||
|
setter.Set("Monolith.words", words);
|
||||||
|
setter.Set("Monolith.v3", v3);
|
||||||
|
|
||||||
|
logic.Set(setter);
|
||||||
|
render.Set(setter);
|
||||||
|
|
||||||
|
setter.Queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fetch(InspectorSetter setter)
|
||||||
|
{
|
||||||
|
test = setter.Fetch("Monolith.test", test);
|
||||||
|
words = setter.Fetch("Monolith.words", words);
|
||||||
|
v3 = setter.Fetch("Monolith.v3", v3);
|
||||||
|
|
||||||
|
logic.Fetch(setter);
|
||||||
|
render.Fetch(setter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
logic.Start(this);
|
||||||
|
render.Start(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
logic.Update();
|
||||||
|
render.Update();
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Monolith.cs.meta
Normal file
11
Assets/Scripts/Monolith.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0a00aee37b6d4e24e9b7afeeffd9e427
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Scripts/Remember.cs
Normal file
7
Assets/Scripts/Remember.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[CreateAssetMenu]
|
||||||
|
public class Remember : ScriptableObject
|
||||||
|
{
|
||||||
|
public bool queued;
|
||||||
|
}
|
11
Assets/Scripts/Remember.cs.meta
Normal file
11
Assets/Scripts/Remember.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9979df78c5c6af94ca9d03ad1c89cceb
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
29
Assets/Scripts/Render.cs
Normal file
29
Assets/Scripts/Render.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class Render
|
||||||
|
{
|
||||||
|
[HideInInspector]
|
||||||
|
public Monolith mono;
|
||||||
|
|
||||||
|
public void Set(InspectorSetter setter)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fetch(InspectorSetter setter)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start(Monolith mono)
|
||||||
|
{
|
||||||
|
this.mono = mono;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Render.cs.meta
Normal file
11
Assets/Scripts/Render.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d1df8e974ecde244aaa4f06a76d91063
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -2,8 +2,12 @@ using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.XR;
|
using UnityEngine.XR;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
public class Rig : MonoBehaviour
|
public class Rig : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[HideInInspector]
|
||||||
|
public Monolith mono;
|
||||||
|
|
||||||
[Header("References")]
|
[Header("References")]
|
||||||
public Design design;
|
public Design design;
|
||||||
public Main main;
|
public Main main;
|
||||||
|
|
|
@ -649,7 +649,8 @@ PlayerSettings:
|
||||||
allowUnsafeCode: 0
|
allowUnsafeCode: 0
|
||||||
additionalIl2CppArgs:
|
additionalIl2CppArgs:
|
||||||
scriptingRuntimeVersion: 1
|
scriptingRuntimeVersion: 1
|
||||||
apiCompatibilityLevelPerPlatform: {}
|
apiCompatibilityLevelPerPlatform:
|
||||||
|
Standalone: 3
|
||||||
m_RenderingPath: 1
|
m_RenderingPath: 1
|
||||||
m_MobileRenderingPath: 1
|
m_MobileRenderingPath: 1
|
||||||
metroPackageName: Template_3D
|
metroPackageName: Template_3D
|
||||||
|
|
|
@ -41,17 +41,4 @@ QualitySettings:
|
||||||
asyncUploadPersistentBuffer: 1
|
asyncUploadPersistentBuffer: 1
|
||||||
resolutionScalingFixedDPIFactor: 1
|
resolutionScalingFixedDPIFactor: 1
|
||||||
excludedTargetPlatforms: []
|
excludedTargetPlatforms: []
|
||||||
m_PerPlatformDefaultQuality:
|
m_PerPlatformDefaultQuality: {}
|
||||||
Android: 0
|
|
||||||
Nintendo 3DS: 0
|
|
||||||
Nintendo Switch: 0
|
|
||||||
PS4: 0
|
|
||||||
PSP2: 0
|
|
||||||
Standalone: 0
|
|
||||||
Tizen: 0
|
|
||||||
WebGL: 0
|
|
||||||
WiiU: 0
|
|
||||||
Windows Store Apps: 0
|
|
||||||
XboxOne: 0
|
|
||||||
iPhone: 0
|
|
||||||
tvOS: 0
|
|
||||||
|
|
Reference in a new issue