示例#1
0
    void Awake()
    {
        mainCam = GetComponent <Camera>();

        //Reference to the MapNav.js script and gpsFix variable. gpsFix will be true when a valid location data has been set.
        gps = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
    }
示例#2
0
    //This function is similar to GeoLocation() but is to be used by SetGeoInspector.cs
    public void EditorGeoLocation()
    {
        gps    = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
        fixLat = gps.fixLat;
        fixLon = gps.fixLon;

        initX = fixLon * 20037508.34f / 18000;
        initZ = (float)(System.Math.Log(System.Math.Tan((90 + fixLat) * System.Math.PI / 360)) / (System.Math.PI / 180));
        initZ = initZ * 20037508.34f / 18000;

        //Translate the geographical coordinate system used by gps mobile devices(WGS84), into Unity's Vector2 Cartesian coordinates(x,z) and set height(1:100 scale).
        transform.position = new Vector3(((lon * 20037508.34f) / 18000) - initX, height / 100, ((Mathf.Log(Mathf.Tan((90 + lat) * Mathf.PI / 360)) / (Mathf.PI / 180)) * 1113.19490777778f) - initZ);

        //Set object orientation
        Vector3 tmp = transform.eulerAngles;

        tmp.y = orientation;
        transform.eulerAngles = tmp;

        //Set local object scale
        if (transform.localScale != Vector3.zero)
        {
            transform.localScale = new Vector3(scaleX, scaleY, scaleZ);
        }
    }
示例#3
0
 void Awake()
 {
     //Reference to MapNav.cs script. Make sure that the map object containing the MapNav.cs script is tagged as "GameController"
     gps = GameObject.FindGameObjectWithTag("GameController").GetComponent<MapNav>();
     screenX = Screen.width;
     screenY = Screen.height;
 }
示例#4
0
 void Awake()
 {
     //Reference to the MapNav.js script and gpsFix variable. gpsFix will be true when a valid location data has been set.
     gps         = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
     gpsFix      = gps.gpsFix;
     scaleFactor = gps.scaleFactor;
 }
示例#5
0
    //This function is similar to GeoLocation() but is to be used by SetGeoInspector.cs
    public void EditorGeoLocation()
    {
        gps         = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
        fixLat      = gps.fixLat;
        fixLon      = gps.fixLon;
        scaleFactor = gps.scaleFactor;

        initX = fixLon * 20037508.34f / (180 * scaleFactor);
        initZ = (float)(System.Math.Log(System.Math.Tan((90 + fixLat) * System.Math.PI / 360)) / (System.Math.PI / 180));
        initZ = initZ * 20037508.34f / (180 * scaleFactor);

        //Translate the geographical coordinate system used by gps mobile devices(WGS84), into Unity's Vector2 Cartesian coordinates(x,z) and set height(1:100 scale).
        transform.position = WGS84toWebMercator(lon, lat, height);

        //Set object orientation
        Vector3 tmp = transform.eulerAngles;

        tmp.y = orientation;
        transform.eulerAngles = tmp;

        //Set local object scale
        if (transform.localScale != Vector3.zero)
        {
            transform.localScale = new Vector3(scaleX * 100 / scaleFactor, scaleY * 100 / scaleFactor, scaleZ * 100 / scaleFactor);
        }
    }
示例#6
0
 void Awake()
 {
     gps          = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
     mycam        = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
     lineRenderer = gameObject.AddComponent <LineRenderer> ();
     waypoints    = new Vector3[resolution + 1];
 }
示例#7
0
 void Awake()
 {
     //Reference to MapNav.cs script. Make sure that the map object containing the MapNav.cs script is tagged as "GameController"
     gps     = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
     screenX = Screen.width;
     screenY = Screen.height;
 }
示例#8
0
    /// <summary>
    /// 加载指定路径的地图prefab作为地表
    /// </summary>
    /// <param name="mapname"></param>
    /// <returns>加载是否成功</returns>
    public bool LoadMap(string mapname)
    {
        foreach (var i in Role.All.ToList())
        {
            if (MainRole.Instance != null && MainRole.Instance.Role.ServerInfo.charid == i.Value.ServerInfo.charid)
            {
                continue;
            }
            else
            {
                Role.All.Remove(i.Value.ServerInfo.charid);
                GameObject.Destroy(i.Value.gameObject);
            }
        }
        //Role.All.Clear();

        foreach (var i in Npc.All)
        {
            GameObject.Destroy(i.Value.gameObject);
        }
        Npc.All.Clear();

        foreach (var i in SceneItem.All)
        {
            GameObject.Destroy(i.Value.gameObject);
        }
        SceneItem.All.Clear();

        //跨地图关闭窗口
        BattleScene.Instance.Gui <NpcDialog>().gameObject.SetActive(false);
        BattleScene.Instance.Gui <CopyEnter>().gameObject.SetActive(false);
        BattleScene.Instance.Gui <CopyEnter2>().gameObject.SetActive(false);

        var path = "Map/" + mapname;
        var map  = Resources.Load(path);

        if (map == null)
        {
            Debug.LogError("Load map error: " + path);
            return(false);
        }
        Debug.Log("Load map: " + path);
        if (terrain != null)
        {
            GameObject.Destroy(terrain);
        }
        terrain      = GameObject.Instantiate(map) as GameObject;
        terrain.name = path.Replace('/', '.');

        // 删除地图中在编辑器中预制的Npc
        foreach (var npc in terrain.GetComponentsInChildren <NpcEditor>())
        {
            GameObject.Destroy(npc.gameObject);
        }

        MapNav = terrain.GetComponentInChildren <MapNav>();
        return(true);
    }
示例#9
0
 void Awake()
 {
     //Reference to the MapNav.js script and gpsFix variable. gpsFix will be true when a valid location data has been set.
     gps                = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
     status             = GameObject.FindGameObjectWithTag("GameController").GetComponent <GPS_Status>();
     gpsFix             = gps.gpsFix;
     status.speedometer = true;
     user               = GameObject.FindGameObjectWithTag("Player").transform;
 }
示例#10
0
	private float delayTimer = 0f;			// used when unit isDelayed

	#endregion
	// ====================================================================================================================
	#region pub

	/// <summary>Instantiates a new unit on target node</summary>
	public static NaviUnit SpawnUnit(GameObject unitFab, MapNav mapnav, TileNode node)
	{
		GameObject go = (GameObject)GameObject.Instantiate(unitFab);
        go.transform.position = node.transform.position;
		NaviUnit unit = go.GetComponent<NaviUnit>();
		unit.mapnav = mapnav;
		unit._tr = go.transform;
		unit.LinkWith(node);
		return unit;
	}
