Exemple #1
0
    private Save CreateSaveGameObject()
    {
        Save save = new Save();

        // Player Data
        FirstPersonCharacterController player = FindObjectOfType <FirstPersonCharacterController>();

        save.playerPositionX      = player.transform.position.x;
        save.playerPositionY      = player.transform.position.y;
        save.playerPositionZ      = player.transform.position.z;
        save.playerHeadRotation   = player.headJoint.transform.rotation.eulerAngles;
        save.playerCameraRotation = player.cam.transform.rotation.eulerAngles;
        foreach (Interactive.Items i in player.items)
        {
            save.playerInventory.Add((int)i);
        }

        // Power Switches
        PowerSwitch[] powerSwitches = (PowerSwitch[])Resources.FindObjectsOfTypeAll(typeof(PowerSwitch));
        foreach (PowerSwitch p in powerSwitches)
        {
            if (p.isOn)
            {
                save.powerSwitchesActive.Add(p.switchSaveName);
            }
        }

        return(save);
    }
Exemple #2
0
    override public void Interact()
    {
        base.Interact();

        FirstPersonCharacterController player = FindObjectOfType <FirstPersonCharacterController>();

        if (itemToUnlock != Items.NONE)
        {
            isLocked = true;
            if (player.HasItem(itemToUnlock))
            {
                isLocked = false;
            }
        }

        print("Interacted with " + transform.gameObject.name);
        if (isLocked)
        {
            handleAnimator.Play("Locked");
            AudioManager.PlaySound(doorLockedSound);
        }
        else
        {
            handleAnimator.Play("Unlocked");
            AudioManager.PlaySound(doorUnlockedSound);
            m_IsOpen = !m_IsOpen;
        }
    }
