Some minor updates to the shader scripts

Added the new Compression and Serialization utilities.  Completely not UI but too awesome not to add

--HG--
branch : develop_5.3
release
Simon (darkside) Jackson 2016-06-02 22:05:21 +01:00
parent 8178bfc7c6
commit 7aed82c821
57 changed files with 2623 additions and 10 deletions

View File

@ -0,0 +1,218 @@
using NUnit.Framework;
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using UnityEngine;
using UnityEngine.UI.Extensions;
public class CompressionTests {
[Test]
public void RandomGUIDCompressionTestLength()
{
string x = string.Empty;
using (var sequence = Enumerable.Range(1, 100).GetEnumerator())
{
while(sequence.MoveNext()) // string length 3600
{
x += Guid.NewGuid();
}
}
byte[] byteText = Encoding.Unicode.GetBytes(x);
var compressed = CLZF2.Compress(byteText);
var decompressed = CLZF2.Decompress(compressed);
Assert.AreEqual(byteText.Length, decompressed.Length);
}
[Test]
public void RandomGUIDCompressionTestBytes()
{
string x = string.Empty;
using (var sequence = Enumerable.Range(1, 100).GetEnumerator())
{
while (sequence.MoveNext()) // string length 3600
{
x += Guid.NewGuid();
}
}
byte[] byteText = Encoding.Unicode.GetBytes(x);
var compressed = CLZF2.Compress(byteText);
var decompressed = CLZF2.Decompress(compressed);
Assert.AreEqual(byteText, decompressed);
}
[Test]
public void RandomGUIDCompressionTestString()
{
string x = string.Empty;
using (var sequence = Enumerable.Range(1, 100).GetEnumerator())
{
while (sequence.MoveNext()) // string length 3600
{
x += Guid.NewGuid();
}
}
byte[] byteText = Encoding.Unicode.GetBytes(x);
var compressed = CLZF2.Compress(byteText);
var decompressed = CLZF2.Decompress(compressed);
var outString = Encoding.Unicode.GetString(decompressed);
Assert.AreEqual(outString, x);
}
[Test]
public void ThousandCharacterCompressionTest()
{
var x = new string('X', 10000);
byte[] byteText = Encoding.Unicode.GetBytes(x);
byte[] compressed = CLZF2.Compress(byteText);
byte[] decompressed = CLZF2.Decompress(compressed);
var outString = Encoding.Unicode.GetString(decompressed);
Assert.AreEqual(byteText.Length, decompressed.Length);
Assert.AreEqual(byteText, decompressed);
Assert.AreEqual(outString, x);
}
[Test]
public void LongFormattedStringCompressionTest()
{
string longstring = "defined input is deluciously delicious.14 And here and Nora called The reversal from ground from here and executed with touch the country road, Nora made of, reliance on, cant publish the goals of grandeur, said to his book and encouraging an envelope, and enable entry into the chryssial shimmering of hers, so God of information in her hands Spiros sits down the sign of winter? —Its kind of Spice Christ. It is one hundred birds circle above the text: They did we said. 69 percent dead. Sissy Cogans shadow. —Are you x then sings.) Im 96 percent dead humanoid figure,";
byte[] byteText = Encoding.Unicode.GetBytes(longstring);
byte[] compressed = CLZF2.Compress(byteText);
byte[] decompressed = CLZF2.Decompress(compressed);
var outString = Encoding.Unicode.GetString(decompressed);
Assert.AreEqual(byteText.Length, decompressed.Length);
Assert.AreEqual(byteText, decompressed);
Assert.AreEqual(outString, longstring);
}
[Test]
public void SavingSimpleObject()
{
Vector3[] MySaveItem = new Vector3[1000];
for (int i = 0; i < MySaveItem.Length; i++)
{
MySaveItem[i] = Vector3.one * i;
}
var mySaveObject = ObjectToByteArray(MySaveItem);
byte[] compressed = CLZF2.Compress(mySaveObject);
byte[] decompressed = CLZF2.Decompress(compressed);
var outSaveObject = ObjectToByteArray<Vector3[]>(decompressed);
Assert.AreEqual(mySaveObject.Length, decompressed.Length);
Assert.AreEqual(mySaveObject, decompressed);
Assert.AreEqual(outSaveObject, MySaveItem);
}
[Test]
public void SavingComplexObject()
{
MyComplexObject[] MySaveItem = new MyComplexObject[1000];
for (int i = 0; i < MySaveItem.Length; i++)
{
var item = new MyComplexObject();
item.myPosition = Vector3.one * i;
item.myPositionHistory = new Vector3[100];
item.myChatHistory = new string[100];
for (int j = 0; j < 100; j++)
{
item.myPositionHistory[j] = Vector3.one * j;
item.myChatHistory[j] = "Chat line: " + j;
}
}
var mySaveObject = ObjectToByteArray(MySaveItem);
byte[] compressed = CLZF2.Compress(mySaveObject);
byte[] decompressed = CLZF2.Decompress(compressed);
var outSaveObject = ObjectToByteArray<MyComplexObject[]>(decompressed);
Assert.AreEqual(mySaveObject.Length, decompressed.Length);
Assert.AreEqual(mySaveObject, decompressed);
Assert.AreEqual(outSaveObject, MySaveItem);
}
[Serializable]
struct MyComplexObject
{
public Vector3 myPosition;
public Vector3[] myPositionHistory;
public Transform mytransform;
public string[] myChatHistory;
}
byte[] ObjectToByteArray(object obj)
{
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
// 1. Construct a SurrogateSelector object
SurrogateSelector ss = new SurrogateSelector();
// 2. Add the ISerializationSurrogates to our new SurrogateSelector
AddSurrogates(ref ss);
// 3. Have the formatter use our surrogate selector
bf.SurrogateSelector = ss;
using (MemoryStream ms = new MemoryStream())
{
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
T ObjectToByteArray<T>(byte[] arrBytes)
{
if (arrBytes == null)
return default(T);
using (MemoryStream memStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
// 1. Construct a SurrogateSelector object
SurrogateSelector ss = new SurrogateSelector();
// 2. Add the ISerializationSurrogates to our new SurrogateSelector
AddSurrogates(ref ss);
// 3. Have the formatter use our surrogate selector
bf.SurrogateSelector = ss;
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
T obj = (T)bf.Deserialize(memStream);
return obj;
}
}
private static void AddSurrogates(ref SurrogateSelector ss)
{
Vector2Surrogate Vector2_SS = new Vector2Surrogate();
ss.AddSurrogate(typeof(Vector2),
new StreamingContext(StreamingContextStates.All),
Vector2_SS);
Vector3Surrogate Vector3_SS = new Vector3Surrogate();
ss.AddSurrogate(typeof(Vector3),
new StreamingContext(StreamingContextStates.All),
Vector3_SS);
Vector4Surrogate Vector4_SS = new Vector4Surrogate();
ss.AddSurrogate(typeof(Vector4),
new StreamingContext(StreamingContextStates.All),
Vector4_SS);
ColorSurrogate Color_SS = new ColorSurrogate();
ss.AddSurrogate(typeof(Color),
new StreamingContext(StreamingContextStates.All),
Color_SS);
QuaternionSurrogate Quaternion_SS = new QuaternionSurrogate();
ss.AddSurrogate(typeof(Quaternion),
new StreamingContext(StreamingContextStates.All),
Quaternion_SS);
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ff5c7cf8d5ccd284482327cd78debc20
timeCreated: 1464888738
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,7 +10,6 @@ namespace UnityEngine.UI.Extensions
public class UIAdditiveEffect : MonoBehaviour
{
MaskableGraphic mGraphic;
Material mat;
// Use this for initialization
void Start()
@ -28,7 +27,6 @@ namespace UnityEngine.UI.Extensions
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UIAdditive"));
}
mat = mGraphic.material;
}
else
{

View File

@ -10,7 +10,6 @@ namespace UnityEngine.UI.Extensions
public class UILinearDodgeEffect : MonoBehaviour
{
MaskableGraphic mGraphic;
Material mat;
// Use this for initialization
void Start()
@ -28,7 +27,6 @@ namespace UnityEngine.UI.Extensions
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UILinearDodge"));
}
mat = mGraphic.material;
}
else
{

View File

@ -10,7 +10,6 @@ namespace UnityEngine.UI.Extensions
public class UIMultiplyEffect : MonoBehaviour
{
MaskableGraphic mGraphic;
Material mat;
// Use this for initialization
void Start()
@ -28,7 +27,6 @@ namespace UnityEngine.UI.Extensions
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UIMultiply"));
}
mat = mGraphic.material;
}
else
{

View File

@ -10,7 +10,6 @@ namespace UnityEngine.UI.Extensions
public class UIScreenEffect : MonoBehaviour
{
MaskableGraphic mGraphic;
Material mat;
// Use this for initialization
void Start()
@ -28,7 +27,6 @@ namespace UnityEngine.UI.Extensions
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UIScreen"));
}
mat = mGraphic.material;
}
else
{

View File

@ -10,7 +10,6 @@ namespace UnityEngine.UI.Extensions
public class UISoftAdditiveEffect : MonoBehaviour
{
MaskableGraphic mGraphic;
Material mat;
// Use this for initialization
void Start()
@ -28,7 +27,6 @@ namespace UnityEngine.UI.Extensions
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UISoftAdditive"));
}
mat = mGraphic.material;
}
else
{

340
Scripts/Utilities/CLZF2.cs Normal file
View File

@ -0,0 +1,340 @@
//
// http://forum.unity3d.com/threads/lzf-compression-and-decompression-for-unity.152579/
//
/*
* Improved version to C# LibLZF Port:
* Copyright (c) 2010 Roman Atachiants <kelindar@gmail.com>
*
* Original CLZF Port:
* Copyright (c) 2005 Oren J. Maurice <oymaurice@hazorea.org.il>
*
* Original LibLZF Library Algorithm:
* Copyright (c) 2000-2008 Marc Alexander Lehmann <schmorp@schmorp.de>
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
* CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
* ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License version 2 (the "GPL"), in which case the
* provisions of the GPL are applicable instead of the above. If you wish to
* allow the use of your version of this file only under the terms of the
* GPL and not to allow others to use your version of this file under the
* BSD license, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the GPL. If
* you do not delete the provisions above, a recipient may use your version
* of this file under either the BSD or the GPL.
*/
/* Benchmark with Alice29 Canterbury Corpus
---------------------------------------
(Compression) Original CLZF C#
Raw = 152089, Compressed = 101092
8292,4743 ms.
---------------------------------------
(Compression) My LZF C#
Raw = 152089, Compressed = 101092
33,0019 ms.
---------------------------------------
(Compression) Zlib using SharpZipLib
Raw = 152089, Compressed = 54388
8389,4799 ms.
---------------------------------------
(Compression) QuickLZ C#
Raw = 152089, Compressed = 83494
80,0046 ms.
---------------------------------------
(Decompression) Original CLZF C#
Decompressed = 152089
16,0009 ms.
---------------------------------------
(Decompression) My LZF C#
Decompressed = 152089
15,0009 ms.
---------------------------------------
(Decompression) Zlib using SharpZipLib
Decompressed = 152089
3577,2046 ms.
---------------------------------------
(Decompression) QuickLZ C#
Decompressed = 152089
21,0012 ms.
*/
using System;
namespace UnityEngine.UI.Extensions
{
/// <summary>
/// Improved C# LZF Compressor, a very small data compression library. The compression algorithm is extremely fast.
/// Note for strings, ensure you only use Unicode else specaial characters may get corrupted.
public static class CLZF2
{
private static readonly uint HLOG = 14;
private static readonly uint HSIZE = (1 << 14);
private static readonly uint MAX_LIT = (1 << 5);
private static readonly uint MAX_OFF = (1 << 13);
private static readonly uint MAX_REF = ((1 << 8) + (1 << 3));
/// <summary>
/// Hashtable, that can be allocated only once
/// </summary>
private static readonly long[] HashTable = new long[HSIZE];
// Compresses inputBytes
public static byte[] Compress(byte[] inputBytes)
{
// Starting guess, increase it later if needed
int outputByteCountGuess = inputBytes.Length * 2;
byte[] tempBuffer = new byte[outputByteCountGuess];
int byteCount = lzf_compress(inputBytes, ref tempBuffer);
// If byteCount is 0, then increase buffer and try again
while (byteCount == 0)
{
outputByteCountGuess *= 2;
tempBuffer = new byte[outputByteCountGuess];
byteCount = lzf_compress(inputBytes, ref tempBuffer);
}
byte[] outputBytes = new byte[byteCount];
Buffer.BlockCopy(tempBuffer, 0, outputBytes, 0, byteCount);
return outputBytes;
}
// Decompress outputBytes
public static byte[] Decompress(byte[] inputBytes)
{
// Starting guess, increase it later if needed
int outputByteCountGuess = inputBytes.Length * 2;
byte[] tempBuffer = new byte[outputByteCountGuess];
int byteCount = lzf_decompress(inputBytes, ref tempBuffer);
// If byteCount is 0, then increase buffer and try again
while (byteCount == 0)
{
outputByteCountGuess *= 2;
tempBuffer = new byte[outputByteCountGuess];
byteCount = lzf_decompress(inputBytes, ref tempBuffer);
}
byte[] outputBytes = new byte[byteCount];
Buffer.BlockCopy(tempBuffer, 0, outputBytes, 0, byteCount);
return outputBytes;
}
/// <summary>
/// Compresses the data using LibLZF algorithm
/// </summary>
/// <param name="input">Reference to the data to compress</param>
/// <param name="output">Reference to a buffer which will contain the compressed data</param>
/// <returns>The size of the compressed archive in the output buffer</returns>
public static int lzf_compress(byte[] input, ref byte[] output)
{
int inputLength = input.Length;
int outputLength = output.Length;
Array.Clear(HashTable, 0, (int)HSIZE);
long hslot;
uint iidx = 0;
uint oidx = 0;
long reference;
uint hval = (uint)(((input[iidx]) << 8) | input[iidx + 1]); // FRST(in_data, iidx);
long off;
int lit = 0;
for (;;)
{
if (iidx < inputLength - 2)
{
hval = (hval << 8) | input[iidx + 2];
hslot = ((hval ^ (hval << 5)) >> (int)(((3 * 8 - HLOG)) - hval * 5) & (HSIZE - 1));
reference = HashTable[hslot];
HashTable[hslot] = (long)iidx;
if ((off = iidx - reference - 1) < MAX_OFF
&& iidx + 4 < inputLength
&& reference > 0
&& input[reference + 0] == input[iidx + 0]
&& input[reference + 1] == input[iidx + 1]
&& input[reference + 2] == input[iidx + 2]
)
{
/* match found at *reference++ */
uint len = 2;
uint maxlen = (uint)inputLength - iidx - len;
maxlen = maxlen > MAX_REF ? MAX_REF : maxlen;
if (oidx + lit + 1 + 3 >= outputLength)
return 0;
do
len++;
while (len < maxlen && input[reference + len] == input[iidx + len]);
if (lit != 0)
{
output[oidx++] = (byte)(lit - 1);
lit = -lit;
do
output[oidx++] = input[iidx + lit];
while ((++lit) != 0);
}
len -= 2;
iidx++;
if (len < 7)
{
output[oidx++] = (byte)((off >> 8) + (len << 5));
}
else
{
output[oidx++] = (byte)((off >> 8) + (7 << 5));
output[oidx++] = (byte)(len - 7);
}
output[oidx++] = (byte)off;
iidx += len - 1;
hval = (uint)(((input[iidx]) << 8) | input[iidx + 1]);
hval = (hval << 8) | input[iidx + 2];
HashTable[((hval ^ (hval << 5)) >> (int)(((3 * 8 - HLOG)) - hval * 5) & (HSIZE - 1))] = iidx;
iidx++;
hval = (hval << 8) | input[iidx + 2];
HashTable[((hval ^ (hval << 5)) >> (int)(((3 * 8 - HLOG)) - hval * 5) & (HSIZE - 1))] = iidx;
iidx++;
continue;
}
}
else if (iidx == inputLength)
break;
/* one more literal byte we must copy */
lit++;
iidx++;
if (lit == MAX_LIT)
{
if (oidx + 1 + MAX_LIT >= outputLength)
return 0;
output[oidx++] = (byte)(MAX_LIT - 1);
lit = -lit;
do
output[oidx++] = input[iidx + lit];
while ((++lit) != 0);
}
}
if (lit != 0)
{
if (oidx + lit + 1 >= outputLength)
return 0;
output[oidx++] = (byte)(lit - 1);
lit = -lit;
do
output[oidx++] = input[iidx + lit];
while ((++lit) != 0);
}
return (int)oidx;
}
/// <summary>
/// Decompresses the data using LibLZF algorithm
/// </summary>
/// <param name="input">Reference to the data to decompress</param>
/// <param name="output">Reference to a buffer which will contain the decompressed data</param>
/// <returns>Returns decompressed size</returns>
public static int lzf_decompress(byte[] input, ref byte[] output)
{
int inputLength = input.Length;
int outputLength = output.Length;
uint iidx = 0;
uint oidx = 0;
do
{
uint ctrl = input[iidx++];
if (ctrl < (1 << 5)) /* literal run */
{
ctrl++;
if (oidx + ctrl > outputLength)
{
//SET_ERRNO (E2BIG);
return 0;
}
do
output[oidx++] = input[iidx++];
while ((--ctrl) != 0);
}
else /* back reference */
{
uint len = ctrl >> 5;
int reference = (int)(oidx - ((ctrl & 0x1f) << 8) - 1);
if (len == 7)
len += input[iidx++];
reference -= input[iidx++];
if (oidx + len + 2 > outputLength)
{
//SET_ERRNO (E2BIG);
return 0;
}
if (reference < 0)
{
//SET_ERRNO (EINVAL);
return 0;
}
output[oidx++] = output[reference++];
output[oidx++] = output[reference++];
do
output[oidx++] = output[reference++];
while ((--len) != 0);
}
}
while (iidx < inputLength);
return (int)oidx;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f69e6f88ce470d742adfcbaf0bcbd001
timeCreated: 1464877682
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1ef00bcef4289ff46a687da0f3bb245a
folderAsset: yes
timeCreated: 1435843505
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: de298d0f8df2abd4b898cede877984fc
folderAsset: yes
timeCreated: 1435844327
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
using System;
namespace UnityEngine.UI.Extensions
{
public class DontSaveField : Attribute
{
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b76f678f8bde62944a2a2b76e40acd89
timeCreated: 1435851264
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 130e60ba03fb5aa49861fbf664f0f633
folderAsset: yes
timeCreated: 1435853426
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,623 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
SceneSettings:
m_ObjectHideFlags: 0
m_PVSData:
m_PVSObjectsArray: []
m_PVSPortalsArray: []
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 6
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
--- !u!157 &4
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 6
m_GIWorkflowMode: 0
m_LightmapsMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 3
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AOMaxDistance: 1
m_Padding: 2
m_CompAOExponent: 0
m_LightmapParameters: {fileID: 0}
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherRayCount: 1024
m_ReflectionCompression: 2
m_LightingDataAsset: {fileID: 0}
m_RuntimeCPUUsage: 25
--- !u!196 &5
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
accuratePlacement: 0
minRegionArea: 2
cellSize: 0.16666667
manualCellSize: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &295572876
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 295572881}
- 33: {fileID: 295572880}
- 135: {fileID: 295572879}
- 23: {fileID: 295572878}
- 114: {fileID: 295572877}
m_Layer: 0
m_Name: Persistent GameObject
m_TagString: DontDestroy
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &295572877
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 295572876}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bd4dc9485ec174c44bb7aa7b9d65f7e4, type: 3}
m_Name:
m_EditorClassIdentifier:
showMenu: 0
usePersistentDataPath: 1
savePath: 633a2f4d792053617665642047616d65732f
--- !u!23 &295572878
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 295572876}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_Materials:
- {fileID: 10754, guid: 0000000000000000e000000000000000, type: 0}
m_SubsetIndices:
m_StaticBatchRoot: {fileID: 0}
m_UseLightProbes: 1
m_ReflectionProbeUsage: 1
m_ProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!135 &295572879
SphereCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 295572876}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &295572880
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 295572876}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &295572881
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 295572876}
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_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
--- !u!1 &469137979
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 191666, guid: f3b705d54062603418fef7f609535a48, type: 2}
m_PrefabInternal: {fileID: 1984912377}
serializedVersion: 4
m_Component:
- 4: {fileID: 469137984}
- 33: {fileID: 469137983}
- 136: {fileID: 469137982}
- 23: {fileID: 469137981}
- 114: {fileID: 469137980}
m_Layer: 0
m_Name: TestObject 2
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &469137980
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11483362, guid: f3b705d54062603418fef7f609535a48,
type: 2}
m_PrefabInternal: {fileID: 1984912377}
m_GameObject: {fileID: 469137979}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0c19f3e134862e74dbc98cb514a82ef5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!23 &469137981
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 2343766, guid: f3b705d54062603418fef7f609535a48,
type: 2}
m_PrefabInternal: {fileID: 1984912377}
m_GameObject: {fileID: 469137979}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_SubsetIndices:
m_StaticBatchRoot: {fileID: 0}
m_UseLightProbes: 1
m_ReflectionProbeUsage: 1
m_ProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!136 &469137982
CapsuleCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 13676560, guid: f3b705d54062603418fef7f609535a48,
type: 2}
m_PrefabInternal: {fileID: 1984912377}
m_GameObject: {fileID: 469137979}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Radius: 0.5
m_Height: 2
m_Direction: 1
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &469137983
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 3370042, guid: f3b705d54062603418fef7f609535a48,
type: 2}
m_PrefabInternal: {fileID: 1984912377}
m_GameObject: {fileID: 469137979}
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &469137984
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2}
m_PrefabInternal: {fileID: 1984912377}
m_GameObject: {fileID: 469137979}
m_LocalRotation: {x: -0.09426609, y: 0.4054792, z: -0.45864588, w: 0.7850761}
m_LocalPosition: {x: -2.29, y: 0, z: 1.79}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
--- !u!1 &574899098
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 574899100}
- 108: {fileID: 574899099}
m_Layer: 0
m_Name: Directional Light
m_TagString: DontDestroy
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &574899099
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 574899098}
m_Enabled: 1
serializedVersion: 6
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_BounceIntensity: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
m_AreaSize: {x: 1, y: 1}
--- !u!4 &574899100
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 574899098}
m_LocalRotation: {x: 0.40821794, y: -0.23456973, z: 0.109381676, w: 0.87542605}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
--- !u!1 &635294011
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 635294016}
- 20: {fileID: 635294015}
- 92: {fileID: 635294014}
- 124: {fileID: 635294013}
- 81: {fileID: 635294012}
m_Layer: 0
m_Name: Main Camera
m_TagString: DontDestroy
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &635294012
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 635294011}
m_Enabled: 1
--- !u!124 &635294013
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 635294011}
m_Enabled: 1
--- !u!92 &635294014
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 635294011}
m_Enabled: 1
--- !u!20 &635294015
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 635294011}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0.019607844}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!4 &635294016
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 635294011}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!1001 &1034211790
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: m_LocalPosition.x
value: -4.51999998
objectReference: {fileID: 0}
- target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: m_LocalPosition.y
value: 1.69000006
objectReference: {fileID: 0}
- target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: m_LocalPosition.z
value: 3.06999993
objectReference: {fileID: 0}
- target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: 11498422, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: someGameObject
value:
objectReference: {fileID: 1034211791}
- target: {fileID: 11498422, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: testClassArray.Array.data[0].go
value:
objectReference: {fileID: 1034211791}
- target: {fileID: 11498422, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
propertyPath: TransformThatWontBeSaved
value:
objectReference: {fileID: 1034211797}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
m_RootGameObject: {fileID: 1034211791}
m_IsPrefabParent: 0
--- !u!1 &1034211791
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 106558, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
m_PrefabInternal: {fileID: 1034211790}
serializedVersion: 4
m_Component:
- 4: {fileID: 1034211797}
- 33: {fileID: 1034211796}
- 65: {fileID: 1034211795}
- 23: {fileID: 1034211794}
- 114: {fileID: 1034211793}
- 114: {fileID: 1034211792}
m_Layer: 0
m_Name: TestObject 1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1034211792
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11498422, guid: 6ab4be07dd04115438edfc50dd6ed81e,
type: 2}
m_PrefabInternal: {fileID: 1034211790}
m_GameObject: {fileID: 1034211791}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 693e98742914c7b40b6f0d1b51020e3c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1034211793
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11438930, guid: 6ab4be07dd04115438edfc50dd6ed81e,
type: 2}
m_PrefabInternal: {fileID: 1034211790}
m_GameObject: {fileID: 1034211791}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0c19f3e134862e74dbc98cb514a82ef5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!23 &1034211794
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 2315152, guid: 6ab4be07dd04115438edfc50dd6ed81e,
type: 2}
m_PrefabInternal: {fileID: 1034211790}
m_GameObject: {fileID: 1034211791}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_SubsetIndices:
m_StaticBatchRoot: {fileID: 0}
m_UseLightProbes: 1
m_ReflectionProbeUsage: 1
m_ProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!65 &1034211795
BoxCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 6552138, guid: 6ab4be07dd04115438edfc50dd6ed81e,
type: 2}
m_PrefabInternal: {fileID: 1034211790}
m_GameObject: {fileID: 1034211791}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &1034211796
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 3398618, guid: 6ab4be07dd04115438edfc50dd6ed81e,
type: 2}
m_PrefabInternal: {fileID: 1034211790}
m_GameObject: {fileID: 1034211791}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1034211797
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2}
m_PrefabInternal: {fileID: 1034211790}
m_GameObject: {fileID: 1034211791}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -4.52, y: 1.69, z: 3.07}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
--- !u!1001 &1984912377
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2}
propertyPath: m_LocalPosition.x
value: -2.28999996
objectReference: {fileID: 0}
- target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2}
propertyPath: m_LocalPosition.z
value: 1.78999996
objectReference: {fileID: 0}
- target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2}
propertyPath: m_LocalRotation.x
value: -.0942660868
objectReference: {fileID: 0}
- target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2}
propertyPath: m_LocalRotation.y
value: .405479193
objectReference: {fileID: 0}
- target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2}
propertyPath: m_LocalRotation.z
value: -.45864588
objectReference: {fileID: 0}
- target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2}
propertyPath: m_LocalRotation.w
value: .785076082
objectReference: {fileID: 0}
- target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2}
propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: f3b705d54062603418fef7f609535a48, type: 2}
m_RootGameObject: {fileID: 469137979}
m_IsPrefabParent: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6eac4e9e69c0f7645b30c39bfa564d95
timeCreated: 1435852640
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
using UnityEngine;
[System.Serializable]
public class TestClass {
public string myString;
public GameObject go;
public string go_id;
public Vector3 somePosition;
public Color color;
public int[] myArray = new int[] {2,43,12};
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e7a05842b3056ca42ac57d79fb273d79
timeCreated: 1435853431
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,81 @@
using UnityEngine;
using UnityEngine.UI.Extensions;
public class TestScript : MonoBehaviour {
public string testString = "Hello";
public GameObject someGameObject;
public string someGameObject_id;
public TestClass testClass = new TestClass();
public TestClass[] testClassArray = new TestClass[2];
[DontSaveField] public Transform TransformThatWontBeSaved;//The [DontSaveField] attribute we wrote ourselves prevents the field from being included in the packed component data
public void OnSerialize() {
//This is an example of a OnSerialize method, called before a gameobject is packed into serializable form.
//In this case, the GameObject variable "someGameObject" and those in the testClass and testclass Array instances of TestClass should be reconstructed after loading.
//Since GameObject (and Transform) references assigned during runtime can't be serialized directly,
//we keep a seperate string variable for each GO variable that holds the ID of the GO instead.
//This allows us to just save the ID instead.
//This example is one way of dealing with GameObject (and Transform) references. If a lot of those occur in your project,
//it might be more efficient to go directly into the static SaveLoad.PackComponent method. and doing it there.
if(someGameObject != null && someGameObject.GetComponent<ObjectIdentifier>()) {
someGameObject_id = someGameObject.GetComponent<ObjectIdentifier>().id;
}
else {
someGameObject_id = null;
}
if(testClassArray != null) {
foreach(TestClass testClass_cur in testClassArray) {
if(testClass_cur.go != null && testClass_cur.go.GetComponent<ObjectIdentifier>()) {
testClass_cur.go_id = testClass_cur.go.GetComponent<ObjectIdentifier>().id;
}
else {
testClass_cur.go_id = null;
}
}
}
}
public void OnDeserialize() {
//Since we saved the ID of the GameObject references, we can now use those to recreate the references.
//We just iterate through all the ObjectIdentifier component occurences in the scene, compare their id value to our saved and loaded someGameObject id (etc.) value,
//and assign the component's GameObject if it matches.
//Note that the "break" command is important, both because it elimitates unneccessary iterations,
//and because continuing after having found a match might for some reason find another, wrong match that makes a null reference.
ObjectIdentifier[] objectsIdentifiers = FindObjectsOfType(typeof(ObjectIdentifier)) as ObjectIdentifier[];
if(string.IsNullOrEmpty(someGameObject_id) == false) {
foreach(ObjectIdentifier objectIdentifier in objectsIdentifiers) {
if(string.IsNullOrEmpty(objectIdentifier.id) == false) {
if(objectIdentifier.id == someGameObject_id) {
someGameObject = objectIdentifier.gameObject;
break;
}
}
}
}
if(testClassArray != null) {
foreach(TestClass testClass_cur in testClassArray) {
if(string.IsNullOrEmpty(testClass_cur.go_id) == false) {
foreach (ObjectIdentifier objectIdentifier in objectsIdentifiers) {
if(string.IsNullOrEmpty(objectIdentifier.id) == false) {
if(objectIdentifier.id == testClass_cur.go_id) {
testClass_cur.go = objectIdentifier.gameObject;
break;
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 693e98742914c7b40b6f0d1b51020e3c
timeCreated: 1435853426
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6c24ae448872e974aab97c935d25c3b3
folderAsset: yes
timeCreated: 1435844196
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
//The ObjectComponent class holds all data of a gameobject's component.
//The Dictionary holds the actual data of a component; A field's name as key and the corresponding value (object) as value. Confusing, right?
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[System.Serializable]
public class ObjectComponent
{
public string componentName;
public Dictionary<string, object> fields;
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ab93d4079c9c0724f9855a7e549d3189
timeCreated: 1435844196
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[System.Serializable]
public class SaveGame
{
public string savegameName = "New SaveGame";
public List<SceneObject> sceneObjects = new List<SceneObject>();
public SaveGame()
{
}
public SaveGame(string s, List<SceneObject> list)
{
savegameName = s;
sceneObjects = list;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5d1cbba8c8c32a44daf9525381cfd6b0
timeCreated: 1435844196
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,24 @@
//This class holds is meant to hold all the data of a GameObject in the scene which has an ObjectIdentifier component.
//The values from the OI component are mirrored here, along with misc. stuff like the activation state of the gameObect (bool active), and of course it's components.
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[System.Serializable]
public class SceneObject
{
public string name;
public string prefabName;
public string id;
public string idParent;
public bool active;
public Vector3 position;
public Vector3 localScale;
public Quaternion rotation;
public List<ObjectComponent> objectComponents = new List<ObjectComponent>();
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fab7f6b7ed3c13b4a8222ec3607582b8
timeCreated: 1435844197
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,50 @@
//Add an ObjectIdentifier component to each Prefab that might possibly be serialized and deserialized.
//The name variable is not used by the serialization; it is just there so you can name your prefabs any way you want,
//while the "in-game" name can be something different
//for example, an item that the play can inspect might have the prefab name "sword_01_a",
//but the name (not the GameObject name; that is the prefab name! We are talking about the variable "name" here!) can be "Short Sword",
//which is what the palyer will see when inspecting it.
//To clarify again: A GameObject's (and thus, prefab's) name should be the same as prefabName, while the varialbe "name" in this script can be anything you want (or nothing at all).
namespace UnityEngine.UI.Extensions
{
public class ObjectIdentifier : MonoBehaviour
{
//public string name;
public string prefabName;
public string id;
public string idParent;
public bool dontSave = false;
public void SetID()
{
id = System.Guid.NewGuid().ToString();
CheckForRelatives();
}
private void CheckForRelatives()
{
if (transform.parent == null)
{
idParent = null;
}
else
{
ObjectIdentifier[] childrenIds = GetComponentsInChildren<ObjectIdentifier>();
foreach (ObjectIdentifier idScript in childrenIds)
{
if (idScript.transform.gameObject != gameObject)
{
idScript.idParent = id;
idScript.SetID();
}
}
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0c19f3e134862e74dbc98cb514a82ef5
timeCreated: 1435843519
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,132 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace UnityEngine.UI.Extensions
{
public static class SaveLoad
{
//You may define any path you like, such as "c:/Saved Games"
//remember to use slashes instead of backslashes! ("/" instead of "\")
//Application.DataPath: http://docs.unity3d.com/ScriptReference/Application-dataPath.html
//Application.persistentDataPath: http://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
public static string saveGamePath = Application.persistentDataPath + "/Saved Games/";
public static void Save(SaveGame saveGame)
{
BinaryFormatter bf = new BinaryFormatter();
// 1. Construct a SurrogateSelector object
SurrogateSelector ss = new SurrogateSelector();
// 2. Add the ISerializationSurrogates to our new SurrogateSelector
AddSurrogates(ref ss);
// 3. Have the formatter use our surrogate selector
bf.SurrogateSelector = ss;
//Application.persistentDataPath is a string, so if you wanted you can put that into debug.log if you want to know where save games are located
//You can also use any path you like
CheckPath(saveGamePath);
FileStream file = File.Create(saveGamePath + saveGame.savegameName + ".sav"); //you can call it anything you want including the file extension
bf.Serialize(file, saveGame);
file.Close();
Debug.Log("Saved Game: " + saveGame.savegameName);
}
public static SaveGame Load(string gameToLoad)
{
if (File.Exists(saveGamePath + gameToLoad + ".sav"))
{
BinaryFormatter bf = new BinaryFormatter();
// 1. Construct a SurrogateSelector object
SurrogateSelector ss = new SurrogateSelector();
// 2. Add the ISerializationSurrogates to our new SurrogateSelector
AddSurrogates(ref ss);
// 3. Have the formatter use our surrogate selector
bf.SurrogateSelector = ss;
FileStream file = File.Open(saveGamePath + gameToLoad + ".sav", FileMode.Open);
SaveGame loadedGame = (SaveGame)bf.Deserialize(file);
file.Close();
Debug.Log("Loaded Game: " + loadedGame.savegameName);
return loadedGame;
}
else
{
Debug.Log(gameToLoad + " does not exist!");
return null;
}
}
private static void AddSurrogates(ref SurrogateSelector ss)
{
Vector2Surrogate Vector2_SS = new Vector2Surrogate();
ss.AddSurrogate(typeof(Vector2),
new StreamingContext(StreamingContextStates.All),
Vector2_SS);
Vector3Surrogate Vector3_SS = new Vector3Surrogate();
ss.AddSurrogate(typeof(Vector3),
new StreamingContext(StreamingContextStates.All),
Vector3_SS);
Vector4Surrogate Vector4_SS = new Vector4Surrogate();
ss.AddSurrogate(typeof(Vector4),
new StreamingContext(StreamingContextStates.All),
Vector4_SS);
ColorSurrogate Color_SS = new ColorSurrogate();
ss.AddSurrogate(typeof(Color),
new StreamingContext(StreamingContextStates.All),
Color_SS);
QuaternionSurrogate Quaternion_SS = new QuaternionSurrogate();
ss.AddSurrogate(typeof(Quaternion),
new StreamingContext(StreamingContextStates.All),
Quaternion_SS);
//Reserved for future implementation
//Texture2DSurrogate Texture2D_SS = new Texture2DSurrogate();
//ss.AddSurrogate(typeof(Texture2D),
// new StreamingContext(StreamingContextStates.All),
// Texture2D_SS);
//GameObjectSurrogate GameObject_SS = new GameObjectSurrogate();
//ss.AddSurrogate(typeof(GameObject),
// new StreamingContext(StreamingContextStates.All),
// GameObject_SS);
//TransformSurrogate Transform_SS = new TransformSurrogate();
//ss.AddSurrogate(typeof(Transform),
// new StreamingContext(StreamingContextStates.All),
// Transform_SS);
}
private static void CheckPath(string path)
{
try
{
// Determine whether the directory exists.
if (Directory.Exists(path))
{
//Debug.Log("That path exists already.");
return;
}
// Try to create the directory.
//DirectoryInfo dir = Directory.CreateDirectory(path);
Directory.CreateDirectory(path);
Debug.Log("The directory was created successfully at " + path);
}
catch (Exception e)
{
Debug.Log("The process failed: " + e.ToString());
}
finally { }
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b920ef6d49aee1a48926564263c95432
timeCreated: 1435845727
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,438 @@
using System;//for Type class
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
namespace UnityEngine.UI.Extensions
{
public class SaveLoadMenu : MonoBehaviour
{
public bool showMenu;
public bool usePersistentDataPath = true;
public string savePath;
public Dictionary<string, GameObject> prefabDictionary;
// Use this for initialization
void Start()
{
if (usePersistentDataPath == true)
{
savePath = Application.persistentDataPath + "/Saved Games/";
}
prefabDictionary = new Dictionary<string, GameObject>();
GameObject[] prefabs = Resources.LoadAll<GameObject>("");
foreach (GameObject loadedPrefab in prefabs)
{
if (loadedPrefab.GetComponent<ObjectIdentifier>())
{
prefabDictionary.Add(loadedPrefab.name, loadedPrefab);
Debug.Log("Added GameObject to prefabDictionary: " + loadedPrefab.name);
}
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
showMenu = !showMenu;
}
if (Input.GetKeyDown(KeyCode.F5))
{
SaveGame();
}
if (Input.GetKeyDown(KeyCode.F9))
{
LoadGame();
}
}
void OnGUI()
{
if (showMenu == true)
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Exit to Windows"))
{
Application.Quit();
return;
}
if (GUILayout.Button("Save Game"))
{
SaveGame();
return;
}
if (GUILayout.Button("Load Game"))
{
LoadGame();
return;
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
}
IEnumerator wait(float time)
{
yield return new WaitForSeconds(time);
}
//Use this for quicksaving
public void SaveGame()
{
SaveGame("QuickSave");
}
//use this one for specifying a filename
public void SaveGame(string saveGameName)
{
if (string.IsNullOrEmpty(saveGameName))
{
Debug.Log("SaveGameName is null or empty!");
return;
}
SaveLoad.saveGamePath = savePath;
//Create a new instance of SaveGame. This will hold all the data that should be saved in our scene.
SaveGame newSaveGame = new SaveGame();
newSaveGame.savegameName = saveGameName;
List<GameObject> goList = new List<GameObject>();
//Find all ObjectIdentifier components in the scene.
//Since we can access the gameObject to which each one belongs with .gameObject, we thereby get all GameObject in the scene which should be saved!
ObjectIdentifier[] objectsToSerialize = FindObjectsOfType(typeof(ObjectIdentifier)) as ObjectIdentifier[];
//Go through the "raw" collection of components
foreach (ObjectIdentifier objectIdentifier in objectsToSerialize)
{
//if the gameObject shouldn't be saved, for whatever reason (maybe it's a temporary ParticleSystem that will be destroyed anyway), ignore it
if (objectIdentifier.dontSave == true)
{
Debug.Log("GameObject " + objectIdentifier.gameObject.name + " is set to dontSave = true, continuing loop.");
continue;
}
//First, we will set the ID of the GO if it doesn't already have one.
if (string.IsNullOrEmpty(objectIdentifier.id) == true)
{
objectIdentifier.SetID();
}
//store it in the goList temporarily, so we can first set it's ID (done above),
//then go through the list and call all OnSerialize methods on it,
//and finally go through the list again to pack the GO and add the packed data to the sceneObjects list of the new SaveGame.
goList.Add(objectIdentifier.gameObject);
}
//This is a good time to call any functions on the GO that should be called before it gets serialized as part of a SaveGame. Example below.
foreach (GameObject go in goList)
{
go.SendMessage("OnSerialize", SendMessageOptions.DontRequireReceiver);
}
foreach (GameObject go2 in goList)
{
//Convert the GameObject's data into a form that can be serialized (an instance of SceneObject),
//and add it to the SaveGame instance's list of SceneObjects.
newSaveGame.sceneObjects.Add(PackGameObject(go2));
}
//Call the static method that serialized our game and writes the data to a file.
SaveLoad.Save(newSaveGame);
}
//Use this for quickloading
public void LoadGame()
{
LoadGame("QuickSave");
}
//use this one for loading a saved gamt with a specific filename
public void LoadGame(string saveGameName)
{
//First, we will destroy all objects in the scene which are not tagged with "DontDestroy" (such as Cameras, Managers of any type, and so on... things that should persist)
ClearScene();
//Call the static method that will attempt to load the specified file and deserialize it's data into a form that we can use
SaveGame loadedGame = SaveLoad.Load(saveGameName);
if (loadedGame == null)
{
Debug.Log("saveGameName " + saveGameName + "couldn't be found!");
return;
}
//create a new list that will hold all the gameObjects we will create anew from the deserialized data
List<GameObject> goList = new List<GameObject>();
//iterate through the loaded game's sceneObjects list to access each stored objet's data and reconstruct it with all it's components
foreach (SceneObject loadedObject in loadedGame.sceneObjects)
{
GameObject go_reconstructed = UnpackGameObject(loadedObject);
if (go_reconstructed != null)
{
//Add the reconstructed GO to the list we created earlier.
goList.Add(go_reconstructed);
}
}
//Go through the list of reconstructed GOs and reassign any missing children
foreach (GameObject go in goList)
{
string parentId = go.GetComponent<ObjectIdentifier>().idParent;
if (string.IsNullOrEmpty(parentId) == false)
{
foreach (GameObject go_parent in goList)
{
if (go_parent.GetComponent<ObjectIdentifier>().id == parentId)
{
go.transform.parent = go_parent.transform;
}
}
}
}
//This is when you might want to call any functions that should be called when a gameobject is loaded. Example below.
foreach (GameObject go2 in goList)
{
go2.SendMessage("OnDeserialize", SendMessageOptions.DontRequireReceiver);
}
}
public void ClearScene()
{
//Clear the scene of all non-persistent GameObjects so we have a clean slate
object[] obj = GameObject.FindObjectsOfType(typeof(GameObject));
foreach (object o in obj)
{
GameObject go = (GameObject)o;
//if the GO is tagged with DontDestroy, ignore it. (Cameras, Managers, etc. which should survive loading)
//these kind of GO's shouldn't have an ObjectIdentifier component!
if (go.CompareTag("DontDestroy"))
{
Debug.Log("Keeping GameObject in the scene: " + go.name);
continue;
}
Destroy(go);
}
}
public SceneObject PackGameObject(GameObject go)
{
ObjectIdentifier objectIdentifier = go.GetComponent<ObjectIdentifier>();
//Now, we create a new instance of SceneObject, which will hold all the GO's data, including it's components.
SceneObject sceneObject = new SceneObject();
sceneObject.name = go.name;
sceneObject.prefabName = objectIdentifier.prefabName;
sceneObject.id = objectIdentifier.id;
if (go.transform.parent != null && go.transform.parent.GetComponent<ObjectIdentifier>() == true)
{
sceneObject.idParent = go.transform.parent.GetComponent<ObjectIdentifier>().id;
}
else
{
sceneObject.idParent = null;
}
//in this case, we will only store MonoBehavior scripts that are on the GO. The Transform is stored as part of the ScenObject isntance (assigned further down below).
//If you wish to store other component types, you have to find you own ways to do it if the "easy" way that is used for storing components doesn't work for them.
List<string> componentTypesToAdd = new List<string>() {
"UnityEngine.MonoBehaviour"
};
//This list will hold only the components that are actually stored (MonoBehavior scripts, in this case)
List<object> components_filtered = new List<object>();
//Collect all the components that are attached to the GO.
//This includes MonoBehavior scripts, Renderers, Transform, Animator...
//If it
object[] components_raw = go.GetComponents<Component>() as object[];
foreach (object component_raw in components_raw)
{
if (componentTypesToAdd.Contains(component_raw.GetType().BaseType.FullName))
{
components_filtered.Add(component_raw);
}
}
foreach (object component_filtered in components_filtered)
{
sceneObject.objectComponents.Add(PackComponent(component_filtered));
}
//Assign all the GameObject's misc. values
sceneObject.position = go.transform.position;
sceneObject.localScale = go.transform.localScale;
sceneObject.rotation = go.transform.rotation;
sceneObject.active = go.activeSelf;
return sceneObject;
}
public ObjectComponent PackComponent(object component)
{
//This will go through all the fields of a component, check each one if it is serializable, and it it should be stored,
//and puts it into the fields dictionary of a new instance of ObjectComponent,
//with the field's name as key and the field's value as (object)value
//for example, if a script has the field "float myFloat = 12.5f", then the key would be "myFloat" and the value "12.5f", tha latter stored as an object.
ObjectComponent newObjectComponent = new ObjectComponent();
newObjectComponent.fields = new Dictionary<string, object>();
const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
var componentType = component.GetType();
FieldInfo[] fields = componentType.GetFields(flags);
newObjectComponent.componentName = componentType.ToString();
foreach (FieldInfo field in fields)
{
if (field != null)
{
if (field.FieldType.IsSerializable == false)
{
//Debug.Log(field.Name + " (Type: " + field.FieldType + ") is not marked as serializable. Continue loop.");
continue;
}
if (TypeSystem.IsEnumerableType(field.FieldType) == true || TypeSystem.IsCollectionType(field.FieldType) == true)
{
Type elementType = TypeSystem.GetElementType(field.FieldType);
//Debug.Log(field.Name + " -> " + elementType);
if (elementType.IsSerializable == false)
{
continue;
}
}
object[] attributes = field.GetCustomAttributes(typeof(DontSaveField), true);
bool stop = false;
foreach (Attribute attribute in attributes)
{
if (attribute.GetType() == typeof(DontSaveField))
{
//Debug.Log(attribute.GetType().Name.ToString());
stop = true;
break;
}
}
if (stop == true)
{
continue;
}
newObjectComponent.fields.Add(field.Name, field.GetValue(component));
//Debug.Log(field.Name + " (Type: " + field.FieldType + "): " + field.GetValue(component));
}
}
return newObjectComponent;
}
public GameObject UnpackGameObject(SceneObject sceneObject)
{
//This is where our prefabDictionary above comes in. Each GameObject that was saved needs to be reconstucted, so we need a Prefab,
//and we know which prefab it is because we stored the GameObject's prefab name in it's ObjectIdentifier/SceneObject script/class.
//Theoretically, we could even reconstruct GO's that have no prefab by instatiating an empty GO and filling it with the required components... I'lll leave that to you.
if (prefabDictionary.ContainsKey(sceneObject.prefabName) == false)
{
Debug.Log("Can't find key " + sceneObject.prefabName + " in SaveLoadMenu.prefabDictionary!");
return null;
}
//instantiate the gameObject
GameObject go = Instantiate(prefabDictionary[sceneObject.prefabName], sceneObject.position, sceneObject.rotation) as GameObject;
//Reassign values
go.name = sceneObject.name;
go.transform.localScale = sceneObject.localScale;
go.SetActive(sceneObject.active);
if (go.GetComponent<ObjectIdentifier>() == false)
{
//ObjectIdentifier oi = go.AddComponent<ObjectIdentifier>();
go.AddComponent<ObjectIdentifier>();
}
ObjectIdentifier idScript = go.GetComponent<ObjectIdentifier>();
idScript.id = sceneObject.id;
idScript.idParent = sceneObject.idParent;
UnpackComponents(ref go, sceneObject);
//Destroy any children that were not referenced as having a parent
ObjectIdentifier[] childrenIds = go.GetComponentsInChildren<ObjectIdentifier>();
foreach (ObjectIdentifier childrenIDScript in childrenIds)
{
if (childrenIDScript.transform != go.transform)
{
if (string.IsNullOrEmpty(childrenIDScript.id) == true)
{
Destroy(childrenIDScript.gameObject);
}
}
}
return go;
}
public void UnpackComponents(ref GameObject go, SceneObject sceneObject)
{
//Go through the stored object's component list and reassign all values in each component, and add components that are missing
foreach (ObjectComponent obc in sceneObject.objectComponents)
{
if (go.GetComponent(obc.componentName) == false)
{
Type componentType = Type.GetType(obc.componentName);
go.AddComponent(componentType);
}
object obj = go.GetComponent(obc.componentName) as object;
var tp = obj.GetType();
foreach (KeyValuePair<string, object> p in obc.fields)
{
var fld = tp.GetField(p.Key,
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.SetField);
if (fld != null)
{
object value = p.Value;
fld.SetValue(obj, value);
}
}
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bd4dc9485ec174c44bb7aa7b9d65f7e4
timeCreated: 1435848358
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2e48060c8c4bc3d448dcaffe916307ca
folderAsset: yes
timeCreated: 1435845247
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,32 @@
using System.Runtime.Serialization;
namespace UnityEngine.UI.Extensions
{
public sealed class ColorSurrogate : ISerializationSurrogate
{
// Method called to serialize a Vector3 object
public void GetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context)
{
Color color = (Color)obj;
info.AddValue("r", color.r);
info.AddValue("g", color.g);
info.AddValue("b", color.b);
info.AddValue("a", color.a);
}
// Method called to deserialize a Vector3 object
public System.Object SetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context,
ISurrogateSelector selector)
{
Color color = (Color)obj;
color.r = (float)info.GetValue("r", typeof(float));
color.g = (float)info.GetValue("g", typeof(float));
color.b = (float)info.GetValue("b", typeof(float));
color.a = (float)info.GetValue("a", typeof(float));
obj = color;
return obj;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 81d3e9dc19c30c24483b1f77953a82c3
timeCreated: 1435845247
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,29 @@
using System.Runtime.Serialization;
namespace UnityEngine.UI.Extensions
{
/// <summary>
/// Doesn't seem fully implemented yet?
/// </summary>
//public sealed class GameObjectSurrogate : ISerializationSurrogate
//{
// // Method called to serialize a Vector3 object
// public void GetObjectData(System.Object obj,
// SerializationInfo info, StreamingContext context)
// {
// GameObject go = (GameObject)obj;
// }
// // Method called to deserialize a Vector3 object
// public System.Object SetObjectData(System.Object obj,
// SerializationInfo info, StreamingContext context,
// ISurrogateSelector selector)
// {
// GameObject go = (GameObject)obj;
// return obj;
// }
//}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2e0e2f61dca10bf4e95ecd579cc58e1a
timeCreated: 1435845247
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,35 @@
using System.Runtime.Serialization;
namespace UnityEngine.UI.Extensions
{
public sealed class QuaternionSurrogate : ISerializationSurrogate
{
// Method called to serialize a Vector3 object
public void GetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context)
{
Quaternion quaternion = (Quaternion)obj;
info.AddValue("x", quaternion.x);
info.AddValue("y", quaternion.y);
info.AddValue("z", quaternion.z);
info.AddValue("w", quaternion.w);
}
// Method called to deserialize a Vector3 object
public System.Object SetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context,
ISurrogateSelector selector)
{
Quaternion quaternion = (Quaternion)obj;
quaternion.x = (float)info.GetValue("x", typeof(float));
quaternion.y = (float)info.GetValue("y", typeof(float));
quaternion.z = (float)info.GetValue("z", typeof(float));
quaternion.w = (float)info.GetValue("w", typeof(float));
obj = quaternion;
return obj;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 095b25ad2d34e594bb0fdafe57f1cdcf
timeCreated: 1435851264
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,12 @@
ISerializationSurrogates are used to tell a BinaryFormatter how to serialize and deserialize certain types.
For example, a BinaryFormatter can't (de)serialize a Vector3 instance.
This is true for most, or even all, Unity-specific types like Transform, GameObject, Color, Mesh, and so on.
What a ISerializationSurrogate does is tell the Formatter, if it is used, how to serialize and deserialize each field of a type.
A Vector3 is just made of three floats: x, y and z. These can easily be serialized one by one.
An ISS can't be written for the type GameObject that easily, as it is vastly more complex. The Formatter will throw an error when trying to serialize it.
However, we are using a workaround for saving & loading GOs anyway (by storing their positions, rotations, scales, active states, and components one by one),
so we can use a ISS for type GameObject that uses none of a GO's fields. Nothing will be serialized, but we won't get an error either, which is the point of the empty ISS.
Note that we could use the attribute [DontSerializeField] to make our algorithm skip a field of type GameObject,
but this will only work if the GO field sits in the class that is to be serialized itself. If we want to save a MonoBehavior script which contains a field of type (CustomClass),
which in turn contains a field of type GameObject, then this will not work as we can only go through each field of a component, not through each field of each field, so to speak.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e65ea62503a78f14182bc6c9d9a05106
timeCreated: 1435845250
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,29 @@
using System.Runtime.Serialization;
namespace UnityEngine.UI.Extensions
{
/// <summary>
/// Doesn't seem fully implemented yet?
/// </summary>
//public sealed class Texture2DSurrogate : ISerializationSurrogate
//{
// // Method called to serialize a Vector3 object
// public void GetObjectData(System.Object obj,
// SerializationInfo info, StreamingContext context)
// {
// Texture2D t = (Texture2D)obj;
// }
// // Method called to deserialize a Vector3 object
// public System.Object SetObjectData(System.Object obj,
// SerializationInfo info, StreamingContext context,
// ISurrogateSelector selector)
// {
// Texture2D t = (Texture2D)obj;
// return obj;
// }
//}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 90fc034c9d310aa4fbff10d91d4d91ee
timeCreated: 1435845247
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,30 @@
using System.Runtime.Serialization;
namespace UnityEngine.UI.Extensions
{
/// <summary>
/// Doesn't seem fully implemented yet?
/// </summary>
//public sealed class TransformSurrogate : ISerializationSurrogate
//{
// // Method called to serialize a Vector3 object
// public void GetObjectData(System.Object obj,
// SerializationInfo info, StreamingContext context)
// {
// Transform tr = (Transform)obj;
// }
// // Method called to deserialize a Vector3 object
// public System.Object SetObjectData(System.Object obj,
// SerializationInfo info, StreamingContext context,
// ISurrogateSelector selector)
// {
// Transform tr = (Transform)obj;
// return obj;
// }
//}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c882de0bea6973f4fa729fa1dd81a99a
timeCreated: 1435845250
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,29 @@
using System.Runtime.Serialization;
namespace UnityEngine.UI.Extensions
{
public sealed class Vector2Surrogate : ISerializationSurrogate
{
// Method called to serialize a Vector2 object
public void GetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context)
{
Vector2 v2 = (Vector2)obj;
info.AddValue("x", v2.x);
info.AddValue("y", v2.y);
}
// Method called to deserialize a Vector2 object
public System.Object SetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context,
ISurrogateSelector selector)
{
Vector2 v2 = (Vector2)obj;
v2.x = (float)info.GetValue("x", typeof(float));
v2.y = (float)info.GetValue("y", typeof(float));
obj = v2;
return obj;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 02aba5388a28c944787d5d61deafed98
timeCreated: 1464901177
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,31 @@
using System.Runtime.Serialization;
namespace UnityEngine.UI.Extensions
{
public sealed class Vector3Surrogate : ISerializationSurrogate
{
// Method called to serialize a Vector3 object
public void GetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context)
{
Vector3 v3 = (Vector3)obj;
info.AddValue("x", v3.x);
info.AddValue("y", v3.y);
info.AddValue("z", v3.z);
}
// Method called to deserialize a Vector3 object
public System.Object SetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context,
ISurrogateSelector selector)
{
Vector3 v3 = (Vector3)obj;
v3.x = (float)info.GetValue("x", typeof(float));
v3.y = (float)info.GetValue("y", typeof(float));
v3.z = (float)info.GetValue("z", typeof(float));
obj = v3;
return obj;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b812bdab84e09a8478923cbe2b562d61
timeCreated: 1435845247
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,33 @@
using System.Runtime.Serialization;
namespace UnityEngine.UI.Extensions
{
public sealed class Vector4Surrogate : ISerializationSurrogate
{
// Method called to serialize a Vector4 object
public void GetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context)
{
Vector4 v4 = (Vector4)obj;
info.AddValue("x", v4.x);
info.AddValue("y", v4.y);
info.AddValue("w", v4.w);
info.AddValue("z", v4.z);
}
// Method called to deserialize a Vector4 object
public System.Object SetObjectData(System.Object obj,
SerializationInfo info, StreamingContext context,
ISurrogateSelector selector)
{
Vector4 v4 = (Vector4)obj;
v4.x = (float)info.GetValue("x", typeof(float));
v4.y = (float)info.GetValue("y", typeof(float));
v4.w = (float)info.GetValue("w", typeof(float));
v4.z = (float)info.GetValue("z", typeof(float));
obj = v4;
return obj;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b8d9d01e813a7f647b39998b6e31af44
timeCreated: 1464901177
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b02d1e4ae10379b42a2fa24244dd991a
folderAsset: yes
timeCreated: 1435851264
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,63 @@
//This is used to get teh element type of a collection
//source: http://stackoverflow.com/questions/1900353/how-to-get-the-type-contained-in-a-collection-through-reflection
//via http://blogs.msdn.com/b/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx
//The methods IsEnumerableType and IsCollectionType were added by myself (Cherno). Use them to find out wether a Type is a collection (array, List,...)
using System;
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
internal static class TypeSystem
{
internal static Type GetElementType(Type seqType)
{
Type ienum = FindIEnumerable(seqType);
if (ienum == null) return seqType;
return ienum.GetGenericArguments()[0];
}
private static Type FindIEnumerable(Type seqType)
{
if (seqType == null || seqType == typeof(string))
return null;
if (seqType.IsArray)
return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());
if (seqType.IsGenericType)
{
foreach (Type arg in seqType.GetGenericArguments())
{
Type ienum = typeof(IEnumerable<>).MakeGenericType(arg);
if (ienum.IsAssignableFrom(seqType))
{
return ienum;
}
}
}
Type[] ifaces = seqType.GetInterfaces();
if (ifaces != null && ifaces.Length > 0)
{
foreach (Type iface in ifaces)
{
Type ienum = FindIEnumerable(iface);
if (ienum != null) return ienum;
}
}
if (seqType.BaseType != null && seqType.BaseType != typeof(object))
{
return FindIEnumerable(seqType.BaseType);
}
return null;
}
//is a type a collection?
public static bool IsEnumerableType(Type type)
{
return (type.GetInterface("IEnumerable") != null);
}
public static bool IsCollectionType(Type type)
{
return (type.GetInterface("ICollection") != null);
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ee3f0396a2ae70749a914a63018d074f
timeCreated: 1435851264
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
public class TestCompression : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 585e75d4a56389b4690b3506f37751bc
timeCreated: 1464883584
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: