コード例 #1
0
ファイル: Reactor.cs プロジェクト: UnityEQ/UnityEQWebGL
                // Use reflection to find the named float field
                public static TargetBinding BindTarget(GameObject target, string fieldName)
                {
                    fieldName = fieldName.Trim();
                    TargetBinding binding = new TargetBinding();

                    GameObjectFieldScanner scanner = new GameObjectFieldScanner();

                    scanner.OnLeafField = (fullName, fieldInfo, rootFieldOwner, value) =>
                    {
                        //Debug.Log(fullName);
                        if (fullName == fieldName)
                        {
                            binding.mTargetFieldInfo     = fieldInfo.ToArray();
                            binding.mTargetFieldOwner    = new object[binding.mTargetFieldInfo.Length];
                            binding.mTargetFieldOwner[0] = rootFieldOwner;
                            binding.mInitialValue        = Convert.ToSingle(value);
                            return(false); // abort scan, we're done
                        }
                        return(true);
                    };
                    scanner.ScanFields(target);

                    if (!binding.IsValid)
                    {
                        CinemachineDebugLogger.LogWarn(
                            GetFullName(target) + " Reactor: can't find " +
                            ((fieldName.Length == 0) ? "(empty)" : fieldName));
                    }

                    return(binding);
                }
コード例 #2
0
        private float GetTargetHeading(float currentHeading, Vector3 up, float deltaTime)
        {
            if (VirtualCamera.Follow == null)
            {
                return(currentHeading);
            }

            if (m_RecenterToTargetHeading.m_HeadingDerivationMode
                == Recentering.HeadingDerivationMode.Velocity &&
                mTargetRigidBody == null)
            {
                CinemachineDebugLogger.LogWarn(
                    "Attempted to use HeadingDerivationMode.Velocity to calculate heading for {0}. No RigidBody was present on '{1}'. Defaulting to position delta",
                    GetFullName(VirtualCamera.VirtualCameraGameObject), VirtualCamera.Follow);
                m_RecenterToTargetHeading.m_HeadingDerivationMode
                    = Recentering.HeadingDerivationMode.PositionDelta;
            }

            Vector3 velocity = Vector3.zero;

            switch (m_RecenterToTargetHeading.m_HeadingDerivationMode)
            {
            case Recentering.HeadingDerivationMode.PositionDelta:
                velocity = VirtualCamera.Follow.position - mLastTargetPosition;
                break;

            case Recentering.HeadingDerivationMode.Velocity:
                velocity = mTargetRigidBody.velocity;
                break;

            default:
            case Recentering.HeadingDerivationMode.EulerYRotation:
                return(VirtualCamera.Follow.rotation.eulerAngles.y);

            case Recentering.HeadingDerivationMode.WorldHeading:
                return(m_RecenterToTargetHeading.m_WorldDefaultHeading);
            }

            // Process the velocity and derive the heading from it.
            int filterSize = m_RecenterToTargetHeading.m_VelocityFilterStrength * 5;

            if (mHeadingTracker == null || mHeadingTracker.FilterSize != filterSize)
            {
                mHeadingTracker = new HeadingTracker(filterSize);
            }
            mHeadingTracker.DecayHistory();
            velocity = velocity.ProjectOntoPlane(up);
            if (!velocity.AlmostZero())
            {
                mHeadingTracker.Add(velocity);
            }

            velocity = mHeadingTracker.GetReliableHeading();
            if (!velocity.AlmostZero())
            {
                Vector3 fwd = (-GetBackVector(up)).ProjectOntoPlane(up);
                return(UnityVectorExtensions.SignedAngle(fwd, velocity, up));
            }

            // If no reliable heading, then stay where we are.
            return(currentHeading);
        }