Skip to content
🤔prompts chat🧠
🔍
question:как в unity получить время через которое закончится анимация?

answer:В Unity, чтобы узнать время до окончания анимации, вы можете использовать `Animator` компонент, который управляет анимацией. У этого компонента есть несколько полезных функций и свойств, которые позволяют вам получить длительность анимации и текущую позицию воспроизведения. Чтобы узнать оставшееся время анимации, вам нужно будет выполнить некоторые расчеты. Вот как вы можете это сделать: 1. Получите ссылку на `Animator` компонент вашего объекта. 2. Активируйте анимацию, если это еще не сделано. 3. Используйте `GetCurrentAnimatorStateInfo` для получения информации о текущем состоянии анимации. 4. Используйте свойства `length` и `normalizedTime` для расчета оставшегося времени. Вот пример кода, который можно использовать в скрипте Unity: ```csharp using UnityEngine; public class AnimationTimer : MonoBehaviour { private Animator animator; void Start() { animator = GetComponent<Animator>(); // Запустите вашу анимацию здесь animator.Play("YourAnimation"); } void Update() { AnimatorStateInfo animationState = animator.GetCurrentAnimatorStateInfo(0); float timeLeft = animationState.length - (animationState.normalizedTime % 1) * animationState.length; Debug.Log("Время до окончания анимации: " + timeLeft); } } ``` Пояснение к коду: - `GetCurrentAnimatorStateInfo(0)` возвращает информацию о текущем состоянии анимации для слоя номер 0 (в Unity могут быть разные слои анимации). - `animationState.length` - это длительность анимации в секундах. - `animationState.normalizedTime` - это нормализованное время проигрывания анимации, где 1.0 означает, что анимация прошла один цикл полностью. Заметьте, что это значение может быть больше 1, если анимация проигрывается в цикле. - `(animationState.normalizedTime % 1)` - получаем дробную часть нормализованного времени, что даёт прогресс текущего цикла анимации. - `(animationState.normalizedTime % 1) * animationState.length` - расчет времени, которое уже прошло в текущем цикле. - `timeLeft` - оставшееся время до конца анимации. Обратите внимание, что если анимация зациклена, то `normalizedTime` будет увеличиваться бесконечно, и вам, возможно, потребуется другой способ определения конца анимации в зависимости от вашего варианта использования.

question:Fix this command: adb shell 'while :; do ! ps -A | grep frida-server > /dev/null && echo "Restarting Frida" && /data/local/tmp/frida-server & sleep 60; done'

answer:The command you've provided is meant to run a loop on an Android device using ADB (Android Debug Bridge) to check if `frida-server` is running; if it's not, it will print "Restarting Frida", start `frida-server`, and then wait for 60 seconds before checking again. However, there is an issue with the use of the `!` in the `do` loop. Here's the corrected command: ```sh adb shell 'while :; do ps -A | grep -q frida-server || (echo "Restarting Frida" && /data/local/tmp/frida-server &); sleep 60; done' ``` Changes and explanation: 1. Replaced `! ps -A | grep frida-server > /dev/null` with a more readable `ps -A | grep -q frida-server ||`. The `-q` flag for `grep` makes it quiet (no output), which is effectively like redirecting to `/dev/null`. The `||` means that the following commands will be executed only if `grep` doesn't find `frida-server` (i.e., it exits with a non-zero status). 2. Removed the `!` operator preceding the `ps` command. It was negating the result incorrectly. 3. Enclosed `echo "Restarting Frida" && /data/local/tmp/frida-server &` in parentheses to ensure that the echo and the frida-server restart command are considered a single unit for the condition. 4. The `&` after `/data/local/tmp/frida-server` is kept to run `frida-server` in the background. After running this command, your ADB shell will enter a loop that checks if `frida-server` is running every 60 seconds, and if it's not, it will print "Restarting Frida" to the shell, start `frida-server` in the background, and then sleep for 60 seconds before checking again.

question:) was unexpected at this time.

answer:Apologies for the confusion. It looks like there is an issue with the command syntax for the shell invoked by `adb`. When using adb shell with a while loop, you should take care to escape certain characters and ensure the syntax is compatible with the shell used on the device (typically `sh`). Let's fix the command accordingly: ```sh adb shell 'while true; do ps -A | grep -q frida-server || (echo "Restarting Frida"; /data/local/tmp/frida-server &); sleep 60; done' ``` Or you can use escaped characters to avoid issues with parentheses: ```sh adb shell 'while true; do ps -A | grep -q frida-server || { echo "Restarting Frida"; /data/local/tmp/frida-server & }; sleep 60; done' ``` Here's a breakdown of the corrected command: 1. `while true` is another way to write `while :` and represents an infinite loop. 2. `ps -A | grep -q frida-server` searches for `frida-server` among the running processes. The `-q` flag tells `grep` to be quiet and just return an exit code. 3. The `||` operator is a logical OR that will execute the following command block only if the previous command (the `grep`) fails to find `frida-server`. 4. `{ echo "Restarting Frida"; /data/local/tmp/frida-server & }` is a group of commands. First, it outputs the message, then starts `frida-server` in the background. 5. `sleep 60;` pauses the loop for 60 seconds before it runs again. 6. The whole command is single-quoted to be passed as a single argument to `adb shell`. 7. If you encounter issues with the curly braces `{` `}`, you can also try using parentheses, but the `&` after frida-server may need to be escaped (as in the first version). Make sure the frida-server binary at `/data/local/tmp/frida-server` has execute permissions (`chmod +x /data/local/tmp/frida-server`) before running this command.

question:Is grep in adb?

answer:Yes, `grep` is typically available in the shell environment of most Unix-like systems, including many Android devices. However, some Android device manufacturers might ship devices with a shell environment that is more limited and does not include `grep`. For example, on devices with a restricted or minimal set of utilities, you may find that `grep` or other standard Unix tools are not present. If you find that `grep` is not available in your Android shell environment, you have a few options: 1. **Use Toybox:** Modern Android versions come with Toybox, a collection of common Unix utilities combined into a single executable. You can use Toybox commands for similar functionality. For instance, you can use `toybox ps` and `toybox grep`. 2. **Install BusyBox:** You can install BusyBox, which provides implementations of many common Unix utilities like `grep`. BusyBox is designed for embedded systems and is a common addition for rooted Android devices. 3. **Find Alternatives:** You could also attempt to use `findstr` on some devices, which serves a similar purpose to `grep`, or you can use shell-specific constructs to filter process lists instead. Here is an example of how you might rewrite the command without using `grep`: ```sh adb shell 'while true; do for proc in (ps -A | awk '''{print NF}'''); do [ "proc" = "frida-server" ] && break; done; [ "proc" != "frida-server" ] && echo "Restarting Frida" && /data/local/tmp/frida-server &; sleep 60; done' ``` In this example, `awk` is used to extract the last field of each line output by `ps`, assumed to be the process name. The loop checks whether `frida-server` is one of those process names. If not, it proceeds to restart `frida-server`. This is assuming that `awk` is available, which is generally more likely than `grep`. However, if `awk` is also not available, you might need to rely on even more basic shell commands, or consider installing BusyBox or another environment that provides the needed utilities.

Released under the MIT License.

has loaded