Exemple #1
0
    private void Start()
    {
        look = GetComponent <LookAtConstraint>();

        player = look.GetSource(0);
        target = look.GetSource(1);
    }
Exemple #2
0
    void Die()
    {
        LookAtConstraint constraint = fpsCamera.GetComponent <LookAtConstraint>();

        if (constraint != null)
        {
            constraint.enabled = false;
        }

        LookAtConstraint chestLookAt = spine.GetComponent <LookAtConstraint>();

        if (chestLookAt != null)
        {
            chestLookAt.enabled = false;
        }
        animator = GetComponent <Animator>();
        animator.SetBool("Dead", true);
        Rigidbody rb = GetComponent <Rigidbody>();

        if (rb)
        {
            Destroy(rb);
        }
        transform.position = new Vector3(transform.position.x, 0f, transform.position.z);
    }
Exemple #3
0
    //Look Constrait-------------------------------------------------------------
    //Clear Sourcers
    public static void ClearSources(this LookAtConstraint posCons)
    {
        int length = posCons.sourceCount;

        for (int i = 0; i < length; i++)
        {
            posCons.RemoveSource(0);
        }
    }
Exemple #4
0
    //Add Sourcer
    public static void AddTransform(this LookAtConstraint posCons, Transform source, float weight = 1)
    {
        ConstraintSource constraint = new ConstraintSource();

        constraint.sourceTransform = source;
        constraint.weight          = weight;

        posCons.AddSource(constraint);
    }
Exemple #5
0
    private void Start()
    {
        LookAtConstraint c = GetComponent <LookAtConstraint>();
        ConstraintSource constraintSource = new ConstraintSource {
            sourceTransform = Camera.main.transform, weight = 1
        };

        c.AddSource(constraintSource);
    }
        // PRIVATE METHODS: -----------------------------------------------------------------------

        private static IEnumerator CoroutineShow(string message, Color color,
                                                 GameObject instance, float duration)
        {
            Canvas canvas = instance.GetComponent <Canvas>();
            Camera camera = HookCamera.Instance != null?HookCamera.Instance.Get <Camera>() : null;

            if (!camera)
            {
                camera = GameObject.FindObjectOfType <Camera>();
            }

            if (canvas != null)
            {
                canvas.worldCamera = camera;
            }

            Animator animator = instance.GetComponentInChildren <Animator>();
            Text     text     = instance.GetComponentInChildren <Text>();

            text.text  = message;
            text.color = color;

            LookAtConstraint constraint = instance.GetComponent <LookAtConstraint>();

            if (constraint != null)
            {
                constraint.SetSources(new List <ConstraintSource>()
                {
                    new ConstraintSource()
                    {
                        sourceTransform = HookCamera.Instance.transform,
                        weight          = 1.0f
                    }
                });

                constraint.constraintActive = true;
            }

            WaitForSecondsRealtime wait = new WaitForSecondsRealtime(duration - TRANSITION_TIME);

            yield return(wait);

            if (animator != null)
            {
                animator.SetTrigger(ANIMATOR_HASH_CLOSE);
            }

            wait = new WaitForSecondsRealtime(TRANSITION_TIME);
            yield return(wait);

            if (instance != null)
            {
                GameObject.Destroy(instance);
            }
        }
Exemple #7
0
    // Start is called before the first frame update
    void Start()
    {
        LookAtConstraint lac = GetComponent <LookAtConstraint>();

        if (lac)
        {
            ConstraintSource src = new ConstraintSource();
            src.sourceTransform = UnityEngine.GameObject.FindGameObjectWithTag("Player").transform;
            src.weight          = 1;
            lac.AddSource(src);
            lac.constraintActive = true;
        }

        float max_audio_len = 0, max_part_len = 0;

        foreach (AudioSource aud in GetComponentsInChildren <AudioSource>())
        {
            if (!aud.clip)
            {
                continue;
            }
            if (vol != -1)
            {
                aud.volume = vol;
            }
            aud.outputAudioMixerGroup = mixerGroup;
            aud.pitch  += Random.Range(-pitch_range, pitch_range);
            aud.volume += Random.Range(-amp_range, 0);
            if (mixerGroup)
            {
                aud.outputAudioMixerGroup = mixerGroup;
            }
            if (aud.clip.length > max_audio_len)
            {
                max_audio_len = aud.clip.length;
            }
        }
        foreach (ParticleSystem part in GetComponentsInChildren <ParticleSystem>())
        {
            if (part.main.duration > max_part_len)
            {
                max_part_len = part.main.duration;
            }
        }
        if (live_forever)
        {
            lifetime = float.MaxValue;
        }
        else
        {
            lifetime = Mathf.Max(lifetime, max_audio_len);
            lifetime = Mathf.Max(lifetime, max_part_len);
            Destroy(gameObject, lifetime);
        }
    }
