Exemplo n.º 1
0
 protected virtual void ToggleLockOnGUI()
 {
     if (currentCharaInfo)
     {
         var targetManager = CameraTargetManager.GetTargetManager(currentCharaInfo);
         targetManager.ToggleGUITargets();
     }
 }
Exemplo n.º 2
0
        protected virtual bool LockOn()
        {
            if (currentCharaInfo)
            {
                var targets = CameraTargetManager.GetTargetManager(currentCharaInfo).GetTargets();

                if (shouldResetLock)
                {
                    shouldResetLock = false;
                    return(LockOn(targets[0]));
                }

                if (reduceOffset == true)
                {
                    CameraTargetPos += targetOffsetSize;
                    targetOffsetSize = new Vector3();
                }
                else if (targetOffsetSize.magnitude > 0f)
                {
                    reduceOffset = true;
                    return(true);
                }

                if (!lockOnTarget)
                {
                    return(LockOn(targets[0]));
                }
                else
                {
                    for (int i = 0; i < targets.Count; i++)
                    {
                        if (lockOnTarget == targets[i])
                        {
                            int next = i + 1 > targets.Count - 1 ? 0 : i + 1;
                            return(LockOn(targets[next]));
                        }
                    }

                    return(LockOn(targets[0]));
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        protected virtual bool LockOn(string targetName, bool lockOnAnyway = false, bool resetOffset = true)
        {
            foreach (var target in CameraTargetManager.GetTargetManager(currentCharaInfo).GetTargets())
            {
                if (target.name == targetName)
                {
                    if (LockOn(target, resetOffset))
                    {
                        return(true);
                    }
                }
            }

            if (lockOnAnyway)
            {
                if (LockOn())
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        protected virtual void Update()
        {
            if (!lockOnTarget && lockedOn)
            {
                Console.WriteLine("Reset LockOnPlugin");
                ResetModState();
            }

            lockOnHotkey.KeyHoldAction(LockOnRelease);
            lockOnHotkey.KeyUpAction(() => LockOn());
            lockOnGUIHotkey.KeyDownAction(ToggleLockOnGUI);
            prevCharaHotkey.KeyDownAction(() => CharaSwitch(false));
            nextCharaHotkey.KeyDownAction(() => CharaSwitch(true));

            if (lockOnTarget && CameraEnabled)
            {
                if (Input.GetMouseButton(0) && Input.GetMouseButton(1))
                {
                    float x = Input.GetAxis("Mouse X");
                    float y = Input.GetAxis("Mouse Y");
                    if (Mathf.Abs(x) > 0f || Mathf.Abs(y) > 0f)
                    {
                        targetOffsetSize += (CameraRight * x * defaultCameraSpeed) + (CameraForward * y * defaultCameraSpeed);
                        reduceOffset      = false;
                    }
                }
                else if (Input.GetMouseButton(1))
                {
                    float x = Input.GetAxis("Mouse X");
                    if (Input.GetKey(KeyCode.LeftControl))
                    {
                        Guitime.angle = 0.1f;
                        if (Mathf.Abs(x) > 0f)
                        {
                            //camera tilt adjustment
                            float newAngle = CameraAngle.z - x;
                            newAngle    = Mathf.Repeat(newAngle, 360f);
                            CameraAngle = new Vector3(CameraAngle.x, CameraAngle.y, newAngle);
                        }
                    }
                    else if (Input.GetKey(KeyCode.LeftShift))
                    {
                        Guitime.fov = 0.1f;
                        if (Mathf.Abs(x) > 0f)
                        {
                            //fov adjustment
                            float newFov = CameraFov + x;
                            CameraFov = Mathf.Clamp(newFov, 1f, 160f);
                        }
                    }
                    else if (!InputFieldSelected)
                    {
                        if (Mathf.Abs(x) > 0f)
                        {
                            //handle zooming manually when camera.movespeed == 0
                            float newDir = CameraDir.z - x * CameraZoomSpeed;
                            newDir       = Mathf.Clamp(newDir, float.MinValue, 0f);
                            CameraDir    = new Vector3(0f, 0f, newDir);
                            reduceOffset = false;
                        }

                        float y = Input.GetAxis("Mouse Y");
                        if (Mathf.Abs(y) > 0f)
                        {
                            targetOffsetSize += (Vector3.up * y * defaultCameraSpeed);
                            reduceOffset      = false;
                        }
                    }
                }

                bool RightArrow = Input.GetKey(KeyCode.RightArrow), LeftArrow = Input.GetKey(KeyCode.LeftArrow);
                bool UpArrow = Input.GetKey(KeyCode.UpArrow), DownArrow = Input.GetKey(KeyCode.DownArrow);
                bool PageUp = Input.GetKey(KeyCode.PageUp), PageDown = Input.GetKey(KeyCode.PageDown);

                if (!InputFieldSelected && Hotkey.allowHotkeys && (RightArrow || LeftArrow || UpArrow || DownArrow || PageUp || PageDown))
                {
                    reduceOffset   = false;
                    offsetKeyHeld += Time.deltaTime / 3f;
                    if (offsetKeyHeld > 1f)
                    {
                        offsetKeyHeld = 1f;
                    }
                    float speed = Time.deltaTime * Mathf.Lerp(0.2f, 2f, offsetKeyHeld);

                    if (RightArrow)
                    {
                        targetOffsetSize += CameraRight * speed;
                    }
                    else if (LeftArrow)
                    {
                        targetOffsetSize += CameraRight * -speed;
                    }

                    if (UpArrow)
                    {
                        targetOffsetSize += CameraForward * speed;
                    }
                    else if (DownArrow)
                    {
                        targetOffsetSize += CameraForward * -speed;
                    }

                    if (PageUp)
                    {
                        targetOffsetSize += CameraUp * speed;
                    }
                    else if (PageDown)
                    {
                        targetOffsetSize += CameraUp * -speed;
                    }
                }
                else
                {
                    offsetKeyHeld -= Time.deltaTime * 2f;
                    if (offsetKeyHeld < 0f)
                    {
                        offsetKeyHeld = 0f;
                    }
                }

                if (reduceOffset)
                {
                    // add this as a setting
                    if (targetOffsetSize.magnitude > 0.00001f)
                    {
                        float trackingSpeed = CameraTargetManager.IsMovementPoint(lockOnTarget) ? trackingSpeedMax : LockOnPlugin.TrackingSpeedNormal.Value;
                        targetOffsetSize = Vector3.MoveTowards(targetOffsetSize, new Vector3(), targetOffsetSize.magnitude / (1f / trackingSpeed));
                    }
                    else
                    {
                        targetOffsetSize = new Vector3();
                        reduceOffset     = false;
                    }
                }

                if (AllowTracking)
                {
                    float trackingSpeed;
                    float leash;

                    if (CameraTargetManager.IsMovementPoint(lockOnTarget))
                    {
                        trackingSpeed = trackingSpeedMax;
                        leash         = 0f;
                    }
                    else
                    {
                        trackingSpeed = LockOnPlugin.TrackingSpeedNormal.Value;
                        leash         = LockOnPlugin.LockLeashLength.Value;
                    }

                    float distance = Vector3.Distance(CameraTargetPos, lastTargetPos.Value);
                    if (distance > leash + 0.00001f)
                    {
                        CameraTargetPos = Vector3.MoveTowards(CameraTargetPos, LockOnTargetPos + targetOffsetSize, (distance - leash) * trackingSpeed * Time.deltaTime * 60f);
                    }
                    CameraTargetPos      += targetOffsetSize - targetOffsetSizeAdded;
                    targetOffsetSizeAdded = targetOffsetSize;
                    lastTargetPos         = LockOnTargetPos + targetOffsetSize;
                }
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                HideLockOnTargets();
            }
        }