示例#11
0
    void Awake()
    {
        //Reference to the MapNav.cs script and GUI elements
        mapnav = GameObject.FindGameObjectWithTag("GameController").GetComponent<MapNav>();
        initText = transform.Find("GUIText");
        initBackg = transform.Find("GUITexture");

        //Set GUIText font size according to our device screen size
        initText.guiText.fontSize = (int)Mathf.Round(15 * Screen.width / 320);
    }
示例#12
0
    void Awake()
    {
        //Reference to the MapNav.cs script and GUI elements
        mapnav    = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
        initText  = transform.Find("GUIText");
        initBackg = transform.Find("GUITexture");

        //Set GUIText font size according to our device screen size
        initText.GetComponent <GUIText>().fontSize = (int)Mathf.Round(15 * Screen.width / 320);
    }
示例#13
0
	void Awake(){
		target = transform.parent.transform;
		mapnav = GameObject.FindGameObjectWithTag("GameController").GetComponent<MapNav>();
		screenX = Screen.width;
		screenY = Screen.height;
		if(screenY >= screenX){
			dot = screenY/800;
		}else{
			dot = screenX/800;
		}
	}
示例#14
0
文件: Minimap.cs 项目: PenpenLi/BWM
    void OnMapChanged(MapNav map)
    {
        uiMapTexture.mainTexture = map.transform.parent.GetComponentInChildren <MapTexture>().texture;
        uiMapTexture.gameObject.SetActive(uiMapTexture.mainTexture != null);

        mapSize        = new Vector2(MapGrid.Width * map.gridXNum, MapGrid.Height * map.gridZNum);
        Extent         = Mathf.Min(Extent, uiMapTexture.mainTexture.width, uiMapTexture.mainTexture.height);
        relativeExtent = new Vector2(Extent / (float)uiMapTexture.mainTexture.width, Extent / (float)uiMapTexture.mainTexture.height);

        Layout = true;
    }
示例#15
0
    private float delayTimer = 0f;                     // used when unit isDelayed

    #endregion
    // ====================================================================================================================
    #region pub

    /// <summary>Instantiates a new unit on target node</summary>
    public static NaviUnit SpawnUnit(GameObject unitFab, MapNav mapnav, TileNode node)
    {
        GameObject go = (GameObject)GameObject.Instantiate(unitFab);

        go.transform.position = node.transform.position;
        NaviUnit unit = go.GetComponent <NaviUnit>();

        unit.mapnav = mapnav;
        unit._tr    = go.transform;
        unit.LinkWith(node);
        return(unit);
    }
示例#16
0
    //This function is to be used by SetGeoInspector.cs
    public void EditorGeoLocation()
    {
        gps      = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
        fixLat   = gps.fixLat;
        fixLon   = gps.fixLon;
        mapScale = gps.mapScale;

        initX = fixLon * 20037508.34f / (180 * mapScale);
        initZ = (float)(System.Math.Log(System.Math.Tan((90 + fixLat) * System.Math.PI / 360)) / (System.Math.PI / 180));
        initZ = initZ * 20037508.34f / (180 * mapScale);

        GeoLocation();
    }
示例#17
0
	private LayerMask _rayMask = 0;				// used to determine what can be clicked on (Tiles and Units) Inited in Start()

	#endregion
	// ====================================================================================================================
	#region start/init

	public virtual void Start()
	{
		if (map == null)
		{
			Debug.LogWarning("The 'map' property was not set, attempting to find a MapNav in the scene.");
			Object obj = GameObject.FindObjectOfType(typeof(MapNav));
			if (obj != null) map = obj as MapNav;

			// I'm not gonan do extra if() tests in the HandleInput.. tell coder now there is problem he should be sorting out asap
			if (map == null) Debug.LogError("Could not find a MapNav in the scene. You gonna get NullRef errors soon!");
		}

		_rayMask = (1<<map.tilesLayer | 1<<this.unitsLayer);
	}
示例#18
0
        public PathNode(int _index, int _parentIndex, float _g, float _h, MapNav mapNav)
        {
            index       = _index;
            parentIndex = _parentIndex;
            g           = _g;
            h           = _h;
            f           = g + h;

            grid = new MapGrid()
            {
                x = index % mapNav.gridXNum, z = index / mapNav.gridXNum
            };
            position = mapNav.GetWorldPosition(grid);
        }
示例#19
0
 void Awake()
 {
     target  = transform.parent.transform;
     mapnav  = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
     screenX = Screen.width;
     screenY = Screen.height;
     if (screenY >= screenX)
     {
         dot = screenY / 800;
     }
     else
     {
         dot = screenX / 800;
     }
 }
示例#20
0
    void Awake()
    {
        infoCanvas   = GameObject.FindGameObjectWithTag("LocationInfo").transform;
        UI_latitude  = infoCanvas.Find("Latitude").GetComponent <Text>();
        UI_longitude = infoCanvas.Find("Longitude").GetComponent <Text>();
        UI_altitude  = infoCanvas.Find("Altitude").GetComponent <Text>();
        UI_status    = infoCanvas.Find("Status").GetComponent <Text>();
        UI_heading   = infoCanvas.Find("Heading").GetComponent <Text>();
        UI_zoom      = infoCanvas.Find("Zoom").GetComponent <Text>();
        UI_accuracy  = infoCanvas.Find("Accuracy").GetComponent <Text>();
        UI_speed     = infoCanvas.Find("Speed").GetComponent <Text>();

        //Reference to MapNav.cs script. Make sure that the map object containing the MapNav.cs script is tagged as "GameController"
        gps = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapNav>();
    }
示例#21
0
    private void CreateMapNav()
    {
        GameObject go = new GameObject();

        go.name = "MapNav";
        MapNav mn = go.AddComponent <MapNav>();

        mn.tilesLayer                    = tileLayer;
        mn.tilesLayout                   = (MapNav.TilesLayout)tilesLayout;
        mn.tileSpacing                   = tileSpacing;
        mn.tileSize                      = tileSize;
        mn.oneUnitPerTileOnly            = oneUnitPerTileOnly;
        mn.oneUnitExceptionAllowMoveOver = oneUnitExceptionAllowMoveOver;

        if (edNewNodesXY[0] > 0 && edNewNodesXY[1] > 0 && tileNodeFab != null)
        {
            MapNav.CreateTileNodes(tileNodeFab, mn, (MapNav.TilesLayout)tilesLayout, tileSpacing, tileSize, initialTileTypeMask, edNewNodesXY[0], edNewNodesXY[1]);
            mn.LinkNodes();
        }
    }
示例#22
0
    private LayerMask _rayMask         = 0;             // used to determine what can be clicked on (Tiles and Units) Inited in Start()

    #endregion
    // ====================================================================================================================
    #region start/init

    public virtual void Start()
    {
        if (map == null)
        {
            Debug.LogWarning("The 'map' property was not set, attempting to find a MapNav in the scene.");
            Object obj = GameObject.FindObjectOfType(typeof(MapNav));
            if (obj != null)
            {
                map = obj as MapNav;
            }

            // I'm not gonan do extra if() tests in the HandleInput.. tell coder now there is problem he should be sorting out asap
            if (map == null)
            {
                Debug.LogError("Could not find a MapNav in the scene. You gonna get NullRef errors soon!");
            }
        }

        _rayMask = (1 << map.tilesLayer | 1 << this.unitsLayer);
    }