Exemple #3
0
    public void LoadGame()
    {
        if (File.Exists(Application.persistentDataPath + "/saveGame.pd"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/saveGame.pd", FileMode.Open);
            Save            save = (Save)bf.Deserialize(file);
            file.Close();

            playerSavedPositionX      = save.playerPositionX;
            playerSavedPositionY      = save.playerPositionY;
            playerSavedPositionZ      = save.playerPositionZ;
            playerSavedHeadRotation   = save.playerHeadRotation;
            playerSavedCameraRotation = save.playerCameraRotation;
            playerSavedInventory      = save.playerInventory;
            FirstPersonCharacterController player = FindObjectOfType <FirstPersonCharacterController>();
            player.GetComponent <CharacterController>().enabled = false;
            player.transform.position = new Vector3(playerSavedPositionX, playerSavedPositionY, playerSavedPositionZ);
            player.GetComponent <CharacterController>().enabled = true;

            player.headJoint.transform.rotation = Quaternion.Euler(playerSavedHeadRotation);
            player.cam.transform.rotation       = Quaternion.Euler(playerSavedCameraRotation);

            foreach (int i in playerSavedInventory)
            {
                player.items.Add((Interactive.Items)i);

                //foreach (Interactive thing in FindObjectsOfType(typeof(Interactive)))
                //{
                //    if ((int)thing.item == i)
                //    {
                //        Destroy(thing.gameObject);
                //    }
                //}
            }

            powerSwitchesSavedActive = save.powerSwitchesActive;

            foreach (PowerSwitch p in (PowerSwitch[])Resources.FindObjectsOfTypeAll(typeof(PowerSwitch)))
            {
                foreach (string n in powerSwitchesSavedActive)
                {
                    if (p.switchSaveName == n)
                    {
                        p.isOn = true;
                        p.SetLights(p.isOn);
                    }
                }
            }

            Debug.Log("Game Loaded!");
        }
        else
        {
            Debug.Log("No Save File!");
        }
    }
Exemple #4
0
        /// <summary>
        /// Checks if the character has leave the boundings.
        /// </summary>
        /// <param name="c">The collider to be tested.</param>
        private void OnTriggerExit(Collider c)
        {
            FirstPersonCharacterController FPController = c.GetComponent <FirstPersonCharacterController>();

            if (FPController != null)
            {
                FPController.ClimbingLadder(false, Vector3.zero, m_SurfaceIdentifier);
            }
        }
        /// <summary>
        /// Initializes the component.
        /// </summary>
        internal void Init(FirstPersonCharacterController FPController)
        {
            m_FPController          = FPController;
            m_VelocityParameterHash = Animator.StringToHash(m_VelocityParameter);

            // Audio Source
            m_PlayerBodySource = AudioManager.Instance.RegisterSource("[AudioEmitter] CharacterBody", m_FPController.transform.root, spatialBlend: 0);
            Initialized        = true;
        }
Exemple #6
0
        /// <summary>
        /// Checks if the character is within the boundings of the ladder.
        /// </summary>
        /// <param name="c">The collider to be tested.</param>
        private void OnTriggerStay(Collider c)
        {
            FirstPersonCharacterController FPController = c.GetComponent <FirstPersonCharacterController>();
            Bounds ladderBounds = GetComponent <Collider>().bounds;

            if (FPController != null)
            {
                FPController.ClimbingLadder(true, ladderBounds.max, m_SurfaceIdentifier);
            }
        }
Exemple #7
0
    private void Start()
    {
        agent = GetComponent <NavMeshAgent>();

        GameObject playerObj = GameObject.FindGameObjectWithTag("Player");

        playerTransform = playerObj.transform;
        player          = playerObj.GetComponent <FirstPersonCharacterController>();
        availableStates = GetComponents <BaseState>();
        state           = GetComponent <PatrolState>();
        state.Construct();
    }
        /// <summary>
        /// Simulates the swinging effect animation on the weapon relative to the character movement.
        /// </summary>
        /// <param name="weaponSwing">The target Transform reference.</param>
        /// <param name="FPController">The CharacterController reference.</param>
        internal void Swing(Transform weaponSwing, FirstPersonCharacterController FPController)
        {
            if (Mathf.Abs(Time.timeScale) < float.Epsilon)
            {
                return;
            }

            if (m_Swing)
            {
                // Calculates the swing angle by the mouse movement
                float yRot = Mathf.Clamp(Input.GetAxis("Mouse X") * -m_SwingAngle.x * GameplayManager.Instance.OverallMouseSensitivity, -m_SwingAngle.y, m_SwingAngle.y);
                float xRot = Mathf.Clamp(Input.GetAxis("Mouse Y") * -m_SwingAngle.x * GameplayManager.Instance.OverallMouseSensitivity, -m_SwingAngle.y, m_SwingAngle.y);

                // Calculates the tilt angle by sideways movement
                float zRot = FPController.Velocity.sqrMagnitude > 1 && !FPController.IsSliding
                    ? Mathf.Clamp(FPController.GetInput().x * -m_TiltAngle.x, -m_TiltAngle.y, m_TiltAngle.y) : 0;

                float zRotBoost = Mathf.Clamp(m_AnimateAllAxes ? Input.GetAxis("Mouse X") * GameplayManager.Instance.OverallMouseSensitivity * -m_TiltBoost.x : 0, -m_TiltBoost.y, m_TiltBoost.y);

                // Simulates the tremor effect (shaking effect)
                if (FPController.TremorTrauma)
                {
                    yRot += UnityEngine.Random.Range(-1.0f, 1.0f) * m_TremorAmount;
                    xRot += UnityEngine.Random.Range(-1.0f, 1.0f) * m_TremorAmount;
                }

                if (m_SwingTarget == SwingTarget.Fist)
                {
                    m_TargetRot = Quaternion.Euler(xRot, yRot, zRot + zRotBoost);
                    m_TargetPos = new Vector3(-yRot / 100 + (zRot + zRotBoost) / 500, xRot / 100, 0);

                    if (FPController.IsAiming)
                    {
                        m_TargetPos /= 2;
                    }
                }
                else
                {
                    m_TargetRot = Quaternion.Euler(-xRot, yRot, zRot + zRotBoost);
                    m_TargetPos = new Vector3((zRot + zRotBoost) / 500, 0, 0);
                }
            }
            else
            {
                m_TargetRot = Quaternion.identity;
                m_TargetPos = Vector3.zero;
            }

            weaponSwing.localPosition = Vector3.Lerp(weaponSwing.localPosition, m_TargetPos * m_ScaleFactor, Time.deltaTime * m_Speed * 10);
            weaponSwing.localRotation = Quaternion.Slerp(weaponSwing.localRotation, m_TargetRot, Time.deltaTime * m_Speed * 10);
        }
        protected virtual void Start()
        {
            // References
            m_FPController               = GetComponent <FirstPersonCharacterController>();
            m_BloodSplashEffect          = GetComponentInChildren <BloodSplashEffect>();
            m_FPController.LandingEvent += FallDamage;

            // Audio Sources
            m_PlayerHealthSource = AudioManager.Instance.RegisterSource("[AudioEmitter] CharacterHealth", transform.root);
            m_PlayerBreathSource = AudioManager.Instance.RegisterSource("[AudioEmitter] CharacterGeneric", transform.root);

            // Body parts
            for (int i = 0, bodyPartsCount = m_BodyParts.Count; i < bodyPartsCount; i++)
            {
                if (!m_BodyParts[i])
                {
                    continue;
                }

                m_BodyParts[i].Init(this);
                m_TotalVitality += m_BodyParts[i].Vitality;
            }
            m_CurrentVitality = m_TotalVitality;
        }
Exemple #10
0
        private static void CreateCharacter()
        {
            EditorGUI.BeginChangeCheck();

            GameObject obj_fpsCharacter = new GameObject("FPCharacter");
            FirstPersonCharacterController fpsCharacter = obj_fpsCharacter.AddComponent <FirstPersonCharacterController>();
            HealthController healthController           = obj_fpsCharacter.AddComponent <HealthController>();

            healthController.RegisterBodyPart(obj_fpsCharacter.AddComponent <DamageHandler>());

            Rigidbody rigidbody = fpsCharacter.GetComponent <Rigidbody>();

            rigidbody.drag                   = 5;
            rigidbody.useGravity             = false;
            rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
            CapsuleCollider capsuleCollider = fpsCharacter.GetComponent <CapsuleCollider>();

            capsuleCollider.height = 2;

            obj_fpsCharacter.transform.position = new Vector3(0, 1, 0);

            GameObject managers = new GameObject("Managers");

            GameObject obj_fpsCamera = new GameObject("FPSCamera");

            obj_fpsCamera.AddComponent <AudioListener>();

            Camera fpsCamera = obj_fpsCamera.AddComponent <Camera>();

            SerializedObject   editor_fpsCharacter            = new SerializedObject(fpsCharacter);
            SerializedProperty editor_fpsCharacter_mainCamera = editor_fpsCharacter.FindProperty("m_MainCamera");

            editor_fpsCharacter_mainCamera.objectReferenceValue = fpsCamera;
            editor_fpsCharacter.ApplyModifiedProperties();

            // Character Structure
            managers.transform.SetParent(obj_fpsCharacter.transform);
            managers.transform.localPosition = new Vector3(0, 0.5f, 0);

            GameObject fp = new GameObject("FirstPerson");

            fp.transform.SetParent(obj_fpsCharacter.transform);
            fp.transform.localPosition = new Vector3(0, 0, 0);

            GameObject obj_cameraAnimator = new GameObject("CameraAnimator");

            obj_cameraAnimator.transform.SetParent(fp.transform);
            obj_cameraAnimator.transform.localPosition = new Vector3(0, 0, 0);
            CameraAnimator cameraAnimator = obj_cameraAnimator.AddComponent <CameraAnimator>();

            SerializedObject   editor_cameraAnimator = new SerializedObject(cameraAnimator);
            SerializedProperty editor_cameraAnimator_fpsCharacter = editor_cameraAnimator.FindProperty("m_FPController");

            editor_cameraAnimator_fpsCharacter.objectReferenceValue = fpsCharacter;

            SerializedProperty editor_cameraAnimator_healthController = editor_cameraAnimator.FindProperty("m_HealthController");

            editor_cameraAnimator_healthController.objectReferenceValue = healthController;

            SerializedProperty editor_cameraAnimator_MotionAnimation = editor_cameraAnimator.FindProperty("m_MotionAnimation");

            editor_cameraAnimator_MotionAnimation.FindPropertyRelative("m_TargetTransform").objectReferenceValue = obj_cameraAnimator.transform;
            editor_cameraAnimator_MotionAnimation.FindPropertyRelative("m_JumpAnimation").FindPropertyRelative("m_TargetPosition").vector3Value = new Vector3(0, 0, 0);
            editor_cameraAnimator_MotionAnimation.FindPropertyRelative("m_JumpAnimation").FindPropertyRelative("m_TargetRotation").vector3Value = new Vector3(-5, 0, 0);
            editor_cameraAnimator_MotionAnimation.FindPropertyRelative("m_JumpAnimation").FindPropertyRelative("m_Duration").floatValue         = 0.25f;
            editor_cameraAnimator_MotionAnimation.FindPropertyRelative("m_JumpAnimation").FindPropertyRelative("m_ReturnDuration").floatValue   = 0.25f;

            editor_cameraAnimator_MotionAnimation.FindPropertyRelative("m_LandingAnimation").FindPropertyRelative("m_TargetPosition").vector3Value = new Vector3(0, -0.1f, 0);
            editor_cameraAnimator_MotionAnimation.FindPropertyRelative("m_LandingAnimation").FindPropertyRelative("m_TargetRotation").vector3Value = new Vector3(5, 0, 0);
            editor_cameraAnimator_MotionAnimation.FindPropertyRelative("m_LandingAnimation").FindPropertyRelative("m_Duration").floatValue         = 0.2f;
            editor_cameraAnimator_MotionAnimation.FindPropertyRelative("m_LandingAnimation").FindPropertyRelative("m_ReturnDuration").floatValue   = 0.25f;

            editor_cameraAnimator.ApplyModifiedProperties();

            GameObject characterBody = new GameObject("CharacterBody");

            characterBody.transform.SetParent(fp.transform);
            characterBody.transform.localPosition = new Vector3(0, 1, 0);

            obj_fpsCamera.transform.SetParent(cameraAnimator.transform);
            obj_fpsCamera.transform.localPosition = new Vector3(0, 0.8f, 0);

            GameObject weaponsHandler = new GameObject("WeaponsHandler");

            weaponsHandler.transform.SetParent(obj_fpsCamera.transform);
            weaponsHandler.transform.localPosition = new Vector3(0, 1, 0);

            GameObject itemsHandler = new GameObject("ItemsHandler");

            itemsHandler.transform.SetParent(obj_fpsCamera.transform);
            itemsHandler.transform.localPosition = new Vector3(0, 1, 0);

            Selection.activeObject = obj_fpsCharacter;

            if (EditorGUI.EndChangeCheck())
            {
                EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
            }
        }