示例#1
0
        /** Deserializes graphs from the specified byte array.
         * If an error ocurred, it will try to deserialize using the old deserializer.
         * A warning will be logged if all deserializers failed.
         */
        public void DeserializeGraphs(byte[] bytes)
        {
            try {
                if (bytes != null)
                {
                    Pathfinding.Serialization.AstarSerializer sr = new Pathfinding.Serialization.AstarSerializer(this);

                    if (sr.OpenDeserialize(bytes))
                    {
                        DeserializeGraphsPart(sr);
                        sr.CloseDeserialize();
                    }
                    else
                    {
                        Debug.Log("Invalid data file (cannot read zip). Trying to load with old deserializer (pre 3.1)...");
                        AstarSerializer serializer = new AstarSerializer(active);
                        DeserializeGraphs_oldInternal(serializer);
                    }
                }
                else
                {
                    throw new System.ArgumentNullException("Bytes should not be null when passed to DeserializeGraphs");
                }
                active.DataUpdate();
            } catch (System.Exception e) {
                Debug.LogWarning("Caught exception while deserializing data.\n" + e);
                data_backup = bytes;
            }
        }
示例#2
0
        /** Deserializes graphs from the specified byte array additively.
         * An error will be logged if deserialization fails.
         * This function will add loaded graphs to the current ones.
         */
        public void DeserializeGraphsAdditive(byte[] bytes)
        {
            var graphLock = AssertSafe();

            try {
                if (bytes != null)
                {
                    var sr = new AstarSerializer();

                    if (sr.OpenDeserialize(bytes))
                    {
                        DeserializeGraphsPartAdditive(sr);
                        sr.CloseDeserialize();
                    }
                    else
                    {
                        Debug.Log("Invalid data file (cannot read zip).\nThe data is either corrupt or it was saved using a 3.0.x or earlier version of the system");
                    }
                }
                else
                {
                    throw new System.ArgumentNullException("bytes");
                }
                AstarPath.active.VerifyIntegrity();
            } catch (System.Exception e) {
                Debug.LogError("Caught exception while deserializing data.\n" + e);
                graphs = new NavGraph[0];
            }

            UpdateShortcuts();
            graphLock.Release();
        }
示例#3
0
文件: Base.cs 项目: artbane/aetherion
        /** \copydoc Pathfinding::ISerializableObject::DeSerializeSettings */
        public void DeSerializeSettings(AstarSerializer serializer)
        {
            mask.value   = (int)serializer.GetValue("Mask", typeof(int));
            diameter     = (float)serializer.GetValue("Diameter", typeof(float));
            height       = (float)serializer.GetValue("Height", typeof(float));
            type         = (ColliderType)serializer.GetValue("Type", typeof(int));
            rayDirection = (RayDirection)serializer.GetValue("RayDirection", typeof(int));

            heightMask.value     = (int)serializer.GetValue("heightMask", typeof(int), -1);
            fromHeight           = (float)serializer.GetValue("fromHeight", typeof(float), 100.0F);
            thickRaycastDiameter = (float)serializer.GetValue("thickRaycastDiameter", typeof(float));
            thickRaycast         = (bool)serializer.GetValue("thickRaycast", typeof(bool));

            collisionCheck = (bool)serializer.GetValue("collisionCheck", typeof(bool), true);
            heightCheck    = (bool)serializer.GetValue("heightCheck", typeof(bool), true);

            unwalkableWhenNoGround = (bool)serializer.GetValue("unwalkableWhenNoGround", typeof(bool), true);

            collisionOffset = (float)serializer.GetValue("collisionOffset", typeof(float), 0.0F);

            if (fromHeight == 0)
            {
                fromHeight = 100;
            }
        }
示例#4
0
        public void DeSerializeSettings(AstarSerializer serializer)
        {
            System.IO.BinaryReader stream = serializer.readerStream;

            offset   = (Vector3)serializer.GetValue("offset", typeof(Vector3));
            rotation = (Vector3)serializer.GetValue("rotation", typeof(Vector3));
            scale    = (float)serializer.GetValue("scale", typeof(float));

            GenerateMatrix();

            Vector3[] verts = new Vector3[stream.ReadInt32()];
            int[]     tris  = new int[stream.ReadInt32()];

            for (int i = 0; i < verts.Length; i++)
            {
                verts[i] = new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle());
            }

            for (int i = 0; i < tris.Length; i++)
            {
                tris[i] = stream.ReadInt32();
            }

            sourceMesh = serializer.GetUnityReferenceValue("sourceMesh", typeof(Mesh)) as Mesh;

            if (Application.isPlaying)
            {
                sourceMesh           = new Mesh();
                sourceMesh.name      = "NavGraph Mesh";
                sourceMesh.vertices  = verts;
                sourceMesh.triangles = tris;
            }
        }
示例#5
0
        public void DeSerializeSettings(AstarSerializer serializer)
        {
            //erosionRadius = (int)serializer.GetValue ("erosionRadius",typeof(int));
            contourMaxError = (float)serializer.GetValue("contourMaxError", typeof(float));

            cellSize       = (float)serializer.GetValue("cellSize", typeof(float));
            cellHeight     = (float)serializer.GetValue("cellHeight", typeof(float));
            walkableHeight = (float)serializer.GetValue("walkableHeight", typeof(float));
            walkableClimb  = (float)serializer.GetValue("walkableClimb", typeof(float));
            maxSlope       = (float)serializer.GetValue("maxSlope", typeof(float));
            maxEdgeLength  = (float)serializer.GetValue("maxEdgeLength", typeof(float));

            forcedBoundsCenter = (Vector3)serializer.GetValue("forcedBoundsCenter", typeof(Vector3));
            forcedBoundsSize   = (Vector3)serializer.GetValue("forcedBoundsSize", typeof(Vector3));

            mask.value = (int)serializer.GetValue("mask", typeof(int));

            showMeshOutline = (bool)serializer.GetValue("showMeshOutline", typeof(bool));

            includeOutOfBounds = (bool)serializer.GetValue("includeOutOfBounds", typeof(bool));

            regionMinSize   = (int)serializer.GetValue("regionMinSize", typeof(int));
            characterRadius = (float)serializer.GetValue("characterRadius", typeof(float));
            useCRecast      = (bool)serializer.GetValue("useCRecast", typeof(bool));
        }
示例#6
0
        public void SerializeSettings(AstarSerializer serializer)
        {
            //serializer.AddValue ("erosionRadius",erosionRadius);
            serializer.AddValue("contourMaxError", contourMaxError);

            serializer.AddValue("cellSize", cellSize);
            serializer.AddValue("cellHeight", cellHeight);
            serializer.AddValue("walkableHeight", walkableHeight);
            serializer.AddValue("walkableClimb", walkableClimb);
            serializer.AddValue("maxSlope", maxSlope);
            serializer.AddValue("maxEdgeLength", maxEdgeLength);

            serializer.AddValue("forcedBoundsCenter", forcedBoundsCenter);
            serializer.AddValue("forcedBoundsSize", forcedBoundsSize);

            serializer.AddValue("mask", mask.value);

            serializer.AddValue("showMeshOutline", showMeshOutline);

            serializer.AddValue("includeOutOfBounds", includeOutOfBounds);

            serializer.AddValue("regionMinSize", regionMinSize);
            serializer.AddValue("characterRadius", characterRadius);
            serializer.AddValue("useCRecast", useCRecast);
        }