Exemple #8
0
 void OnToggleLookAtConstraint()
 {
     foreach (var selected in Selection.SelectedObjects)
     {
         LookAtConstraint constraint = selected.GetComponent <LookAtConstraint>();
         if (null != constraint)
         {
             constraint.constraintActive = !constraint.constraintActive;
         }
     }
 }
Exemple #9
0
 void Start()
 {
     ovrInput         = GameObject.Find("OVRControllerInput").GetComponent <OVRControllerInputProvider>();
     lookAtConstraint = RController.GetComponent <LookAtConstraint>();
     lookAtConstraint.constraintActive = false;
     Destroy(RConfigurableJoint);
     Destroy(LConfigurableJoint);
     hasLJoint         = false;
     hasRJoint         = false;
     originalTransform = gameObject.transform;
 }
Exemple #10
0
    void createCamera(Vector3 position)
    {
        _camera = new GameObject("Camera");
        Camera           camComponent = _camera.AddComponent <Camera>();
        LookAtConstraint lac          = _camera.AddComponent <LookAtConstraint>();

        lac.constraintActive          = true;
        _camera.transform.position    = new Vector3(position.x, position.y, 0);
        camComponent.orthographic     = true;
        camComponent.orthographicSize = 4.6f;
        camComponent.clearFlags       = CameraClearFlags.SolidColor;
        camComponent.backgroundColor  = Color.white;
    }
    // Start is called before the first frame update
    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player").transform;

        PositionConstraint posConstraint = GetComponent <PositionConstraint>();

        posConstraint.ClearSources();
        posConstraint.AddTransform(player);

        LookAtConstraint lookConstraint = Camera.main.GetComponent <LookAtConstraint>();

        lookConstraint.ClearSources();
        lookConstraint.AddTransform(player.Find("LookAtTarget"));
    }
