Пример #1
0
        void Visualize(RigVisualizer visualizer)
        {
            MyHandles.DragHandleResult result;
            MyHandles.DragHandle(visualizer.GetHashCode(), visualizer.transform.position, Quaternion.identity, .1f, Handles.DotHandleCap, Color.green, out result);
            GUI.color = Color.blue;
            if (RigVisualizer.selected == visualizer)
            {
                GUI.color = Color.green;
            }

            Handles.Label(visualizer.transform.position, new GUIContent(nodeTexture), handleStyle);


            if (result == MyHandles.DragHandleResult.LMBClick)
            {
                RigVisualizer.selected = visualizer;
            }

            if (visualizer.children == null || (visualizer.children.Length > 0 && visualizer.children[0] == null))
            {
                visualizer.Init();
            }
            for (int i = 0; i < visualizer.children.Length; i++)
            {
                Visualize(visualizer.children[i]);
            }
        }
Пример #2
0
    private void OnSceneGUI()
    {
        Handles.Slider2D(Target.transform.position, Vector3.right, Vector3.right, Vector3.right, 1, Handles.ArrowCap, 1);

        MyHandles.DragHandleResult dhResult;
        Vector3 newPosition = MyHandles.DragHandle(Target.transform.position, 1, Handles.ArrowCap, Color.red, out dhResult);

        switch (dhResult)
        {
        case MyHandles.DragHandleResult.LMBDrag:
            Target.transform.position = newPosition;
            break;
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(Target);
        }
    }
    private Vector2 ShowPoint(int index)
    {
        Vector2 point = handleTransform.TransformPoint(spline.GetControlPoint(index));

        float size  = HandleUtility.GetHandleSize(point);
        Color color = modeColors[(int)spline.GetControlPointMode(index)];

        Handles.color = color;
        MyHandles.DragHandleResult dhResult;
        Vector2 newPosition = MyHandles.DragHandle(point, 0.04f * size, Handles.DotCap, color, out dhResult);

        switch (dhResult)
        {
        case MyHandles.DragHandleResult.LMBDrag:
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(index, handleTransform.InverseTransformPoint(newPosition));
            selectedIndex = index;
            Repaint();
            break;

        case MyHandles.DragHandleResult.LMBClick:
            if (selectedIndex == index)
            {
                selectedIndex = -1;
            }
            else
            {
                selectedIndex = index;
            }
            Repaint();
            break;
        }

        if (selectedIndex == index)
        {
            Handles.color = Color.red;
            Handles.CircleCap(0, point, Quaternion.identity, 0.3f * size);
        }
        return(point);
    }
Пример #4
0
    void OnSceneGUI()
    {
        /*SceneView sceneView = SceneView.currentDrawingSceneView;
         * if(Event.current.button == 0 )
         *      if(Event.current.rawType == EventType.MouseDrag){
         *              movingObject = true;
         *
         *              for(int i = 0; i<cell.Length; i++){
         *                      //if(Selection.Contains(c.gameObject));
         *                      cell[i].Map.updateCell(cell[i], Event.current.type == EventType.MouseUp);
         *              }
         *              sceneView.Repaint();
         *              //Event.current.Use();
         *      }else if(Event.current.rawType == EventType.mouseMove){
         *              ratonMovido = true;
         *      }else if(Event.current.rawType == EventType.mouseMove && HandleUtility.niceMouseDelta > 0 && movingObject){
         *
         *      }else if(Event.current.rawType == EventType.MouseUp){
         *              if(movingObject)
         *                      movingObject = false;
         *      }*/

        Cell c = (Cell)target;

        if (target == cell[0])
        {
            Bounds bounds = new Bounds(cell[0].GetComponent <Renderer>().bounds.center, new Vector3(0, 0, 0));
            for (int i = 0; i < cell.Length; i++)
            {
                bounds.Encapsulate(cell[i].GetComponent <Renderer>().bounds);
            }

            MyHandles.DragHandleResult dhResult;


            Vector3 screenStart = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(bounds.center);
            Vector3 end         = SceneView.currentDrawingSceneView.camera.ScreenToWorldPoint(screenStart + new Vector3(0, 120, 0));

            float height = (end - bounds.center).magnitude;

            end = bounds.center + new Vector3(0, height, 0);

            Handles.DrawLine(bounds.center, end);

            Vector3 newPosition = MyHandles.DragHandle(end, angle, 0.1f * height, Handles.CubeCap, Color.white, Color.gray, out dhResult);

            switch (dhResult)
            {
            case MyHandles.DragHandleResult.LMBPress:
                heights.Clear();
                origin = newPosition;
                break;

            case MyHandles.DragHandleResult.LMBDrag:
                if (justCreated)
                {
                    heights.Clear();
                    origin      = newPosition;
                    justCreated = false;
                }

                diference = (newPosition - origin) * 2;
                break;

            case MyHandles.DragHandleResult.LMBRelease:
                diference = ident;
                break;
            }
        }

        if (!heights.ContainsKey(c))
        {
            heights.Add(c, c.Height);
        }

        if (diference.y != 0)
        {
            Undo.RecordObject(target, "Cell height changed...");
            float height = c.Height;
            c.Height = heights[c] + diference.y;
            EditorUtility.SetDirty(c);

            if (c.Height != height)
            {
                c.gameObject.BroadcastMessage("Update");
            }
        }
    }
