예제 #1
0
        private int LocateExistingRigs(string[] rigNames, bool forceOrbital)
        {
            mOrbitals = new CinemachineOrbitalTransposer[rigNames.Length];
            m_Rigs    = new CinemachineVirtualCamera[rigNames.Length];
            int rigsFound = 0;

            foreach (Transform child in transform)
            {
                CinemachineVirtualCamera vcam = child.GetComponent <CinemachineVirtualCamera>();
                if (vcam != null)
                {
                    GameObject go = child.gameObject;
                    for (int i = 0; i < rigNames.Length; ++i)
                    {
                        if (mOrbitals[i] == null && go.name == rigNames[i])
                        {
                            // Must have an orbital transposer or it's no good
                            mOrbitals[i] = vcam.GetCinemachineComponent <CinemachineOrbitalTransposer>();
                            if (mOrbitals[i] == null && forceOrbital)
                            {
                                mOrbitals[i] = vcam.AddCinemachineComponent <CinemachineOrbitalTransposer>();
                            }
                            if (mOrbitals[i] != null)
                            {
                                mOrbitals[i].m_HeadingIsSlave = true;
                                if (i == 0)
                                {
                                    mOrbitals[i].HeadingUpdater
                                        = (CinemachineOrbitalTransposer orbital, float deltaTime, Vector3 up)
                                          => { return(orbital.UpdateHeading(deltaTime, up, ref m_XAxis)); }
                                }
                                ;
                                m_Rigs[i] = vcam;
                                ++rigsFound;
                            }
                        }
                    }
                }
            }
            return(rigsFound);
        }

        void PushSettingsToRigs()
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFreeLook.PushSettingsToRigs");
            UpdateRigCache();
            for (int i = 0; i < m_Rigs.Length; ++i)
            {
                //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFreeLook.PushSettingsToRigs.m_Rigs[i] == null");
                if (m_Rigs[i] == null)
                {
                    //UnityEngine.Profiling.Profiler.EndSample();
                    continue;
                }
                //UnityEngine.Profiling.Profiler.EndSample();

                //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFreeLook.PushSettingsToRigs.m_CommonLens");
                if (m_CommonLens)
                {
                    m_Rigs[i].m_Lens = m_Lens;
                }
                //UnityEngine.Profiling.Profiler.EndSample();

                // If we just deserialized from a legacy version,
                // pull the orbits and targets from the rigs
                //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFreeLook.PushSettingsToRigs.mUseLegacyRigDefinitions");
                if (mUseLegacyRigDefinitions)
                {
                    mUseLegacyRigDefinitions = false;
                    m_Orbits[i].m_Height     = mOrbitals[i].m_FollowOffset.y;
                    m_Orbits[i].m_Radius     = -mOrbitals[i].m_FollowOffset.z;
                    if (m_Rigs[i].Follow != null)
                    {
                        Follow = m_Rigs[i].Follow;
                    }
                }
                m_Rigs[i].Follow = null;
                //UnityEngine.Profiling.Profiler.EndSample();

                // Hide the rigs from prying eyes
                //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFreeLook.PushSettingsToRigs.Hide the rigs");
                if (CinemachineCore.sShowHiddenObjects)
                {
                    m_Rigs[i].gameObject.hideFlags
                        &= ~(HideFlags.HideInHierarchy | HideFlags.HideInInspector);
                }
                else
                {
                    m_Rigs[i].gameObject.hideFlags
                        |= (HideFlags.HideInHierarchy | HideFlags.HideInInspector);
                }
                //UnityEngine.Profiling.Profiler.EndSample();

                //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFreeLook.PushSettingsToRigs.Push");
                mOrbitals[i].m_FollowOffset            = GetLocalPositionForCameraFromInput(m_YAxis.Value);
                mOrbitals[i].m_BindingMode             = m_BindingMode;
                mOrbitals[i].m_Heading                 = m_Heading;
                mOrbitals[i].m_XAxis                   = m_XAxis;
                mOrbitals[i].m_RecenterToTargetHeading = m_RecenterToTargetHeading;
                if (i > 0)
                {
                    mOrbitals[i].m_RecenterToTargetHeading.m_enabled = false;
                }

                // Hack to get SimpleFollow with heterogeneous dampings to work
                if (m_BindingMode == CinemachineTransposer.BindingMode.SimpleFollowWithWorldUp)
                {
                    m_Rigs[i].SetStateRawPosition(State.RawPosition);
                }

                //UnityEngine.Profiling.Profiler.EndSample();
            }
            //UnityEngine.Profiling.Profiler.EndSample();
        }
예제 #2
0
        private CinemachineVirtualCamera[] CreateRigs(CinemachineVirtualCamera[] copyFrom)
        {
            // Invalidate the cache
            mOrbitals = null;
            float[] softCenterDefaultsV        = new float[] { 0.5f, 0.55f, 0.6f };
            CinemachineVirtualCamera[] newRigs = new CinemachineVirtualCamera[3];
            for (int i = 0; i < RigNames.Length; ++i)
            {
                CinemachineVirtualCamera src = null;
                if (copyFrom != null && copyFrom.Length > i)
                {
                    src = copyFrom[i];
                }

                if (CreateRigOverride != null)
                {
                    newRigs[i] = CreateRigOverride(this, RigNames[i], src);
                }
                else
                {
                    // Create a new rig with default components
                    GameObject go = new GameObject(RigNames[i]);
                    go.transform.parent = transform;
                    newRigs[i]          = go.AddComponent <CinemachineVirtualCamera>();
                    if (src != null)
                    {
                        ReflectionHelpers.CopyFields(src, newRigs[i]);
                    }
                    else
                    {
                        go = newRigs[i].GetComponentOwner().gameObject;
                        go.AddComponent <CinemachineOrbitalTransposer>();
                        go.AddComponent <CinemachineComposer>();
                    }
                }

                // Set up the defaults
                newRigs[i].InvalidateComponentPipeline();
                CinemachineOrbitalTransposer orbital = newRigs[i].GetCinemachineComponent <CinemachineOrbitalTransposer>();
                if (orbital == null)
                {
                    orbital = newRigs[i].AddCinemachineComponent <CinemachineOrbitalTransposer>(); // should not happen
                }
                if (src == null)
                {
                    // Only set defaults if not copying
                    orbital.m_YawDamping = 0;
                    CinemachineComposer composer = newRigs[i].GetCinemachineComponent <CinemachineComposer>();
                    if (composer != null)
                    {
                        composer.m_HorizontalDamping = composer.m_VerticalDamping = 0;
                        composer.m_ScreenX           = 0.5f;
                        composer.m_ScreenY           = softCenterDefaultsV[i];
                        composer.m_DeadZoneWidth     = composer.m_DeadZoneHeight = 0.1f;
                        composer.m_SoftZoneWidth     = composer.m_SoftZoneHeight = 0.8f;
                        composer.m_BiasX             = composer.m_BiasY = 0;
                    }
                }
            }
            return(newRigs);
        }