示例#7
0
        /** Deserializes common info.
         * Common info is what is shared between the editor serialization and the runtime serializer.
         * This is mostly everything except the graph inspectors which serialize some extra data in the editor
         */
        public void DeserializeGraphsPart(AstarSerializer sr)
        {
            ClearGraphs();
            graphs = sr.DeserializeGraphs();
            if (graphs != null)
            {
                for (var i = 0; i < graphs.Length; i++)
                {
                    if (graphs[i] != null)
                    {
                        graphs[i].graphIndex = (uint)i;
                    }
                }
            }

            userConnections = sr.DeserializeUserConnections();
            //sr.DeserializeNodes();
            sr.DeserializeExtraInfo();

            //Assign correct graph indices.
            for (var i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] == null)
                {
                    continue;
                }
                graphs[i].GetNodes(delegate(GraphNode node) {
                    node.GraphIndex = (uint)i;
                    return(true);
                });
            }

            sr.PostDeserialization();
        }
示例#8
0
        /** Deserializes graphs from the specified byte array.
         * If an error occured, it will try to deserialize using the old deserializer.
         * A warning will be logged if all deserializers failed.
         */
        public void DeserializeGraphs(byte[] bytes)
        {
            AstarPath.active.BlockUntilPathQueueBlocked();

            try {
                if (bytes != null)
                {
                    var sr = new AstarSerializer(this);

                    if (sr.OpenDeserialize(bytes))
                    {
                        DeserializeGraphsPart(sr);
                        sr.CloseDeserialize();
                        UpdateShortcuts();
                    }
                    else
                    {
                        Debug.Log("Invalid data file (cannot read zip).\nThe data is either corrupt or it was saved using a 3.0.x or earlier version of the system");
                    }
                }
                else
                {
                    throw new ArgumentNullException("Bytes should not be null when passed to DeserializeGraphs");
                }
                active.VerifyIntegrity();
            } catch (Exception e) {
                Debug.LogWarning("Caught exception while deserializing data.\n" + e);
                data_backup = bytes;
            }
        }
示例#9
0
 public void DeserializeGraphsAdditive(byte[] bytes)
 {
     AstarPath.active.BlockUntilPathQueueBlocked();
     try
     {
         if (bytes == null)
         {
             throw new ArgumentNullException("bytes");
         }
         AstarSerializer astarSerializer = new AstarSerializer(this);
         if (astarSerializer.OpenDeserialize(bytes))
         {
             this.DeserializeGraphsPartAdditive(astarSerializer);
             astarSerializer.CloseDeserialize();
         }
         else
         {
             Debug.Log("Invalid data file (cannot read zip).");
         }
         AstarData.active.VerifyIntegrity();
     }
     catch (Exception arg)
     {
         Debug.LogWarning("Caught exception while deserializing data.\n" + arg);
     }
 }
示例#10
0
        public void DeserializeGraphsPart(AstarSerializer sr)
        {
            this.ClearGraphs();
            this.graphs = sr.DeserializeGraphs();
            if (this.graphs != null)
            {
                for (int j = 0; j < this.graphs.Length; j++)
                {
                    if (this.graphs[j] != null)
                    {
                        this.graphs[j].graphIndex = (uint)j;
                    }
                }
            }
            this.userConnections = sr.DeserializeUserConnections();
            sr.DeserializeExtraInfo();
            int i;

            for (i = 0; i < this.graphs.Length; i++)
            {
                if (this.graphs[i] != null)
                {
                    this.graphs[i].GetNodes(delegate(GraphNode node)
                    {
                        node.GraphIndex = (uint)i;
                        return(true);
                    });
                }
            }
            sr.PostDeserialization();
        }
示例#11
0
 public void SerializeGraphsPart(AstarSerializer sr)
 {
     sr.SerializeGraphs(this.graphs);
     sr.SerializeUserConnections(this.userConnections);
     sr.SerializeNodes();
     sr.SerializeExtraInfo();
 }
示例#12
0
        //These functions are for serialization, the static ones are there so other graphs using mesh nodes can serialize them more easily
        public static void SerializeMeshNodes(INavmesh graph, Node[] nodes, AstarSerializer serializer)
        {
            System.IO.BinaryWriter stream = serializer.writerStream;

            for (int i = 0; i < nodes.Length; i++)
            {
                MeshNode node = nodes[i] as MeshNode;

                if (node == null)
                {
                    Debug.LogError("Serialization Error : Couldn't cast the node to the appropriate type - NavMeshGenerator");
                    return;
                }

                stream.Write(node.v1);
                stream.Write(node.v2);
                stream.Write(node.v3);
            }

            Int3[] vertices = graph.vertices;

            if (vertices == null)
            {
                vertices = new Int3[0];
            }

            stream.Write(vertices.Length);

            for (int i = 0; i < vertices.Length; i++)
            {
                stream.Write(vertices[i].x);
                stream.Write(vertices[i].y);
                stream.Write(vertices[i].z);
            }
        }
示例#13
0
 public void DeserializeGraphs(byte[] bytes)
 {
     AstarPath.active.BlockUntilPathQueueBlocked();
     try
     {
         if (bytes == null)
         {
             throw new ArgumentNullException("bytes");
         }
         AstarSerializer astarSerializer = new AstarSerializer(this);
         if (astarSerializer.OpenDeserialize(bytes))
         {
             this.DeserializeGraphsPart(astarSerializer);
             astarSerializer.CloseDeserialize();
             this.UpdateShortcuts();
         }
         else
         {
             Debug.Log("Invalid data file (cannot read zip).\nThe data is either corrupt or it was saved using a 3.0.x or earlier version of the system");
         }
         AstarData.active.VerifyIntegrity();
     }
     catch (Exception arg)
     {
         Debug.LogWarning("Caught exception while deserializing data.\n" + arg);
         this.data_backup = bytes;
     }
 }
示例#14
0
 public void DeserializeGraphsAdditive(byte[] bytes)
 {
     PathProcessor.GraphUpdateLock graphUpdateLock = this.AssertSafe(false);
     try
     {
         if (bytes == null)
         {
             throw new ArgumentNullException("bytes");
         }
         AstarSerializer astarSerializer = new AstarSerializer(this);
         if (astarSerializer.OpenDeserialize(bytes))
         {
             this.DeserializeGraphsPartAdditive(astarSerializer);
             astarSerializer.CloseDeserialize();
         }
         else
         {
             Debug.Log("Invalid data file (cannot read zip).\nThe data is either corrupt or it was saved using a 3.0.x or earlier version of the system");
         }
         AstarData.active.VerifyIntegrity();
     }
     catch (Exception arg)
     {
         Debug.LogError("Caught exception while deserializing data.\n" + arg);
         this.graphs      = new NavGraph[0];
         this.data_backup = bytes;
     }
     this.UpdateShortcuts();
     graphUpdateLock.Release();
 }