Пример #5
0
        private void DrawSceneNodesGUI()
        {
            Camera sceneCamera = Camera.current;
            var    allNodes    = net.data.GetNodeList();
            bool   dirty       = false;

            foreach (var node in allNodes)
            {
                var nodePositon = node.position + net.transform.position;
                if (Vector3.Dot(sceneCamera.transform.forward, nodePositon - sceneCamera.transform.position) < 0)
                {
                    continue;
                }

                int selectedIndex = net.SelectedIndex;
                // Undo.RecordObject(node, "Modifying node");
                Handles.Label(nodePositon, "Node" + node.id);

                var pointHandleSize = HandleUtility.GetHandleSize(nodePositon) * HANDLE_SCALE;
                Handles.color = (node.id == selectedIndex) ? Color.red : Color.green;

                MyHandles.DragHandleResult dhResult;
                Vector3 newPosition = MyHandles.DragHandle(nodePositon, pointHandleSize, caps[(int)node.type], Color.blue, out dhResult);

                switch (dhResult)
                {
                case MyHandles.DragHandleResult.LMBClick:
                    ChangeSelectedPointIndex(node.id);
                    GUI.changed = true;
                    break;

                case MyHandles.DragHandleResult.LMBDrag:

                    if (editmode == EditMode.ConnectLine)
                    {
                        Vector3 position2  = Camera.current.WorldToScreenPoint(Handles.matrix.MultiplyPoint(newPosition));
                        var     dragNodeTo = allNodes.Where(n =>
                        {
                            return(n != node &&
                                   Vector3.Distance(Camera.current.WorldToScreenPoint(Handles.matrix.MultiplyPoint(n.position + net.transform.position)), position2) < 30);
                        }).FirstOrDefault();

                        if (dragNodeTo != null)
                        {
                            if (net.data.ConnectNode(node.id, dragNodeTo.id))
                            {
                                net.CheckLineNode(node);
                                net.CheckLineNode(dragNodeTo);
                                net.UpdateLineNode(node);
                            }
                        }
                    }
                    break;
                }

                // Move node position
                if (editmode == EditMode.Transform)
                {
                    if (node.id == selectedIndex)
                    {
                        var currentPosition = tp = node.position + net.transform.position;
                        currentPosition = Handles.DoPositionHandle(currentPosition, Quaternion.identity);

                        if (tp != currentPosition)
                        {
                            node.position = net.attachToGround ? PipeNetUtils.GroundHeight(currentPosition) : currentPosition - net.transform.position;
                            net.UpdateNodeSign(node);
                            net.UpdateLineNode(node);
                            dirty = true;
                        }
                    }
                }
            }

            if (dirty)
            {
                Undo.RecordObject(net, "Refresh");
                net.Refresh();
            }
        }