示例#1
0
    void ToggleLook(bool _isLocked)
    {
        if (index >= targetCollider.targets.Count)
        {
            index = 0;
        }

        if (isLockedOn != _isLocked && _isLocked == true)
        {
            float duration = .1f;

            if (orient != null)
            {
                StopCoroutine(orient);
            }

            orient = StartCoroutine(Interpolater.InterpolateLocalRotation(camControl.turn, Quaternion.Euler(10, 0, 0), duration));
        }

        //The camera aim target object
        Transform _targeter = target.sourceTransform;

        isLockedOn = _isLocked;
        camControl.pitchIsLocked = _isLocked;

        camControl.enabled = !_isLocked;

        player.weight = _isLocked ? 0 : 1;
        target.weight = _isLocked ? 1 : 0;

        playerLook.constraintActive = _isLocked;

        look.SetSource(0, player);
        look.SetSource(1, target);

        if (targetCollider.targets.Count == 0)
        {
            return;
        }

        lockTarget = targetCollider.targets[index].transform;

        _targeter.parent        = _isLocked ? lockTarget : player.sourceTransform;
        _targeter.localPosition = Vector3.zero;
        _targeter.localRotation = new Quaternion(0, 0, 0, 0);

        index++;
    }
示例#2
0
        System.Collections.IEnumerator WaitTillEOF()
        {
            yield return(new WaitForEndOfFrame());

            if (string.IsNullOrEmpty(j_input.Text))
            {
                HandleMessage(Constants.CASE_TAP);
            }
            // HideKeyBoard();
            while (JMRCameraUtility.Main == null)
            {
                yield return(null);
            }

            // Set the parameters for LookAtConstraint for the Keyboard to look at Camera.
            j_LookAtSource.sourceTransform = JMRCameraUtility.Main.transform;
            lookAt.SetSource(0, j_LookAtSource);
            lookAt.constraintActive = false;
        }
    void SetTarget()
    {
        ConstraintSource cs = new ConstraintSource();

        cs.sourceTransform = targets[curTargetIndex].transform;
        cs.weight          = 1;
        LookAtConstraint las = gameObject.GetComponent <LookAtConstraint>();

        las.SetSource(0, cs);


        MouseOrbitImproved moi = gameObject.GetComponent <MouseOrbitImproved>();

        moi.target = targets[curTargetIndex].transform;


        targetIndicator.transform.parent        = targets[curTargetIndex].transform;
        targetIndicator.transform.localPosition = Vector3.zero;
    }
示例#4
0
        public static void AddLookAtConstraint(GameObject gobject, GameObject target, int index = -1)
        {
            LookAtConstraint constraint = gobject.GetComponent <LookAtConstraint>();

            if (null == constraint)
            {
                constraint = gobject.AddComponent <LookAtConstraint>();
                ParametersController parametersController = gobject.GetComponent <ParametersController>();
                if (null == parametersController)
                {
                    gobject.AddComponent <ParametersController>();
                }
                Constraint newConstraint = new Constraint {
                    gobject = gobject, target = target.transform, constraintType = ConstraintType.LookAt
                };
                if (index == -1)
                {
                    constraints.Add(newConstraint);
                }
                else
                {
                    constraints.Insert(index, newConstraint);
                }

                ParametersController targetParametersController = target.GetComponent <ParametersController>();
                if (null == targetParametersController)
                {
                    targetParametersController = target.AddComponent <ParametersController>();
                }
                targetParametersController.AddConstraintHolder(gobject);
            }
            else
            {
                // update visual target for LineRenderer
                foreach (Constraint c in constraints)
                {
                    if (c.gobject == gobject && c.constraintType == ConstraintType.LookAt)
                    {
                        c.target = target.transform;
                        break;
                    }
                }
            }
            ConstraintSource source;

            if (constraint.sourceCount == 0)
            {
                source = new ConstraintSource();
                constraint.AddSource(source);
            }
            else
            {
                source = constraint.GetSource(0);
            }

            source.sourceTransform = target.transform;
            source.weight          = 1f;
            constraint.SetSource(0, source);
            constraint.rotationOffset = new Vector3(0, 180, 0);

            constraint.constraintActive = true;

            GlobalState.FireObjectConstraint(gobject);
        }