示例#1
0
    void Reset()
    {
        playerLookAt = GameObject.Find("Head").transform;
        playerFollow = GameObject.Find("Logger").transform;

        stateDrivenCamera = GameObject.Find("CM_StateDrivenCamera").GetComponent <CinemachineStateDrivenCamera>();
    }
            void CollectStatesFromFSM(
                AnimatorStateMachine fsm, string hashPrefix, int parentHash, string displayPrefix)
            {
                ChildAnimatorState[] states = fsm.states;
                for (int i = 0; i < states.Length; i++)
                {
                    AnimatorState state = states[i].state;
                    int           hash  = AddState(hashPrefix + state.name, parentHash, displayPrefix + state.name);

                    // Also process clips as pseudo-states, if more than 1 is present.
                    // Since they don't have hashes, we can manufacture some.
                    List <string> clips = CollectClipNames(state.motion);
                    if (clips.Count > 1)
                    {
                        string substatePrefix = displayPrefix + state.name + ".";
                        foreach (string name in clips)
                        {
                            AddState(
                                CinemachineStateDrivenCamera.CreateFakeHashName(hash, name),
                                hash, substatePrefix + name);
                        }
                    }
                }

                ChildAnimatorStateMachine[] fsmChildren = fsm.stateMachines;
                foreach (var child in fsmChildren)
                {
                    string name        = hashPrefix + child.stateMachine.name;
                    string displayName = displayPrefix + child.stateMachine.name;
                    int    hash        = AddState(name, parentHash, displayName);
                    CollectStatesFromFSM(child.stateMachine, name + ".", hash, displayName + ".");
                }
            }
示例#3
0
    // Use this for initialization
    void Awake()
    {
        playableDirector = this.GetComponent <PlayableDirector>();
        camera           = GameObject.FindObjectOfType <CameraFollow>();

        statemachine = GameObject.FindObjectOfType <CinemachineStateDrivenCamera>();
    }
 //private Button btn;
 private void Awake()
 {
     //PlayerTransform = GameObject.FindGameObjectWithTag("Player").transform;
     //Debug.Log(PlayerTransform.name);
     //realCamera = transform.GetChild(0).GetComponent<Camera>();
     tool = GameObject.FindObjectOfType <SelectTool>();
     //freeLook = GameObject.FindObjectOfType<CinemachineFreeLook>();
     stateCamera = GameObject.FindObjectOfType <CinemachineStateDrivenCamera>();
 }
 private void Awake()
 {
     m_Animator = GetComponent <Animator>();
     m_CinemachineStateDrivenCamera = FindObjectOfType <CinemachineStateDrivenCamera>();
     m_CinemachineVirtualCameras    = GetComponentsInChildren <CinemachineVirtualCamera>();
     foreach (CinemachineVirtualCamera cinemachineVirtualCamera in m_CinemachineVirtualCameras)
     {
     }
 }
示例#6
0
        void Awake()
        {
            animator = GetComponent <Animator> ();

            cameras      = GameObject.FindObjectOfType(typeof(CinemachineStateDrivenCamera)) as CinemachineStateDrivenCamera;
            cameraOffset = cameras.gameObject.GetComponent <CinemachineCameraOffset> ();

            targetGroup        = GetComponent <CinemachineTargetGroup> ();
            closeUpTargetGroup = cameras.GetComponentInChildren <CinemachineTargetGroup> ();
        }
示例#7
0
 // Message then methods
 void Start()
 {
     myRigidBody                  = GetComponent <Rigidbody2D>();
     myAnimator                   = GetComponent <Animator>();
     myCollider                   = GetComponent <CapsuleCollider2D>();
     myCineMachineCamera          = GameObject.FindGameObjectWithTag("CMVirtualCam");
     CinemachineStateDrivenCamera = myCineMachineCamera.GetComponent <CinemachineStateDrivenCamera>();
     gravityScaleAtStart          = myRigidBody.gravityScale;
     JetpackParticleShape         = JetpackParticles.shape;
 }
