static CreatePipelineWithUndo()
            {
                CinemachineVirtualCamera.CreatePipelineOverride =
                    (CinemachineVirtualCamera vcam, string name, CinemachineComponentBase[] copyFrom) =>
                {
                    // Create a new pipeline
                    GameObject go = InspectorUtility.CreateGameObject(name);
                    Undo.RegisterCreatedObjectUndo(go, "created pipeline");
                    bool partOfPrefab = PrefabUtility.IsPartOfAnyPrefab(vcam.gameObject);
                    if (!partOfPrefab)
                    {
                        Undo.SetTransformParent(go.transform, vcam.transform, "parenting pipeline");
                    }
                    Undo.AddComponent <CinemachinePipeline>(go);

                    // If copying, transfer the components
                    if (copyFrom != null)
                    {
                        foreach (Component c in copyFrom)
                        {
                            Component copy = Undo.AddComponent(go, c.GetType());
                            Undo.RecordObject(copy, "copying pipeline");
                            ReflectionHelpers.CopyFields(c, copy);
                        }
                    }
                    return(go.transform);
                };
                CinemachineVirtualCamera.DestroyPipelineOverride = (GameObject pipeline) =>
                {
                    Undo.DestroyObjectImmediate(pipeline);
                };
            }
Exemplo n.º 2
0
        private static void CreateBlendListCamera()
        {
            CreateCameraBrainIfAbsent();
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineBlendListCamera), "CM BlendListCamera"),
                typeof(CinemachineBlendListCamera));

            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create Blend List camera");
            var vcam = go.GetComponent <CinemachineBlendListCamera>();

            Selection.activeGameObject = go;

            // Give it a couple of children
            var child1 = CreateDefaultVirtualCamera();

            Undo.SetTransformParent(child1.transform, go.transform, "create BlendListCam child");
            var child2 = CreateDefaultVirtualCamera();

            child2.m_Lens.FieldOfView = 10;
            Undo.SetTransformParent(child2.transform, go.transform, "create BlendListCam child");

            // Set up initial instruction set
            vcam.m_Instructions = new CinemachineBlendListCamera.Instruction[2];
            vcam.m_Instructions[0].m_VirtualCamera = child1;
            vcam.m_Instructions[0].m_Hold          = 1f;
            vcam.m_Instructions[1].m_VirtualCamera = child2;
            vcam.m_Instructions[1].m_Blend.m_Style = CinemachineBlendDefinition.Style.EaseInOut;
            vcam.m_Instructions[1].m_Blend.m_Time  = 2f;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a Virtual Camera, with components
        /// </summary>
        static CinemachineVirtualCamera InternalCreateVirtualCamera(
            string name, bool selectIt, params Type[] components)
        {
            // Create a new virtual camera
            CreateCameraBrainIfAbsent();
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineVirtualCamera), name),
                typeof(CinemachineVirtualCamera));

            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create " + name);
            CinemachineVirtualCamera vcam = go.GetComponent <CinemachineVirtualCamera>();
            GameObject componentOwner     = vcam.GetComponentOwner().gameObject;

            foreach (Type t in components)
            {
                Undo.AddComponent(componentOwner, t);
            }
            vcam.InvalidateComponentPipeline();
            if (selectIt)
            {
                Selection.activeObject = go;
            }
            return(vcam);
        }