示例#15
0
        public static void DeSerializeMeshNodes(INavmesh graph, Node[] nodes, AstarSerializer serializer)
        {
            System.IO.BinaryReader stream = serializer.readerStream;

            for (int i = 0; i < nodes.Length; i++)
            {
                MeshNode node = nodes[i] as MeshNode;

                if (node == null)
                {
                    Debug.LogError("Serialization Error : Couldn't cast the node to the appropriate type - NavMeshGenerator");
                    return;
                }

                node.v1 = stream.ReadInt32();
                node.v2 = stream.ReadInt32();
                node.v3 = stream.ReadInt32();
            }

            int numVertices = stream.ReadInt32();

            graph.vertices = new Int3[numVertices];

            for (int i = 0; i < numVertices; i++)
            {
                int x = stream.ReadInt32();
                int y = stream.ReadInt32();
                int z = stream.ReadInt32();

                graph.vertices[i] = new Int3(x, y, z);
            }

            RebuildBBTree(graph as NavGraph);
        }
示例#16
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);
        }
示例#17
0
 public void DeserializeGraphsPart(AstarSerializer sr)
 {
     PathProcessor.GraphUpdateLock graphUpdateLock = this.AssertSafe(false);
     this.ClearGraphs();
     this.DeserializeGraphsPartAdditive(sr);
     graphUpdateLock.Release();
 }
示例#18
0
 public void DeserializeGraphsAdditive(byte[] bytes)
 {
     AstarPath.active.BlockUntilPathQueueBlocked();
     try
     {
         if (bytes == null)
         {
             throw new ArgumentNullException("Bytes should not be null when passed to DeserializeGraphs");
         }
         AstarSerializer sr = new AstarSerializer(this);
         if (sr.OpenDeserialize(bytes))
         {
             this.DeserializeGraphsPartAdditive(sr);
             sr.CloseDeserialize();
         }
         else
         {
             Debug.Log("Invalid data file (cannot read zip).");
         }
         this.active.VerifyIntegrity();
     }
     catch (Exception exception)
     {
         Debug.LogWarning("Caught exception while deserializing data.\n" + exception);
     }
 }
示例#19
0
        public void SaveCacheData(int mask)
        {
            AstarSerializer serializer = new AstarSerializer(active);

            serializer.mask    = mask;         //AstarSerializer.SaveNodes;
            data_cachedStartup = SerializeGraphs(serializer);
            cacheStartup       = true;
        }
示例#20
0
        public void DeserializeGraphsPartAdditive(AstarSerializer sr)
        {
            if (this.graphs == null)
            {
                this.graphs = new NavGraph[0];
            }
            if (this.userConnections == null)
            {
                this.userConnections = new UserConnection[0];
            }
            List <NavGraph> list = new List <NavGraph>(this.graphs);

            list.AddRange(sr.DeserializeGraphs());
            this.graphs = list.ToArray();
            if (this.graphs != null)
            {
                for (int l = 0; l < this.graphs.Length; l++)
                {
                    if (this.graphs[l] != null)
                    {
                        this.graphs[l].graphIndex = (uint)l;
                    }
                }
            }
            List <UserConnection> list2 = new List <UserConnection>(this.userConnections);

            list2.AddRange(sr.DeserializeUserConnections());
            this.userConnections = list2.ToArray();
            sr.DeserializeNodes();
            DebugHelper.Assert(this.graphs != null, "不能为空");
            int i;

            for (i = 0; i < this.graphs.Length; i++)
            {
                if (this.graphs[i] != null)
                {
                    this.graphs[i].GetNodes(delegate(GraphNode node)
                    {
                        node.GraphIndex = (uint)i;
                        return(true);
                    });
                }
            }
            sr.DeserializeExtraInfo();
            sr.PostDeserialization();
            for (int j = 0; j < this.graphs.Length; j++)
            {
                for (int k = j + 1; k < this.graphs.Length; k++)
                {
                    if (this.graphs[j] != null && this.graphs[k] != null && this.graphs[j].guid == this.graphs[k].guid)
                    {
                        Debug.LogWarning("Guid Conflict when importing graphs additively. Imported graph will get a new Guid.\nThis message is (relatively) harmless.");
                        this.graphs[j].guid = Guid.NewGuid();
                        break;
                    }
                }
            }
        }
示例#21
0
        public byte[] SerializeGraphs(SerializeSettings settings, out uint checksum)
        {
            AstarPath.active.BlockUntilPathQueueBlocked();
            AstarSerializer astarSerializer = new AstarSerializer(this, settings);

            astarSerializer.OpenSerialize();
            this.SerializeGraphsPart(astarSerializer);
            byte[] result = astarSerializer.CloseSerialize();
            checksum = astarSerializer.GetChecksum();
            return(result);
        }
示例#22
0
        public byte[] SerializeGraphsExtra(SerializeSettings settings)
        {
            AstarPath.active.BlockUntilPathQueueBlocked();
            AstarSerializer astarSerializer = new AstarSerializer(this, settings);

            astarSerializer.OpenSerialize();
            astarSerializer.graphs = this.graphs;
            byte[] result = astarSerializer.SerializeExtraInfoBytes();
            astarSerializer.CloseSerialize();
            return(result);
        }
示例#23
0
        //End Serialization Settings

        /** Loads the graphs from memory, will load cached graphs if any exists */
        public void Awake()
        {
            if (cacheStartup && data_cachedStartup != null)
            {
                LoadFromCache();
            }
            else
            {
                AstarSerializer serializer = new AstarSerializer(active);
                DeserializeGraphs(serializer);
            }
        }
示例#24
0
        public void DeSerializeSettings(AstarSerializer serializer)
        {
            root = (Transform)serializer.GetUnityReferenceValue("root", typeof(Transform));

            maxDistance        = (float)serializer.GetValue("maxDistance", typeof(float));
            limits             = (Vector3)serializer.GetValue("limits", typeof(Vector3));
            mask.value         = (int)serializer.GetValue("mask", typeof(int));
            thickRaycast       = (bool)serializer.GetValue("thickRaycast", typeof(bool));
            thickRaycastRadius = (float)serializer.GetValue("thickRaycastRadius", typeof(float));
            searchTag          = (string)serializer.GetValue("searchTag", typeof(string));
            recursive          = (bool)serializer.GetValue("recursive", typeof(bool));
        }
示例#25
0
 public void LoadFromCache()
 {
     if (data_cachedStartup != null && data_cachedStartup.Length > 0)
     {
         AstarSerializer serializer = new AstarSerializer(active);
         DeserializeGraphs(serializer, data_cachedStartup);
     }
     else
     {
         Debug.LogError("Can't load from cache since the cache is empty");
     }
 }
示例#26
0
        public byte[] SerializeGraphs(SerializeSettings settings, out uint checksum)
        {
            PathProcessor.GraphUpdateLock graphUpdateLock = this.AssertSafe(false);
            AstarSerializer astarSerializer = new AstarSerializer(this, settings);

            astarSerializer.OpenSerialize();
            this.SerializeGraphsPart(astarSerializer);
            byte[] result = astarSerializer.CloseSerialize();
            checksum = astarSerializer.GetChecksum();
            graphUpdateLock.Release();
            return(result);
        }
