Пример #1
0
    IEnumerator Start()
    {
        if (fireSound)
        {
            if (!audioSource)
            {
                audioSource = GetComponent <AudioSource>();
            }
        }

        if (!audioSource)
        {
            audioSource = gameObject.AddComponent <AudioSource>();
            audioSource.spatialBlend = 1f;
        }

        yield return(new WaitForEndOfFrame());

        playerTr = WheelDriveCustom.s_player.transform;

        //if (fireAtStart)
        //{
        //    yield return new WaitForSeconds(2f);
        //    FireRandomDelayLoop();
        //}

        ConstraintSource cs = new ConstraintSource {
            sourceTransform = playerTr, weight = 1
        };

        lookAtConstraint.RemoveSource(0);
        lookAtConstraint.AddSource(cs);
    }
Пример #2
0
    private void Start()
    {
        LookAtConstraint c = GetComponent <LookAtConstraint>();
        ConstraintSource constraintSource = new ConstraintSource {
            sourceTransform = Camera.main.transform, weight = 1
        };

        c.AddSource(constraintSource);
    }
Пример #3
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);
    }
Пример #4
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);
        }
    }
Пример #5
0
    /// <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);
    }
Пример #6
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;
            }
        }
Пример #7
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);
        }