示例#8
0
 void Start()
 {
     myRigidBody             = GetComponent <Rigidbody2D>();
     myAnimator              = GetComponentInChildren <Animator>();
     myBoxCollider           = GetComponent <BoxCollider2D>();
     myCapsuleCollider       = GetComponent <CapsuleCollider2D>();
     myHealth                = GetComponent <Health>();
     capsuleOffset           = new Vector3(myCapsuleCollider.offset.x, myCapsuleCollider.offset.y);
     gravityScaleNotGrounded = myRigidBody.gravityScale;
     myStateDrivenCamera     = FindObjectOfType <CinemachineStateDrivenCamera>();
 }
        private void FindPlayerInput(bool autoDisable)
        {
            if (m_playerInput == null)
            {
                PlayerInput[] playerInputObjects = FindObjectsOfType <PlayerInput>();
                int           length             = playerInputObjects.Length;
                bool          found = true;
                if (length != 1)
                {
                    string errorMessage = "No ThirdPersonBrain in scene! Disabling Camera Controller";
                    if (length > 1)
                    {
                        errorMessage = "Too many ThirdPersonBrains in scene! Disabling Camera Controller";
                    }
                    else // none found
                    {
                        found = false;
                    }

                    if (autoDisable)
                    {
                        Debug.LogError(errorMessage);
#if UNITY_EDITOR
                        EditorUtility.DisplayDialog("Error detecting ThirdPersonBrain", errorMessage, "Ok");
#endif
                        gameObject.SetActive(false);
                    }
                }

                if (found)
                {
                    m_playerInput = playerInputObjects[0];
                }
                else
                {
                    return;
                }
            }


            m_stateDrivenCam = GetComponent <CinemachineStateDrivenCamera>();
            if (m_stateDrivenCam != null)
            {
                m_stateDrivenCam.m_LookAt         = m_playerInput.vcamTarget;
                m_stateDrivenCam.m_Follow         = m_playerInput.vcamTarget;
                m_stateDrivenCam.m_AnimatedTarget = m_playerInput.GetComponent <Animator>();
            }
        }
示例#10
0
        // Finds the ThirdPersonBrain and automatically sets up the required fields for the Cinemachine cameras
        void FindThirdPersonBrain(bool autoDisable)
        {
            if (m_ThirdPersonBrain == null)
            {
                ThirdPersonBrain[] thirdPersonBrainObjects = FindObjectsOfType <ThirdPersonBrain>();
                int  length = thirdPersonBrainObjects.Length;
                bool found  = true;
                if (length != 1)
                {
                    string errorMessage = "No ThirdPersonBrain in scene! Disabling Camera Controller";
                    if (length > 1)
                    {
                        errorMessage = "Too many ThirdPersonBrains in scene! Disabling Camera Controller";
                    }
                    else         // none found
                    {
                        found = false;
                    }

                    if (autoDisable)
                    {
                        Debug.LogError(errorMessage);
#if UNITY_EDITOR
                        EditorUtility.DisplayDialog("Error detecting ThirdPersonBrain", errorMessage, "Ok");
#endif
                        gameObject.SetActive(false);
                    }
                }

                if (found)
                {
                    m_ThirdPersonBrain = thirdPersonBrainObjects[0];
                }
                else
                {
                    return;
                }
            }

            //auto-set up the necessary state driven camera data
            m_SDC = GetComponent <CinemachineStateDrivenCamera>();
            if (m_SDC != null)
            {
                m_SDC.m_LookAt         = m_ThirdPersonBrain.vcamTarget;
                m_SDC.m_Follow         = m_ThirdPersonBrain.vcamTarget;
                m_SDC.m_AnimatedTarget = m_ThirdPersonBrain.GetComponent <Animator>();
            }
        }
示例#11
0
    private void Awake()
    {
        cam = GetComponent <CinemachineStateDrivenCamera>();
        var secCams = cam.ChildCameras;

        secVirtualCams = new CinemachineVirtualCamera[secCams.Length];
        fTCams         = new CinemachineFramingTransposer[secCams.Length];
        for (int i = 0; i < secCams.Length; i++)
        {
            secVirtualCams[i] = secCams[i].GetComponent <CinemachineVirtualCamera>();
            fTCams[i]         = secVirtualCams[i].GetCinemachineComponent <CinemachineFramingTransposer>();
        }
        camConfiner          = GetComponent <CinemachineConfiner>();
        cam.Follow           = playerGameObj.transform;
        cam.m_AnimatedTarget = playerGameObj.GetComponent <Animator>();
    }
