本文整理汇总了C#中Pathfinding.AstarSerializer类的典型用法代码示例。如果您正苦于以下问题:C# AstarSerializer类的具体用法?C# AstarSerializer怎么用?C# AstarSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AstarSerializer类属于Pathfinding命名空间,在下文中一共展示了AstarSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
//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);
}
}
示例2: SerializeSettings
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);
}*/
}
示例3: DeSerializeSettings
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));
}
示例4: SerializeSettings
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);
}
示例5: DeSerializeSettings
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);
}
示例6: DeSerializeSettings
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)));
}
示例7: SerializeSettings
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]);
}
}
示例8: ApplyUndo
/*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
//.........这里部分代码省略.........
示例9: DeserializeGraphs
/** 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;
}
}
示例10: SerializeSettings
/** \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);
}
示例11: DeSerializeSettings
/** \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;
}
示例12: ReadUnityReference
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;
}
示例13: WriteUnityReference
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 ("");
}
}
示例14: DeSerializationInterrupt
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;
}
}
示例15: DeSerializeSettings
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;
}
}