示例#23
0
    public virtual void Start()
    {
        if (map == null)
        {
            Debug.LogWarning("The map is not set, attempting to find a MapNav in the scene.");
            Object obj = GameObject.FindObjectOfType(typeof(MapNav));
            //  get the map
            if (obj != null)
            {
                map = obj as MapNav;
            }

            //  fail to get the map
            if (map == null)
            {
                Debug.LogError("Could not find a MapNav in the scene. You gonna get NullRef errors soon!");
            }
        }

        _rayMask = (1 << map.tilesLayer | 1 << map.unitsLayer);
    }
示例#24
0
    //This function is similar to GeoLocation() but is to be used by SetGeoInspector.cs
    public void EditorGeoLocation()
    {
        gps = GameObject.FindGameObjectWithTag("GameController").GetComponent<MapNav>();
        fixLat = gps.fixLat;
        fixLon = gps.fixLon;

        initX = fixLon * 20037508.34f / 18000;
        initZ = (float) (System.Math.Log(System.Math.Tan((90 + fixLat) * System.Math.PI / 360)) / (System.Math.PI / 180));
        initZ = initZ * 20037508.34f / 18000;

        //Translate the geographical coordinate system used by gps mobile devices(WGS84), into Unity's Vector2 Cartesian coordinates(x,z) and set height(1:100 scale).
        transform.position = new Vector3(((lon * 20037508.34f) / 18000) - initX, height / 100, ((Mathf.Log(Mathf.Tan((90 + lat) * Mathf.PI / 360)) / (Mathf.PI / 180)) * 1113.19490777778f) - initZ);
       
        //Set object orientation
        Vector3 tmp = transform.eulerAngles;
        tmp.y = orientation;
        transform.eulerAngles = tmp;
       
        //Set local object scale
        transform.localScale = new Vector3(scaleX, scaleY, scaleZ);
    }
示例#25
0
        private async Task <bool> DockAlignAsync()
        {
            _mapNav = new MapNav(_misty, _skillHelper, HEAD_PITCH_OFFSET, HEAD_ROLL_OFFSET, HEAD_YAW_OFFSET);

            bool gotPose = await _mapNav.StartTrackingAsync(MAP_NAME);

            if (!gotPose)
            {
                _misty.PlayAudio("s_Annoyance.wav", 100, OnResponse);
                await Task.Delay(2000);

                _mapNav.Cleanup();
                return(false);
            }

            await _mapNav.MoveToAsync(MAP_DOCK_X, MAP_DOCK_Y, MAP_DOCK_YAW, 0);

            _mapNav.Cleanup();

            return(true);
        }
示例#26
0
    private void CreateMapNav()
    {
        GameObject go = new GameObject();

        go.name = "MapNav";
        MapNav mn = go.AddComponent <MapNav>();

        mn.tilesLayer  = tileLayer;
        mn.unitsLayer  = unitLayer;
        mn.tilesLayout = (MapNav.TilesLayout)tilesLayout;
        mn.tileSpacing = tileSpacing;
        mn.tileSize    = tileSize;

        //if (edNewNodesXY[0] > 0 && edNewNodesXY[1] > 0)
        //{
        //    GameObject nodeFab = (GameObject)AssetDatabase.LoadAssetAtPath(MapNavEditor.PREFABS_PATH + "tile_nodes/" + (mn.tilesLayout == MapNav.TilesLayout.Hex ? "TIleNode_Hex.prefab" : "TIleNode_Square.prefab"), typeof(GameObject));
        //    MapNav.CreateTileNodes(nodeFab, mn, (MapNav.TilesLayout)tilesLayout, tileSpacing, tileSize, initialTileTypeMask, edNewNodesXY[0], edNewNodesXY[1]);
        //}
        if (edNewNodesXY[0] > 0 && edNewNodesXY[1] > 0 && tileNodeFab != null)
        {
            MapNav.CreateTileNodes(tileNodeFab, mn, (MapNav.TilesLayout)tilesLayout, tileSpacing, tileSize, initialTileTypeMask, edNewNodesXY[0], edNewNodesXY[1]);
            mn.LinkNodes();
        }
    }
示例#27
0
 public TileNode[] GetPathTo(MapNav map, TileNode targetNode)
 {
     return(map.GetPath(node, targetNode, tileLevel));
 }
示例#28
0
    // 移动 断开和当前节点链接->移动->链接至目标节点
    public bool MoveTo(MapNav map, TileNode targetNode, ref int moves)
    {
        if (moves == 0)
        {
            return(false);
        }

        TileNode[] path = map.GetPath(node, targetNode, tileLevel);
        if (path == null)
        {
            return(false);
        }
        if (path.Length == 0)
        {
            return(false);
        }

        int useMoves = path.Length;

        if (moves >= 0)
        {
            if (moves <= useMoves)
            {
                useMoves = moves; moves = 0;
            }
            else
            {
                moves -= useMoves;
            }
        }
        else
        {
            moves = path.Length;
        }

        node.units.Remove(this);
        node = path[useMoves - 1];
        node.units.Add(this);

        isMoving = true;

        System.Collections.Hashtable opt = iTween.Hash(
            "orienttopath", true,
            "easetype", "linear",
            "oncomplete", "_OnCompleteMoveTo",
            "oncompletetarget", gameObject);

        if (!tiltToPath)
        {
            opt.Add("axis", "y");
        }

        if ((adjustNormals || adjustToCollider) && adjustmentLayerMask != 0)
        {
            opt.Add("onupdate", "_OnMoveToUpdate");
            opt.Add("onupdatetarget", gameObject);
        }

        if (path.Length > 1)
        {
            Vector3[] points = new Vector3[useMoves];
            for (int i = 0; i < useMoves; i++)
            {
                points[i] = path[i].transform.position;
            }
            endPointToReach = points[points.Length - 1];
            opt.Add("path", points);
            opt.Add("speed", ((move_speedMulti * useMoves) + 1f) * move_speed);
            iTween.MoveTo(gameObject, opt);
        }
        else
        {
            endPointToReach = path[0].transform.position;
            opt.Add("position", endPointToReach);
            opt.Add("speed", move_speed);
            iTween.MoveTo(gameObject, opt);
        }
        return(true);
    }
示例#29
0
		public PathNode(int _index, int _parentIndex, float _g, float _h, MapNav mapNav)
		{
			index = _index;
			parentIndex = _parentIndex;
			g = _g;
			h = _h;
			f = g + h;

			grid = new MapGrid(){x = index % mapNav.gridXNum, z = index / mapNav.gridXNum};
			position = mapNav.GetWorldPosition(grid);
		}
