Beispiel #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);
    }
Beispiel #2
0
    }                                                                           // cache of the component

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

    void Start()
    {
        units = new List <NaviUnit>();

        linkOnOffSwitch = gameObject.GetComponent <TNELinksOnOffSwitch>();
        movesMod        = gameObject.GetComponent <TNEMovementModifier>();
    }
Beispiel #3
0
    /// <summary>
    /// Checks if link with the target node is on or off. See TNELinksOnOffSwitch
    /// </summary>
    public bool LinkIsOnWith(TileNode withNode)
    {
        // first check if provided link is actually a neighbour of this one
        if (!IsDirectNeighbour(withNode))
        {
            return(false);
        }

        int state = -1;

        // linkOnOffSwitch might not be inited this fcuntion is called from editor
        if (linkOnOffSwitch == null)
        {
            linkOnOffSwitch = gameObject.GetComponent <TNELinksOnOffSwitch>();
        }

        // check if the link with the target is on or off
        if (linkOnOffSwitch != null)
        {               // check if link is on with neighbour
            state = linkOnOffSwitch.LinkIsOn(withNode);
        }

        // not found? check if the neighbour is on carrying the link info
        if (state == -1)
        {
            if (withNode.linkOnOffSwitch != null)
            {                   // check if link is on from neighbour's side
                state = withNode.linkOnOffSwitch.LinkIsOn(this);
            }
        }

        // default is true, only return false if specifically told that link is off
        return(state == 0?false:true);
    }
Beispiel #4
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);
    }
Beispiel #5
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);
                }
            }
        }
    }
    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);
                }
            }
        }
    }
Beispiel #7
0
    private Projector projector;                        // used if projector on this or child object found

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

    void Start()
    {
        units = new List <NaviUnit>();

        linkOnOffSwitch = gameObject.GetComponent <TNELinksOnOffSwitch>();
        movesMod        = gameObject.GetComponent <TNEMovementModifier>();

        if (!projector)
        {
            projector = gameObject.GetComponent <Projector>();
        }
        if (!projector && transform.childCount > 0)
        {
            for (int i = 0; i < transform.childCount; i++)
            {
                projector = transform.GetChild(i).GetComponent <Projector>();
                if (projector)
                {
                    break;
                }
            }
        }
    }
Beispiel #8
0
    static void RenderTileNodeGizmo(TileNode node, GizmoType gizmoType)
    {
        if (node.mapnav == null)
        {
            return;
        }
        Vector3 position  = node.transform.position;
        Vector3 gizmoSize = TileNode.GizmoSize * (node.mapnav.tileSpacing / TileNode.GizmoSizeDiv);

        // draw cube(s) for node
        if (node.mapnav.gizmoDrawNodes || ((gizmoType & GizmoType.Selected) != 0))
        {
            if ((gizmoType & GizmoType.Selected) != 0)
            {
                Gizmos.color = Color.red;
                Gizmos.DrawCube(position, gizmoSize);
            }

            else if (node.mapnav.gizmoColorCoding)
            {
                bool    drawn = false;
                Vector3 offs  = Vector3.zero;
                for (int i = 0; i < TileNode.GizmoColourCoding.Length; i++)
                {
                    int t = (int)Mathf.Pow(2, i);
                    if (((int)node.tileTypeMask & t) == t)
                    {
                        Gizmos.color = TileNode.GizmoColourCoding[i];
                        Gizmos.DrawCube(position + offs, gizmoSize);
                        offs.y += gizmoSize.y;
                        drawn   = true;
                    }
                }

                if (!drawn)
                {
                    Gizmos.color = Color.black;
                    Gizmos.DrawCube(position, gizmoSize);
                }
            }

            else
            {
                Gizmos.color = Color.black;
                Gizmos.DrawCube(position, gizmoSize);
            }
        }

        // draw the node links
        if (node.nodeLinks != null && (node.mapnav.gizmoDrawLinks || (gizmoType & GizmoType.Selected) != 0))
        {
            TNELinksOnOffSwitch linkSwitch = node.gameObject.GetComponent <TNELinksOnOffSwitch>();
            foreach (TileNode n in node.nodeLinks)
            {
                if (n != null)
                {
                    Gizmos.color = Color.blue;

                    if (linkSwitch != null)
                    {                           // check if lik is on with neighbour
                        if (linkSwitch.LinkIsOn(n) == 0)
                        {
                            Gizmos.color = Color.red;
                        }
                    }

                    TNELinksOnOffSwitch nls = n.gameObject.GetComponent <TNELinksOnOffSwitch>();
                    if (nls != null)
                    {                           // check if neighbour's link with me is on
                        if (nls.LinkIsOn(node) == 0)
                        {
                            Gizmos.color = Color.red;
                        }
                    }

                    Gizmos.DrawLine(position, n.transform.position);
                }
            }

            // look for forced links
            TNEForcedLink fl = node.gameObject.GetComponent <TNEForcedLink>();
            if (fl != null)
            {
                foreach (TileNode link in fl.links)
                {
                    if (link == null)
                    {
                        continue;
                    }
                    Gizmos.DrawLine(position, link.transform.position);
                }
            }
        }
    }
Beispiel #9
0
	private Projector projector;			// used if projector on this or child object found

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

	void Start()
	{
		units = new List<NaviUnit>();

		linkOnOffSwitch = gameObject.GetComponent<TNELinksOnOffSwitch>();
		movesMod = gameObject.GetComponent<TNEMovementModifier>();

		if (!projector) projector = gameObject.GetComponent<Projector>();
		if (!projector && transform.childCount > 0)
		{
			for (int i = 0; i < transform.childCount; i++)
			{
				projector = transform.GetChild(i).GetComponent<Projector>();
				if (projector) break;
			}
		}
	}
Beispiel #10
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;
	}
Beispiel #11
0
	/// <summary>
	/// Checks if link with the target node is on or off. See TNELinksOnOffSwitch
	/// </summary>
	public bool LinkIsOnWith(TileNode withNode, TileType forType)
	{
		// first check if provided link is actually a neighbour of this one
		if (!IsDirectNeighbour(withNode)) return false;

		int state = -1;

		// linkOnOffSwitch might not be inited this function is called from editor
		if (linkOnOffSwitch == null)
		{
			linkOnOffSwitch = gameObject.GetComponent<TNELinksOnOffSwitch>();
		}

		// check if the link with the target is on or off
		if (linkOnOffSwitch != null)
		{	// check if link is on with neighbour
			state = linkOnOffSwitch.LinkIsOn(withNode, forType);
		}

		// not found? check if the neighbour is on carrying the link info
		if (state == -1)
		{
			if (withNode.linkOnOffSwitch != null)
			{	// check if link is on from neighbour's side
				state = withNode.linkOnOffSwitch.LinkIsOn(this, forType);
			}
		}

		// default is true, only return false if specifically told that link is off 
		return (state == 0 ? false : true);
	}