Exemplo n.º 4
0
        private static void CreateDollyTrackWithCart()
        {
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineSmoothPath), "DollyTrack"),
                typeof(CinemachineSmoothPath));

            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create track");
            CinemachineSmoothPath path = go.GetComponent <CinemachineSmoothPath>();

            Selection.activeGameObject = go;

            go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineDollyCart), "DollyCart"),
                typeof(CinemachineDollyCart));
            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create cart");
            CinemachineDollyCart cart = go.GetComponent <CinemachineDollyCart>();

            Undo.RecordObject(cart, "create track");
            cart.m_Path = path;
        }
        /// <summary>
        /// Create a Virtual Camera, with components
        /// </summary>
        static CinemachineVirtualCamera InternalCreateVirtualCamera(
            string name, bool selectIt, params Type[] components)
        {
            // Create a new virtual camera
            var        brain = CreateCameraBrainIfAbsent();
            GameObject go    = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineVirtualCamera), name),
                typeof(CinemachineVirtualCamera));
            CinemachineVirtualCamera vcam = go.GetComponent <CinemachineVirtualCamera>();

            SetVcamFromSceneView(vcam);
            Undo.RegisterCreatedObjectUndo(go, "create " + name);
            GameObject componentOwner = vcam.GetComponentOwner().gameObject;

            foreach (Type t in components)
            {
                Undo.AddComponent(componentOwner, t);
            }
            vcam.InvalidateComponentPipeline();
            if (brain != null && brain.OutputCamera != null)
            {
                vcam.m_Lens = LensSettings.FromCamera(brain.OutputCamera);
            }
            if (selectIt)
            {
                Selection.activeObject = go;
            }
            return(vcam);
        }
        static void CreateDollyTrackWithCart(MenuCommand command)
        {
            CinemachineEditorAnalytics.SendCreateEvent("Dolly Track with Cart");
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineSmoothPath), "DollyTrack"),
                typeof(CinemachineSmoothPath));

            SetParentToMenuContextObject(go, command);
            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create track");
            CinemachineSmoothPath path = go.GetComponent <CinemachineSmoothPath>();

            go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineDollyCart), "DollyCart"),
                typeof(CinemachineDollyCart));
            SetParentToMenuContextObject(go, command);
            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create cart");
            go.GetComponent <CinemachineDollyCart>().m_Path = path;
        }
Exemplo n.º 7
0
        private static void CreateFreeLookCamera()
        {
            CreateCameraBrainIfAbsent();
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineFreeLook), "CM FreeLook"),
                typeof(CinemachineFreeLook));

            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Selection.activeGameObject = go;
        }
        static void CreateFreeLookCamera(MenuCommand command)
        {
            CinemachineEditorAnalytics.SendCreateEvent("FreeLook Camera");
            CreateCameraBrainIfAbsent();
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineFreeLook), "CM FreeLook"),
                typeof(CinemachineFreeLook));

            SetParentToMenuContextObject(go, command);
            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
        }
Exemplo n.º 9
0
        private static void CreateTargetGroupCamera()
        {
            CinemachineVirtualCamera vcam = InternalCreateVirtualCamera(
                "CM vcam", true, typeof(CinemachineGroupComposer), typeof(CinemachineTransposer));
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineTargetGroup), "TargetGroup"),
                typeof(CinemachineTargetGroup));

            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create target group");
            vcam.LookAt = go.transform;
            vcam.Follow = go.transform;
        }
Exemplo n.º 10
0
        private static void CreateStateDivenCamera()
        {
            CreateCameraBrainIfAbsent();
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineStateDrivenCamera), "CM StateDrivenCamera"),
                typeof(CinemachineStateDrivenCamera));

            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create state driven camera");
            Selection.activeGameObject = go;

            // Give it a child
            Undo.SetTransformParent(CreateDefaultVirtualCamera().transform, go.transform, "create state driven camera");
        }
        static void CreateTargetGroupCamera(MenuCommand command)
        {
            CinemachineEditorAnalytics.SendCreateEvent("Target Group Camera");
            CinemachineVirtualCamera vcam = InternalCreateVirtualCamera(
                "CM vcam", true, typeof(CinemachineGroupComposer), typeof(CinemachineTransposer));
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineTargetGroup), "TargetGroup"),
                typeof(CinemachineTargetGroup));

            SetParentToMenuContextObject(go, command);
            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create target group");
            vcam.LookAt = go.transform;
            vcam.Follow = go.transform;
        }
        static void CreateStateDivenCamera(MenuCommand command)
        {
            CinemachineEditorAnalytics.SendCreateEvent("State-Driven Camera");
            CreateCameraBrainIfAbsent();
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineStateDrivenCamera), "CM StateDrivenCamera"),
                typeof(CinemachineStateDrivenCamera));

            SetParentToMenuContextObject(go, command);
            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create state driven camera");

            // Give it a child
            Undo.SetTransformParent(CreateDefaultVirtualCamera().transform, go.transform, "create state driven camera");
        }