示例#30
0
	public static void CreateMarker(GameObject markerFab, MapNav.TilesLayout markerLayout, float markerSpacing, float markerSize, int markerRadius, bool adaptToTileHeight, int tileMask)
	{
		if (markerFab == null) return;
		if (markerRadius < 1) markerRadius = 1;
		GameObject go = new GameObject();
		go.name = "Marker";
		RadiusMarker marker = go.AddComponent<RadiusMarker>();
		marker.prefab = markerFab;
		marker.markerLayout = markerLayout;
		marker.markerSpacing = markerSpacing;
		marker.markerSize = markerSize;
		marker.markerRadius = markerRadius;
		marker.adaptToTileHeight = adaptToTileHeight;
		marker.tilesMask = tileMask;
		CreateMarkerNodes(markerFab, marker, markerLayout, markerSpacing, markerSize, markerRadius);
	}
示例#31
0
    public static void CreateTileNodes(GameObject nodeFab, MapNav map, MapNav.TilesLayout layout, float tileSpacing, float tileSize, TileNode.TileType initialMask, int xCount, int yCount)
    {
        if (xCount <= 0 || yCount <= 0)
        {
            return;
        }

        map.tilesLayout = layout;
        map.tileSpacing = tileSpacing;
        map.tileSize    = tileSize;

        // 删除旧的节点
        List <GameObject> remove = new List <GameObject>();

        foreach (Transform t in map.transform)
        {
            if (t.name.Contains("node"))
            {
                remove.Add(t.gameObject);                                      // 确保创建的是节点
            }
        }
        remove.ForEach(go => DestroyImmediate(go));

        // 创建地图

        map.nodesXCount = xCount;
        map.nodesYCount = yCount;
        map.nodesCache  = new GameObject[map.nodesXCount * map.nodesYCount];

        int   count  = 0;
        bool  atoffs = false;
        float offs   = 0f;
        float xOffs  = map.tileSpacing;
        float yOffs  = map.tileSpacing;

        if (map.tilesLayout == MapNav.TilesLayout.Hex)
        {   // 计算地板的偏移量
            xOffs = Mathf.Sqrt(3f) * map.tileSpacing * 0.5f;
            offs  = xOffs * 0.5f;
            yOffs = yOffs * 0.75f;
        }

        for (int y = 0; y < yCount; y++)
        {
            for (int x = 0; x < xCount; x++)
            {
                // 创建节点
                GameObject go = (GameObject)GameObject.Instantiate(nodeFab);
                go.name  = "node" + count.ToString();
                go.layer = map.tilesLayer;

                // 定位节点并使节点在MapNav下
                go.transform.parent        = map.transform;
                go.transform.localPosition = new Vector3(x * xOffs + (atoffs ? offs : 0f), 0f, y * yOffs);
                go.transform.localScale    = new Vector3(map.tileSize, map.tileSize, map.tileSize);

                //更新TileNode组件
                TileNode n = go.GetComponent <TileNode>();
                n.idx          = count;
                n.parent       = map;
                n.tileTypeMask = initialMask;

                // 关掉Unity碰撞检测机
                go.GetComponent <Collider>().enabled = false;

                //缓存节点
                map.nodesCache[count] = go;
                count++;
            }
            atoffs = !atoffs;
        }
    }
示例#32
0
    // ====================================================================================================================
    #region create / setup tools

    /// <summary>
    /// Creates a new grid of tile nodes of x by y count
    /// </summary>
    public static void CreateTileNodes(GameObject nodeFab, MapNav map, MapNav.TilesLayout layout, float tileSpacing, float tileSize, TileNode.TileType initialMask, int xCount, int yCount)
    {
        if (xCount <= 0 || yCount <= 0)
        {
            return;
        }

        map.tilesLayout = layout;
        map.tileSpacing = tileSpacing;
        map.tileSize    = tileSize;

        // first delete the old nodes
        List <GameObject> remove = new List <GameObject>();

        foreach (Transform t in map.transform)
        {               // just make sure it is a node in case there are other kinds of objects under MapNav object
            if (t.name.Contains("node"))
            {
                remove.Add(t.gameObject);
            }
        }
        remove.ForEach(go => DestroyImmediate(go));

        // now create new nodes

        map.nodesXCount = xCount;
        map.nodesYCount = yCount;
        map.nodesCache  = new GameObject[map.nodesXCount * map.nodesYCount];

        int   count  = 0;
        bool  atoffs = false;
        float offs   = 0f;
        float xOffs  = map.tileSpacing;
        float yOffs  = map.tileSpacing;

        if (map.tilesLayout == MapNav.TilesLayout.Hex)
        {               // calculate offset to correctly plate hextiles
            xOffs = Mathf.Sqrt(3f) * map.tileSpacing * 0.5f;
            offs  = xOffs * 0.5f;
            yOffs = yOffs * 0.75f;
        }

        for (int y = 0; y < yCount; y++)
        {
            for (int x = 0; x < xCount; x++)
            {
                // create the node
                GameObject go = (GameObject)GameObject.Instantiate(nodeFab);
                go.name  = "node" + count.ToString();
                go.layer = map.tilesLayer;

                // parent under MapNav and position the node
                go.transform.parent        = map.transform;
                go.transform.localPosition = new Vector3(x * xOffs + (atoffs ? offs : 0f), 0f, y * yOffs);
                go.transform.localScale    = new Vector3(map.tileSize, map.tileSize, map.tileSize);

                // update TileNode component
                TileNode n = go.GetComponent <TileNode>();
                n.idx          = count;
                n.mapnav       = map;
                n.tileTypeMask = initialMask;

                // turn off the collider, don't need it now
                go.GetComponent <Collider>().enabled = false;

                // cache the node
                map.nodesCache[count] = go;
                count++;
            }
            atoffs = !atoffs;
        }
    }
