public void OnSceneGUI()
    {
        AttachedPathScript pathScript = (AttachedPathScript)target as AttachedPathScript;

        Event currentEvent = Event.current;



        if (pathScript.addNodeMode == true)
        {
            // If P is pressed, than create a node at selected point (window has to have focus)
            if (currentEvent.isKey && currentEvent.character == 'p')
            {
                Vector3 pathNode = GetTerrainCollisionInEditor(currentEvent);
                Debug.Log(currentEvent);
                TerrainPathCell pathNodeCell = new TerrainPathCell();
                Debug.Log(pathNode);
                pathNodeCell.position.x   = pathNode.x;
                pathNodeCell.position.y   = pathNode.z;
                pathNodeCell.heightAtCell = pathNode.y;

                pathScript.CreatePathNode(pathNodeCell);
                pathScript.addNodeMode = false;
            }
        }

        if (pathScript.nodeObjects != null && pathScript.nodeObjects.Length != 0)
        {
            int n = pathScript.nodeObjects.Length;
            for (int i = 0; i < n; i++)
            {
                PathNodeObjects node = pathScript.nodeObjects[i];
                node.position = Handles.PositionHandle(node.position, Quaternion.identity);
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(pathScript);

            if ((pathScript.pathFlat || pathScript.isRoad) && (pathScript.isFinalized == false))
            {
                pathScript.CreatePath(pathScript.pathSmooth, true, false);
            }

            else if (!pathScript.pathFlat && !pathScript.isRoad)
            {
                pathScript.CreatePath(pathScript.pathSmooth, false, false);
            }

            else if (pathScript.isFinalized)
            {
                pathScript.CreatePath(pathScript.pathSmooth, true, true);
            }
        }
    }
    public void AddNode(Vector3 position, float width)
    {
        PathNodeObjects newPathNodeObject = new PathNodeObjects();
        int             nNodes;

        if (nodeObjects == null)
        {
            nodeObjects = new PathNodeObjects[0];
            nNodes      = 1;
            newPathNodeObject.position = position;
        }

        else
        {
            nNodes = nodeObjects.Length + 1;
            newPathNodeObject.position = position;
        }

        PathNodeObjects[] newNodeObjects = new PathNodeObjects[nNodes];
        newPathNodeObject.width = width;

        int n = newNodeObjects.Length;

        for (int i = 0; i < n; i++)
        {
            if (i != n - 1)
            {
                newNodeObjects[i] = nodeObjects[i];
            }

            else
            {
                newNodeObjects[i] = newPathNodeObject;
            }
        }

        nodeObjects = newNodeObjects;
    }
	public void AddNode(Vector3 position, float width)
	{
		PathNodeObjects newPathNodeObject = new PathNodeObjects();
		int nNodes;
		
		if(nodeObjects == null)
		{
			nodeObjects = new PathNodeObjects[0];
			nNodes = 1;
			newPathNodeObject.position = position;
		}
		
		else
		{
			nNodes = nodeObjects.Length + 1;
			newPathNodeObject.position = position;
		}

		PathNodeObjects[] newNodeObjects = new PathNodeObjects[nNodes];
		newPathNodeObject.width = width;
		
		int n = newNodeObjects.Length;
		
		for (int i = 0; i < n; i++) 
		{
			if (i != n - 1) 
			{
				newNodeObjects[i] = nodeObjects[i];
			} 
			
			else 
			{
				newNodeObjects[i] = newPathNodeObject;
			}
		}
		
		nodeObjects = newNodeObjects;
	}