private GoldPlayerController SetupPlayer()
        {
            GameObject           playerGO         = new GameObject("[TEST] Test Player");
            GoldPlayerController playerController = playerGO.AddComponent <GoldPlayerController>();
            GameObject           playerCameraHead = new GameObject("[TEST] Test Player Camera Head");
            Camera camera = playerCameraHead.AddComponent <Camera>();

#if ENABLE_INPUT_SYSTEM && UNITY_2019_3_OR_NEWER
            GoldPlayerInputSystem input = playerGO.AddComponent <GoldPlayerInputSystem>();
#else
            GoldPlayerInput input = playerGO.AddComponent <GoldPlayerInput>();
#endif
            playerController.GetComponent <CharacterController>().center = new Vector3(0, 1, 0);
            playerController.Camera.CameraHead = playerCameraHead.transform;
            playerController.Camera.FieldOfViewKick.EnableFOVKick = false;
            playerController.HeadBob.BobTarget = playerCameraHead.transform;

            playerController.Movement.MovingPlatforms.Enabled = true;
            playerController.Movement.MovingPlatforms.Initialize(playerController, input);

            //GameObject raycastWeaponGO = new GameObject("[Test] Raycast Weapon");
            //GoldPlayerWeapon raycastWeapon = raycastWeaponGO.AddComponent<GoldPlayerWeapon>();
            //raycastWeapon.ProjectileType = GoldPlayerWeapon.ProjectileTypeEnum.Raycast;
            //raycastWeapon.ShootOrigin = playerCameraHead.transform;

            //GoldPlayerWeapons weapons = playerGO.AddComponent<GoldPlayerWeapons>();
            //weapons.AvailableWeapons = new GoldPlayerWeapon[] { raycastWeapon };
            //weapons.AddWeapon(raycastWeapon);

            return(playerController);
        }
Beispiel #2
0
        /// <summary>
        /// Sets the player and finds all required components.
        /// </summary>
        private void SetPlayer(GoldPlayerController player)
        {
#if GOLD_PLAYER_INTERACTION
            // Only get the interaction if the previous set player isn't the new player.
            if (player != null && this.player != player)
            {
                playerInteraction = player.GetComponent <GoldPlayerInteraction>();
            }
#endif
            // Set the player.
            this.player = player;
        }
Beispiel #3
0
 protected virtual void AwakePlayerInteraction()
 {
     // Get the player interaction.
     if (player)
     {
         playerInteraction = player.GetComponent <GoldPlayerInteraction>();
     }
     else if (autoFindPlayer)
     {
         playerInteraction = FindObjectOfType <GoldPlayerInteraction>();
     }
 }
        protected virtual GoldPlayerController SetupPlayer()
        {
            GameObject playerGO = new GameObject("[TEST] Test Player", typeof(CharacterController));

            playerGO.transform.position = new Vector3(0, 0.08f, 0);
            playerGO.layer = 31;

            GameObject bobTarget = new GameObject("[TEST] Test Player Bob Target");

            bobTarget.transform.SetParent(playerGO.transform);
            bobTarget.transform.localPosition = new Vector3(0, 1.6f, 0);

            GameObject playerCameraHead = new GameObject("[TEST] Test Player Camera Head");

            playerCameraHead.transform.SetParent(bobTarget.transform);
            playerCameraHead.transform.localPosition = new Vector3(0, 0, 0);
            Camera camera = playerCameraHead.AddComponent <Camera>();

            input = playerGO.AddComponent <GoldPlayerTestInput>();

            GoldPlayerController playerController = playerGO.AddComponent <GoldPlayerController>();

            playerController.GetComponent <CharacterController>().center = new Vector3(0, 1, 0);

            playerController.Camera.CameraHead   = playerCameraHead.transform;
            playerController.Camera.TargetCamera = camera;
            playerController.Camera.FieldOfViewKick.EnableFOVKick = true;

            playerController.HeadBob.BobTarget = bobTarget.transform;

            playerController.Movement.GroundLayer = 1;

            playerController.Movement.MoveInput   = GoldPlayerTestInput.MOVE;
            playerController.Movement.JumpInput   = GoldPlayerTestInput.JUMP;
            playerController.Movement.RunInput    = GoldPlayerTestInput.RUN;
            playerController.Movement.CrouchInput = GoldPlayerTestInput.CROUCH;

            playerController.Camera.LookInput = GoldPlayerTestInput.LOOK;

            playerController.InitOnStart = false;
            playerController.GetReferences();
            playerController.Initialize();

            return(playerController);
        }