示例#33
0
	// ====================================================================================================================
	#region create / setup tools

	/// <summary>
	/// Creates a new grid of tile nodes of x by y count
	/// </summary>
	public static void CreateTileNodes(GameObject nodeFab, MapNav map, MapNav.TilesLayout layout, float tileSpacing, float tileSize, TileNode.TileType initialMask, int xCount, int yCount)
	{
		if (xCount <= 0 || yCount <= 0) return;

		map.tilesLayout = layout;
		map.tileSpacing = tileSpacing;
		map.tileSize = tileSize;

		// first delete the old nodes
		List<GameObject> remove = new List<GameObject>();
		foreach (Transform t in map.transform)
		{	// just make sure it is a node in case there are other kinds of objects under MapNav object
			if (t.name.Contains("node")) remove.Add(t.gameObject);
		}
		remove.ForEach(go => DestroyImmediate(go));

		// now create new nodes

		map.nodesXCount = xCount;
		map.nodesYCount = yCount;
		map.nodesCache = new GameObject[map.nodesXCount * map.nodesYCount];

		int count = 0;
		bool atoffs = false;
		float offs = 0f;
		float xOffs = map.tileSpacing;
		float yOffs = map.tileSpacing;

		if (map.tilesLayout == MapNav.TilesLayout.Hex)
		{	// calculate offset to correctly plate hextiles
			xOffs = Mathf.Sqrt(3f) * map.tileSpacing * 0.5f;
			offs = xOffs * 0.5f;
			yOffs = yOffs * 0.75f;
		}

		for (int y = 0; y < yCount; y++)
		{
			for (int x = 0; x < xCount; x++)
			{
				// create the node
				GameObject go = (GameObject)GameObject.Instantiate(nodeFab);
				go.name = "node" + count.ToString();
				go.layer = map.tilesLayer;

				// parent under MapNav and position the node
				go.transform.parent = map.transform;
				go.transform.localPosition = new Vector3(x * xOffs + (atoffs ? offs : 0f), 0f, y * yOffs);
				go.transform.localScale = new Vector3(map.tileSize, map.tileSize, map.tileSize);

				// update TileNode component
				TileNode n = go.GetComponent<TileNode>();
				n.idx = count;
				n.mapnav = map;
				n.tileTypeMask = initialMask;

				// turn off the collider, don't need it now
				go.collider.enabled = false;

				// cache the node
				map.nodesCache[count] = go;
				count++;
			}
			atoffs = !atoffs;
		}
	}
示例#34
0
 void Awake()
 {
     //Reference to the MapNav.js script and gpsFix variable. gpsFix will be true when a valid location data has been set.
     gps = GameObject.FindGameObjectWithTag("GameController").GetComponent<MapNav>();
     gpsFix = gps.gpsFix;
 }
示例#35
0
	void OnMapChanged(MapNav map)
	{
		uiMapTexture.mainTexture = map.transform.parent.GetComponentInChildren<MapTexture>().texture;
		uiMapTexture.gameObject.SetActive(uiMapTexture.mainTexture != null);

		mapSize = new Vector2(MapGrid.Width * map.gridXNum, MapGrid.Height * map.gridZNum);
		Extent = Mathf.Min(Extent, uiMapTexture.mainTexture.width, uiMapTexture.mainTexture.height);
		relativeExtent = new Vector2(Extent / (float)uiMapTexture.mainTexture.width, Extent / (float)uiMapTexture.mainTexture.height);

		Layout = true;
	}
