Beispiel #1
0
        public override Dictionary <string, object> WriteJson(Type type, object value)
        {
            Pathfinding.Util.Guid       guid       = (Pathfinding.Util.Guid)value;
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary.Add("value", guid.ToString());
            return(dictionary);
        }
Beispiel #2
0
 // Token: 0x06000316 RID: 790 RVA: 0x00018B14 File Offset: 0x00016F14
 public override Dictionary <string, object> WriteJson(Type type, object value)
 {
     Pathfinding.Util.Guid guid = (Pathfinding.Util.Guid)value;
     return(new Dictionary <string, object>
     {
         {
             "value",
             guid.ToString()
         }
     });
 }
Beispiel #3
0
 // Token: 0x06000083 RID: 131 RVA: 0x00007020 File Offset: 0x00005420
 public NavGraph GuidToGraph(Pathfinding.Util.Guid guid)
 {
     if (this.graphs == null)
     {
         return(null);
     }
     for (int i = 0; i < this.graphs.Length; i++)
     {
         if (this.graphs[i] != null)
         {
             if (this.graphs[i].guid == guid)
             {
                 return(this.graphs[i]);
             }
         }
     }
     return(null);
 }
Beispiel #4
0
 // Token: 0x06000082 RID: 130 RVA: 0x00006FC0 File Offset: 0x000053C0
 public int GuidToIndex(Pathfinding.Util.Guid guid)
 {
     if (this.graphs == null)
     {
         return(-1);
     }
     for (int i = 0; i < this.graphs.Length; i++)
     {
         if (this.graphs[i] != null)
         {
             if (this.graphs[i].guid == guid)
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Beispiel #5
0
		/** Tries to find a graph with the specified GUID in the #graphs array. Returns null if none is found
		 * \see GuidToIndex */
		public NavGraph GuidToGraph (Guid guid) {
			
			if (graphs == null) {
				return null;
				//CollectGraphs ();
			}
			
			for (int i=0;i<graphs.Length;i++) {
				if (graphs[i] == null) {
					continue;
				}
				if (graphs[i].guid == guid) {
					return graphs[i];
				}
			}
			return null;
		}
Beispiel #6
0
		/** Tries to find a graph with the specified GUID in the #graphs array.
		 * If a graph is found it returns its index, otherwise it returns -1
		 * \see GuidToGraph */
		public int GuidToIndex (Guid guid) {
			
			if (graphs == null) {
				return -1;
				//CollectGraphs ();
			}
			
			for (int i=0;i<graphs.Length;i++) {
				if (graphs[i] == null) {
					continue;
				}
				if (graphs[i].guid == guid) {
					return i;
				}
			}
			return -1;
		}
Beispiel #7
0
		public virtual void DeserializeSettings ( GraphSerializationContext ctx ) {

			guid = new Guid(ctx.reader.ReadBytes (16));
			initialPenalty = ctx.reader.ReadUInt32 ();
			open = ctx.reader.ReadBoolean();
			name = ctx.reader.ReadString();
			drawGizmos = ctx.reader.ReadBoolean();
			infoScreenOpen = ctx.reader.ReadBoolean();

			for ( int i = 0; i < 4; i++ ) {
				Vector4 row = Vector4.zero;
				for ( int j = 0; j < 4; j++ ) {
					row[j] = ctx.reader.ReadSingle ();
				}
				matrix.SetRow (i, row);
			}
		}
Beispiel #8
0
        /** Tries to find a graph with the specified GUID in the #graphs array.
         * If a graph is found it returns its index, otherwise it returns -1
         * \see GuidToGraph */
        public int GuidToIndex(Guid guid)
        {
            if (graphs == null) {
                return -1;
                //CollectGraphs ();
            }

            for (int i=0;i<graphs.Length;i++) {
                if (graphs[i] == null) {
                    Debug.LogWarning ("Graph "+i+" is null - This should not happen");
                    continue;
                }
                if (graphs[i].guid == guid) {
                    return i;
                }
            }
            return -1;
        }
Beispiel #9
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;
            }
        }
        private object Deserialize(Type tp, object populate = null)
        {
            Type typeInfo = WindowsStoreCompatibility.GetTypeInfo(tp);

            if (typeInfo.IsEnum)
            {
                return(Enum.Parse(tp, this.EatField()));
            }
            if (this.TryEat('n'))
            {
                this.Eat("ull");
                this.TryEat(',');
                return(null);
            }
            if (object.Equals(tp, typeof(float)))
            {
                return(float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat));
            }
            if (object.Equals(tp, typeof(int)))
            {
                return(int.Parse(this.EatField(), TinyJsonDeserializer.numberFormat));
            }
            if (object.Equals(tp, typeof(uint)))
            {
                return(uint.Parse(this.EatField(), TinyJsonDeserializer.numberFormat));
            }
            if (object.Equals(tp, typeof(bool)))
            {
                return(bool.Parse(this.EatField()));
            }
            if (object.Equals(tp, typeof(string)))
            {
                return(this.EatField());
            }
            if (object.Equals(tp, typeof(Version)))
            {
                return(new Version(this.EatField()));
            }
            if (object.Equals(tp, typeof(Vector2)))
            {
                this.Eat("{");
                Vector2 vector = default(Vector2);
                this.EatField();
                vector.x = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat);
                this.EatField();
                vector.y = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat);
                this.Eat("}");
                return(vector);
            }
            if (object.Equals(tp, typeof(Vector3)))
            {
                this.Eat("{");
                Vector3 vector2 = default(Vector3);
                this.EatField();
                vector2.x = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat);
                this.EatField();
                vector2.y = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat);
                this.EatField();
                vector2.z = float.Parse(this.EatField(), TinyJsonDeserializer.numberFormat);
                this.Eat("}");
                return(vector2);
            }
            if (object.Equals(tp, typeof(Pathfinding.Util.Guid)))
            {
                this.Eat("{");
                this.EatField();
                Pathfinding.Util.Guid guid = Pathfinding.Util.Guid.Parse(this.EatField());
                this.Eat("}");
                return(guid);
            }
            if (object.Equals(tp, typeof(LayerMask)))
            {
                this.Eat("{");
                this.EatField();
                LayerMask layerMask = int.Parse(this.EatField());
                this.Eat("}");
                return(layerMask);
            }
            if (object.Equals(tp, typeof(List <string>)))
            {
                IList list = new List <string>();
                this.Eat("[");
                while (!this.TryEat(']'))
                {
                    list.Add(this.Deserialize(typeof(string), null));
                    this.TryEat(',');
                }
                return(list);
            }
            if (typeInfo.IsArray)
            {
                List <object> list2 = new List <object>();
                this.Eat("[");
                while (!this.TryEat(']'))
                {
                    list2.Add(this.Deserialize(tp.GetElementType(), null));
                    this.TryEat(',');
                }
                Array array = Array.CreateInstance(tp.GetElementType(), list2.Count);
                list2.ToArray().CopyTo(array, 0);
                return(array);
            }
            if (object.Equals(tp, typeof(Mesh)) || object.Equals(tp, typeof(Texture2D)) || object.Equals(tp, typeof(Transform)) || object.Equals(tp, typeof(GameObject)))
            {
                return(this.DeserializeUnityObject());
            }
            object obj = populate ?? Activator.CreateInstance(tp);

            this.Eat("{");
            while (!this.TryEat('}'))
            {
                string    name  = this.EatField();
                FieldInfo field = tp.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (field == null)
                {
                    this.SkipFieldData();
                }
                else
                {
                    field.SetValue(obj, this.Deserialize(field.FieldType, null));
                }
                this.TryEat(',');
            }
            return(obj);
        }