示例#1
0
文件: RootNode.cs 项目: jwatte/UReact
    public static NodeElem New(RootProps props)
    {
        var root = new NodeElem("Draggable Objects");

        foreach (var keyval in props.state.objects)
        {
            var id        = keyval.Key;
            var draggable = keyval.Value;
            root.Child(DraggableNode.New(new DraggableProps {
                key      = $"Draggable {id}",
                position = draggable.position,
                size     = draggable.size,
                onClick  = () => {
                    if (props.state.heldObject == null)
                    {
                        props.state.heldObject = id;
                    }
                    else
                    {
                        props.state.heldObject = null;
                    }
                },
                material = props.material,
                mesh     = props.mesh,
            }));
        }
        return(root);
    }
示例#2
0
文件: RootNode.cs 项目: Cifram/UReact
    public static UReact.NodeElem New(State state, Material material, Mesh mesh)
    {
        // Create an empty node, as a parent object to organize all the draggable objects together
        var root = new NodeElem("Draggable Objects");

        // Iterate through each of the draggables in the state, to make a child node from each
        foreach (var keyval in state.objects)
        {
            var id        = keyval.Key;
            var draggable = keyval.Value;

            // Use the `Child` function to add a child to the root node
            root.Child(
                DraggableNode.New(
                    id: id,
                    position: draggable.position,
                    size: draggable.size,
                    onClick: () => {
                if (state.heldObject == null)
                {
                    state.heldObject = id;
                }
                else
                {
                    state.heldObject = null;
                }
            },
                    material: material,
                    mesh: mesh
                    )
                );
        }

        return(root);
    }
 private void AddNode(Block block, bool draggable)
 {
     if (isDragging is false)
     {
         GameObject obj = CreateCodeBlock(block);
         if (draggable)
         {
             Node node = obj.GetComponent <Node>();
             node.controller = this;
             if (node.GetType().IsSubclassOf(typeof(DraggableNode)))
             {
                 DraggableNode draggableNode = (DraggableNode)node;
                 draggableNode.SetDragging(true);
                 draggableNode.MoveToMouse();
             }
         }
         obj.SetActive(true);
         nodes.Add(obj);
     }
 }