Пример #1
0
    public void Draw()
    {
        Event guiEvent = Event.current;

        //Handling every line
        for (int i = 0; i < l.line.Count; i++)
        {
            Handles.color = Color.black;
            Handles.DrawLine(l.node[l.line[i]._lineProp.node1]._nodeProp.position, l.node[l.line[i]._lineProp.node2]._nodeProp.position);
            //If it's a selected line, mark its center point with red, otherwise mark it blue
            if (i == l.activeLineIndex)
            {
                Handles.color = Color.red;
            }
            else
            {
                Handles.color = Color.blue;
            }

            //The line's center point
            Vector3 lineVec = (l.node[l.line[i]._lineProp.node2]._nodeProp.position - l.node[l.line[i]._lineProp.node1]._nodeProp.position) / 2;
            Vector3 linePos = Handles.FreeMoveHandle
                              (
                i + 300,
                l.node[l.line[i]._lineProp.node1]._nodeProp.position + lineVec,
                Quaternion.identity,
                .2f,
                Vector3.zero,
                Handles.SphereHandleCap
                              );
            //Debug.Log(l.line[i]._lineProp.node2+", "+l.line[i]._lineProp.node1);
            //Check if it's selected
            if (guiEvent.button == 0 && GUIUtility.hotControl == i + 300)
            {
                l.activeLineIndex = i;
                l.activeRotation  = l.line[i].rotation;
                l.UpdateAllLines();
            }
            //Check if it's been moved
            if ((l.node[l.line[i]._lineProp.node1] + ((l.node[l.line[i]._lineProp.node2] - l.node[l.line[i]._lineProp.node1]) / 2)) != linePos)
            {
                if (l.CheckNode(l.line[i]._lineProp.node1) && l.CheckNode(l.line[i]._lineProp.node2))
                {
                    Undo.RecordObject(l, "Moved line position");
                    l.node[l.line[i]._lineProp.node1]._nodeProp.position = linePos - lineVec;
                    l.node[l.line[i]._lineProp.node2]._nodeProp.position = linePos + lineVec;
                    l.UpdateAllLines();
                }
            }
        }

        //Handling every node
        for (int i = 0; i < l.node.Count; i++)
        {
            //If it's a selected node
            if (i == l.activeNodeIndex)
            {
                Handles.color = new Color(1, 1, 1, 0.5f);
            }
            else
            {
                Handles.color = new Color(0, 0, 0, 0.5f);
            }
            Vector3 nodePos = Handles.FreeMoveHandle(i + 200, l.node[i]._nodeProp.position, Quaternion.identity, l.node[i]._nodeProp.maxRadius, Vector3.zero, Handles.SphereHandleCap);
            //Check if it's selected
            if (guiEvent.button == 0 && GUIUtility.hotControl == i + 200)
            {
                l.activeNodeIndex    = i;
                l.activeNodePosition = l.node[l.activeNodeIndex]._nodeProp.position;
                l.minRadius          = l.node[l.activeNodeIndex]._nodeProp.minRadius;
                l.maxRadius          = l.node[l.activeNodeIndex]._nodeProp.maxRadius;
                l.UpdateAllLines();
            }


            //Check if it's selected and shift button is pressed to connect line between two nodes


            //Check if it's been moved
            if (l.node[i]._nodeProp.position != nodePos)
            {
                Undo.RecordObject(l, "Moved node position");
                l.node[i]._nodeProp.position = nodePos;
                l.node[i].ClampPosZeroMax(new Vector3(
                                              l.voxelGrids.boundaryWorldPos.x * l.densityGenerator.numberOfGeneratedMeshObject.x,
                                              l.voxelGrids.boundaryWorldPos.y * l.densityGenerator.numberOfGeneratedMeshObject.y,
                                              l.voxelGrids.boundaryWorldPos.z * l.densityGenerator.numberOfGeneratedMeshObject.z));
                l.UpdateAllLines();
            }
        }
        Handles.color = Color.red;
        Handles.DrawLine(
            (l.GetActiveLineNode(true) + (l.GetCenter(l.activeLineIndex) / 2)),
            (l.GetActiveLineNode(true) + (l.GetCenter(l.activeLineIndex) / 2)) + l.line[l.activeLineIndex]._lineProp.rightLocal
            );
        Handles.color = Color.green;
        Handles.DrawLine(
            (l.GetActiveLineNode(true) + (l.GetCenter(l.activeLineIndex) / 2)),
            (l.GetActiveLineNode(true) + (l.GetCenter(l.activeLineIndex) / 2)) + l.line[l.activeLineIndex]._lineProp.upLocal
            );
    }