示例#12
0
        public override void SetUp()
        {
            CreateGameObject("Camera", typeof(Camera), typeof(CinemachineBrain));

            // Create a minimal character controller
            var character  = CreateGameObject("Character", typeof(Animator));
            var controller = AssetDatabase.LoadMainAssetAtPath("Packages/com.unity.cinemachine/Tests/Runtime/TestController.controller") as AnimatorController;

            character.GetComponent <Animator>().runtimeAnimatorController = controller;

            // Create a state-driven camera with two vcams
            var stateDrivenCamera = CreateGameObject("CM StateDrivenCamera", typeof(CinemachineStateDrivenCamera)).GetComponent <CinemachineStateDrivenCamera>();

            stateDrivenCamera.m_AnimatedTarget = character.GetComponent <Animator>();

            var vcam1 = CreateGameObject("Vcam1", typeof(CinemachineVirtualCamera)).GetComponent <CinemachineVirtualCamera>();
            var vcam2 = CreateGameObject("Vcam1", typeof(CinemachineVirtualCamera)).GetComponent <CinemachineVirtualCamera>();

            vcam1.gameObject.transform.SetParent(stateDrivenCamera.gameObject.transform);
            vcam2.gameObject.transform.SetParent(stateDrivenCamera.gameObject.transform);

            // Map states to vcams
            stateDrivenCamera.m_Instructions = new[]
            {
                new CinemachineStateDrivenCamera.Instruction()
                {
                    m_FullHash = controller.layers[0].stateMachine.states[0].GetHashCode(), m_VirtualCamera = vcam1
                },
                new CinemachineStateDrivenCamera.Instruction()
                {
                    m_FullHash = controller.layers[0].stateMachine.states[1].GetHashCode(), m_VirtualCamera = vcam2
                }
            };

            this.stateDrivenCamera = stateDrivenCamera;
            animator   = character.GetComponent <Animator>();
            this.vcam1 = vcam1;
            this.vcam2 = vcam2;

            base.SetUp();
        }
        private bool SetCamera()
        {
            CinemachineBrain brain = FindObjectOfType <CinemachineBrain>();

            if (brain == null)
            {
                Undo.AddComponent <CinemachineBrain>(Camera.main.transform.gameObject);
            }

            CinemachineStateDrivenCamera camera = FindObjectOfType <CinemachineStateDrivenCamera>();

            if (camera == null)
            {
                camera = AssetDatabase.LoadAssetAtPath <CinemachineStateDrivenCamera>("Assets/Dias Games/Third Person System/Prefabs/Camera State Driven.prefab");
                Object newCam = PrefabUtility.InstantiatePrefab(camera);

                GameObject character = GameObject.FindGameObjectWithTag("Player");
                if (character != null)
                {
                    Transform target = character.transform.Find("Camera Track Pos");

                    SerializedObject cameraObj = new SerializedObject(newCam);
                    cameraObj.Update();

                    cameraObj.FindProperty("m_LookAt").objectReferenceValue         = target;
                    cameraObj.FindProperty("m_Follow").objectReferenceValue         = target;
                    cameraObj.FindProperty("m_AnimatedTarget").objectReferenceValue = character.GetComponent <Animator>();

                    cameraObj.ApplyModifiedProperties();
                }


                return(true);
            }

            return(false);
        }
 void Awake()
 {
     SDC   = GetComponent <CinemachineStateDrivenCamera>();
     Brain = GetComponentInParent <CharacterBrain>();
     Input = GetComponentInParent <InputController>();
 }
        void SetupInstructionList()
        {
            mInstructionList = new UnityEditorInternal.ReorderableList(serializedObject,
                                                                       serializedObject.FindProperty(() => Target.m_Instructions),
                                                                       true, true, true, true);

            // Needed for accessing field names as strings
            CinemachineStateDrivenCamera.Instruction def = new CinemachineStateDrivenCamera.Instruction();

            float vSpace          = 2;
            float hSpace          = 3;
            float floatFieldWidth = EditorGUIUtility.singleLineHeight * 2.5f;

            mInstructionList.drawHeaderCallback = (Rect rect) =>
            {
                rect.width -= (EditorGUIUtility.singleLineHeight + 3 * hSpace);
                rect.width -= 2 * floatFieldWidth; rect.width /= 2;
                Vector2 pos = rect.position; pos.x += EditorGUIUtility.singleLineHeight;
                rect.position = pos;
                EditorGUI.LabelField(rect, "State");

                pos.x += rect.width + hSpace; rect.position = pos;
                EditorGUI.LabelField(rect, "Camera");

                pos.x += rect.width + hSpace; rect.width = floatFieldWidth; rect.position = pos;
                EditorGUI.LabelField(rect, "Wait");

                pos.x += rect.width + hSpace; rect.position = pos;
                EditorGUI.LabelField(rect, "Min");
            };

            mInstructionList.drawElementCallback
                = (Rect rect, int index, bool isActive, bool isFocused) =>
                {
                SerializedProperty instProp
                    = mInstructionList.serializedProperty.GetArrayElementAtIndex(index);

                rect.y     += vSpace;
                rect.height = EditorGUIUtility.singleLineHeight;
                Vector2 pos = rect.position;
                rect.width -= 3 * hSpace;
                rect.width -= 2 * floatFieldWidth; rect.width /= 2;
                SerializedProperty stateSelProp = instProp.FindPropertyRelative(() => def.m_FullHash);
                int currentState   = GetStateHashIndex(stateSelProp.intValue);
                int stateSelection = EditorGUI.Popup(rect, currentState, mTargetStateNames);
                if (currentState != stateSelection)
                {
                    stateSelProp.intValue = mTargetStates[stateSelection];
                }

                pos.x += rect.width + hSpace; rect.position = pos;
                SerializedProperty vcamSelProp = instProp.FindPropertyRelative(() => def.m_VirtualCamera);
                int currentVcam   = GetCameraIndex(vcamSelProp.objectReferenceValue);
                int vcamSelection = EditorGUI.Popup(rect, currentVcam, mCameraCandidates);
                if (currentVcam != vcamSelection)
                {
                    vcamSelProp.objectReferenceValue = (vcamSelection == 0)
                            ? null : Target.ChildCameras[vcamSelection - 1];
                }

                pos.x += rect.width + hSpace; rect.width = floatFieldWidth; rect.position = pos;
                SerializedProperty activeAfterProp = instProp.FindPropertyRelative(() => def.m_ActivateAfter);
                EditorGUI.PropertyField(rect, activeAfterProp, activeAfterLabel);

                pos.x += rect.width + hSpace; rect.position = pos;
                SerializedProperty minDurationProp = instProp.FindPropertyRelative(() => def.m_MinDuration);
                EditorGUI.PropertyField(rect, minDurationProp, minDurationLabel);
                };

            mInstructionList.onAddDropdownCallback = (Rect buttonRect, UnityEditorInternal.ReorderableList l) =>
            {
                var menu = new GenericMenu();
                menu.AddItem(new GUIContent("New State"),
                             false, (object data) =>
                {
                    ++mInstructionList.serializedProperty.arraySize;
                    serializedObject.ApplyModifiedProperties();
                    Target.ValidateInstructions();
                },
                             null);
                menu.AddItem(new GUIContent("All Unhandled States"),
                             false, (object data) =>
                {
                    CinemachineStateDrivenCamera target = Target;
                    int len = mInstructionList.serializedProperty.arraySize;
                    for (int i = 0; i < mTargetStates.Length; ++i)
                    {
                        int hash = mTargetStates[i];
                        if (hash == 0)
                        {
                            continue;
                        }
                        bool alreadyThere = false;
                        for (int j = 0; j < len; ++j)
                        {
                            if (target.m_Instructions[j].m_FullHash == hash)
                            {
                                alreadyThere = true;
                                break;
                            }
                        }
                        if (!alreadyThere)
                        {
                            int index = mInstructionList.serializedProperty.arraySize;
                            ++mInstructionList.serializedProperty.arraySize;
                            SerializedProperty p = mInstructionList.serializedProperty.GetArrayElementAtIndex(index);
                            p.FindPropertyRelative(() => def.m_FullHash).intValue = hash;
                        }
                    }
                    serializedObject.ApplyModifiedProperties();
                    Target.ValidateInstructions();
                },
                             null);
                menu.ShowAsContext();
            };
        }
