Ejemplo n.º 1
0
    /// <summary>
    /// Set the link withNode on or off. Returns false if operation could not be completed,
    /// for example withNode was not a neighbour of this node
    /// </summary>
    public bool SetLinkState(TileNode withNode, bool on)
    {
        if (!IsDirectNeighbour(withNode))
        {
            return(false);
        }

        bool needToAdd = false;

        if (linkOnOffSwitch != null)
        {
            linkOnOffSwitch.SetLinkStateWith(withNode, on);
            needToAdd = false;
        }

        // check if neighbour might carry a link back to this node, and update
        if (withNode.linkOnOffSwitch != null)
        {
            withNode.linkOnOffSwitch.SetLinkStateWith(this, on);
            needToAdd = false;
        }

        // if none had link info, then add it now
        if (needToAdd)
        {
            linkOnOffSwitch = gameObject.AddComponent <TNELinksOnOffSwitch>();
            linkOnOffSwitch.SetLinkStateWith(withNode, on);
        }

        return(true);
    }
Ejemplo n.º 2
0
    public bool SetLinkState(TileNode withNode, bool on)
    {
        if (!IsDirectNeighbour(withNode))
        {
            return(false);
        }

        bool needToAdd = false;

        if (linkOnOffSwitch != null)
        {
            linkOnOffSwitch.SetLinkStateWith(withNode, on);
            needToAdd = false;
        }
        if (withNode.linkOnOffSwitch != null)
        {
            withNode.linkOnOffSwitch.SetLinkStateWith(this, on);
            needToAdd = false;
        }
        if (needToAdd)
        {
            linkOnOffSwitch = gameObject.AddComponent <TNELinksOnOffSwitch>();
            linkOnOffSwitch.SetLinkStateWith(withNode, on);
        }
        return(true);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// This will help setup the node links. It will turn off a link betwene two nodes of the height
    /// difference betwene them are more than maxHeightDifference. Have a look TNELinksOnOffSwitch.cs
    /// </summary>
    public void SetupNodeLinkSwitches(float maxHeightDifference)
    {
        if (nodesCache == null)
        {
            return;
        }

        // nodes must be linked for this to work
        if (nodes == null)
        {
            LinkNodes();
        }
        if (nodes == null)
        {
            return;
        }

        maxHeightDifference = Mathf.Abs(maxHeightDifference);
        foreach (TileNode node in nodes)
        {
            if (node == null)
            {
                continue;
            }

            // check this node against its neighbours
            foreach (TileNode n in node.nodeLinks)
            {
                if (n == null)
                {
                    continue;
                }
                float h = Mathf.Abs(node.transform.position.y - n.transform.position.y);
                if (h >= maxHeightDifference)
                {
                    // height is greater than allowed, turn off the link
                    TNELinksOnOffSwitch ls = node.gameObject.GetComponent <TNELinksOnOffSwitch>();
                    if (ls == null)
                    {
                        ls = node.gameObject.AddComponent <TNELinksOnOffSwitch>();
                    }

                    ls.SetLinkStateWith(n, false);
                }
            }
        }
    }
Ejemplo n.º 4
0
    private void SetLinkBetweenSelected(bool on)
    {
        // get list of selected nodes
        List <TileNode> nodes = new List <TileNode>();

        foreach (GameObject go in Selection.gameObjects)
        {
            TileNode n = go.GetComponent <TileNode>();
            if (n != null)
            {
                nodes.Add(n);
            }
        }

        // now update links between these nodes
        foreach (TileNode n in nodes)
        {
            TNELinksOnOffSwitch ls = n.gameObject.GetComponent <TNELinksOnOffSwitch>();
            if (ls == null)
            {
                ls = n.gameObject.AddComponent <TNELinksOnOffSwitch>();
            }

            // set link state with all other selected nodes
            foreach (TileNode n2 in nodes)
            {
                if (n2 != n)
                {
                    // first do a neighbours check if possible
                    if (n.nodeLinks != null)
                    {
                        if (!n.IsDirectNeighbour(n2))
                        {
                            continue;
                        }
                    }

                    ls.SetLinkStateWith(n2, on);
                }
            }
        }
    }
Ejemplo n.º 5
0
	/// <summary>
	/// Set the link withNode on or off. Returns false if operation could not be completed, 
	/// for example withNode was not a neighbour of this node
	/// </summary>
	public bool SetLinkState(TileNode withNode, bool on)
	{
		if (!IsDirectNeighbour(withNode)) return false;

		bool needToAdd = false;
		if (linkOnOffSwitch != null)
		{
			linkOnOffSwitch.SetLinkStateWith(withNode, on);
			needToAdd = false;
		}
		
		// check if neighbour might carry a link back to this node, and update
		if (withNode.linkOnOffSwitch != null)
		{
			withNode.linkOnOffSwitch.SetLinkStateWith(this, on);
			needToAdd = false;
		}

		// if none had link info, then add it now
		if (needToAdd)
		{
			linkOnOffSwitch = gameObject.AddComponent<TNELinksOnOffSwitch>();
			linkOnOffSwitch.SetLinkStateWith(withNode, on);
		}

		return true;
	}