Пример #1
0
 public override object Read <T>(ES3Reader reader)
 {
     return(new Color(reader.ReadProperty <float>(ES3Type_float.Instance),
                      reader.ReadProperty <float>(ES3Type_float.Instance),
                      reader.ReadProperty <float>(ES3Type_float.Instance),
                      reader.ReadProperty <float>(ES3Type_float.Instance)));
 }
Пример #2
0
 public override object Read <T>(ES3Reader reader)
 {
     return(new UnityEngine.Keyframe(reader.ReadProperty <System.Single>(ES3Type_float.Instance),
                                     reader.ReadProperty <System.Single>(ES3Type_float.Instance),
                                     reader.ReadProperty <System.Single>(ES3Type_float.Instance),
                                     reader.ReadProperty <System.Single>(ES3Type_float.Instance)));
 }
Пример #3
0
        public override object Read <T>(ES3Reader reader)
        {
            var prefabId      = reader.ReadProperty <long>(ES3Type_long.Instance);
            var localToGlobal = reader.ReadProperty <Dictionary <long, long> >();

            if (ES3ReferenceMgrBase.Current == null)
            {
                return(null);
            }

            var es3Prefab = ES3ReferenceMgrBase.Current.GetPrefab(prefabId);

            if (es3Prefab == null)
            {
                throw new MissingReferenceException("Prefab with ID " + prefabId + " could not be found.");
            }
            var instance          = GameObject.Instantiate(es3Prefab.gameObject);
            var instanceES3Prefab = ((GameObject)instance).GetComponent <ES3Prefab>();

            if (instanceES3Prefab == null)
            {
                throw new MissingReferenceException("Prefab with ID " + prefabId + " was found, but it does not have an ES3Prefab component attached.");
            }

            instanceES3Prefab.ApplyReferences(localToGlobal);

            return(instanceES3Prefab.gameObject);
        }
Пример #4
0
 public override object Read <T>(ES3Reader reader)
 {
     return(new Color32(reader.ReadProperty <byte>(ES3Type_byte.Instance),
                        reader.ReadProperty <byte>(ES3Type_byte.Instance),
                        reader.ReadProperty <byte>(ES3Type_byte.Instance),
                        reader.ReadProperty <byte>(ES3Type_byte.Instance)));
 }