示例#27
0
		//End Serialization Settings
		
		/** Loads the graphs from memory, will load cached graphs if any exists */
		public void Awake () {
			
			
			if (cacheStartup && data_cachedStartup != null) {
				LoadFromCache ();
			} else {
				AstarSerializer serializer = new AstarSerializer (active);
				DeserializeGraphs (serializer);
			}
			
			
		}
示例#28
0
        public void SerializeSettings(AstarSerializer serializer)
        {
            ;

            serializer.AddUnityReferenceValue("root", root);
            serializer.AddValue("maxDistance", maxDistance);
            serializer.AddValue("limits", limits);
            serializer.AddValue("mask", mask.value);
            serializer.AddValue("thickRaycast", thickRaycast);
            serializer.AddValue("thickRaycastRadius", thickRaycastRadius);
            serializer.AddValue("searchTag", searchTag);
            serializer.AddValue("recursive", recursive);
        }
示例#29
0
        /** Main serializer function, a similar one exists in the AstarEditor.cs script to save additional info */
        public byte[] SerializeGraphs(AstarSerializer serializer)
        {
            serializer.OpenSerialize();

            SerializeGraphsPart(serializer);

            serializer.Close();

            byte[] bytes = (serializer.writerStream.BaseStream as System.IO.MemoryStream).ToArray();

            Debug.Log("Got a whole bunch of data, " + bytes.Length + " bytes");
            return(bytes);
        }
示例#30
0
        /** Main serializer function.
         * Serializes all graphs to a byte array
         * A similar function exists in the AstarPathEditor.cs script to save additional info */
        public byte[] SerializeGraphs(SerializeSettings settings, out uint checksum)
        {
            AstarPath.active.BlockUntilPathQueueBlocked();

            var sr = new AstarSerializer(this, settings);

            sr.OpenSerialize();
            SerializeGraphsPart(sr);
            var bytes = sr.CloseSerialize();

            checksum = sr.GetChecksum();
            return(bytes);
        }
示例#31
0
        /** Saves all graphs and also user connections, but does not close, nor opens the stream */
        public void SerializeGraphsPart(AstarSerializer serializer)
        {
            //AstarSerializer serializer = new AstarSerializer ();

            //serializer.OpenSerializeSettings ();
            SizeProfiler.Initialize();
            SizeProfiler.Begin("File", serializer.writerStream, false);
            SizeProfiler.Begin("Graphs init", serializer.writerStream);
            serializer.writerStream.Write(graphs.Length);
            serializer.writerStream.Write(graphs.Length);

            SizeProfiler.End("Graphs init", serializer.writerStream);

            int[] masks = new int[graphs.Length];

            for (int i = 0; i < graphs.Length; i++)
            {
                NavGraph graph = graphs[i];

                int tmpMask = serializer.mask;

                SizeProfiler.Begin("Graphs type " + i, serializer.writerStream);

                serializer.AddAnchor("Graph" + i);
                serializer.writerStream.Write(graph.GetType().Name);
                serializer.writerStream.Write(graph.guid.ToString());

                SizeProfiler.Begin("Graphs settings " + i, serializer.writerStream);

                //Set an unique prefix for all variables in this graph
                serializer.sPrefix = i.ToString();
                serializer.SerializeSettings(graph, active);
                serializer.sPrefix = "";

                masks[i]        = serializer.mask;
                serializer.mask = tmpMask;

                SizeProfiler.End("Graphs settings " + i, serializer.writerStream);
            }


            SizeProfiler.Begin("User Connections", serializer.writerStream);

            serializer.SerializeUserConnections(userConnections);

            SizeProfiler.End("User Connections", serializer.writerStream);
            //data = (serializer.writerStream.BaseStream as System.IO.MemoryStream).ToArray ();
            //serializer.Close ();
            SizeProfiler.End("File", serializer.writerStream);
            SizeProfiler.Log();
        }
	public void SerializeSettings (NavGraph target, AstarSerializer serializer) {
		//NavMeshGraph graph = target as NavMeshGraph;
		
		//string meshPath = AssetDatabase.GetAssetPath (graph.sourceMesh);
		//string meshGUID = AssetDatabase.AssetPathToGUID (meshPath);
		
		
		/*if (graph == null) {
			serializer.writerStream.Write (-1);
		} else {
			int instanceID = graph.sourceMesh != null ? graph.sourceMesh.GetInstanceID () : -1;
			serializer.writerStream.Write (instanceID);
		}*/
	}
	public void DeSerializeSettings (NavGraph target, AstarSerializer serializer) {
		//NavMeshGraph graph = target as NavMeshGraph;
		
		//string meshGUID = serializer.readerStream.ReadString ();
		//int instanceID = serializer.readerStream.ReadInt32 ();
		
		//Mesh ob = EditorUtility.InstanceIDToObject (instanceID) as Mesh;
		
		//if (!Application.isPlaying) {
			//graph.sourceMesh = ob;
			/*string meshPath = AssetDatabase.GUIDToAssetPath (meshGUID);
			Debug.Log (meshGUID +" "+ meshPath);
			graph.sourceMesh = AssetDatabase.LoadAssetAtPath (meshPath,typeof(Mesh)) as Mesh;*/
		//}
		
		//Debug.Log ("Did succeed? "+(graph.sourceMesh != null));
	}
示例#34
0
	public static void WriteUnityReference (AstarSerializer serializer, UnityEngine.Object ob) {
		
		if (ob == null) {
			serializer.writerStream.Write ("");
			serializer.writerStream.Write ("");
			return;
		}
		
		string assetPath = AssetDatabase.GetAssetPath (ob);
		if (assetPath != "") {
			string guid = AssetDatabase.AssetPathToGUID (assetPath);
			serializer.writerStream.Write (guid);
		} else {
			serializer.writerStream.Write ("");
		}
	}
示例#35
0
		public void DeSerializeSettings (AstarSerializer serializer) {
			
			root = (Transform)serializer.GetUnityReferenceValue ("root",typeof(Transform));
			
			maxDistance = (float)serializer.GetValue ("maxDistance",typeof(float));
			limits = (Vector3)serializer.GetValue ("limits",typeof(Vector3));
			mask.value = (int)serializer.GetValue ("mask",typeof(int));
			thickRaycast = (bool)serializer.GetValue ("thickRaycast",typeof(bool));
			thickRaycastRadius = (float)serializer.GetValue ("thickRaycastRadius",typeof(float));
			searchTag = (string)serializer.GetValue ("searchTag",typeof(string));
			recursive = (bool)serializer.GetValue ("recursive",typeof(bool));
			raycast	  = (bool)serializer.GetValue ("raycast",typeof(bool),true);
		}
示例#36
0
		public void DeSerializeNodes (Node[] nodes, AstarSerializer serializer) {
			//NavMeshGraph.DeSerializeMeshNodes (this as INavmesh, nodes, serializer);
		}
        public new void SerializeSettings(AstarSerializer serializer)
        {
            (this as GridGraph).SerializeSettings (serializer);

            serializer.AddValue ("mergeSpanRange",mergeSpanRange);
            serializer.AddValue ("characterHeight",characterHeight);
            //serializer.AddValue ("maxClimb",maxClimb);
        }
