Example #1
0
    public static void UpdateMarker(GameObject markerFab, RadiusMarker marker, MapNav.TilesLayout markerLayout, float markerSpacing, float markerSize, int markerRadius)
    {
        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;
        CreateMarkerNodes(markerFab, marker, markerLayout, markerSpacing, markerSize, markerRadius);
    }
Example #2
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);
    }
Example #3
0
    void OnEnable()
    {
        RadiusMarker marker = (target as RadiusMarker);

        markerLayout  = marker.markerLayout;
        markerSpacing = marker.markerSpacing;
        markerSize    = marker.markerSize;
        markerRadius  = marker.markerRadius;
        markerFab     = marker.prefab;
    }
	void OnEnable()
	{
		RadiusMarker marker = (target as RadiusMarker);
		markerLayout = marker.markerLayout;
		markerSpacing = marker.markerSpacing;
		markerSize = marker.markerSize;
		markerRadius = marker.markerRadius;
		markerFab = marker.prefab;
		adaptToTileHeight = marker.adaptToTileHeight;
		tilesMask = marker.tilesMask;
	}
    void OnEnable()
    {
        RadiusMarker marker = (target as RadiusMarker);

        markerLayout      = marker.markerLayout;
        markerSpacing     = marker.markerSpacing;
        markerSize        = marker.markerSize;
        markerRadius      = marker.markerRadius;
        markerFab         = marker.prefab;
        adaptToTileHeight = marker.adaptToTileHeight;
        tilesMask         = marker.tilesMask;
    }
Example #6
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);
     }
 }
Example #7
0
    public static void CreateMarker(GameObject markerFab, MapNav.TilesLayout markerLayout, float markerSpacing, float markerSize, int markerRadius)
    {
        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;
        CreateMarkerNodes(markerFab, marker, markerLayout, markerSpacing, markerSize, markerRadius);
    }
	public override void OnInspectorGUI()
	{
		EditorGUILayout.Space();
		markerFab = (GameObject)EditorGUILayout.ObjectField("Marker Node Prefab", markerFab, typeof(GameObject), false);
		markerLayout = (MapNav.TilesLayout)EditorGUILayout.EnumPopup("Marker Layout", markerLayout);
		markerSpacing = EditorGUILayout.FloatField("Marker Node Spacing", markerSpacing);
		markerSize = EditorGUILayout.FloatField("Marker Node Size", markerSize);
		adaptToTileHeight = EditorGUILayout.Toggle("Adapt to Tile Height", adaptToTileHeight);
		GUI.enabled = adaptToTileHeight;
		tilesMask = EditorGUILayout.LayerField("Tiles Layer", tilesMask);
		GUI.enabled = true;
		EditorGUILayout.BeginHorizontal();
			markerRadius = EditorGUILayout.IntField("Marker Radius", markerRadius);
			if (GUILayout.Button("-")) { markerRadius--; RadiusMarker.UpdateMarker(markerFab, (RadiusMarker)target, markerLayout, markerSpacing, markerSize, markerRadius, adaptToTileHeight, tilesMask); }
			if (GUILayout.Button("+")) { markerRadius++; RadiusMarker.UpdateMarker(markerFab, (RadiusMarker)target, markerLayout, markerSpacing, markerSize, markerRadius, adaptToTileHeight, tilesMask); }
		EditorGUILayout.EndHorizontal();

		//  update the marker with new values
		EditorGUILayout.Space();
		if (GUILayout.Button("Update"))
		{
			RadiusMarker.UpdateMarker(markerFab, (RadiusMarker)target, markerLayout, markerSpacing, markerSize, markerRadius, adaptToTileHeight, tilesMask);
		}
	}
Example #9
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;
        }
    }
Example #10
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;
        }
    }
Example #11
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));
            }
        }
    }
Example #12
0
 private static void CreateHexNodes(GameObject markerFab, RadiusMarker marker, MapNav.TilesLayout markerLayout, float markerSpacing, float markerSize, int markerRadius)
 {
     // ÔÝδʵÏÖ
 }
Example #13
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));
            }
        }
    }