Exemple #12
0
        bool HasParentOrConstraintSelected(Transform t, ref string parentLayerName)
        {
            Transform parent = t.parent;

            while (null != parent && parent.name != "RightHanded")
            {
                if (Selection.IsSelected(parent.gameObject))
                {
                    parentLayerName = LayerMask.LayerToName(parent.gameObject.layer);
                    return(true);
                }
                parent = parent.parent;
            }

            ParentConstraint constraint = t.gameObject.GetComponent <ParentConstraint>();

            if (null != constraint)
            {
                if (constraint.sourceCount > 0)
                {
                    GameObject sourceObject = constraint.GetSource(0).sourceTransform.gameObject;
                    if (Selection.IsSelected(sourceObject))
                    {
                        parentLayerName = LayerMask.LayerToName(sourceObject.layer);
                        return(true);
                    }
                }
            }

            LookAtConstraint lookAtConstraint = t.gameObject.GetComponent <LookAtConstraint>();

            if (null != lookAtConstraint)
            {
                if (lookAtConstraint.sourceCount > 0)
                {
                    ConstraintSource constraintSource = lookAtConstraint.GetSource(0);
                    GameObject       sourceObject     = constraintSource.sourceTransform.gameObject;
                    if (Selection.IsSelected(lookAtConstraint.GetSource(0).sourceTransform.gameObject))
                    {
                        parentLayerName = LayerMask.LayerToName(sourceObject.layer);
                        return(true);
                    }
                }
            }

            return(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;
    }
    /// <summary>
    /// This script will make sure that the lookatConstraint of this object will look at the main camera
    /// </summary>
    public void FindCamera()
    {
        //We get the camera
        GameObject[] cameras = GameObject.FindGameObjectsWithTag("MainCamera");
        if (cameras.Length <= 0)
        {
            return;
        }
        GameObject mainCamera = cameras[0];

        //Then the lookatConstraint
        LookAtConstraint lookAtConstraint = this.GetComponent <LookAtConstraint>();

        //And add the constraint
        ConstraintSource constraint = new ConstraintSource();

        constraint.sourceTransform = mainCamera.transform;
        constraint.weight          = 1f;
        lookAtConstraint.AddSource(constraint);
    }
Exemple #15
0
    public void AddEye(LookAtConstraint eye)
    {
        if (eye != null)
        {
            if (eyes.Count == 0)
            {
                eyeMaterial = new Material(eye.GetComponent <MeshRenderer>().material);
                InitializeCharacterEmotion();
            }
            eyesLookAt.Add(eye);
            eyes.Add(eye.GetComponent <MeshRenderer>());

            Material[] materials = eyes[eyes.Count - 1].materials;
            for (int i = 0; i < materials.Length; i++)
            {
                materials[0] = eyeMaterial;
            }
            eyes[eyes.Count - 1].materials = materials;
        }
    }
        private void Setup()
        {
            LookAtConstraint constraint = GetComponent <LookAtConstraint>();

            if (constraint == null)
            {
                constraint = gameObject.AddComponent <LookAtConstraint>();
            }
            constraint.rotationOffset = new Vector3(0, 180, 0);
            constraint.SetSources(new List <ConstraintSource>()
            {
                new ConstraintSource()
                {
                    sourceTransform = HookCamera.Instance.transform,
                    weight          = 1.0f
                }
            });

            constraint.constraintActive = true;

            enabled = false;
            Destroy(this);
        }
 public static Tween TweenRoll(this LookAtConstraint constraint, float to, float duration) =>
 Tweening.To(getter: () => constraint.roll,
             setter: roll => constraint.roll = roll,
             to, duration).SetTarget(constraint);
Exemple #18
0
        public void FixSpecialPoints()
        {
            if (!source)
            {
                source = GetComponent <HandSearchEngine>();
            }

            Transform wrist    = hand.wristPoint.original;
            Transform index1   = hand.index1Point.original;
            Transform middle1  = hand.middle1Point.original;
            Transform ring1    = hand.middle1Point.original;
            Transform pinky1   = hand.pinky1Point.original;
            Transform thumb1   = hand.thumb1Point.original;
            Transform indexTip = hand.indexTipPoint.original;
            Transform thumbTip = hand.thumbTipPoint.original;

            Vector3 wristToRing1  = ring1.position - wrist.position;
            Vector3 wristToIndex1 = index1.position - wrist.position;

            Vector3 worldPalmNormalDir;

            if (side == Side.Left)
            {
                worldPalmNormalDir = Vector3.Cross(wristToIndex1, wristToRing1);
            }
            else
            {
                worldPalmNormalDir = Vector3.Cross(wristToRing1, wristToIndex1);
            }

            Vector3 frontFingerCenter  = (index1.position + middle1.position + ring1.position + pinky1.position) / 4.0f;
            Vector3 worldPalmCenterPos = (wrist.position * centerRange + frontFingerCenter * (1.0f - centerRange));

            Vector3 centerToWristDir             = wrist.position - worldPalmCenterPos;
            Vector3 frontFingerCenterToIndex1Dir = index1.position - frontFingerCenter;

            Vector3 frontFingerCenterToIndex = index1.position - frontFingerCenter;

            if (!specialPoints.palmCenterPoint.original)
            {
                specialPoints.palmCenterPoint.original          = BasicHelpers.InstantiateEmptyChild(wrist.gameObject, "PalmCenter." + side.ToString()).transform;
                specialPoints.palmCenterPoint.original.position = worldPalmCenterPos + (worldPalmNormalDir * centerToSurfaceDistance);
                specialPoints.palmCenterPoint.original.rotation = Quaternion.LookRotation(Vector3.Cross(centerToWristDir, frontFingerCenterToIndex1Dir), frontFingerCenterToIndex1Dir);
            }

            if (!specialPoints.palmNormalPoint.original)
            {
                specialPoints.palmNormalPoint.original          = BasicHelpers.InstantiateEmptyChild(wrist.gameObject, "PalmNormal." + side.ToString()).transform;
                specialPoints.palmNormalPoint.original.position = worldPalmCenterPos + (worldPalmNormalDir * centerToSurfaceDistance);
                specialPoints.palmNormalPoint.original.rotation = Quaternion.LookRotation(worldPalmNormalDir, frontFingerCenterToIndex1Dir);
            }

            if (!specialPoints.palmInteriorPoint.original)
            {
                specialPoints.palmInteriorPoint.original          = BasicHelpers.InstantiateEmptyChild(wrist.gameObject, "PalmInterior." + side.ToString()).transform;
                specialPoints.palmInteriorPoint.original.rotation = specialPoints.palmCenterPoint.original.rotation;
                specialPoints.palmInteriorPoint.original.position = specialPoints.palmCenterPoint.original.position + frontFingerCenterToIndex;
            }

            if (!specialPoints.palmExteriorPoint.original)
            {
                specialPoints.palmExteriorPoint.original          = BasicHelpers.InstantiateEmptyChild(wrist.gameObject, "PalmExterior." + side.ToString()).transform;
                specialPoints.palmExteriorPoint.original.rotation = specialPoints.palmCenterPoint.original.rotation;
                specialPoints.palmExteriorPoint.original.position = specialPoints.palmCenterPoint.original.position - frontFingerCenterToIndex;
            }

            if (!specialPoints.rayPoint.original)
            {
                specialPoints.rayPoint.original          = BasicHelpers.InstantiateEmptyChild(wrist.gameObject, "Ray." + side.ToString()).transform;
                specialPoints.rayPoint.original.position = specialPoints.palmCenterPoint.original.position;
                specialPoints.rayPoint.original.rotation = specialPoints.palmNormalPoint.original.rotation;
            }

            if (!specialPoints.pinchCenterPoint.original)
            {
                specialPoints.pinchCenterPoint.original = BasicHelpers.InstantiateEmptyChild(wrist.gameObject, "PinchCenter." + side.ToString()).transform;
            }

            if (!specialPoints.throatCenterPoint.original)
            {
                specialPoints.throatCenterPoint.original = BasicHelpers.InstantiateEmptyChild(wrist.gameObject, "ThroatCenter." + side.ToString()).transform;
            }

            PositionConstraint pinchPosConstraint = specialPoints.pinchCenterPoint.original.GetComponent <PositionConstraint>();
            LookAtConstraint   pinchRotConstraint = specialPoints.pinchCenterPoint.original.GetComponent <LookAtConstraint>();

            PositionConstraint throatPosConstraint = specialPoints.throatCenterPoint.original.GetComponent <PositionConstraint>();
            LookAtConstraint   throatRotConstraint = specialPoints.throatCenterPoint.original.GetComponent <LookAtConstraint>();

            ConstraintSource indexTipSource = new ConstraintSource();

            indexTipSource.sourceTransform = indexTip;
            indexTipSource.weight          = 1.0f;

            ConstraintSource index1Source = new ConstraintSource();

            index1Source.sourceTransform = index1;
            index1Source.weight          = 1.0f;

            ConstraintSource thumbTipSource = new ConstraintSource();

            thumbTipSource.sourceTransform = thumbTip;
            thumbTipSource.weight          = 1.0f;

            ConstraintSource thumb1Source = new ConstraintSource();

            thumb1Source.sourceTransform = thumb1;
            thumb1Source.weight          = 1.0f;

            if (pinchPosConstraint == null)
            {
                pinchPosConstraint = specialPoints.pinchCenterPoint.original.gameObject.AddComponent <PositionConstraint>();
                pinchPosConstraint.constraintActive = true;
                pinchPosConstraint.AddSource(indexTipSource);
                pinchPosConstraint.AddSource(thumbTipSource);

                pinchPosConstraint.locked            = false;
                pinchPosConstraint.translationOffset = pinchPosConstraint.translationAtRest = Vector3.zero;
                pinchPosConstraint.locked            = true;
            }

            if (pinchRotConstraint == null)
            {
                pinchRotConstraint = specialPoints.pinchCenterPoint.original.gameObject.AddComponent <LookAtConstraint>();
                pinchRotConstraint.constraintActive = true;
                pinchRotConstraint.AddSource(indexTipSource);

                pinchRotConstraint.locked         = false;
                pinchRotConstraint.rotationOffset = pinchRotConstraint.rotationAtRest = Vector3.zero;
                pinchRotConstraint.locked         = true;
            }

            if (throatPosConstraint == null)
            {
                throatPosConstraint = specialPoints.throatCenterPoint.original.gameObject.AddComponent <PositionConstraint>();
                throatPosConstraint.constraintActive = true;
                throatPosConstraint.AddSource(index1Source);
                throatPosConstraint.AddSource(thumb1Source);

                throatPosConstraint.locked            = false;
                throatPosConstraint.translationOffset = throatPosConstraint.translationAtRest = Vector3.zero;
                throatPosConstraint.locked            = true;
            }

            if (throatRotConstraint == null)
            {
                throatRotConstraint = specialPoints.throatCenterPoint.original.gameObject.AddComponent <LookAtConstraint>();
                throatRotConstraint.constraintActive = true;
                throatRotConstraint.AddSource(indexTipSource);

                throatRotConstraint.locked         = false;
                throatRotConstraint.rotationOffset = throatRotConstraint.rotationAtRest = Vector3.zero;
                throatRotConstraint.locked         = true;
            }
        }
Exemple #19
0
        void UpdateUIOnSelectionChanged(HashSet <GameObject> _, HashSet <GameObject> __)
        {
            if (null == selectedObjectNameLabel)
            {
                return;
            }
            // Clear
            selectedObjectNameLabel.Text = "";

            enableParentButton.Checked = false;
            parentTargetLabel.Text     = "";

            enableLookAtButton.Checked = false;
            lookAtTargetLabel.Text     = "";

            posLockButton.Checked   = false;
            rotLockButton.Checked   = false;
            scaleLockButton.Checked = false;

            GameObject selected = null;

            foreach (GameObject gobject in Selection.SelectedObjects)
            {
                selected = gobject;
                break;
            }

            if (null == selected)
            {
                return;
            }

            // Selected label
            if (Selection.SelectedObjects.Count > 1)
            {
                selectedObjectNameLabel.Text = $"{Selection.SelectedObjects.Count} objects selected";
            }
            else
            {
                selectedObjectNameLabel.Text = selected.name;
            }
            selectedObjectNameLabel.Text = "<color=#0079FF>" + selectedObjectNameLabel.Text + "</color>";

            // Transform
            UpdateTransformUI(selected);

            // Constraints
            ParentConstraint parentConstraint = selected.GetComponent <ParentConstraint>();

            if (null != parentConstraint && parentConstraint.sourceCount > 0)
            {
                enableParentButton.Checked = parentConstraint.constraintActive;
                parentTargetLabel.Text     = parentConstraint.GetSource(0).sourceTransform.name;
            }

            LookAtConstraint lookAtConstraint = selected.GetComponent <LookAtConstraint>();

            if (null != lookAtConstraint && lookAtConstraint.sourceCount > 0)
            {
                enableLookAtButton.Checked = lookAtConstraint.constraintActive;
                lookAtTargetLabel.Text     = lookAtConstraint.GetSource(0).sourceTransform.name;
            }
        }
 public static Tween TweenRotationAtRest(this LookAtConstraint constraint, Vector3 to, float duration) =>
 Tweening.To(getter: () => constraint.rotationAtRest,
             setter: rotationAtRest => constraint.rotationAtRest = rotationAtRest,
             to, duration).SetTarget(constraint);
Exemple #21
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);
        }
 public static Tween TweenWeight(this LookAtConstraint constraint, float to, float duration) =>
 Tweening.To(getter: () => constraint.weight,
             setter: weight => constraint.weight = weight,
             to, duration).SetTarget(constraint);
Exemple #23
0
 void Start()
 {
     lookAtConstraint = RController.GetComponent <LookAtConstraint>();
     lookAtConstraint.constraintActive = true;
 }