示例#38
0
        public void DeSerializeSettings(AstarSerializer serializer)
        {
            //width = (int)serializer.GetValue ("Width",typeof(int));
            //depth = (int)serializer.GetValue ("Depth",typeof(int));
            //height = (float)serializer.GetValue ("Height",typeof(float));

            unclampedSize = (Vector2)serializer.GetValue ("unclampedSize",typeof(Vector2));

            cutCorners = (bool)serializer.GetValue ("cutCorners",typeof(bool));
            neighbours = (NumNeighbours)serializer.GetValue ("neighbours",typeof(int));

            rotation = (Vector3)serializer.GetValue ("rotation",typeof(Vector3));

            nodeSize = (float)serializer.GetValue ("nodeSize",typeof(float));

            collision = (GraphCollision)serializer.GetValue ("collision",typeof(GraphCollision));

            center = (Vector3)serializer.GetValue ("center",typeof(Vector3));

            maxClimb = (float)serializer.GetValue ("maxClimb",typeof(float));
            maxClimbAxis = (int)serializer.GetValue ("maxClimbAxis",typeof(int),1);
            maxSlope = (float)serializer.GetValue ("maxSlope",typeof(float),90.0F);

            erodeIterations = (int)serializer.GetValue ("erodeIterations",typeof(int));

            penaltyAngle = 			(bool)serializer.GetValue ("penaltyAngle",typeof(bool));
            penaltyAngleFactor = 	(float)serializer.GetValue ("penaltyAngleFactor",typeof(float));
            penaltyPosition = 		(bool)serializer.GetValue ("penaltyPosition",typeof(bool));
            penaltyPositionOffset = (float)serializer.GetValue ("penaltyPositionOffset",typeof(float));
            penaltyPositionFactor = (float)serializer.GetValue ("penaltyPositionFactor",typeof(float));

            aspectRatio = (float)serializer.GetValue ("aspectRatio",typeof(float),1F);

            textureData			=	serializer.GetValue ("textureData",typeof(TextureData)) as TextureData;
            if (textureData == null) textureData = new TextureData ();

            #if UNITY_EDITOR
            Matrix4x4 oldMatrix = matrix;
            #endif

            GenerateMatrix ();
            SetUpOffsetsAndCosts ();

            #if UNITY_EDITOR
            if (serializer.onlySaveSettings) {
                if (oldMatrix != matrix && nodes != null) {
                    AstarPath.active.AutoScan ();
                }
            }
            #endif

            //Debug.Log ((string)serializer.GetValue ("SomeString",typeof(string)));
            //Debug.Log ((Bounds)serializer.GetValue ("SomeBounds",typeof(Bounds)));
        }
示例#39
0
 public void SerializeSettings(AstarSerializer serializer)
 {
     serializer.AddUnityReferenceValue ("source",source);
     serializer.AddValue ("enabled",enabled);
     for (int i=0;i<factors.Length;i++) {
         serializer.AddValue ("factor"+i,factors[i]);
     }
     for (int i=0;i<channels.Length;i++) {
         serializer.AddValue ("channel"+i,(int)channels[i]);
     }
 }
示例#40
0
        /** Serialize Settings.
         * \deprecated This function is obsolete. New serialization functions exist */
        public void SerializeSettings(AstarSerializer serializer)
        {
            serializer.mask -= AstarSerializer.SMask.SaveNodePositions;

            //serializer.AddValue ("Width",width);
            //serializer.AddValue ("Depth",depth);
            //serializer.AddValue ("Height",height);

            serializer.AddValue ("unclampedSize",unclampedSize);

            serializer.AddValue ("cutCorners",cutCorners);
            serializer.AddValue ("neighbours",(int)neighbours);

            serializer.AddValue ("center",center);
            serializer.AddValue ("rotation",rotation);
            serializer.AddValue ("nodeSize",nodeSize);
            serializer.AddValue ("collision",collision == null ? new GraphCollision () : collision);

            serializer.AddValue ("maxClimb",maxClimb);
            serializer.AddValue ("maxClimbAxis",maxClimbAxis);
            serializer.AddValue ("maxSlope",maxSlope);

            serializer.AddValue ("erodeIterations",erodeIterations);

            serializer.AddValue ("penaltyAngle",penaltyAngle);
            serializer.AddValue ("penaltyAngleFactor",penaltyAngleFactor);
            serializer.AddValue ("penaltyPosition",penaltyPosition);
            serializer.AddValue ("penaltyPositionOffset",penaltyPositionOffset);
            serializer.AddValue ("penaltyPositionFactor",penaltyPositionFactor);

            serializer.AddValue ("aspectRatio",aspectRatio);

            serializer.AddValue ("textureData",textureData);
        }
示例#41
0
        /** Deserializes all graphs and also user connections \deprecated */
        public void DeserializeGraphsPart(AstarSerializer serializer)
        {
            if (serializer.error != AstarSerializer.SerializerError.Nothing) {
                data_backup = (serializer.readerStream.BaseStream as System.IO.MemoryStream).ToArray ();
                Debug.Log ("Error encountered : "+serializer.error+"\nWriting data to AstarData.data_backup");
                graphs = new NavGraph[0];
                return;
            }

            try {
                int count1 = serializer.readerStream.ReadInt32 ();
                int count2 = serializer.readerStream.ReadInt32 ();

                if (count1 != count2) {
                    Debug.LogError ("Data is corrupt ("+count1 +" != "+count2+")");
                    graphs = new NavGraph[0];
                    return;
                }

                NavGraph[] _graphs = new NavGraph[count1];
                //graphs = new NavGraph[count1];

                for (int i=0;i<_graphs.Length;i++) {

                    if (!serializer.MoveToAnchor ("Graph"+i)) {
                        Debug.LogError ("Couldn't find graph "+i+" in the data");
                        Debug.Log ("Logging... "+serializer.anchors.Count);
                        foreach (KeyValuePair<string,int> value in serializer.anchors) {
                            Debug.Log ("KeyValuePair "+value.Key);
                        }
                        _graphs[i] = null;
                        continue;
                    }
                    string graphType = serializer.readerStream.ReadString ();

                    graphType = graphType.Replace ("ListGraph","PointGraph");

                    Guid guid = new Guid (serializer.readerStream.ReadString ());

                    //Search for existing graphs with the same GUID. If one is found, that means that we are loading another version of that graph
                    //Use that graph then and just load it with some new settings
                    NavGraph existingGraph = GuidToGraph (guid);

                    if (existingGraph != null) {
                        _graphs[i] = existingGraph;
                        //Replace
                        //graph.guid = new System.Guid ();
                        //serializer.loadedGraphGuids[i] = graph.guid.ToString ();
                    } else {
                        _graphs[i] = CreateGraph (graphType);
                    }

                    NavGraph graph = _graphs[i];

                    if (graph == null) {
                        Debug.LogError ("One of the graphs saved was of an unknown type, the graph was of type '"+graphType+"'");
                        data_backup = data;
                        graphs = new NavGraph[0];
                        return;
                    }

                    _graphs[i].guid = guid;

                    //Set an unique prefix for all variables in this graph
                    serializer.sPrefix = i.ToString ();
                    serializer.DeSerializeSettings (graph,active);
                }

                serializer.SetUpGraphRefs (_graphs);

                for (int i=0;i<_graphs.Length;i++) {

                    NavGraph graph = _graphs[i];

                    if (serializer.MoveToAnchor ("GraphNodes_Graph"+i)) {
                        serializer.mask = serializer.readerStream.ReadInt32 ();
                        serializer.sPrefix = i.ToString ()+"N";
                        serializer.DeserializeNodes (graph,_graphs,i,active);
                        serializer.sPrefix = "";
                    }

                    //Debug.Log ("Graph "+i+" has loaded "+(graph.nodes != null ? graph.nodes.Length.ToString () : "null")+" nodes");

                }

                userConnections = serializer.DeserializeUserConnections ();

                //Remove null graphs
                List<NavGraph> tmp = new List<NavGraph>(_graphs);
                for (int i=0;i<_graphs.Length;i++) {
                    if (_graphs[i] == null) {
                        tmp.Remove (_graphs[i]);
                    }
                }

                graphs = tmp.ToArray ();
            } catch (System.Exception e) {
                data_backup = (serializer.readerStream.BaseStream as System.IO.MemoryStream).ToArray ();
                Debug.LogWarning ("Deserializing Error Encountered - Writing data to AstarData.data_backup:\n"+e.ToString ());
                graphs = new NavGraph[0];
                return;
            }
        }
