Exemple #1
0
    /* Initializes the tee with a given fab and populates the node with info */
    public GameObject init(GameObject preFab, NodeInfo info)
    {
        GameObject nN = Instantiate(preFab);

        nN.transform.position = START_POS;
        NormalNode nNode = nN.GetComponent <NormalNode>();

        nNode.connectionFab = connectionFab;
        nNode.init(info);
        nodes.Add(nN);
        isInit = true;
        return(nN);
    }
Exemple #2
0
    /* Generates a node using a given prefab, returns the node GameObject */
    public GameObject generateNode(GameObject prefab)
    {
        GameObject  newNode = Instantiate(prefab);
        NodeWithPos nP      = getNextNodePos();

        newNode.transform.position = nP.nextPos;
        NormalNode cNode = newNode.GetComponent <NormalNode>();

        cNode.connectionFab = connectionFab;
        cNode.init();
        NormalNode pNode = nP.lastNode.GetComponent <NormalNode>();

        cNode.addParent(pNode);
        pNode.addChild(cNode);
        nodes.Add(newNode);
        return(newNode);
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        //dataContainer = dataObject.GetComponent<DataContainer>();
        foreach (GameObject o in selection.Keys)
        {
            o.GetComponent <NormalNode>().tempColor(originalColor, 1f);
        }

        if (cSelected != null)
        {
            cSelected.GetComponent <NormalNode>().tempColor(pinColor, 1f);
            displayInfo(cSelected.GetComponent <NormalNode>().getInfo());
        }

        /* This is for both style and user feedback */
        if ((getTouchType() == TButtonType.middle || getTouchType() == TButtonType.left || getTouchType() == TButtonType.right) && alpha < 255f)
        {
            alpha += alphaIncrement;
        }
        else if (alpha > 0f)
        {
            alpha -= alphaIncrement;
        }

        // Sets the color of the laser according to the type
        if (getTouchType() == TButtonType.left)
        {
            line.GetComponent <Renderer>().material.color = deleteColor;
        }
        else if (getTouchType() == TButtonType.right)
        {
            line.GetComponent <Renderer>().material.color = pinColor;
        }
        else
        {
            line.GetComponent <Renderer>().material.color = originalColor;
        }

        textObject.transform.position = controllerPose.transform.position + Vector3.up * 0.1f;
        textObject.transform.LookAt(headObject.transform);

        /* This handles the laser that shoots out of the controller and how it collides with things */
        if (alpha > 0)
        {
            RaycastHit hit;

            if (Physics.Raycast(controllerPose.transform.position, transform.forward, out hit, 50, layerMask))
            {
                showLine(hit.point, hit.distance);
                GameObject o = hit.transform.gameObject;
                if (o.GetComponent <NormalNode>() != null)
                {
                    if (lastTouched != null && !lastTouched.Equals(o))
                    {
                    }
                    else
                    {
                        o.GetComponent <NormalNode>().tempColor(line.GetComponent <Renderer>().material.color, 1f);
                        lastTouched = o;
                        displayInfo(o.GetComponent <NormalNode>().getInfo());
                    }
                }
            }
            else
            {
                showLine(controllerPose.transform.position + transform.forward * 10000f, 10000f);
                if (lastTouched != null)
                {
                    lastTouched = null;
                    if (cSelected == null)
                    {
                        hideInfo();
                    }
                }
            }
        }
        else
        {
            line.SetActive(false);
            if (cSelected == null)
            {
                hideInfo();
            }
        }

        // Animates the little nodes in and out
        if (getTouchType() == TButtonType.bottom)
        {
            if (rad < outerLimit)
            {
                rad = Mathf.Min(rad + 0.001f, outerLimit);
            }
        }
        else if (getTouchType() == TButtonType.top)
        {
            if (rad > innerLimit)
            {
                rad = Mathf.Max(rad - 0.001f, innerLimit);
            }
        }
        else
        {
            if (rad > middleLimit)
            {
                rad = Mathf.Max(rad - 0.001f, middleLimit);
            }
            else if (rad < middleLimit)
            {
                rad = Mathf.Min(rad + 0.001f, middleLimit);
            }
        }

        if (isClick.state && !isClick.lastState)
        {
            // Selection add case
            if (lastTouched != null && getButtonPress() == TButtonType.middle)
            {
                if (selection.ContainsKey(lastTouched))
                {
                    selection[lastTouched].GetComponent <NormalNode>().remove();
                    selection.Remove(lastTouched);
                }
                else
                {
                    GameObject copy  = Instantiate(lastTouched);
                    NormalNode nCopy = copy.GetComponent <NormalNode>();
                    nCopy.setColor(lastTouched.GetComponent <NormalNode>().getColor());
                    nCopy.size           = 0.02f;
                    nCopy.nodeGrowthRate = 0.001f;
                    copy.layer           = noTouch;
                    nCopy.init(lastTouched.GetComponent <NormalNode>().getInfo());
                    copy.transform.parent = controllerPose.transform;
                    selection.Add(lastTouched, copy);
                }
            }

            // Deletion case
            if (lastTouched != null && getButtonPress() == TButtonType.left)
            {
                lastTouched.GetComponent <NormalNode>().remove();
                foreach (GameObject o in selection.Values)
                {
                    o.GetComponent <NormalNode>().remove();
                }
                selection.Clear();
            }

            // Pin case
            if (getButtonPress() == TButtonType.right)
            {
                if (lastTouched != null)
                {
                    if (cSelected == lastTouched)
                    {
                        cSelected = null;
                        hideInfo();
                    }
                    else
                    {
                        cSelected = lastTouched;
                        cSelected.GetComponent <NormalNode>().tempColor(pinColor, 1f);
                    }
                }
                else
                {
                    hideInfo();
                    cSelected = null;
                }
            }


            // Clear selection case
            if (getButtonPress() == TButtonType.bottom)
            {
                foreach (GameObject o in selection.Values)
                {
                    o.GetComponent <NormalNode>().remove();
                }
                selection.Clear();
            }

            // Spawn case
            if (getButtonPress() == TButtonType.top)
            {
                spawnConstellation();
            }
        }

        // Animation code
        animateSelected();
        circleDeg = (circleDeg + 1f) % 360f;
    }