示例#1
0
    IEnumerator LookAt(Interface other)
    {
        Quaternion rotStart = nodeAnchor.rotation;
        Quaternion rotEnd   = Quaternion.LookRotation(other.node.transform.position - nodeAnchor.position);
        float      t        = 0f;

        while (t < 0.5f)
        {
            yield return(null);

            t += Time.deltaTime;
            nodeAnchor.rotation = Quaternion.Lerp(rotStart, rotEnd, t / 0.5f);
        }
        //create line
        if (connectionLine == null)
        {
            connectedTo = other.GetComponent <InterfaceVisuals> ();
            Lines.Pair pair = Lines.RenderStraightLine(modelTransform, connectedTo.modelTransform, 0.02f, 0.2f);
            StartCoroutine(LineRoutine(pair.lineRenderer, modelTransform, connectedTo.modelTransform, 0.2f));
            connectionLine             = pair.gameObject;
            pair.lineRenderer.material = lineMaterial;

            connectedTo.connectionLine = pair.gameObject;
            line = pair.lineRenderer;
            connectedTo.connectedTo = this;
            connectedTo.line        = line;

            ChangeColor(meshRenderer.material.color);
        }
    }
示例#2
0
    IEnumerator MultipleLookAt(List <Interface> ifaces)
    {
        int total = ifaces.Count;

        //Get initial rotations
        Transform[]        transforms      = new Transform[total];
        Transform[]        otherTransforms = new Transform[total];
        Quaternion[]       rotsStart       = new Quaternion[total];
        Quaternion[]       otherRotsStart  = new Quaternion[total];
        InterfaceVisuals[] visuals         = new InterfaceVisuals[total];
        InterfaceVisuals[] otherVisuals    = new InterfaceVisuals[total];
        for (int i = 0; i < total; ++i)
        {
            visuals[i]                     = ifaces [i].GetComponent <InterfaceVisuals> ();
            otherVisuals[i]                = ifaces [i].connectedTo.GetComponent <InterfaceVisuals> ();
            visuals[i].blockAnimation      = true;
            otherVisuals[i].blockAnimation = true;
            transforms [i]                 = visuals[i].nodeAnchor;
            otherTransforms [i]            = otherVisuals[i].nodeAnchor;

            rotsStart [i]      = transforms [i].rotation;
            otherRotsStart [i] = otherTransforms [i].rotation;
        }

        //Final rotations maths
        Quaternion[] rotsEnd      = new Quaternion[total];
        Quaternion[] otherRotsEnd = new Quaternion[total];
        Quaternion   baseRotation = Quaternion.LookRotation(nodeAnchor.position - iface.connectedTo.node.transform.position);
        float        offset       = 15f;
        float        baseY        = baseRotation.eulerAngles.y - offset * 0.5f * total;
        float        otherBaseY   = baseRotation.eulerAngles.y + 180f + offset * 0.5f * total;

        for (int i = 0; i < total; ++i)
        {
            //print ((baseY + i * offset * 2f) + ", " + (otherBaseY - i * offset * 2f));
            otherRotsEnd[i] = Quaternion.Euler(0, baseY + i * offset * 2f, 0);
            rotsEnd[i]      = Quaternion.Euler(0, otherBaseY - i * offset * 2f, 0);
        }

        //Movement
        float t = 0f;

        while (t < 0.5f)
        {
            yield return(null);

            t += Time.deltaTime;
            float p = t / 0.5f;
            for (int i = 0; i < total; ++i)
            {
                transforms [i].rotation      = Quaternion.Lerp(rotsStart[i], rotsEnd[i], p);
                otherTransforms [i].rotation = Quaternion.Lerp(otherRotsStart[i], otherRotsEnd[i], p);
            }
        }

        //Create lines
        for (int i = 0; i < total; ++i)
        {
            visuals[i].blockAnimation = false;
            if (visuals [i].connectionLine == null)
            {
                Lines.Pair pair = Lines.RenderStraightLine(visuals [i].modelTransform, otherVisuals [i].modelTransform, 0.02f, 0.2f);
                connectionLine             = pair.gameObject;
                pair.lineRenderer.material = lineMaterial;

                visuals [i].StartCoroutine(LineRoutine(pair.lineRenderer, visuals [i].modelTransform, otherVisuals [i].modelTransform, 0.2f));
                otherVisuals [i].blockAnimation = false;
                otherVisuals [i].connectionLine = pair.gameObject;

                visuals [i].line             = pair.lineRenderer;
                visuals [i].connectedTo      = otherVisuals [i];
                otherVisuals [i].line        = pair.lineRenderer;
                otherVisuals [i].connectedTo = visuals [i];

                visuals [i].ChangeColor(visuals [i].meshRenderer.material.color);
            }
        }
    }