コード例 #1
0
        // Update the (possibly) ongoing interaction
        public void Update(Transform root, float speed)
        {
            if (!inInteraction)
            {
                // If the InteractionObject has been destroyed, reset to defaults
                if (started)
                {
                    isPaused   = false;
                    pickedUp   = false;
                    defaults   = false;
                    resetTimer = 1f;
                    started    = false;
                }
                return;
            }

            // Rotate target
            if (interactionTarget != null && !interactionTarget.rotateOnce)
            {
                interactionTarget.RotateTo(effector.bone.position);
            }

            if (isPaused)
            {
                effector.position = target.TransformPoint(pausePositionRelative);
                effector.rotation = target.rotation * pauseRotationRelative;

                // Apply the current interaction state to the solver
                interactionObject.Apply(interactionSystem.ik.solver, effectorType, interactionTarget, timer, weight);

                return;
            }

            // Advance the interaction timer and weight
            timer += Time.deltaTime * speed * (interactionTarget != null? interactionTarget.interactionSpeedMlp: 1f);
            weight = Mathf.Clamp(weight + Time.deltaTime * fadeInSpeed * speed, 0f, 1f);

            // Interaction events
            bool pickUp = false;
            bool pause  = false;

            TriggerUntriggeredEvents(true, out pickUp, out pause);

            // Effector target positions and rotations
            Vector3    targetPosition = pickedUp? pickUpPosition: target.position;
            Quaternion targetRotation = pickedUp? pickUpRotation: target.rotation;

            // Interpolate effector position and rotation
            effector.position = Vector3.Lerp(effector.bone.position, targetPosition, weight);
            effector.rotation = Quaternion.Lerp(effector.bone.rotation, targetRotation, weight);

            // Apply the current interaction state to the solver
            interactionObject.Apply(interactionSystem.ik.solver, effectorType, interactionTarget, timer, weight);

            if (pickUp)
            {
                PickUp(root);
            }
            if (pause)
            {
                Pause();
            }

            // Hand poser weight
            float poserWeight = interactionObject.GetValue(InteractionObject.WeightCurve.Type.PoserWeight, interactionTarget, timer);

            if (poser != null)
            {
                poser.weight = Mathf.Lerp(poser.weight, poserWeight, weight);
            }
            else
            {
                if (poserWeight > 0f)
                {
                    Warning.Log("InteractionObject " + interactionObject.name + " has a curve/multipler for Poser Weight, but the bone of effector " + effectorType.ToString() + " has no HandPoser/GenericPoser attached.", effector.bone);
                }
            }

            if (timer >= length)
            {
                Stop();
            }
        }
コード例 #2
0
        // Update the (possibly) ongoing interaction
        public void Update(IKSolverFullBodyBiped solver, float speed)
        {
            if (!inInteraction)
            {
                return;
            }

            // Rotate target
            if (interactionTarget != null && !interactionTarget.rotateOnce)
            {
                interactionTarget.RotateTo(effector.bone.position);
            }

            if (isPaused)
            {
                effector.position = target.TransformPoint(pausePositionRelative);
                effector.rotation = target.rotation * pauseRotationRelative;

                // Apply the current interaction state to the solver
                interactionObject.Apply(solver, effectorType, interactionTarget, timer, weight);

                return;
            }

            // Advance the interaction timer and weight
            timer += Time.deltaTime * speed * (interactionTarget != null? interactionTarget.interactionSpeedMlp: 1f);
            weight = Mathf.Clamp(weight + Time.deltaTime * fadeInSpeed, 0f, 1f);

            if (!triggered && timer >= interactionObject.triggerTime)
            {
                timer = interactionObject.triggerTime;
            }

            // Effector target positions and rotations
            Vector3    targetPosition = pickedUp? pickUpPosition: target.position;
            Quaternion targetRotation = pickedUp? pickUpRotation: target.rotation;

            // Interpolate effector position and rotation
            effector.position = Vector3.Lerp(effector.position, targetPosition, weight * weight);
            effector.rotation = Quaternion.Lerp(effector.rotation, targetRotation, weight * weight);

            // Apply the current interaction state to the solver
            interactionObject.Apply(solver, effectorType, interactionTarget, timer, weight);

            // Hand poser weight
            if (poser != null)
            {
                poser.weight = pickedUp? 1f: effector.positionWeight;
            }

            // Interaction events
            if (!triggered && timer >= interactionObject.triggerTime)
            {
                Trigger();
            }
            if (!released && timer >= interactionObject.releaseTime)
            {
                Release();
            }
            if (timer >= length)
            {
                Stop();
            }
        }