示例#42
0
 public void DeserializeGraphs(AstarSerializer serializer, byte[] bytes)
 {
     DeserializeGraphs_oldInternal (serializer, bytes);
 }
示例#43
0
        /** Deserializes graphs from the specified byte array.
         * If an error ocurred, it will try to deserialize using the old deserializer.
         * A warning will be logged if all deserializers failed.
          */
        public void DeserializeGraphs(byte[] bytes)
        {
            try {
                if (bytes != null) {
                    Pathfinding.Serialize.AstarSerializer sr = new Pathfinding.Serialize.AstarSerializer(this);

                    if (sr.OpenDeserialize(bytes)) {
                        DeserializeGraphsPart (sr);
                        sr.CloseDeserialize();
                    } else {
                        Debug.Log ("Invalid data file (cannot read zip). Trying to load with old deserializer (pre 3.1)...");
                        AstarSerializer serializer = new AstarSerializer (active);
                        DeserializeGraphs_oldInternal (serializer);
                    }
                } else {
                    throw new System.ArgumentNullException ("Bytes should not be null when passed to DeserializeGraphs");
                }
                active.DataUpdate ();
            } catch (System.Exception e) {
                Debug.LogWarning ("Caught exception while deserializing data.\n"+e);
                data_backup = bytes;
            }
        }
示例#44
0
	public void DeSerializationInterrupt (AstarSerializer serializer, bool isNewer, System.Guid g1) {
		if (EditorUtility.DisplayDialog ("Replace Graph?","Another version of this graph already exists. Do you want to replace it?","Replace","Add")) {
			serializer.replaceOldGraphs = true;
		} else {
			serializer.replaceOldGraphs = false;
		}
	}
示例#45
0
文件: Base.cs 项目: rmkeezer/fpsgame
        /** \copydoc Pathfinding::ISerializableObject::SerializeSettings \copybrief Pathfinding::ISerializableObject::SerializeSettings */
        public void SerializeSettings(AstarSerializer serializer)
        {
            serializer.AddValue ("Mask",(int)mask);
            serializer.AddValue ("Diameter",diameter);
            serializer.AddValue ("Height",height);
            serializer.AddValue ("Type",(int)type);
            serializer.AddValue ("RayDirection",(int)rayDirection);

            serializer.AddValue ("heightMask",(int)heightMask);
            serializer.AddValue ("fromHeight",fromHeight);
            serializer.AddValue ("thickRaycastDiameter",thickRaycastDiameter);
            serializer.AddValue ("thickRaycast",thickRaycast);

            serializer.AddValue ("collisionCheck",collisionCheck);
            serializer.AddValue ("heightCheck",heightCheck);

            serializer.AddValue ("unwalkableWhenNoGround",unwalkableWhenNoGround);

            serializer.AddValue ("collisionOffset",collisionOffset);
        }
示例#46
0
    /*public void OnDisableUndo () {
        return;
        if (!editor.enableUndo) {
            return;
        }

        if (undoState != null) {
            ScriptableObject.DestroyImmediate (undoState);
            undoState = null;
        }
    }

    private void ApplyUndo () {
        return;
        if (!editor.enableUndo) {
            return;
        }

        undoState.hasBeenReverted = false;

        if (AstarPath.active == null) {
            return;
        }

        byte[] bytes = GetSerializedBytes (target);

        bool isDifferent = false;

        //Check if the data is any different from the last saved data, if it isn't, don't load it
        if (undoState.data == null || bytes.Length != undoState.data.Length) {
            isDifferent = true;
        } else {
            for (int i=0;i<bytes.Length;i++) {
                if (bytes[i] != undoState.data[i]) {
                    isDifferent = true;
                    break;
                }
            }
        }

        if (isDifferent) {

            Debug.Log ("The undo is different "+ Event.current.type +" "+Event.current.commandName);
            //Event.current.Use ();
            AstarSerializer sz = new AstarSerializer (editor.script);
            sz.OpenDeserialize (undoState.data);
            sz.DeSerializeSettings (target,AstarPath.active);
            sz.Close ();
        }
    }

    public void ModifierKeysChanged () {
        return;
        if (!editor.enableUndo) {
            return;
        }

        if (undoState == null) {
            return;
        }
        //The user has tried to undo something, apply that
        if (undoState.hasBeenReverted) {
            ApplyUndo ();
            GUI.changed = true;
            editor.Repaint ();
        }

    }

    /** Handles undo operations for the graph *
    public void HandleUndo (NavGraph target) {
        return;
        if (!editor.enableUndo) {
            return;
        }

        if (undoState == null) {
            undoState = ScriptableObject.CreateInstance<GraphUndo>();
        }

        Event e = Event.current;

        //ModifierKeysChanged ();

        //To serialize settings for a grid graph takes from 0.00 ms to 7.8 ms (usually 0.0, but sometimes jumps up to 7.8 (no values in between)
        if ((e.button == 0 && (e.type == EventType.MouseDown || e.type == EventType.MouseUp)) || (e.isKey && (e.keyCode == KeyCode.Tab || e.keyCode == KeyCode.Return))) {
            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();

            //Serialize the settings of the graph
            byte[] bytes = GetSerializedBytes (target);

            bool isDifferent = false;

            if (undoState.data == null) {
                Debug.LogError ("UndoState.data == null - This should not happen");
                return;
            }

            //Check if the data is any different from the last saved data, if it isn't, don't save it
            if (bytes.Length != undoState.data.Length) {
                isDifferent = true;
            } else {
                for (int i=0;i<bytes.Length;i++) {
                    if (bytes[i] != undoState.data[i]) {
                        isDifferent = true;
                        break;
                    }
                }
            }

            //Only save undo if the data was different from the last saved undo
            if (isDifferent) {
                //This flag is set to true so we can detect if the object has been reverted
                undoState.hasBeenReverted = true;

                Undo.RegisterUndo (undoState,"A* inspector");

                //Assign the new data
                undoState.data = bytes;

                //Undo.SetSnapshotTarget(undoState,"A* inspector");
                //Undo.CreateSnapshot ();
                //Undo.RegisterSnapshot();

                undoState.hasBeenReverted = false;
                Debug.Log ("Saved "+bytes.Length+" bytes");
                stopWatch.Stop();
                Debug.Log ("Adding Undo "+stopWatch.Elapsed.ToString ());
            }

        }
    }*/
    /** Returns a byte array with the settings of the graph. This function serializes the graph's settings and stores them in a byte array, used for undo operations. This will not save any additional metadata such as which A* version we are working on. */
    private byte[] GetSerializedBytes(NavGraph target)
    {
        //Serialize the settings of the graph
        AstarSerializer sz = new AstarSerializer (editor.script);
        sz.OpenSerialize ();
        sz.SerializeSettings (target,AstarPath.active);
        sz.Close ();
        byte[] bytes = (sz.writerStream.BaseStream as System.IO.MemoryStream).ToArray ();

        return bytes;
    }