Пример #5
0
        public override void ReadInto <T>(ES3Reader reader, object obj)
        {
            var instance = (UnityEngine.Gradient)obj;

            instance.SetKeys(
                reader.ReadProperty <UnityEngine.GradientColorKey[]>(ES3Type_GradientColorKeyArray.Instance),
                reader.ReadProperty <UnityEngine.GradientAlphaKey[]>(ES3Type_GradientAlphaKeyArray.Instance)
                );

            string propertyName;

            while ((propertyName = reader.ReadPropertyName()) != null)
            {
                switch (propertyName)
                {
                case "mode":
                    instance.mode = reader.Read <UnityEngine.GradientMode>();
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
        }
Пример #6
0
        public override object Read <T>(ES3Reader reader)
        {
            var matrix = new Matrix4x4();

            matrix.SetColumn(0, reader.ReadProperty <Vector4>(ES3Type_Vector4.Instance));
            matrix.SetColumn(1, reader.ReadProperty <Vector4>(ES3Type_Vector4.Instance));
            matrix.SetColumn(2, reader.ReadProperty <Vector4>(ES3Type_Vector4.Instance));
            matrix.SetColumn(3, reader.ReadProperty <Vector4>(ES3Type_Vector4.Instance));
            return(matrix);
        }
Пример #7
0
        protected override object ReadUnityObject <T>(ES3Reader reader)
        {
            var instance = new Texture2D(reader.Read <int>(ES3Type_int.Instance),               // Property name has already been read in ES3UnityObjectType, so we only need to read the value.
                                         reader.ReadProperty <int>(ES3Type_int.Instance),
                                         reader.ReadProperty <TextureFormat>(),
                                         (reader.ReadProperty <int>(ES3Type_int.Instance) > 1));

            ReadObject <T>(reader, instance);
            return(instance);
        }
Пример #8
0
        public override object Read <T>(ES3Reader reader)
        {
            var prefabId = reader.ReadRefProperty();
            // Load as ES3Refs and convert to longs.
            var localToGlobal_refs = reader.ReadProperty <Dictionary <ES3Ref, ES3Ref> >();
            var localToGlobal      = new Dictionary <long, long>();

            foreach (var kvp in localToGlobal_refs)
            {
                localToGlobal.Add(kvp.Key.id, kvp.Value.id);
            }

            if (ES3ReferenceMgrBase.Current == null)
            {
                return(null);
            }

            var es3Prefab = ES3ReferenceMgrBase.Current.GetPrefab(prefabId);

            if (es3Prefab == null)
            {
                throw new MissingReferenceException("Prefab with ID " + prefabId + " could not be found.");
            }
            var instance          = GameObject.Instantiate(es3Prefab.gameObject);
            var instanceES3Prefab = ((GameObject)instance).GetComponent <ES3Prefab>();

            if (instanceES3Prefab == null)
            {
                throw new MissingReferenceException("Prefab with ID " + prefabId + " was found, but it does not have an ES3Prefab component attached.");
            }

            instanceES3Prefab.ApplyReferences(localToGlobal);

            return(instanceES3Prefab.gameObject);
        }
Пример #9
0
        protected override object ReadUnityObject <T>(ES3Reader reader)
        {
            var instance = new Texture2D(reader.ReadProperty <int>(ES3Type_int.Instance), reader.ReadProperty <int>(ES3Type_int.Instance), reader.ReadProperty <TextureFormat>(), (reader.ReadProperty <int>(ES3Type_int.Instance) > 1));

            ReadObject <T>(reader, instance);
            return(instance);
        }
Пример #10
0
        public override object Read <T>(ES3Reader reader)
        {
            var instance = new UnityEngine.Font(reader.ReadProperty <string>(ES3Type_string.Instance));

            ReadInto <T>(reader, instance);
            return(instance);
        }
Пример #11
0
        protected override object ReadUnityObject <T>(ES3Reader reader)
        {
            var instance = new UnityEngine.Font(reader.ReadProperty <string>(ES3Type_string.Instance));

            ReadObject <T>(reader, instance);
            return(instance);
        }
Пример #12
0
        protected override object ReadObject <T>(ES3Reader reader)
        {
            var descriptor = reader.ReadProperty <RenderTextureDescriptor>();
            var instance   = new UnityEngine.RenderTexture(descriptor);

            ReadObject <T>(reader, instance);
            return(instance);
        }
Пример #13
0
        public override object Read <T>(ES3Reader reader)
        {
            Shader obj = Shader.Find(reader.ReadProperty <string>(ES3Type_string.Instance));

            if (obj == null)
            {
                obj = Shader.Find("Diffuse");
            }
            ReadInto <T>(reader, obj);
            return(obj);
        }
Пример #14
0
        public override object Read <T>(ES3Reader reader)
        {
            var obj = new BoneWeight();

            obj.boneIndex0 = reader.ReadProperty <int>(ES3Type_int.Instance);
            obj.boneIndex1 = reader.ReadProperty <int>(ES3Type_int.Instance);
            obj.boneIndex2 = reader.ReadProperty <int>(ES3Type_int.Instance);
            obj.boneIndex3 = reader.ReadProperty <int>(ES3Type_int.Instance);

            obj.weight0 = reader.ReadProperty <float>(ES3Type_float.Instance);
            obj.weight1 = reader.ReadProperty <float>(ES3Type_float.Instance);
            obj.weight2 = reader.ReadProperty <float>(ES3Type_float.Instance);
            obj.weight3 = reader.ReadProperty <float>(ES3Type_float.Instance);

            return(obj);
        }
        protected override void ReadComponent <T>(ES3Reader reader, object obj)
        {
            var instance = (UnityEngine.PolygonCollider2D)obj;

            foreach (string propertyName in reader.Properties)
            {
                switch (propertyName)
                {
                case "points":
                    instance.points = reader.Read <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance);
                    break;

                case "pathCount":
                    int pathCount = reader.Read <System.Int32>(ES3Type_int.Instance);
                    for (int i = 0; i < pathCount; i++)
                    {
                        instance.SetPath(i, reader.ReadProperty <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance));
                    }
                    break;

                case "density":
                    instance.density = reader.Read <System.Single>(ES3Type_float.Instance);
                    break;

                case "isTrigger":
                    instance.isTrigger = reader.Read <System.Boolean>(ES3Type_bool.Instance);
                    break;

                case "usedByEffector":
                    instance.usedByEffector = reader.Read <System.Boolean>(ES3Type_bool.Instance);
                    break;

                case "offset":
                    instance.offset = reader.Read <UnityEngine.Vector2>(ES3Type_Vector2.Instance);
                    break;

                case "sharedMaterial":
                    instance.sharedMaterial = reader.Read <UnityEngine.PhysicsMaterial2D>(ES3Type_PhysicsMaterial2D.Instance);
                    break;

                case "enabled":
                    instance.enabled = reader.Read <System.Boolean>(ES3Type_bool.Instance);
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
        }
Пример #16
0
        public override void ReadInto <T>(ES3Reader reader, object obj)
        {
            // Load as ES3Refs and convert to longs.
            var localToGlobal_refs = reader.ReadProperty <Dictionary <ES3Ref, ES3Ref> >(ES3Type_ES3RefDictionary.Instance);
            var localToGlobal      = new Dictionary <long, long>();

            foreach (var kvp in localToGlobal_refs)
            {
                localToGlobal.Add(kvp.Key.id, kvp.Value.id);
            }

            if (ES3ReferenceMgrBase.Current == null)
            {
                return;
            }

            ((GameObject)obj).GetComponent <ES3Prefab>().ApplyReferences(localToGlobal);
        }
Пример #17
0
        public override object Read <T>(ES3Reader reader)
        {
            var prefabId = reader.ReadRefProperty();
            // Load as ES3Refs and convert to longs.
            var localToGlobal_refs = reader.ReadProperty <Dictionary <ES3Ref, ES3Ref> >();
            var localToGlobal      = new Dictionary <long, long>();

            foreach (var kvp in localToGlobal_refs)
            {
                localToGlobal.Add(kvp.Key.id, kvp.Value.id);
            }

            if (ES3ReferenceMgrBase.Current == null)
            {
                return(null);
            }

            var es3Prefab = ES3ReferenceMgrBase.Current.GetPrefab(prefabId);

            if (es3Prefab == null)
            {
                throw new MissingReferenceException("Prefab with ID " + prefabId + " could not be found.\nPress the 'Refresh References' button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in the scene to refresh prefabs.");
            }


#if UNITY_EDITOR
            // Use PrefabUtility.InstantiatePrefab if we're saving in the Editor and the application isn't playing.
            // This keeps the connection to the prefab, which is useful for Editor scripts saving data outside of runtime.
            var instance = Application.isPlaying ? GameObject.Instantiate(es3Prefab.gameObject) : PrefabUtility.InstantiatePrefab(es3Prefab.gameObject);
#else
            var instance = GameObject.Instantiate(es3Prefab.gameObject);
#endif
            var instanceES3Prefab = ((GameObject)instance).GetComponent <ES3Prefab>();
            if (instanceES3Prefab == null)
            {
                throw new MissingReferenceException("Prefab with ID " + prefabId + " was found, but it does not have an ES3Prefab component attached.");
            }

            instanceES3Prefab.ApplyReferences(localToGlobal);

            return(instanceES3Prefab.gameObject);
        }
Пример #18
0
        public override object Read <T>(ES3Reader reader)
        {
            UnityEngine.Object obj = null;

            // Read the intial properties regarding the instance we're loading.
            while (true)
            {
                var propertyName = ReadPropertyName(reader);
                if (propertyName == ES3Type.typeFieldName)
                {
                    return(ES3TypeMgr.GetOrCreateES3Type(reader.ReadType()).Read <T>(reader));
                }

                else if (propertyName == ES3ReferenceMgrBase.referencePropertyName)
                {
                    var refMgr = ES3ReferenceMgrBase.Current;
                    if (refMgr == null)
                    {
                        reader.Skip();
                        continue;
                    }

                    long id = reader.Read <long>(ES3Type_long.Instance);
                    obj = refMgr.Get(id);

                    if (obj == null)
                    {
                        // If an instance isn't already registered for this object, create an instance and register the reference.
                        obj = new GameObject();
                        refMgr.Add(obj, id);
                    }
                    else if (!ES3Reflection.IsAssignableFrom(typeof(T), obj.GetType()))
                    {
                        throw new MissingReferenceException("The instance with ID \"" + id + "\" is a different type than expected. Expected \"" + typeof(T) + "\", found \"" + obj.GetType() + "\"");
                    }

                    // Now load the Transform's ID and assign it to the Transform of our object.
                    long transformID = reader.ReadProperty <long>(ES3Type_long.Instance);
                    refMgr.Add(((GameObject)obj).transform, transformID);
                }

                else if (propertyName == prefabPropertyName)
                {
                    if (ES3ReferenceMgrBase.Current == null)
                    {
                        reader.Skip();
                    }
                    else
                    {
                        obj = reader.Read <GameObject>(ES3Type_ES3PrefabInternal.Instance);
                    }
                }
                else if (propertyName == null)
                {
                    return(obj);
                }
                else
                {
                    reader.overridePropertiesName = propertyName;
                    break;
                }
            }

            if (obj == null)
            {
                obj = new GameObject();
            }

            ReadInto <T>(reader, obj);
            return(obj);
        }
        protected override void ReadUnityObject <T>(ES3Reader reader, object obj)
        {
            var instance = (UnityEngine.Mesh)obj;

            if (instance == null)
            {
                return;
            }

            if (!instance.isReadable)
            {
                Debug.LogWarning("Easy Save cannot load the vertices for this Mesh because it is not marked as readable, so it will be loaded by reference. To load the vertex data for this Mesh, check the 'Read/Write Enabled' checkbox in its Import Settings.", instance);
            }

            foreach (string propertyName in reader.Properties)
            {
                // If this Mesh isn't readable, we should skip past all of its properties.
                if (!instance.isReadable)
                {
                    reader.Skip();
                    continue;
                }

                switch (propertyName)
                {
                                        #if UNITY_2017_3
                case "indexFormat":
                    instance.indexFormat = reader.Read <UnityEngine.Rendering.IndexFormat>();
                    break;
                                        #endif
                case "bounds":
                    instance.bounds = reader.Read <UnityEngine.Bounds>(ES3Type_Bounds.Instance);
                    break;

                case "boneWeights":
                    instance.boneWeights = reader.Read <UnityEngine.BoneWeight[]>(ES3Type_BoneWeightArray.Instance);
                    break;

                case "bindposes":
                    instance.bindposes = reader.Read <UnityEngine.Matrix4x4[]>(ES3Type_Matrix4x4Array.Instance);
                    break;

                case "vertices":
                    instance.vertices = reader.Read <UnityEngine.Vector3[]>(ES3Type_Vector3Array.Instance);
                    break;

                case "normals":
                    instance.normals = reader.Read <UnityEngine.Vector3[]>(ES3Type_Vector3Array.Instance);
                    break;

                case "tangents":
                    instance.tangents = reader.Read <UnityEngine.Vector4[]>(ES3Type_Vector4Array.Instance);
                    break;

                case "uv":
                    instance.uv = reader.Read <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance);
                    break;

                case "uv2":
                    instance.uv2 = reader.Read <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance);
                    break;

                case "uv3":
                    instance.uv3 = reader.Read <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance);
                    break;

                case "uv4":
                    instance.uv4 = reader.Read <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance);
                    break;

                case "colors32":
                    instance.colors32 = reader.Read <UnityEngine.Color32[]>(ES3Type_Color32Array.Instance);
                    break;

                case "triangles":
                    instance.triangles = reader.Read <System.Int32[]>(ES3Type_intArray.Instance);
                    break;

                case "subMeshCount":
                    instance.subMeshCount = reader.Read <System.Int32>(ES3Type_int.Instance);
                    for (int i = 0; i < instance.subMeshCount; i++)
                    {
                        instance.SetTriangles(reader.ReadProperty <int[]>(ES3Type_intArray.Instance), i);
                    }
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
        }