コード例 #3
0
        // Start interaction
        public bool Start(InteractionObject interactionObject, string tag, float fadeInTime, bool interrupt)
        {
            // If not in interaction, set effector positions to their bones
            if (!inInteraction)
            {
                effector.position = effector.bone.position;;
                effector.rotation = effector.bone.rotation;;
            }
            else
            {
                if (!interrupt)
                {
                    return(false);
                }
            }

            // Get the InteractionTarget
            target = interactionObject.GetTarget(effectorType, tag);
            if (target == null)
            {
                return(false);
            }
            interactionTarget = target.GetComponent <InteractionTarget>();

            // Start the interaction
            this.interactionObject = interactionObject;
            if (interactionSystem.OnInteractionStart != null)
            {
                interactionSystem.OnInteractionStart(effectorType, interactionObject);
            }
            interactionObject.OnStartInteraction(interactionSystem);

            // Cleared triggered events
            triggered.Clear();

            for (int i = 0; i < interactionObject.events.Length; i++)
            {
                triggered.Add(false);
            }

            // Posing the hand/foot
            if (poser != null)
            {
                if (poser.poseRoot == null)
                {
                    poser.weight = 0f;
                }

                if (interactionTarget != null)
                {
                    poser.poseRoot = target.transform;
                }
                else
                {
                    poser.poseRoot = null;
                }

                poser.AutoMapping();
            }

            // See which InteractionObject.WeightCurve.Types are used
            //private bool positionWeightUsed, rotationWeightUsed, pullUsed, reachUsed, pushUsed, pushParentUsed, poserUsed;
            positionWeightUsed = interactionObject.CurveUsed(InteractionObject.WeightCurve.Type.PositionWeight);
            rotationWeightUsed = interactionObject.CurveUsed(InteractionObject.WeightCurve.Type.RotationWeight);
            pullUsed           = interactionObject.CurveUsed(InteractionObject.WeightCurve.Type.Pull);
            reachUsed          = interactionObject.CurveUsed(InteractionObject.WeightCurve.Type.Reach);
            pushUsed           = interactionObject.CurveUsed(InteractionObject.WeightCurve.Type.Push);
            pushParentUsed     = interactionObject.CurveUsed(InteractionObject.WeightCurve.Type.PushParent);
            //poserUsed = interactionObject.CurveUsed(InteractionObject.WeightCurve.Type.PoserWeight);
            StoreDefaults();

            // Reset internal values
            timer       = 0f;
            weight      = 0f;
            fadeInSpeed = fadeInTime > 0f? 1f / fadeInTime: 1000f;
            length      = interactionObject.length;

            isPaused       = false;
            pickedUp       = false;
            pickUpPosition = Vector3.zero;
            pickUpRotation = Quaternion.identity;

            if (interactionTarget != null)
            {
                interactionTarget.RotateTo(effector.bone.position);
            }

            started = true;

            return(true);
        }