示例#36
0
    public void OnSceneGUI()
    {
        MapNav mapNav = Target;
        float  y      = 0.1f;

        if (curProcessType == ProcessType.None)
        {
            return;
        }

        if (curProcessType == ProcessType.Set || curProcessType == ProcessType.Clear)
        {
            Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
            float rayDistance;
            Ray   ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            if (groundPlane.Raycast(ray, out rayDistance))
            {
                Vector3 hitPoint = ray.GetPoint(rayDistance);
                if (hitPoint.x >= 0.0f && hitPoint.x <= mapNav.gridXNum * MapGrid.Width &&
                    hitPoint.z >= 0.0f && hitPoint.z <= mapNav.gridZNum * MapGrid.Height)
                {
                    Handles.color = Color.black;
                    float _radius = radius * 0.5f;
                    Handles.DrawPolyLine(new Vector3[]
                    {
                        new Vector3(hitPoint.x - _radius * MapGrid.Width, y, hitPoint.z - _radius * MapGrid.Height),
                        new Vector3(hitPoint.x - _radius * MapGrid.Width, y, hitPoint.z + _radius * MapGrid.Height),
                        new Vector3(hitPoint.x + _radius * MapGrid.Width, y, hitPoint.z + _radius * MapGrid.Height),
                        new Vector3(hitPoint.x + _radius * MapGrid.Width, y, hitPoint.z - _radius * MapGrid.Height),
                        new Vector3(hitPoint.x - _radius * MapGrid.Width, y, hitPoint.z - _radius * MapGrid.Height)
                    });

                    if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag)
                    {
                        var grid = new MapGrid(hitPoint);
                        for (int _z = grid.z - Mathf.RoundToInt(_radius); _z <= grid.z + Mathf.RoundToInt(_radius); ++_z)
                        {
                            if (_z < 0)
                            {
                                continue;
                            }
                            if (_z > mapNav.gridZNum - 1)
                            {
                                continue;
                            }
                            for (int _x = grid.x - Mathf.RoundToInt(_radius); _x <= grid.x + Mathf.RoundToInt(_radius); ++_x)
                            {
                                if (_x < 0)
                                {
                                    continue;
                                }
                                if (_x > mapNav.gridXNum - 1)
                                {
                                    continue;
                                }

                                Vector3 position = mapNav.GetWorldPosition(new MapGrid()
                                {
                                    x = _x, z = _z
                                });
                                if (Mathf.Abs(position.x - hitPoint.x) <= _radius * MapGrid.Width &&
                                    Mathf.Abs(position.z - hitPoint.z) <= _radius * MapGrid.Height)
                                {
                                    switch (curProcessType)
                                    {
                                    case ProcessType.Set:
                                        mapNav[_x, _z] |= curTileType;
                                        break;

                                    case ProcessType.Clear:
                                        mapNav[_x, _z] &= ~curTileType;
                                        break;

                                    default:
                                        throw new System.NotImplementedException();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        else if (curProcessType == ProcessType.FindPath)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
                float rayDistance;
                Ray   ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                if (groundPlane.Raycast(ray, out rayDistance))
                {
                    Vector3 hitPoint = ray.GetPoint(rayDistance);
                    if (hitPoint.x >= 0.0f && hitPoint.x <= mapNav.gridXNum * MapGrid.Width &&
                        hitPoint.z >= 0.0f && hitPoint.z <= mapNav.gridZNum * MapGrid.Height)
                    {
                        if (bSampleStart)
                        {
                            vecStart = hitPoint;
                        }
                        else
                        {
                            vecEnd = hitPoint;
                        }
                        bSampleStart = !bSampleStart;

                        MapGrid gridEnd;
                        if (mapNav.GetNearestValidGrid(new MapGrid(vecStart), new MapGrid(vecEnd), out gridEnd, TileType.TileType_Walk))
                        {
                            path = mapNav.GetPath(new MapGrid(vecStart), gridEnd, TileType.TileType_Walk);
                        }
                        else
                        {
                            path.Clear();
                        }
                    }
                }
            }

            Handles.color = Color.red;
            Handles.CubeCap(0, vecStart, new Quaternion(0, 0, 0, 1), 0.1f);

            Handles.color = Color.blue;
            Handles.CubeCap(0, vecEnd, new Quaternion(0, 0, 0, 1), 0.1f);

            if (path.Count > 0)
            {
                Handles.color = Color.black;
                Vector3 lastPoint = vecStart;
                lastPoint.y = y;
                foreach (MapGrid grid in path)
                {
                    Vector3 curPoint = mapNav.GetWorldPosition(grid);
                    curPoint.y    = y;
                    Handles.color = Color.black;
                    Handles.DrawLine(lastPoint, curPoint);
                    lastPoint = curPoint;

                    Handles.color = Color.cyan;
                    Handles.CubeCap(0, curPoint, new Quaternion(0, 0, 0, 1), 0.1f);
                }
            }
        }

        HandleUtility.Repaint();
        switch (Event.current.type)
        {
        case EventType.MouseUp:
        case EventType.MouseDown:
        case EventType.MouseDrag:
        case EventType.MouseMove:
            Event.current.Use();
            break;
        }
    }
示例#37
0
	// ====================================================================================================================
	#region create tools

	public static void UpdateMarker(GameObject markerFab, RadiusMarker marker, MapNav.TilesLayout markerLayout, float markerSpacing, float markerSize, int markerRadius, bool adaptToTileHeight, int tileMask)
	{
		// delete old marker nodes
		List<GameObject> remove = new List<GameObject>();
		foreach (Transform t in marker.transform) remove.Add(t.gameObject);
		remove.ForEach(go => DestroyImmediate(go));

		if (markerFab == null) return;
		if (markerRadius < 1) markerRadius = 1;
		marker.prefab = markerFab;
		marker.markerLayout = markerLayout;
		marker.markerSpacing = markerSpacing;
		marker.markerSize = markerSize;
		marker.markerRadius = markerRadius;
		marker.adaptToTileHeight = adaptToTileHeight;
		marker.tilesMask = tileMask;

		// and create new ones
		CreateMarkerNodes(markerFab, marker, markerLayout, markerSpacing, markerSize, markerRadius);
	}
示例#38
0
	private static void CreateHexNodes(GameObject markerFab, RadiusMarker marker, MapNav.TilesLayout markerLayout, float markerSpacing, float markerSize, int markerRadius)
	{
		GameObject go;
		marker.markerNodes = new GameObject[markerRadius];

		float xOffs = markerSpacing * 0.50f * Mathf.Sqrt(3f);
		float yOffs = markerSpacing * 0.75f;
		float offs = xOffs * 0.5f;

		for (int i = 0; i < markerRadius; i++)
		{
			GameObject parent = new GameObject();
			parent.name = (i < 10 ? "0" : "") + i.ToString();
			parent.transform.position = marker.transform.position + new Vector3(0f, 0.1f, 0f);
			parent.transform.parent = marker.transform;
			marker.markerNodes[i] = parent;

			// right
			go = (GameObject)GameObject.Instantiate(markerFab);
			go.transform.parent = parent.transform;
			go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
			go.transform.localPosition = new Vector3(xOffs * (i + 1), 0f, 0f);
			for (int j = 0; j < i + 1; j++)
			{
				// up
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3((xOffs * (i + 1)) - (offs * (j + 1)), 0f, yOffs * (j + 1));
				// down
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3((xOffs * (i + 1)) - (offs * (j + 1)), 0f, -yOffs * (j + 1));
			}

			// left
			go = (GameObject)GameObject.Instantiate(markerFab);
			go.transform.parent = parent.transform;
			go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
			go.transform.localPosition = new Vector3(-xOffs * (i + 1), 0f, 0f);
			for (int j = 0; j < i + 1; j++)
			{
				// up
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3((-xOffs * (i + 1)) + (offs * (j + 1)), 0f, yOffs * (j + 1));
				// down
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3((-xOffs * (i + 1)) + (offs * (j + 1)), 0f, -yOffs * (j + 1));
			}

			// up
			for (int j = 0; j < i; j++)
			{
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3((xOffs * j) - (offs * (i - 1)), 0f, yOffs * (i + 1));
			}

			// down
			for (int j = 0; j < i; j++)
			{
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3((xOffs * j) - (offs * (i - 1)), 0f, -yOffs * (i + 1));
			}
		}
	}
示例#39
0
	private static void CreateMarkerNodes(GameObject markerFab, RadiusMarker marker, MapNav.TilesLayout markerLayout, float markerSpacing, float markerSize, int markerRadius)
	{
		if (markerLayout == MapNav.TilesLayout.Hex) CreateHexNodes(markerFab, marker, markerLayout, markerSpacing, markerSize, markerRadius);
		else if (markerLayout == MapNav.TilesLayout.Square_4) CreateSquar4Nodes(markerFab, marker, markerLayout, markerSpacing, markerSize, markerRadius);
		else if (markerLayout == MapNav.TilesLayout.Square_8) CreateSquar8Nodes(markerFab, marker, markerLayout, markerSpacing, markerSize, markerRadius);
	}
示例#40
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        // gizmo related and info fields
        TMNEditorUtil.DrawSpacer();
        folds[4] = EditorGUILayout.Foldout(folds[4], folds[4] ? "" : "Gizmos");
        if (folds[4])
        {
            GUILayout.Label("Gizmos", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(gizmoDrawNodes);
            EditorGUILayout.PropertyField(gizmoDrawLinks);
            EditorGUILayout.PropertyField(gizmoColorCoding);
        }

        // info
        TMNEditorUtil.DrawSpacer();
        folds[5] = EditorGUILayout.Foldout(folds[5], folds[5] ? "" : "Basic Settings & Info");
        if (folds[5])
        {
            GUILayout.Label("Info", EditorStyles.boldLabel);
            EditorGUILayout.LabelField("MapNav Size: ", nodesCache.arraySize.ToString() + " (" + ((MapNav)target).nodesXCount + "x" + ((MapNav)target).nodesYCount + ")");
            EditorGUILayout.LabelField("Tiles Layout: ", ((MapNav.TilesLayout)tilesLayout.enumValueIndex).ToString());
            EditorGUILayout.LabelField("Tile Spacing: ", tileSpacing.floatValue.ToString());
            EditorGUILayout.LabelField("Tile Size: ", tileSize.floatValue.ToString());

            // basic fields
            EditorGUILayout.Space();
            GUILayout.Label("Basic Settings", EditorStyles.boldLabel);
            tilesLayer.intValue = EditorGUILayout.LayerField("Tiles Layer", tilesLayer.intValue);
            unitsLayer.intValue = EditorGUILayout.LayerField("Units Layer", unitsLayer.intValue);
        }

        // ...
        serializedObject.ApplyModifiedProperties();

        TMNEditorUtil.DrawSpacer();

        // fields to create new tile grid
        folds[0] = TMNEditorUtil.BeginToggleGroup("TileNodes Create Tool", folds[0]);
        if (folds[0])
        {
            GUILayout.Label("Note that this will delete current nodes", EditorStyles.label);
            EditorGUILayout.Space();
            new_TileNodeFab     = (GameObject)EditorGUILayout.ObjectField("TileNode Prefab", new_TileNodeFab, typeof(GameObject), false);
            new_tilesLayout     = EditorGUILayout.Popup("Tiles Layout", new_tilesLayout, MapNavEditor.TilesLayoutStrings);
            new_tileSpacing     = EditorGUILayout.FloatField("Tile Spacing", new_tileSpacing);
            new_tileSize        = EditorGUILayout.FloatField("Tile Size", new_tileSize);
            initialTileTypeMask = (TileNode.TileType)EditorGUILayout.EnumMaskField("Initial Tile Mask", initialTileTypeMask);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Width x Length: ", EditorStyles.label);
            edNewNodesXY[0] = EditorGUILayout.IntField(edNewNodesXY[0]);
            edNewNodesXY[1] = EditorGUILayout.IntField(edNewNodesXY[1]);
            EditorGUILayout.EndHorizontal();
            if (GUILayout.Button("Create"))
            {
                tilesLayout.intValue   = new_tilesLayout;
                tileSpacing.floatValue = new_tileSpacing;
                tileSize.floatValue    = new_tileSize;

                if (edNewNodesXY[0] <= 0)
                {
                    edNewNodesXY[0] = 1;
                }
                if (edNewNodesXY[1] <= 0)
                {
                    edNewNodesXY[1] = 1;
                }

                //GameObject nodeFab = (GameObject)AssetDatabase.LoadAssetAtPath(MapNavEditor.PREFABS_PATH + "tile_nodes/" + ((MapNav.TilesLayout)new_tilesLayout == MapNav.TilesLayout.Hex ? "TIleNode_Hex.prefab" : "TIleNode_Square.prefab"), typeof(GameObject));
                //MapNav.CreateTileNodes(nodeFab, ((MapNav)target), (MapNav.TilesLayout)new_tilesLayout, new_tileSpacing, new_tileSize, initialTileTypeMask, edNewNodesXY[0], edNewNodesXY[1]);
                if (new_TileNodeFab != null)
                {
                    MapNav.CreateTileNodes(new_TileNodeFab, ((MapNav)target), (MapNav.TilesLayout)new_tilesLayout, new_tileSpacing, new_tileSize, initialTileTypeMask, edNewNodesXY[0], edNewNodesXY[1]);
                    ((MapNav)target).LinkNodes();
                }
            }
        }
        EditorGUILayout.EndToggleGroup();

        // various tools
        if (((MapNav)target).nodesCache != null)
        {
            // hide show node markers
            folds[1] = TMNEditorUtil.BeginToggleGroup("TileNodes Marker Visibility", folds[1]);
            if (folds[1])
            {
                GUILayout.Space(10f);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Show"))
                {
                    ((MapNav)target).ShowTileNodeMarkers(true);
                    EditorUtility.SetDirty(target);
                }
                if (GUILayout.Button("Hide"))
                {
                    ((MapNav)target).ShowTileNodeMarkers(false);
                    EditorUtility.SetDirty(target);
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndToggleGroup();

            // automated setup of nodes' masks
            folds[2] = TMNEditorUtil.BeginToggleGroup("TileNodes Auto Mask-Setup Tool", folds[2]);
            if (folds[2])
            {
                GUILayout.Space(10f);
                maskAutomation_ParentObject = (Transform)EditorGUILayout.ObjectField("Use Parent Object", maskAutomation_ParentObject, typeof(Transform), true);
                if (maskAutomation_ParentObject != null)
                {
                    maskAutomation_ColliderMask = 0;
                }
                maskAutomation_ColliderMask = EditorGUILayout.LayerField("or use Colliders Layer", maskAutomation_ColliderMask);
                if (maskAutomation_ColliderMask != 0)
                {
                    maskAutomation_ParentObject = null;
                }
                GUILayout.Space(10f);
                maskAutomation_AddMask = (TileNode.TileType)EditorGUILayout.EnumMaskField("New TileNode Mask", maskAutomation_AddMask);
                GUILayout.Space(10f);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Set"))
                {
                    if (maskAutomation_ParentObject != null)
                    {
                        ((MapNav)target).SetTileNodeMasks(maskAutomation_AddMask, maskAutomation_ParentObject);
                    }
                    else
                    {
                        ((MapNav)target).SetTileNodeMasks(maskAutomation_AddMask, maskAutomation_ColliderMask);
                    }
                    EditorUtility.SetDirty(target);
                }
                if (GUILayout.Button("Add"))
                {
                    if (maskAutomation_ParentObject != null)
                    {
                        ((MapNav)target).AddToTileNodeMasks(maskAutomation_AddMask, maskAutomation_ParentObject);
                    }
                    else
                    {
                        ((MapNav)target).AddToTileNodeMasks(maskAutomation_AddMask, maskAutomation_ColliderMask);
                    }
                    EditorUtility.SetDirty(target);
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.HelpBox("This tool helps automate the TileNode Mask setup process.\n\nExample, if you wanted to set nodes under tree meshes to be of Wall type, then you would set 'Parent Object' to the container of the trees and select from 'TileNode Mask' the Wall type (if you defined such in TileNode.TileType) and hit Add/Set.\n\nThe tool will go through all child transforms of the Parent Object and check which nodes are under them and update their tile-type masks.\n\nNote that 'Add' will add the mask to a node's current mask while 'Set' will reset the node mask to the given mask.\n\nYou also have the option to rather check against colliders of objects in your scene. This is useful where an object like a wall might span more than one tile and you want those tiles all to be set to tile type, wall. In this case you want to set 'Colliders Layer' to the layer of the objects to test against and make sure they have colliders since this will use ray casting. Make sure 'Parent Object' is not set in this case else this option will be ignored and Parent Object will be used.", MessageType.None);
            }
            EditorGUILayout.EndToggleGroup();

            // resetting nodes' masks
            folds[3] = TMNEditorUtil.BeginToggleGroup("TileNodes Mask Reset Tool", folds[3]);
            if (folds[3])
            {
                GUILayout.Space(10f);
                maskAutomation_ResetMask = (TileNode.TileType)EditorGUILayout.EnumMaskField("Set all to", maskAutomation_ResetMask);
                if (GUILayout.Button("Reset"))
                {
                    ((MapNav)target).SetAllNodeMasksTo(maskAutomation_ResetMask);
                    EditorUtility.SetDirty(target);
                }
            }
            EditorGUILayout.EndToggleGroup();

            // calc node heights
            folds[6] = TMNEditorUtil.BeginToggleGroup("TileNodes Auto Height-Setup Tool ", folds[6]);
            if (folds[6])
            {
                GUILayout.Space(10f);
                heightAutomation_Mask     = EditorGUILayout.LayerField("Colliders Layer", heightAutomation_Mask);
                heightAutomation_DelNodes = EditorGUILayout.Toggle("Node Deletion Active", heightAutomation_DelNodes);
                if (GUILayout.Button("Run Setup"))
                {
                    ((MapNav)target).SetupNodeHeights(heightAutomation_Mask, heightAutomation_DelNodes);
                    EditorUtility.SetDirty(target);
                }
                EditorGUILayout.HelpBox("This tool helps automate the TileNodes height setup. Set the 'Layer' field to the layer used by objects that will determine what height the nodes must be placed at. It is important that the object (for example a variable height terrain) use the same layer and has a collider since this tool will use raycasts the determine at what height to place nodes.\n\nIf Node Deletion is Active, then nodes that did not find anything to adjust their heights against will be unlinked and deleted. This is usefull if you have a non-square terrain area with some overlapping nodes that won't be used and must be deleted.", MessageType.None);
            }
            EditorGUILayout.EndToggleGroup();
        }
    }
示例#41
0
	private static void CreateSquar8Nodes(GameObject markerFab, RadiusMarker marker, MapNav.TilesLayout markerLayout, float markerSpacing, float markerSize, int markerRadius)
	{
		GameObject go;

		marker.markerNodes = new GameObject[markerRadius];

		for (int i = 0; i < markerRadius; i++)
		{
			GameObject parent = new GameObject();
			parent.name = (i < 10 ? "0" : "") + i.ToString();
			parent.transform.position = marker.transform.position + new Vector3(0f, 0.1f, 0f);
			parent.transform.parent = marker.transform;
			marker.markerNodes[i] = parent;

			// up
			go = (GameObject)GameObject.Instantiate(markerFab);
			go.transform.parent = parent.transform;
			go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
			go.transform.localPosition = new Vector3(0f, 0f, markerSpacing * (i + 1));
			for (int j = 0; j < i + 1; j++)
			{	// to right
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3(markerSpacing * (j + 1), 0f, markerSpacing * (i + 1));
				// to left
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3(-markerSpacing * (j + 1), 0f, markerSpacing * (i + 1));
			}

			// down
			go = (GameObject)GameObject.Instantiate(markerFab);
			go.transform.parent = parent.transform;
			go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
			go.transform.localPosition = new Vector3(0f, 0f, -markerSpacing * (i + 1));
			for (int j = 0; j < i + 1; j++)
			{	// to right
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3(markerSpacing * (j + 1), 0f, -markerSpacing * (i + 1));
				// to left
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3(-markerSpacing * (j + 1), 0f, -markerSpacing * (i + 1));
			}

			// right
			go = (GameObject)GameObject.Instantiate(markerFab);
			go.transform.parent = parent.transform;
			go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
			go.transform.localPosition = new Vector3(+markerSpacing * (i + 1), 0f, 0f);
			for (int j = 0; j < i; j++)
			{	// up
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3(markerSpacing * (i + 1), 0f, markerSpacing * (j + 1));
				// down
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3(markerSpacing * (i + 1), 0f, -markerSpacing * (j + 1));
			}

			// left
			go = (GameObject)GameObject.Instantiate(markerFab);
			go.transform.parent = parent.transform;
			go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
			go.transform.localPosition = new Vector3(-markerSpacing * (i + 1), 0f, 0f);
			for (int j = 0; j < i; j++)
			{	// up
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3(-markerSpacing * (i + 1), 0f, markerSpacing * (j + 1));
				// down
				go = (GameObject)GameObject.Instantiate(markerFab);
				go.transform.parent = parent.transform;
				go.transform.localScale = new Vector3(markerSize, markerSize, markerSize);
				go.transform.localPosition = new Vector3(-markerSpacing * (i + 1), 0f, -markerSpacing * (j + 1));
			}
		}
	}
示例#42
0
    /// <summary>
    /// Move the unit to the specified target node. Will make a callback with
    /// eventCode=1 when done moving if a callback was set in Init()
    /// iTween (free on Unity Asset Store) is used to move the Unit
    /// </summary>
    /// <param name="map">NavMap to use</param>
    /// <param name="targetNode">Node to reach</param>
    /// <param name="moves">
    /// Number of moves that can be use to reach target. Pass (-1) to ignore this.
    /// The unit will move as close as possible if not enough moves given.
    /// Moves will be set to moves - actual_moves_use; or if -1 passed, it will be set to number of moves that was taken.
    /// </param>
    /// <returns>True is the unit started moving towards the target</returns>
    public bool MoveTo(MapNav map, TileNode targetNode, ref int moves)
    {
        if (moves == 0)
        {
            return(false);
        }

        TileNode[] path = map.GetPath(this.node, targetNode, this.tileLevel);
        if (path == null)
        {
            return(false);
        }
        if (path.Length == 0)
        {
            return(false);
        }

        // check if enough moves to reach destination
        int useMoves = path.Length;

        if (moves >= 0)
        {
            if (moves <= useMoves)
            {
                useMoves = moves; moves = 0;
            }
            else
            {
                moves -= useMoves;
            }
        }
        else
        {
            moves = path.Length;
        }

        // unlink with current node and link with destination node
        this.node.units.Remove(this);
        this.node = path[useMoves - 1];
        this.node.units.Add(this);

        isMoving = true;

        // *** start jumping from tile to tile
        if (jumpMovement)
        {
            _jump_points   = new Vector3[useMoves];
            _jump_pointIdx = 0;
            for (int i = 0; i < useMoves; i++)
            {
                _jump_points[i] = path[i].transform.position;
            }
            _JumpToNextPoint();
        }

        // *** start normal movement from tile to tile
        else
        {
            System.Collections.Hashtable opt = iTween.Hash(
                "orienttopath", true,
                "easetype", "linear",
                "oncomplete", "_OnCompleteMoveTo",
                "oncompletetarget", gameObject);

            if (!tiltToPath)
            {
                opt.Add("axis", "y");
            }

            if ((adjustNormals || adjustToCollider) && adjustmentLayerMask != 0)
            {
                opt.Add("onupdate", "_OnMoveToUpdate");
                opt.Add("onupdatetarget", gameObject);
            }

            if (path.Length > 1)
            {
                Vector3[] points = new Vector3[useMoves];
                for (int i = 0; i < useMoves; i++)
                {
                    points[i] = path[i].transform.position;
                }
                endPointToReach = points[points.Length - 1];
                opt.Add("path", points);
                opt.Add("speed", ((moveSpeedMulti * useMoves) + 1f) * moveSpeed);
                iTween.MoveTo(this.gameObject, opt);
            }
            else
            {
                endPointToReach = path[0].transform.position;
                opt.Add("position", endPointToReach);
                opt.Add("speed", moveSpeed);
                iTween.MoveTo(this.gameObject, opt);
            }
        }

        return(true);
    }