Пример #20
0
 public override object Read <T>(ES3Reader reader)
 {
     return(Guid.Parse(reader.ReadProperty <string>(ES3Type_string.Instance)));
 }
Пример #21
0
 public override object Read <T>(ES3Reader reader)
 {
     return(new Vector3Int(reader.ReadProperty <int>(ES3Type_int.Instance),
                           reader.ReadProperty <int>(ES3Type_int.Instance),
                           reader.ReadProperty <int>(ES3Type_int.Instance)));
 }
Пример #22
0
 public override object Read <T>(ES3Reader reader)
 {
     return(new Bounds(reader.ReadProperty <Vector3>(ES3Type_Vector3.Instance),
                       reader.ReadProperty <Vector3>(ES3Type_Vector3.Instance)));
 }
Пример #23
0
 public override object Read <T>(ES3Reader reader)
 {
     return(new UnityEngine.GradientAlphaKey(reader.ReadProperty <float>(ES3Type_float.Instance),
                                             reader.ReadProperty <float>(ES3Type_float.Instance)));
 }
Пример #24
0
        protected override void ReadUnityObject <T>(ES3Reader reader, object obj)
        {
            var instance = (UnityEngine.Mesh)obj;

            foreach (string propertyName in reader.Properties)
            {
                switch (propertyName)
                {
                                        #if UNITY_2017_3
                case "indexFormat":
                    instance.indexFormat = reader.Read <UnityEngine.Rendering.IndexFormat>();
                    break;
                                        #endif
                case "bounds":
                    instance.bounds = reader.Read <UnityEngine.Bounds>(ES3Type_Bounds.Instance);
                    break;

                case "boneWeights":
                    instance.boneWeights = reader.Read <UnityEngine.BoneWeight[]>(ES3Type_BoneWeightArray.Instance);
                    break;

                case "bindposes":
                    instance.bindposes = reader.Read <UnityEngine.Matrix4x4[]>(ES3Type_Matrix4x4Array.Instance);
                    break;

                case "vertices":
                    instance.vertices = reader.Read <UnityEngine.Vector3[]>(ES3Type_Vector3Array.Instance);
                    break;

                case "normals":
                    instance.normals = reader.Read <UnityEngine.Vector3[]>(ES3Type_Vector3Array.Instance);
                    break;

                case "tangents":
                    instance.tangents = reader.Read <UnityEngine.Vector4[]>(ES3Type_Vector4Array.Instance);
                    break;

                case "uv":
                    instance.uv = reader.Read <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance);
                    break;

                case "uv2":
                    instance.uv2 = reader.Read <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance);
                    break;

                case "uv3":
                    instance.uv3 = reader.Read <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance);
                    break;

                case "uv4":
                    instance.uv4 = reader.Read <UnityEngine.Vector2[]>(ES3Type_Vector2Array.Instance);
                    break;

                case "colors32":
                    instance.colors32 = reader.Read <UnityEngine.Color32[]>(ES3Type_Color32Array.Instance);
                    break;

                case "triangles":
                    instance.triangles = reader.Read <System.Int32[]>(ES3Type_intArray.Instance);
                    break;

                case "subMeshCount":
                    instance.subMeshCount = reader.Read <System.Int32>(ES3Type_int.Instance);
                    for (int i = 0; i < instance.subMeshCount; i++)
                    {
                        instance.SetTriangles(reader.ReadProperty <int[]>(ES3Type_intArray.Instance), i);
                    }
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
        }