コード例 #4
0
        // Start interaction
        public void Start(InteractionObject interactionObject, string tag, float fadeInTime, bool interrupt)
        {
            // If not in interaction, set effector positions to their bones
            if (!inInteraction)
            {
                effector.position = effector.bone.position;
                effector.rotation = effector.bone.rotation;
            }
            else if (!interrupt)
            {
                return;
            }

            // Get the InteractionTarget
            target = interactionObject.GetTarget(effectorType, tag);
            if (target == null)
            {
                return;
            }
            interactionTarget = target.GetComponent <InteractionTarget>();

            // Start the interaction
            this.interactionObject = interactionObject;
            if (OnStart != null)
            {
                OnStart(effectorType, interactionObject);
            }

            // Posing the hand/foot
            if (poser != null)
            {
                if (poser.poseRoot == null)
                {
                    poser.weight = 0f;
                }

                if (interactionTarget != null)
                {
                    poser.poseRoot = target.transform;
                }
                else
                {
                    poser.poseRoot = null;
                }

                poser.AutoMapping();
            }

            // Reset internal values
            timer       = 0f;
            weight      = 0f;
            fadeInSpeed = fadeInTime > 0f? 1f / fadeInTime: 1000f;
            length      = interactionObject.length;

            triggered = false;
            released  = false;
            isPaused  = false;

            pickedUp       = false;
            pickUpPosition = Vector3.zero;
            pickUpRotation = Quaternion.identity;

            // Call StartInteraction on the InteractionObject
            interactionObject.StartInteraction(effector.bone);
            if (interactionTarget != null)
            {
                interactionTarget.RotateTo(effector.bone.position);
            }
        }
コード例 #5
0
		// Start interaction
		public bool Start(InteractionObject interactionObject, string tag, float fadeInTime, bool interrupt) {
			// If not in interaction, set effector positions to their bones
			if (!inInteraction) {
				effector.position = effector.bone.position;;
				effector.rotation = effector.bone.rotation;;
			} else {
				if (!interrupt) return false;
			}

			// Get the InteractionTarget
			target = interactionObject.GetTarget(effectorType, tag);
			if (target == null) return false;
			interactionTarget = target.GetComponent<InteractionTarget>();

			// Start the interaction
			this.interactionObject = interactionObject;
			if (interactionSystem.OnInteractionStart != null) interactionSystem.OnInteractionStart(effectorType, interactionObject);
			interactionObject.OnStartInteraction(interactionSystem);
			
			// Cleared triggered events
			triggered.Clear();

			for (int i = 0; i < interactionObject.events.Length; i++) {
				triggered.Add(false);
			}

			// Posing the hand/foot
			if (poser != null) {
				if (poser.poseRoot == null) poser.weight = 0f;

				if (interactionTarget != null) poser.poseRoot = target.transform;
				else poser.poseRoot = null;

				poser.AutoMapping();
			}

			// Reset internal values
			timer = 0f;
			weight = 0f;
			fadeInSpeed = fadeInTime > 0f? 1f / fadeInTime: 1000f;
			length = interactionObject.length;
			
			isPaused = false;
			pickedUp = false;
			pickUpPosition = Vector3.zero;
			pickUpRotation = Quaternion.identity;

			if (interactionTarget != null) interactionTarget.RotateTo(effector.bone.position);

			started = true;

			return true;
		}
コード例 #6
0
        // Update the (possibly) ongoing interaction
        public void Update(Transform root, IKSolverFullBodyBiped solver, float speed)
        {
            if (!inInteraction)
            {
                return;
            }

            // Rotate target
            if (interactionTarget != null && !interactionTarget.rotateOnce)
            {
                interactionTarget.RotateTo(effector.bone.position);
            }

            if (isPaused)
            {
                effector.position = target.TransformPoint(pausePositionRelative);
                effector.rotation = target.rotation * pauseRotationRelative;

                // Apply the current interaction state to the solver
                interactionObject.Apply(solver, effectorType, interactionTarget, timer, weight);

                return;
            }

            // Advance the interaction timer and weight
            timer += Time.deltaTime * speed * (interactionTarget != null? interactionTarget.interactionSpeedMlp: 1f);
            weight = Mathf.Clamp(weight + Time.deltaTime * fadeInSpeed, 0f, 1f);

            // Interaction events
            bool pickUp = false;
            bool pause  = false;

            TriggerUntriggeredEvents(true, out pickUp, out pause);

            // Effector target positions and rotations
            Vector3    targetPosition = pickedUp? pickUpPosition: target.position;
            Quaternion targetRotation = pickedUp? pickUpRotation: target.rotation;

            // Interpolate effector position and rotation
            effector.position = Vector3.Lerp(effector.bone.position, targetPosition, weight);
            effector.rotation = Quaternion.Lerp(effector.bone.rotation, targetRotation, weight);

            // Apply the current interaction state to the solver
            interactionObject.Apply(solver, effectorType, interactionTarget, timer, weight);

            if (pickUp)
            {
                PickUp(root);
            }
            if (pause)
            {
                Pause();
            }

            // Hand poser weight
            if (poser != null)
            {
                poser.weight = Mathf.Lerp(poser.weight, interactionObject.GetValue(InteractionObject.WeightCurve.Type.PoserWeight, interactionTarget, timer), weight);
            }

            if (timer >= length)
            {
                Stop();
            }
        }
