Beispiel #1
0
        public sealed override void InitExtension(TargetConstraint t)
        {
            base.InitExtension(t);

            if (!maxDistance)
            {
                Debug.LogError("Missing reference to Max Distance");
                return;
            }

            t.axis.position = t.connectedAnchor.position;
            t.axis.LookAt(maxDistance);

            t.setAxisWhenEnabled = true;
            t.SetAxis(t.axis.rotation);

            limit.limit         = Vector3.Distance(t.connectedAnchor.position, maxDistance.position);
            t.joint.linearLimit = limit;
        }
Beispiel #2
0
        void EnableTarget(TargetConstraint t)
        {
            if (!t.pheasy)
            {
                t.pheasy = this;
            }

            if (!t.joint)
            {
                InstantiateJoint(t);
            }

            if (!t.anchor)
            {
                InstantiateAnchor(t);
            }

            if (!t.connectedAnchor)
            {
                InstantiateConnectedAnchor(t);
            }

            if (t.name == null || t.name == "")
            {
                t.name = t.anchor.name + "->" + t.connectedAnchor.name;
            }

            if (t.keepAxisRelativeToObject)
            {
                t.joint.configuredInWorldSpace = false;
            }
            else
            {
                t.joint.configuredInWorldSpace = true;
            }

            if (!t.axis)
            {
                t.setAxisWhenEnabled = false;

                InstantiateAxis(t);
            }
            else
            {
                t.setAxisWhenEnabled = true;

                t.SetAxis(t.axis.rotation);
            }

            if (t.connectedBody)
            {
                t.joint.connectedBody  = t.connectedBody;
                t.initialLocalRotation = t.joint.connectedBody.transform.localRotation;
            }

            t.initialWorldRotation = t.joint.transform.rotation;

            t.jointFrameRotation = t.GetJointAxisWorldRotation();

            if (axis != null)
            {
                if (!t.anchorAxis)
                {
                    t.anchorAxis = Instantiate(axis, rb.transform);
                    UpdateAxis(t.anchorAxis.transform, t.anchor, axisScale);
                }

                if (!t.connAnchorAxis)
                {
                    t.connAnchorAxis = Instantiate(axis, rb.transform);
                    UpdateAxis(t.connAnchorAxis.transform, t.connectedAnchor, axisScale);
                }
            }

            t.gradualLerp = 0.0f;

            t.extensions.ForEach(e => e.InitExtension(t));

            t.enabled = true;
        }