public static void CreateAstarData() { AstarData asset; string name = "AstarData"; int nameIdx = 0; while( System.IO.File.Exists( Application.dataPath + "/" + name + nameIdx + ".asset" ) ) { nameIdx++; } asset = new AstarData(); //asset.Data = ( new CollectionAsset() ).GetData(); AssetDatabase.CreateAsset( asset, "Assets/" + name + (nameIdx != 0 ? ""+nameIdx : "") + ".asset" ); //EditorUtility.FocusProjectView(); Selection.activeObject = asset; }
/** Makes sure #active is set to this object and that #astarData is not null. * Also calls OnEnable for the #colorSettings and initializes astarData.userConnections if it wasn't initialized before */ public void SetUpReferences () { active = this; if (astarData == null) { astarData = new AstarData (); } if (astarData.userConnections == null) { astarData.userConnections = new UserConnection[0]; } if (colorSettings == null) { colorSettings = new AstarColor (); } colorSettings.OnEnable (); }
void Start() { data = AstarPath.active.astarData; }
public AstarSerializer (AstarData data, SerializeSettings settings) { this.data = data; this.settings = settings; }
public AstarSerializer (AstarData data) { this.data = data; settings = SerializeSettings.Settings; }
void Start() { // Calculate the center of the first map element (i.e. (0, 0)) in // world space coordinates. m_minX = OriginX - ((Width * NodeSize) / 2) + (NodeSize / 2); m_minZ = OriginZ - ((Depth * NodeSize) / 2) + (NodeSize / 2); int[,] mapData; int[,] objectData; if (GenerateMap) { MapGenerator generator = new MapGenerator(Width, Depth, RandomSeed); generator.RoomCount = RoomCount; generator.SpawnDistance = SpawnDistance; generator.MinRoomSideRatio = MinRoomSideRatio; generator.SeparationStrength = SeparationStrength; generator.MinRoomWidth = MinRoomWidth; generator.MaxRoomWidth = MaxRoomWidth; generator.MinRoomHeight = MinRoomHeight; generator.MaxRoomHeight = MaxRoomHeight; generator.UseSmoothing = UseSmoothing; generator.SmoothingThreshold = SmoothingThreshold; generator.SmoothingIterations = SmoothingIterations; generator.WeightedGraphEdgeRadius = WeightedGraphEdgeRadius; generator.Generate(); mapData = generator.MapData; objectData = generator.ObjectData; } else { mapData = MapCrafter.GetMapData(this); objectData = MapCrafter.GetPropData(this); } // The map generator works with 2D arrays of integers. The following // functions convert the output arrays into actual game objects in // the scene. InstantiateMap(mapData); InstantiateProps(objectData); InstantiateStairwells(mapData); // The user interface script can't register for map events until all // grid square prefabs are created. Instruct the script to register for // events now. We can also initialise the minimap at this stage. UserInterface.RegisterForMapEvents(); UserInterface.InitializeMiniMap(mapData); // Initialize a A* pathfinding graph. m_astarData = AstarPath.active.astarData; GridGraph graph = (GridGraph)m_astarData.AddGraph(typeof(GridGraph)); graph.width = Width; graph.depth = Depth; graph.nodeSize = NodeSize; graph.center = new Vector3(OriginX, -10f, OriginZ); graph.UpdateSizeFromWidthDepth(); graph.cutCorners = false; graph.collision.collisionCheck = true; graph.collision.mask = 1 << LayerMask.NameToLayer("Obstacle"); graph.collision.heightCheck = true; graph.collision.heightMask = 1 << LayerMask.NameToLayer("Ground"); AstarPath.active.Scan(); // Spawn enemies on the map. SpawnEnemies(mapData); }
// Use this for initialization void Awake() { //make sure to check for and inheret children of any pre-existing handler if (handler == null) { Debug.Log("Handler == null"); DontDestroyOnLoad(gameObject); handler = this; } else { Debug.Log("Handler exists"); InheritChildren(); Destroy(gameObject); } if (AstarPath.active){ path = AstarPath.active.astarData; graph = path.gridGraph; } }