Exemplo n.º 13
0
        private static void CreateDollyCameraWithPath()
        {
            CinemachineVirtualCamera vcam = InternalCreateVirtualCamera(
                "CM vcam", true, typeof(CinemachineComposer), typeof(CinemachineTrackedDolly));
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineSmoothPath), "DollyTrack"),
                typeof(CinemachineSmoothPath));

            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create track");
            CinemachineSmoothPath path = go.GetComponent <CinemachineSmoothPath>();
            var dolly = vcam.GetCinemachineComponent <CinemachineTrackedDolly>();

            Undo.RecordObject(dolly, "create track");
            dolly.m_Path = path;
        }
        static void CreateDollyCameraWithPath(MenuCommand command)
        {
            CinemachineEditorAnalytics.SendCreateEvent("Dolly Camera with Track");
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineSmoothPath), "DollyTrack"),
                typeof(CinemachineSmoothPath));

            SetParentToMenuContextObject(go, command);
            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create track");
            CinemachineSmoothPath path = go.GetComponent <CinemachineSmoothPath>();

            CinemachineVirtualCamera vcam = InternalCreateVirtualCamera(
                "CM vcam", true, typeof(CinemachineComposer), typeof(CinemachineTrackedDolly));

            SetParentToMenuContextObject(vcam.gameObject, command);
            vcam.GetCinemachineComponent <CinemachineTrackedDolly>().m_Path = path;
        }
Exemplo n.º 15
0
        private static void CreateClearShotVirtualCamera()
        {
            CreateCameraBrainIfAbsent();
            GameObject go = InspectorUtility.CreateGameObject(
                GenerateUniqueObjectName(typeof(CinemachineClearShot), "CM ClearShot"),
                typeof(CinemachineClearShot));

            if (SceneView.lastActiveSceneView != null)
            {
                go.transform.position = SceneView.lastActiveSceneView.pivot;
            }
            Undo.RegisterCreatedObjectUndo(go, "create ClearShot camera");
            Selection.activeGameObject = go;

            // Give it a child
            var child = CreateDefaultVirtualCamera();

            Undo.SetTransformParent(child.transform, go.transform, "create ClearShot camera");
            var collider = Undo.AddComponent <CinemachineCollider>(child.gameObject);

            collider.m_AvoidObstacles = false;
            Undo.RecordObject(collider, "create ClearShot camera");
        }
Exemplo n.º 16
0
        public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
        {
            const float hSpace   = 2;
            float       iconSize = rect.height + 4;

            rect.width -= iconSize + hSpace;
            EditorGUI.PropertyField(rect, property, EditorGUI.BeginProperty(rect, label, property));
            rect.x += rect.width + hSpace; rect.width = iconSize;

            var oldEnabled = GUI.enabled;
            var target     = property.objectReferenceValue as Transform;

            if (target == null || target.GetComponent <CinemachineTargetGroup>() != null)
            {
                GUI.enabled = false;
            }
            if (GUI.Button(rect, EditorGUIUtility.IconContent("_Popup"), GUI.skin.label))
            {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Convert to TargetGroup"), false, () =>
                {
                    GameObject go = InspectorUtility.CreateGameObject(
                        CinemachineMenu.GenerateUniqueObjectName(
                            typeof(CinemachineTargetGroup), "CM TargetGroup"),
                        typeof(CinemachineTargetGroup));
                    var group = go.GetComponent <CinemachineTargetGroup>();
                    Undo.RegisterCreatedObjectUndo(go, "convert to TargetGroup");
                    group.m_RotationMode = CinemachineTargetGroup.RotationMode.GroupAverage;
                    group.AddMember(target, 1, 1);
                    property.objectReferenceValue = group.Transform;
                    property.serializedObject.ApplyModifiedProperties();
                });
                menu.ShowAsContext();
            }
            GUI.enabled = oldEnabled;
        }