Beispiel #5
0
        private void OnEnable()
        {
            currentTab = EditorPrefs.GetInt(SELECTED_TAB_PREFS, 0);

            if (currentTab < 0)
            {
                currentTab = 0;
            }

            if (currentTab > 4)
            {
                currentTab = 4;
            }

            camera   = serializedObject.FindProperty("camera");
            movement = serializedObject.FindProperty("movement");
            headBob  = serializedObject.FindProperty("headBob");
            audio    = serializedObject.FindProperty("audio");

            goldPlayer          = (GoldPlayerController)target;
            characterController = goldPlayer.GetComponent <CharacterController>();
        }
        private void OnSceneGUI()
        {
            GoldPlayerController controller = target as GoldPlayerController;

            if (controller == null)
            {
                return;
            }

            Color oColor = Handles.color;

            Handles.color = Color.blue;

            Vector3 origin = controller.transform.position + controller.Controller.center;

            Handles.DrawLine(origin, origin + controller.Camera.BodyForward);

            if (GoldPlayerProjectSettings.Instance.ShowGroundCheckGizmos)
            {
                float radius = controller.GetComponent <CharacterController>().radius;

                if (controller.Movement.GroundCheck == GroundCheckType.Raycast)
                {
                    Vector3[] rays = new Vector3[controller.Movement.RayAmount + 1];
                    controller.Movement.CreateGroundCheckRayCircle(ref rays, controller.transform.position, radius);

                    for (int i = 0; i < rays.Length; i++)
                    {
                        if (Application.isPlaying)
                        {
                            bool hit = Physics.Raycast(rays[i], Vector3.down, controller.Movement.RayLength, controller.Movement.GroundLayer, QueryTriggerInteraction.Ignore);
                            Handles.color = hit ? new Color(0f, 1f, 0f, 1f) : new Color(1f, 0f, 0f, 1f);
                        }
                        else
                        {
                            Handles.color = Color.white;
                        }

                        Handles.DrawLine(rays[i], new Vector3(rays[i].x, rays[i].y - controller.Movement.RayLength, rays[i].z));
                    }
                }
                else if (controller.Movement.GroundCheck == GroundCheckType.Sphere)
                {
                    Vector3 pos = new Vector3(controller.transform.position.x, controller.transform.position.y + radius - 0.1f, controller.transform.position.z);
                    if (Application.isPlaying)
                    {
                        Handles.color = controller.Movement.IsGrounded ? new Color(0f, 1f, 0f, 0.25f) : new Color(1f, 0f, 0f, 0.25f);
                    }
                    else
                    {
                        Handles.color = new Color(0f, 1f, 0f, 0.25f);
                    }
                    Handles.SphereHandleCap(0, pos, Quaternion.identity, radius * 2, EventType.Repaint);
                    if (Application.isPlaying)
                    {
                        Handles.color = controller.Movement.IsGrounded ? new Color(0f, 1f, 0f, 1f) : new Color(1f, 0f, 0f, 1f);
                    }
                    else
                    {
                        Handles.color = new Color(0f, 1f, 0f, 1f);
                    }
                    //Handles.DrawWireSphere(pos, radius);
                    Handles.RadiusHandle(Quaternion.identity, pos, radius, false);
                }
            }
            Handles.color = oColor;
        }
        private void OnEnable()
        {
            currentTab = EditorPrefs.GetInt(SELECTED_TAB_PREFS, 0);

            if (currentTab < 0)
            {
                currentTab = 0;
            }

            if (currentTab > 4)
            {
                currentTab = 4;
            }

            camera   = serializedObject.FindProperty("cam");
            movement = serializedObject.FindProperty("movement");
            headBob  = serializedObject.FindProperty("headBob");
            audio    = serializedObject.FindProperty("sounds");

            canLookAround    = camera.FindPropertyRelative("canLookAround");
            shoudLockCursor  = camera.FindPropertyRelative("shouldLockCursor");
            rotateCameraOnly = camera.FindPropertyRelative("rotateCameraOnly");
            invertXAxis      = camera.FindPropertyRelative("invertXAxis");
            invertYAxis      = camera.FindPropertyRelative("invertYAxis");
            lookSensitivity  = camera.FindPropertyRelative("lookSensitivity");
            lookDamping      = camera.FindPropertyRelative("lookDamping");
            minimumX         = camera.FindPropertyRelative("minimumX");
            maximumX         = camera.FindPropertyRelative("maximumX");
            cameraHead       = camera.FindPropertyRelative("cameraHead");
            fieldOfViewKick  = camera.FindPropertyRelative("fieldOfViewKick");

            fovEnable       = fieldOfViewKick.FindPropertyRelative("enableFOVKick");
            fovUnscaledTime = fieldOfViewKick.FindPropertyRelative("unscaledTime");
            fovKickWhen     = fieldOfViewKick.FindPropertyRelative("kickWhen");
            fovKickAmount   = fieldOfViewKick.FindPropertyRelative("kickAmount");
            fovTimeTo       = fieldOfViewKick.FindPropertyRelative("lerpTimeTo");
            fovTimeFrom     = fieldOfViewKick.FindPropertyRelative("lerpTimeFrom");
#if GOLD_PLAYER_CINEMACHINE
            useCinemachine      = fieldOfViewKick.FindPropertyRelative("useCinemachine");
            targetVirtualCamera = fieldOfViewKick.FindPropertyRelative("targetVirtualCamera");
#endif
            targetCamera = fieldOfViewKick.FindPropertyRelative("targetCamera");

            canMoveAround    = movement.FindPropertyRelative("canMoveAround");
            moveUnscaledTime = movement.FindPropertyRelative("unscaledTime");

            walkingSpeed = movement.FindPropertyRelative("walkingSpeeds");

            canRun           = movement.FindPropertyRelative("canRun");
            runToggleMode    = movement.FindPropertyRelative("runToggleMode");
            runSpeeds        = movement.FindPropertyRelative("runSpeeds");
            stamina          = movement.FindPropertyRelative("stamina");
            enableStamina    = stamina.FindPropertyRelative("enableStamina");
            drainStaminaWhen = stamina.FindPropertyRelative("drainStaminaWhen");
            maxStamina       = stamina.FindPropertyRelative("maxStamina");
            drainRate        = stamina.FindPropertyRelative("drainRate");
            stillThreshold   = stamina.FindPropertyRelative("stillThreshold");
            regenRateStill   = stamina.FindPropertyRelative("regenRateStill");
            regenRateMoving  = stamina.FindPropertyRelative("regenRateMoving");
            regenWait        = stamina.FindPropertyRelative("regenWait");

            canCrouch        = movement.FindPropertyRelative("canCrouch");
            crouchToggleMode = movement.FindPropertyRelative("crouchToggleMode");
            crouchSpeeds     = movement.FindPropertyRelative("crouchSpeeds");
            crouchJumping    = movement.FindPropertyRelative("crouchJumping");
            crouchHeight     = movement.FindPropertyRelative("crouchHeight");
            crouchHeadLerp   = movement.FindPropertyRelative("crouchHeadLerp");

            canJump = movement.FindPropertyRelative("canJump");
            jumpingRequiresStamina = movement.FindPropertyRelative("jumpingRequiresStamina");
            jumpStaminaRequire     = movement.FindPropertyRelative("jumpStaminaRequire");
            jumpStaminaCost        = movement.FindPropertyRelative("jumpStaminaCost");
            jumpHeight             = movement.FindPropertyRelative("jumpHeight");
            airJump        = movement.FindPropertyRelative("airJump");
            airJumpTime    = movement.FindPropertyRelative("airJumpTime");
            airJumpsAmount = movement.FindPropertyRelative("airJumpsAmount");
            allowAirJumpDirectionChange = movement.FindPropertyRelative("allowAirJumpDirectionChange");

            movingPlatforms         = movement.FindPropertyRelative("movingPlatforms");
            movingPlatformsEnabled  = movingPlatforms.FindPropertyRelative("enabled");
            movingPlatformsPosition = movingPlatforms.FindPropertyRelative("movePosition");
            movingPlatformsRotation = movingPlatforms.FindPropertyRelative("moveRotation");
            movingPlatformsMaxAngle = movingPlatforms.FindPropertyRelative("maxAngle");

            groundLayer       = movement.FindPropertyRelative("groundLayer");
            acceleration      = movement.FindPropertyRelative("acceleration");
            gravity           = movement.FindPropertyRelative("gravity");
            airControl        = movement.FindPropertyRelative("airControl");
            enableGroundStick = movement.FindPropertyRelative("enableGroundStick");
            groundStick       = movement.FindPropertyRelative("groundStick");
            groundCheck       = movement.FindPropertyRelative("groundCheck");
            rayAmount         = movement.FindPropertyRelative("rayAmount");
            rayHeight         = movement.FindPropertyRelative("rayHeight");
            rayLength         = movement.FindPropertyRelative("rayLength");

            enableBob           = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("enableBob");
            bobUnscaledTime     = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("unscaledTime");
            bobFrequency        = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("bobFrequency");
            bobHeight           = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("bobHeight");
            swayAngle           = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("swayAngle");
            sideMovement        = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("sideMovement");
            heightMultiplier    = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("heightMultiplier");
            strideMultiplier    = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("strideMultiplier");
            landMove            = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("landMove");
            landTilt            = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("landTilt");
            enableStrafeTilting = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("enableStrafeTilting");
            strafeTilt          = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("strafeTilt");
            bobTarget           = headBob.FindPropertyRelative("bobClass").FindPropertyRelative("bobTarget");

            enableAudio       = audio.FindPropertyRelative("enableAudio");
            audioUnscaledTime = audio.FindPropertyRelative("unscaledTime");
            audioType         = audio.FindPropertyRelative("audioType");
            basedOnHeadBob    = audio.FindPropertyRelative("basedOnHeadBob");
            stepTime          = audio.FindPropertyRelative("stepTime");
            walkFootsteps     = audio.FindPropertyRelative("walkFootsteps");
            runFootsteps      = audio.FindPropertyRelative("runFootsteps");
            crouchFootsteps   = audio.FindPropertyRelative("crouchFootsteps");
            jumpingSteps      = audio.FindPropertyRelative("jumping");
            landingSteps      = audio.FindPropertyRelative("landing");
            footstepsSource   = audio.FindPropertyRelative("footstepsSource");
            jumpSource        = audio.FindPropertyRelative("jumpSource");
            landSource        = audio.FindPropertyRelative("landSource");

            goldPlayer          = (GoldPlayerController)target;
            characterController = goldPlayer.GetComponent <CharacterController>();
        }