示例#47
0
        public void SerializeNodes(Node[] nodes, AstarSerializer serializer)
        {
            /** \todo Add check for mask == Save Node Positions. Can't use normal mask since it is changed by SerializeSettings */

            GenerateMatrix ();

            int maxValue = 0;
            int minValue = 0;

            for (int i=0;i<nodes.Length;i++) {
                int val = nodes[i].position.y;
                maxValue = val > maxValue ? val : maxValue;
                minValue = val < minValue ? val : minValue;
            }

            int maxRange = maxValue > -minValue ? maxValue : -minValue;

            if (maxRange <= System.Int16.MaxValue) {
                //Int16
                serializer.writerStream.Write ((byte)0);
                for (int i=0;i<nodes.Length;i++) {
                    serializer.writerStream.Write ((System.Int16)(inverseMatrix.MultiplyPoint3x4 ((Vector3)nodes[i].position).y));
                }
            } else {
                //Int32
                serializer.writerStream.Write ((byte)1);
                for (int i=0;i<nodes.Length;i++) {
                    serializer.writerStream.Write (inverseMatrix.MultiplyPoint3x4 ((Vector3)nodes[i].position).y);
                }
            }
            /*for (int i=0;i<nodes.Length;i++) {
                GridNode node = nodes[i] as GridNode;

                if (node == null) {
                    Debug.LogError ("Serialization Error : Couldn't cast the node to the appropriate type - GridGenerator");
                    return;
                }

                serializer.writerStream.Write (node.index);
            }*/
        }
示例#48
0
 /** Main deserializer function (old), loads from the #data variable \deprecated */
 public void DeserializeGraphs_oldInternal(AstarSerializer serializer)
 {
     DeserializeGraphs_oldInternal (serializer, data);
 }
示例#49
0
            public void DeSerializeSettings(AstarSerializer serializer)
            {
                enabled = (bool)serializer.GetValue ("enabled",typeof(bool));
                source = (Texture2D)serializer.GetUnityReferenceValue ("source",typeof(Texture2D));
                factors = new float[3];
                for (int i=0;i<factors.Length;i++) {
                    factors[i] = (float)serializer.GetValue ("factor"+i,typeof(float),1F);
                }

                channels = new ChannelUse[3];
                for (int i=0;i<channels.Length;i++) {
                    channels[i] = (ChannelUse)serializer.GetValue ("channel"+i,typeof(int));
                }
            }
示例#50
0
        /** Main deserializer function (old). Loads from \a bytes variable \deprecated */
        public void DeserializeGraphs_oldInternal(AstarSerializer serializer, byte[] bytes)
        {
            System.DateTime startTime = System.DateTime.UtcNow;

            if (bytes == null || bytes.Length == 0) {
                Debug.Log ("No previous data, assigning default");
                graphs = new NavGraph[0];
                return;
            }

            Debug.Log ("Deserializing...");

            serializer = serializer.OpenDeserialize (bytes);

            DeserializeGraphsPart (serializer);

            serializer.Close ();

            System.DateTime endTime = System.DateTime.UtcNow;
            Debug.Log ("Deserialization complete - Process took "+((endTime-startTime).Ticks*0.0001F).ToString ("0.00")+" ms");
        }