示例#16
0
 private void Start()
 {
     DefaultFOV            = FreeLook.m_Lens.FieldOfView;
     DefaultShoulderOffset = DriftCam.GetCinemachineComponent <Cinemachine3rdPersonFollow>().ShoulderOffset;
     StateCamera           = GetComponent <CinemachineStateDrivenCamera>();
 }
示例#17
0
        void Update()
        {
            inputDataTop   = VirtualInputManager.Instance.GetTopInput();
            keysHoldFrames = VirtualInputManager.Instance.GetKeysHoldFrames();

            if (player != null)
            {
                //Debug.Log(inputDataTop.InputVector);
                player.inputVector    = inputDataTop.InputVector;
                player.inputKeyStates = inputDataTop.KeysState;

                if (VirtualInputManager.Instance.CheckCommandInput())
                {
                    if (VirtualInputManager.Instance.CheckInputInBuffer(InputKeyStateType.KEY_MELEE_ATTACK_DOWN))
                    {
                        player.CommandAttack = true;
                    }
                    if (VirtualInputManager.Instance.CheckInputInBuffer(InputKeyStateType.KEY_EXECUTE_ATTACK_DOWN))
                    {
                        player.CommandExecute = true;
                    }
                    if (VirtualInputManager.Instance.CheckInputInBuffer(InputKeyStateType.KEY_DODGE_DOWN))
                    {
                        player.CommandDodge = true;
                    }
                    if (VirtualInputManager.Instance.CheckInputInBuffer(InputKeyStateType.KEY_GUARD_DOWN))
                    {
                        player.CommandGuard = true;
                    }
                }

                if (!VirtualInputManager.Instance.CheckInputInBuffer(InputKeyStateType.KEY_MELEE_ATTACK_DOWN))
                {
                    player.CommandAttack = false;
                }
                if (!VirtualInputManager.Instance.CheckInputInBuffer(InputKeyStateType.KEY_EXECUTE_ATTACK_DOWN))
                {
                    player.CommandExecute = false;
                }
                if (!VirtualInputManager.Instance.CheckInputInBuffer(InputKeyStateType.KEY_DODGE_DOWN))
                {
                    player.CommandDodge = false;
                }
                if (!VirtualInputManager.Instance.CheckInputInBuffer(InputKeyStateType.KEY_GUARD_DOWN))
                {
                    player.CommandGuard = false;
                }

                if (inputDataTop.KeysState[(int)InputKeyStateType.KEY_CHARGE])
                {
                    player.CommandCharge = true;
                }
                else
                {
                    player.CommandCharge = false;
                }

                //if (inputDataTop.KeysState[(int) InputKeyStateType.KEY_GUARD])

                /*
                 * if (inputDataTop.KeysState[(int) InputKeyStateType.KEY_GUARD_DOWN])
                 *  player.CommandGuard = true;
                 * else
                 *  player.CommandGuard = false;
                 */

                if (inputDataTop.KeysState[(int)InputKeyStateType.KEY_GUARD])
                {
                    player.CommandGuardHoldOn = true;
                }
                else
                {
                    player.CommandGuardHoldOn = false;
                }

                /*
                 *          if (player.DodgeTrigger) {
                 *              VirtualInputManager.Instance.ClearAllInputsInBuffer ();
                 *          }
                 *          if (player.AttackTrigger) {
                 *              VirtualInputManager.Instance.ClearAllInputsInBuffer ();
                 *          }
                 *          if (player.ExecuteTrigger) {
                 *              VirtualInputManager.Instance.ClearAllInputsInBuffer ();
                 *          }
                 */

                player.CommandAttackHoldFrame  = keysHoldFrames[0];
                player.CommandExecuteHoldFrame = keysHoldFrames[1];
                player.CommandDodgeHoldFrame   = keysHoldFrames[2];
                player.InputAxisHoldFrame      = keysHoldFrames[5];

                // for test
                if (Input.GetKeyDown(KeyCode.B))
                {
                    if (player.Animator.GetFloat(TransitionParameter.SpeedMultiplier.ToString()) == 1.0f)
                    {
                        player.Animator.SetFloat(TransitionParameter.SpeedMultiplier.ToString(), 0.1f);
                    }
                    else
                    {
                        player.Animator.SetFloat(TransitionParameter.SpeedMultiplier.ToString(), 1f);
                    }
                }
                // for test
                if (Input.GetKeyDown(KeyCode.Y))
                {
                    if (!player.Animator.GetBool("IsRunning"))
                    {
                        player.Animator.SetBool("IsRunning", true);
                        player.CharacterData.IsRunning = true;
                    }
                    else
                    {
                        player.Animator.SetBool("IsRunning", false);
                        player.CharacterData.IsRunning = false;
                    }
                }

                // for test

                /*
                 * if (Input.GetKeyDown (KeyCode.P)) {
                 *  Dictionary<string, int> dicts = new Dictionary<string, int> ();
                 *  dicts.Add ("Swordman", 1);
                 *  //dicts.Add ("Gunman", 2);
                 *  SpawnEnemyGroup (dicts);
                 * }
                 */

                // for test
                if (Input.GetKeyDown(KeyCode.T))
                {
                    CinemachineStateDrivenCamera camera = GameObject.FindObjectOfType(typeof(CinemachineStateDrivenCamera)) as CinemachineStateDrivenCamera;
                    Animator anim = camera.m_AnimatedTarget;
                    CinemachineCameraOffset offset = camera.gameObject.GetComponent <CinemachineCameraOffset> ();
                    float Offset = anim.GetFloat("ExtraOffset");
                    offset.m_Offset.y += Offset;
                    offset.m_Offset.z += -Offset;
                }
                // for test
                if (Input.GetKeyDown(KeyCode.N))
                {
                    if (player.CharacterData.Energy > 1.0f)
                    {
                        player.TakeEnergy(1.0f, null);
                    }
                }
                if (Input.GetKeyDown(KeyCode.M))
                {
                    player.CharacterData.GetEnergy(4.0f);
                }

                /*
                 *          Vector3 forward = gameObject.transform.forward;
                 *          forward.y = 0f;
                 *          float angle = (Quaternion.LookRotation (forward, Vector3.up)).eulerAngles.y * Mathf.Deg2Rad;
                 *          //Debug.Log(forward.ToString() + " " + Mathf.Cos(angle).ToString() + " " + Mathf.Sin(angle).ToString());
                 *          float blendTreeInputX = player.inputVector.x * Mathf.Cos (angle) - player.inputVector.y * Mathf.Sin (angle);
                 *          float blendTreeInputY = player.inputVector.x * Mathf.Sin (angle) + player.inputVector.y * Mathf.Cos (angle);
                 *          player.Animator.SetFloat ("InputX", blendTreeInputX);
                 *          player.Animator.SetFloat ("InputY", blendTreeInputY);
                 *
                 *          if (Input.GetKeyDown (KeyCode.F)) {
                 *              player.Animator.SetBool ("Fire", true);
                 *          } else {
                 *              player.Animator.SetBool ("Fire", false);
                 *          }
                 */
            }
            if (menu != null)
            {
                menu.inputVector    = inputDataTop.InputVector;
                menu.inputKeyStates = inputDataTop.KeysState;
            }
        }
示例#18
0
 private void Awake()
 {
     _playerRevamp = GlobalState.state.Player;
     _cinemachineStateDrivenCamera = GlobalState.state.StateDrivenCamera;
 }
示例#19
0
 private void Awake()
 {
     c_VirtualCamera = GetComponent <CinemachineStateDrivenCamera>();
     Debug.Log("passed camera awake test");
 }