Example #1
0
        /** Deserializes serialization info. Deserializes Version, mask and #loadedGraphGuids
         * \see OpenDeserialize */
        public AstarSerializer DeserializeSerializationInfo()
        {
            if (!MoveToAnchor("SerializerSettings"))
            {
                throw (new System.NullReferenceException("Anchor SerializerSettings was not found in the data"));
            }

            BinaryReader stream = readerStream;

            System.Version astarVersion = null;

            try {
                astarVersion = new Version(stream.ReadString());
            }

            catch (Exception e) {
                Debug.LogError("Couldn't parse A* version ");
                error = SerializerError.WrongVersion;
                throw new System.FormatException("Couldn't parse A* version", e);
            }

            //System.Version astarVersion2 = AstarPath.Version;

            AstarSerializer returnSerializer = this;

            if (!IgnoreVersionDifferences)
            {
                if (astarVersion > AstarPath.Version)
                {
                    Debug.LogError("Loading graph saved with a newer version of the A* Pathfinding Project, trying to load, but you might get errors.\nFile version: " + astarVersion + " Current A* version: " + AstarPath.Version);
                    //error = SerializerError.WrongVersion;
                    //return;
                }
                else if (astarVersion != AstarPath.Version)
                {
                    Debug.LogWarning("Loading graphs saved with an older version of the A* Pathfinding Project, trying to load.\nFile version: " + astarVersion + " Current A* version: " + AstarPath.Version);

                    //Copy this serializer's loaded values to the new serializer
                    returnSerializer = new AstarSerializer3_01(active);
                    returnSerializer.readerStream = readerStream;
                    returnSerializer.anchors      = anchors;
                }
            }

            int count = stream.ReadInt32();

            //@Fix - Look up existing graph first
            returnSerializer.loadedGraphGuids = new string[count];

            for (int i = 0; i < count; i++)
            {
                returnSerializer.loadedGraphGuids[i] = stream.ReadString();
                //loadedGraphGuids[i] = i;
            }


            returnSerializer.mask = stream.ReadInt32();

            return(returnSerializer);
        }
Example #2
0
        /** Deserializes serialization info. Deserializes Version, mask and #loadedGraphGuids
          * \see OpenDeserialize */
        public AstarSerializer DeserializeSerializationInfo()
        {
            if (!MoveToAnchor ("SerializerSettings")) {
                throw (new System.NullReferenceException ("Anchor SerializerSettings was not found in the data"));
            }

            BinaryReader stream = readerStream;

            System.Version astarVersion = null;

            try {
                astarVersion = new Version (stream.ReadString ());
            }

            catch (Exception e) {
                Debug.LogError ("Couldn't parse A* version ");
                error = SerializerError.WrongVersion;
                throw new System.FormatException ("Couldn't parse A* version",e);
            }

            //System.Version astarVersion2 = AstarPath.Version;

            AstarSerializer returnSerializer = this;

            if (!IgnoreVersionDifferences) {
                if (astarVersion > AstarPath.Version) {
                    Debug.LogError ("Loading graph saved with a newer version of the A* Pathfinding Project, trying to load, but you might get errors.\nFile version: "+astarVersion+" Current A* version: "+AstarPath.Version);
                    //error = SerializerError.WrongVersion;
                    //return;
                } else if (astarVersion != AstarPath.Version) {
                    Debug.LogWarning ("Loading graphs saved with an older version of the A* Pathfinding Project, trying to load.\nFile version: "+astarVersion+" Current A* version: "+AstarPath.Version);

                    //Select the appropriate deserializer
                    if (astarVersion < new Version (3,0,4)) {
                        returnSerializer = new AstarSerializer3_01 (active);
                    } else if (astarVersion < new Version (3,0,5)) {
                        returnSerializer = new AstarSerializer3_04 (active);
                    } else if (astarVersion < new Version (3,0,6)) {
                        returnSerializer = new AstarSerializer3_05 (active);
                    }

                    //Copy this serializer's loaded values to the new serializer
                    returnSerializer.readerStream = readerStream;
                    returnSerializer.anchors = anchors;
                }
            }

            int count = stream.ReadInt32 ();

            //@Fix - Look up existing graph first
            returnSerializer.loadedGraphGuids = new string[count];

            for (int i=0;i<count;i++) {
                returnSerializer.loadedGraphGuids[i] = stream.ReadString ();
                //loadedGraphGuids[i] = i;
            }

            returnSerializer.mask = stream.ReadInt32 ();

            return returnSerializer;
        }