示例#51
0
        public void DeSerializeNodes(Node[] nodes, AstarSerializer serializer)
        {
            /*for (int i=0;i<nodes.Length;i++) {
                GridNode node = nodes[i] as GridNode;

                if (node == null) {
                    Debug.LogError ("DeSerialization Error : Couldn't cast the node to the appropriate type - GridGenerator");
                    return;
                }*/

            GenerateMatrix ();

            SetUpOffsetsAndCosts ();

            if (nodes == null || nodes.Length == 0) {
                return;
            }

            nodes = new GridNode[nodes.Length];

            int gridIndex = GridNode.SetGridGraph (this);

            int numberSize = (int)serializer.readerStream.ReadByte ();

            for (int z = 0; z < depth; z ++) {
                for (int x = 0; x < width; x++) {

                    GridNode node = nodes[z*width+x] as GridNode;

                    nodes[z*width+x] = node;

                    if (node == null) {
                        Debug.LogError ("DeSerialization Error : Couldn't cast the node to the appropriate type - GridGenerator");
                        return;
                    }

                    node.SetIndex  (z*width+x);
                    node.SetGridIndex (gridIndex);

                    float yPos = 0;

                    //if (serializer.mask == AstarSerializer.SMask.SaveNodePositions) {
                        //Needs to multiply with precision factor because the position will be scaled by Int3.Precision later (Vector3 --> Int3 conversion)
                    if (numberSize == 0) {
                        yPos = serializer.readerStream.ReadInt16 ();
                    } else {
                        yPos = serializer.readerStream.ReadInt32 ();
                    }
                    //}

                    node.position = (Int3)matrix.MultiplyPoint3x4 (new Vector3 (x+0.5F,yPos,z+0.5F));
                }
            }
        }
		//These functions are for serialization, the static ones are there so other graphs using mesh nodes can serialize them more easily
		public static void SerializeMeshNodes (INavmesh graph, Node[] nodes, AstarSerializer serializer) {
			
			System.IO.BinaryWriter stream = serializer.writerStream;
			
			for (int i=0;i<nodes.Length;i++) {
				MeshNode node = nodes[i] as MeshNode;
				
				if (node == null) {
					Debug.LogError ("Serialization Error : Couldn't cast the node to the appropriate type - NavMeshGenerator");
					return;
				}
				
				stream.Write (node.v1);
				stream.Write (node.v2);
				stream.Write (node.v3);
			}
			
			Int3[] vertices = graph.vertices;
			
			if (vertices == null) {
				vertices = new Int3[0];
			}
			
			stream.Write (vertices.Length);
			
			for (int i=0;i<vertices.Length;i++) {
				stream.Write (vertices[i].x);
				stream.Write (vertices[i].y);
				stream.Write (vertices[i].z);
			}
		}
		public static void DeSerializeMeshNodes (INavmesh graph, Node[] nodes, AstarSerializer serializer) {
			
			System.IO.BinaryReader stream = serializer.readerStream;
			
			for (int i=0;i<nodes.Length;i++) {
				MeshNode node = nodes[i] as MeshNode;
				
				if (node == null) {
					Debug.LogError ("Serialization Error : Couldn't cast the node to the appropriate type - NavMeshGenerator");
					return;
				}
				
				node.v1 = stream.ReadInt32 ();
				node.v2 = stream.ReadInt32 ();
				node.v3 = stream.ReadInt32 ();
			}
			
			int numVertices = stream.ReadInt32 ();
			
			graph.vertices = new Int3[numVertices];
			
			for (int i=0;i<numVertices;i++) {
				int x = stream.ReadInt32 ();
				int y = stream.ReadInt32 ();
				int z = stream.ReadInt32 ();
				
				graph.vertices[i] = new Int3 (x,y,z);
			}
				
			RebuildBBTree (graph as NavGraph);
		}
		public void SerializeSettings (AstarSerializer serializer) {
			
			System.IO.BinaryWriter stream = serializer.writerStream;
			
			serializer.AddValue ("offset",offset);
			serializer.AddValue ("rotation",rotation);
			serializer.AddValue ("scale",scale);
			
			if (sourceMesh != null) {
				
				Vector3[] verts = sourceMesh.vertices;
				int[] tris = sourceMesh.triangles;
				
				stream.Write (verts.Length);
				stream.Write (tris.Length);
				
				for (int i=0;i<verts.Length;i++) {
					stream.Write (verts[i].x);
					stream.Write (verts[i].y);
					stream.Write (verts[i].z);
				}
				
				for (int i=0;i<tris.Length;i++) {
					stream.Write (tris[i]);
				}
			} else {
				stream.Write (0);
				stream.Write (0);
			}
			
			serializer.AddUnityReferenceValue ("sourceMesh",sourceMesh);
		}
        public new void DeSerializeSettings(AstarSerializer serializer)
        {
            (this as GridGraph).DeSerializeSettings (serializer);

            mergeSpanRange = 	(float)serializer.GetValue ("mergeSpanRange",typeof(float),mergeSpanRange);
            characterHeight = 	(float)serializer.GetValue ("characterHeight",typeof(float),characterHeight);
            //maxClimb = 			(float)serializer.GetValue ("maxClimb",typeof(float),maxClimb);
        }
		public void DeSerializeSettings (AstarSerializer serializer) {
			
			System.IO.BinaryReader stream = serializer.readerStream;
			
			offset = (Vector3)serializer.GetValue ("offset",typeof(Vector3));
			rotation = (Vector3)serializer.GetValue ("rotation",typeof(Vector3));
			scale = (float)serializer.GetValue ("scale",typeof(float));
			
			GenerateMatrix ();
			
			Vector3[] verts = new Vector3[stream.ReadInt32 ()];
			int[] tris = new int[stream.ReadInt32 ()];
			
			for (int i=0;i<verts.Length;i++) {
				verts[i] = new Vector3(stream.ReadSingle (),stream.ReadSingle (),stream.ReadSingle ());
			}
				
			for (int i=0;i<tris.Length;i++) {
				tris[i] = stream.ReadInt32 ();
			}
			
			sourceMesh = serializer.GetUnityReferenceValue ("sourceMesh",typeof(Mesh)) as Mesh;
			
			if (Application.isPlaying) {
				sourceMesh = new Mesh ();
				sourceMesh.name = "NavGraph Mesh";
				sourceMesh.vertices = verts;
				sourceMesh.triangles = tris;
			}
		}
示例#57
0
		public void SerializeSettings (AstarSerializer serializer) {;
		
			serializer.AddUnityReferenceValue ("root",root);
			serializer.AddValue ("maxDistance",maxDistance);
			serializer.AddValue ("limits",limits);
			serializer.AddValue ("mask",mask.value);
			serializer.AddValue ("thickRaycast",thickRaycast);
			serializer.AddValue ("thickRaycastRadius",thickRaycastRadius);
			serializer.AddValue ("searchTag",searchTag);
			serializer.AddValue ("recursive",recursive);
			serializer.AddValue ("raycast",raycast);
		}
示例#58
0
        public void DeSerializeSettings (NavGraph target, AstarSerializer serializer) {
        pivot = (GridPivot)serializer.GetValue ("pivot",typeof(int),GridPivot.BottomLeft);
        locked = (bool)serializer.GetValue ("locked",typeof(bool),true);
        showExtra = (bool)serializer.GetValue ("showExtra",typeof(bool));

        }
示例#59
0
文件: Base.cs 项目: rmkeezer/fpsgame
        /** \copydoc Pathfinding::ISerializableObject::DeSerializeSettings */
        public void DeSerializeSettings(AstarSerializer serializer)
        {
            mask.value = (int)serializer.GetValue ("Mask",typeof (int));
            diameter = (float)serializer.GetValue ("Diameter",typeof (float));
            height = (float)serializer.GetValue ("Height",typeof (float));
            type = (ColliderType)serializer.GetValue ("Type",typeof(int));
            rayDirection = (RayDirection)serializer.GetValue ("RayDirection",typeof(int));

            heightMask.value = (int)serializer.GetValue ("heightMask",typeof (int),-1);
            fromHeight = (float)serializer.GetValue ("fromHeight",typeof (float), 100.0F);
            thickRaycastDiameter = (float)serializer.GetValue ("thickRaycastDiameter",typeof (float));
            thickRaycast = (bool)serializer.GetValue ("thickRaycast",typeof (bool));

            collisionCheck = (bool)serializer.GetValue ("collisionCheck",typeof(bool),true);
            heightCheck = (bool)serializer.GetValue ("heightCheck",typeof(bool),true);

            unwalkableWhenNoGround = (bool)serializer.GetValue ("unwalkableWhenNoGround",typeof(bool),true);

            collisionOffset = (float)serializer.GetValue ("collisionOffset",typeof(float),0.0F);

            if (fromHeight == 0) fromHeight = 100;
        }
示例#60
0
	public static UnityEngine.Object ReadUnityReference (AstarSerializer serializer, string name, int instanceID, System.Type type) {

		Object ob1 = EditorUtility.InstanceIDToObject (instanceID);
		
		//Discard if not the correct type
		if (ob1 != null && !type.IsAssignableFrom (ob1.GetType ())) {
			ob1 = null;
		}
		
		Object ob2 = null;
		
		if (ob1 != null && ob1.name == name) {
			//Debug.Log ("Loading from InstanceID + name");
			return ob1;
		}
		
		string guid = serializer.readerStream.ReadString ();
		
		if (guid != "") {
			string path = AssetDatabase.GUIDToAssetPath (guid);
			ob2 = AssetDatabase.LoadMainAssetAtPath (path);
			
			//Discard if not the correct type
			if (ob2 != null && !type.IsAssignableFrom (ob2.GetType ())) {
				ob2 = null;
			}
			
			//Debug.Log ("Got path "+path+" Got Object "+(ob2 != null));
			if (ob2 != null) {
				if (ob2 == ob1) {
					return ob2;
				}
				if (ob2.name == name) {
					return ob2;
				}
			}
		}
		
		//If any were found, return them in priority order
		if (ob2 != null) {
			return ob2;
		}
		if (ob1 != null) {
			return ob1;
		}
		return null;
	}