コード例 #7
0
        // Start interaction
        public bool Start(InteractionObject interactionObject, string tag, float fadeInTime, bool interrupt)
        {
            // If not in interaction, set effector positions to their bones
            if (!inInteraction)
            {
                effector.position = effector.bone.position;;
                effector.rotation = effector.bone.rotation;;
            }
            else
            {
                if (!interrupt)
                {
                    return(false);
                }
            }

            // Get the InteractionTarget
            target = interactionObject.GetTarget(effectorType, tag);
            if (target == null)
            {
                return(false);
            }
            interactionTarget = target.GetComponent <InteractionTarget>();

            // Start the interaction
            this.interactionObject = interactionObject;
            if (interactionSystem.OnInteractionStart != null)
            {
                interactionSystem.OnInteractionStart(effectorType, interactionObject);
            }

            // Cleared triggered events
            triggered.Clear();

            for (int i = 0; i < interactionObject.events.Length; i++)
            {
                triggered.Add(false);
            }

            // Posing the hand/foot
            if (poser != null)
            {
                if (poser.poseRoot == null)
                {
                    poser.weight = 0f;
                }

                if (interactionTarget != null)
                {
                    poser.poseRoot = target.transform;
                }
                else
                {
                    poser.poseRoot = null;
                }

                poser.AutoMapping();
            }

            // Reset internal values
            timer       = 0f;
            weight      = 0f;
            fadeInSpeed = fadeInTime > 0f? 1f / fadeInTime: 1000f;
            length      = interactionObject.length;

            isPaused       = false;
            pickedUp       = false;
            pickUpPosition = Vector3.zero;
            pickUpRotation = Quaternion.identity;

            if (interactionTarget != null)
            {
                interactionTarget.RotateTo(effector.bone.position);
            }

            return(true);
        }
コード例 #8
0
        // Start interaction
        public void Start(InteractionObject interactionObject, string tag, float fadeInTime, bool interrupt)
        {
            // If not in interaction, set effector positions to their bones
            if (!inInteraction) {
                effector.position = effector.bone.position;
                effector.rotation = effector.bone.rotation;
            } else if (!interrupt) return;

            // Get the InteractionTarget
            target = interactionObject.GetTarget(effectorType, tag);
            if (target == null) return;
            interactionTarget = target.GetComponent<InteractionTarget>();

            // Start the interaction
            this.interactionObject = interactionObject;
            if (OnStart != null) OnStart(effectorType, interactionObject);

            // Posing the hand/foot
            if (poser != null) {
                if (poser.poseRoot == null) poser.weight = 0f;

                if (interactionTarget != null) poser.poseRoot = target.transform;
                else poser.poseRoot = null;

                poser.AutoMapping();
            }

            // Reset internal values
            timer = 0f;
            weight = 0f;
            fadeInSpeed = fadeInTime > 0f? 1f / fadeInTime: 1000f;
            length = interactionObject.length;

            triggered = false;
            released = false;
            isPaused = false;

            pickedUp = false;
            pickUpPosition = Vector3.zero;
            pickUpRotation = Quaternion.identity;

            // Call StartInteraction on the InteractionObject
            interactionObject.StartInteraction(effector.bone);
            if (interactionTarget != null) interactionTarget.RotateTo(effector.bone.position);
        }