Esempio n. 1
0
    void ResetTarget()
    {
        if (target == null)
        {
            return;
        }

        target.locked       = false;
        target.loading      = false;
        target.controllable = false;
        target = null;
    }
Esempio n. 2
0
    void Update()
    {
        if (!recording && Physics.Raycast(p.center, -transform.up, out hit, range))
        {
            GestureTarget gt = hit.transform.GetComponent <GestureTarget> ();
            if (gt != null && !gt.locked && !gt.controlled)
            {
                if (target != null)
                {
                    ResetTarget(target);
                }
                target          = gt;
                gt.controllable = false;
                gt.locked       = true;
                initialPoint    = target.transform.position;
            }
        }
        else if (!recording && target != null)
        {
            target.controllable = true;
            ResetTarget(target);
        }

        if (target != null || recording)
        {
            weight += speed * Time.deltaTime;
            if (weight < 1)
            {
                target.transform.position = Vector3.Lerp(target.transform.position,
                                                         initialPoint + Random.insideUnitSphere * shakeAmount,
                                                         shakeForce * weight * Time.deltaTime
                                                         );
            }
            else if (!recording)
            {
                target.transform.position = initialPoint;
                mark             = Time.time;
                startPosition    = p.center;
                recording        = true;
                target.highlight = true;
            }
            else if (Time.time > mark + recordTime)
            {
                endPosition = p.center;
                ProcessGesture();
                recording = false;
            }
        }

        //Debug
        Debug.DrawRay(p.center, -transform.up * range, Color.yellow);
    }
Esempio n. 3
0
    IEnumerator Reset(GestureTarget gt, bool cool = false)
    {
        target       = null;
        gt.highlight = false;
        weight       = 0;
        if (cool)
        {
            print("cool started");
            yield return(new WaitForSeconds(cooldown));

            print("cool ended");
            //robot
            gt.loading = true;
            while (!robotSynced)
            {
                yield return(null);
            }
            gt.controllable = true;
        }
        gt.loading = false;
        gt.locked  = false;
        gt         = null;
    }
Esempio n. 4
0
 void ResetTarget(GestureTarget gt, bool cool = false)
 {
     StartCoroutine(Reset(gt, cool));
 }
Esempio n. 5
0
    void Update()
    {
        loadingBuffer.text = "";

        if (contextTargets.Count == 0 || !canSelect)
        {
            ResetTarget();
            return;
        }
        if (target != null && target.controlled)
        {
            return;
        }

        //Find closest target
        float     minDist = -1;
        Transform swap    = null;

        foreach (Transform t in contextTargets)
        {
            float d = Vector3.Distance(t.position, pairable.center);
            if (d < range)
            {
                if (d < minDist || minDist == -1)
                {
                    swap    = t;
                    minDist = d;
                }
            }
        }
        if (minDist > -1)
        {
            ResetTarget();
            target        = swap.GetComponent <GestureTarget>();
            target.locked = true;
            //Debug
            Debug.DrawLine(target.transform.position, pairable.center, Color.yellow);
        }
        else
        {
            ResetTarget();
        }

        if (target == null)
        {
            return;
        }

        // here: move the robot to target.position
        robotCtrl.setDestination(target.transform.position);
        robotSynced = robotCtrl.hasArrived();

        //Process target
        target.robot        = robotCtrl.getExecuteRbt();
        target.controllable = robotSynced;
        target.loading      = !robotSynced;
        //
        if (target.loading)
        {
            loadingBuffer.transform.position = target.transform.position + Vector3.up * loadingOffset;
            //copy
            float div = Time.time % 3;
            loadingBuffer.text = div < 1 ? ".  " : div >= 2 ? "..." : ".. ";
        }
    }