Используйте Unity Editor для создания 2D и 3D игр, приложений и экспериментов
Если вы впервые используете Unity, ознакомьтесь с вводной документацией о работе с Unity и ознакомьтесь с учебниками Unity.
Узнайте о пакетах:
Работа с менеджером пакетов
Найдите документацию для конкретного пакета: Подтвержденные пакеты
Пакет, прошедший тестирование на цикл релизов для определенной версии Unity, получает обозначение Подтверждено для. Это означает, что эти пакеты гарантированно работают с назначенной версией Unity.Узнайте, как создавать пользовательские пакеты: Создание пользовательских пакетов
Руководство по bewейшей практике
Разделы руководства пользователя Unity

Создание с Unity
Полное руководство по Unity Editor.

Unity 2D
Все 2D-специфические функции редактора Unity, включая игровой процесс, спрайты и физику.

Графика
Визуальные аспекты редактора Unity, включая камеры и освещение.

Физика
Симуляция 3D движения, массы, гравитации и столкновений.

Сетевые возможности
Как реализовать многопользовательскую и сетевую игру.

Скриптинг
Программирование ваших игр с помощью скриптов в редакторе Unity.

Аудио
Звук в редакторе Unity, включая клипы, источники, слушатели, импорт и настройки звука.

Анимация
Анимация в редакторе Unity.
UI<enter> to interrupt or ? for more options.
## Create a source file
package example
object Hello {
def main(args: Array[String]): Unit = {
println(Hello)
}
}
This new file should be picked up by the running command:
[info] Build triggered by /tmp/foo-build/src/main/scala/example/Hello.scala. Running compile.[info] compiling 1 Scala source to /tmp/foo-build/target/scala-2.12/classes …
[success] Total time: 0 s, completed 28 Jul 2023, 13:38:55
[info] 2. Monitoring source files for foo-build/compile…
[info] Press <enter> to interrupt or ? for more options.
Press `Enter` to exit `~compile`.
## Run a previous command
From sbt shell, press up-arrow twice to find the `compile` command that you executed at the beginning.
sbt:foo-build> compile
## Getting help
Use the `help` command to get basic help about the available commands.
sbt:foo-build> help
<command> (; <command>)* Runs the provided semicolon-separated commands.
libraryDependencies += com.example %% toolkit-test % 1.0.0
## Как использовать SBT для тестирования Scala проектов
---
Когда вы работаете над Scala проектами, использование SBT (Simple Build Tool) может значительно упростить процесс сборки, запуска тестов и добавления зависимостей библиотек. В этой статье мы рассмотрим несколько основных команд SBT и примеров их использования.
## Установка зависимостей
Для добавления зависимостей к вашему проекту, вы можете использовать следующий синтаксис:
```scala
libraryDependencies += org.scala-lang %% toolkit-test % 0.1.7 % Test
После добавления зависимости, используйте команду reload для отражения изменений в build.sbt.
Запуск тестов
Для запуска тестов в вашем проекте, выполните команду:
test
Если вам необходимо запускать тесты в режиме инкрементальной проверки, используйте команду:
~testQuick
Написание тестов
Для написания нового теста в вашем проекте, создайте файл src/test/scala/example/HelloSuite.scala с помощью вашего редактора кода:
class HelloSuite extends munit.FunSuite {
test(Hello should start with H) {
assert(Hello.startsWith(H))
}
}
Использование Scala REPL
Вы можете использовать Scala REPL для выполнения различных операций, например, получить текущую погоду в Нью-Йорке:
sbt:Hello> console
import sttp.client4.quick._
import sttp.client4.Response
val newYorkLatitude: Double = 40.7143
val newYorkLongitude: Double = -74.006
val response: Response[String] = quickRequest
.get(
urihttps://api.open-meteo.com/v1/forecast?latitude=$newYorkLatitude&longitude=$newYorkLongitude¤t_weather=true
)
.send()
println(ujson.read(response.body).render(indent = 2))
С помощью этих примеров использования SBT вы сможете более эффективно управлять вашим Scala проектом. Следуйте инструкциям и примерам, чтобы освоить инструменты SBT и улучшить процесс разработки в Scala.
"temperature": 21.3,
"windspeed": 16.7,
"winddirection": 205,
"weathercode": 3,
"is_day": 1,
"time": "2023-08-04T10:00"
}
}
import sttp.client4.quick._
import sttp.client4.Response
val newYorkLatitude: Double = 40.7143
val newYorkLongitude: Double = -74.006
val response: sttp.client4.Response[String] = Response({"latitude":40.710335,"longitude":-73.99307,"generationtime_ms":0.36704540252685547,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":51.0,"current_weather":{"temperature":21.3,"windspeed":16.7,"winddirection":205.0,"weathercode":3,"is_day":1,"time":"2023-08-04T10:00"}},200,,List(:status: 200, content-encoding: deflate, content-type: application/json; charset=utf-8, date: Fri, 04 Aug 2023 10:09:11 GMT),List(),RequestMetadata(GET,https://api.open-meteo.com/v1/forecast?latitude=40.7143&longitude…
scala> :q // to quit
### Make a subproject
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / organization := "com.example"
lazy val hello = project
.in(file("."))
.settings(
name := "Hello",
libraryDependencies ++= Seq(
"org.scala-lang" %% "toolkit" % "0.1.7",
"org.scala-lang" %% "toolkit-test" % "0.1.7" % Test
)
)
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core"
)
Use the `reload` command to reflect the change in `build.sbt`.
### List all subprojects
sbt:Hello> projects
[info] In file:/tmp/foo-build/ [info] * hello [info] helloCore
### Compile the subproject
sbt:Hello> helloCore/compile
### Add toolkit-test to the subproject
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / organization := "com.example"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"
lazy val hello = project
.in(file("."))
.settings(
name := "Hello",
libraryDependencies ++= Seq(
"org.scala-lang" %% "toolkit" % "0.1.7",
toolkitTest % Test
)
)
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies += toolkitTest % Test
)
### Broadcast commands
Set aggregate so that the command sent to `hello` is broadcast to `helloCore` too:
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / organization := "com.example"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.settings(
name := "Hello",
libraryDependencies ++= Seq(
"org.scala-lang" %% "toolkit" % "0.1.7",
toolkitTest % Test
)
)
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies += toolkitTest % Test
)
After `reload`, `~testQuick` now runs on both subprojects:
sbt:Hello> ~testQuick
Press `Enter` to exit the continuous test.
### Make hello depend on helloCore
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / organization := "com.example"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.dependsOn(helloCore)
.settings(
name := "Hello",
libraryDependencies += toolkitTest % Test
)
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.1.7",
libraryDependencies += toolkitTest % Test
)
### Parse JSON using uJson
Let’s use uJson from the toolkit in `helloCore`.
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / organization := "com.example"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.dependsOn(helloCore)
.settings(
name := "Hello",
libraryDependencies += toolkitTest % Test
)
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.1.7",
libraryDependencies += toolkitTest % Test
)
After `reload`, add `core/src/main/scala/example/core/Weather.scala`:
package example.core
import sttp.client4.quick._
import sttp.client4.Response
object Weather {
def temp() = {
val response: Response[String] = quickRequest
.get(
uri"https://api.open-meteo.com/v1/forecast?latitude=40.7143&longitude=-74.006¤t_weather=true"
)
.send()
val json = ujson.read(response.body)
json.obj("current_weather")("temperature").num
}
}
package example
import example.core.Weather
object Hello {
def main(args: Array[String]): Unit = {
val temp = Weather.temp()
println(s"Hello! The current temperature in New York is $temp C.")
}
}
Let’s run the app to see if it worked:
sbt:Hello> run
[info] compiling 1 Scala source to /tmp/foo-build/core/target/scala-2.13/classes … [info] compiling 1 Scala source to /tmp/foo-build/target/scala-2.13/classes … [info] running example.HelloHello! The current temperature in New York is 22.7 C.
### Add sbt-native-packager plugin
Using an editor, create `project/plugins.sbt`:
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.4")
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / organization := "com.example"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.dependsOn(helloCore)
.enablePlugins(JavaAppPackaging)
.settings(
name := "Hello",
libraryDependencies += toolkitTest % Test,
maintainer := "A Scala Dev!"
)
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.1.7",
libraryDependencies += toolkitTest % Test
)
### Reload and create a .zip distribution
sbt:Hello> reload
…
sbt:Hello> dist
[info] Wrote /private/tmp/foo-build/target/scala-2.13/hello_2.13-0.1.0-SNAPSHOT.pom [info] Main Scala API documentation to /tmp/foo-build/target/scala-2.13/api… [info] Main Scala API documentation successful. [info] Main Scala API documentation to /tmp/foo-build/core/target/scala-2.13/api… [info] Wrote /tmp/foo-build/core/target/scala-2.13/hello-core_2.13-0.1.0-SNAPSHOT.pom [info] Main Scala API documentation successful. [success] All package validations passed [info] Your package is ready in /tmp/foo-build/target/universal/hello-0.1.0-SNAPSHOT.zip
Here’s how you can run the packaged app:
$ /tmp/someother
$ cd /tmp/someother
$ unzip -o -d /tmp/someother /tmp/foo-build/target/universal/hello-0.1.0-SNAPSHOT.zip
$ ./hello-0.1.0-SNAPSHOT/bin/hello
Hello! The current temperature in New York is 22.7 C.
### Dockerize your app
_Note that a Docker daemon will need to be running in order for this to work._
sbt:Hello> Docker/publishLocal
….
[info] Built image hello with tags [0.1.0-SNAPSHOT]
Here’s how to run the Dockerized app:
$ docker run hello:0.1.0-SNAPSHOT
Hello! The current temperature in New York is 22.7 C.
### Set the version
ThisBuild / version := "0.1.0"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / organization := "com.example"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.dependsOn(helloCore)
.enablePlugins(JavaAppPackaging)
.settings(
name := "Hello",
libraryDependencies += toolkitTest % Test,
maintainer := "A Scala Dev!"
)
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.1.7",
libraryDependencies += toolkitTest % Test
)
### Switch scalaVersion temporarily
sbt:Hello> ++3.3.1!
[info] Forcing Scala version to 3.3.1 on all projects. [info] Reapplying settings… [info] Set current project to Hello (in build file:/tmp/foo-build/)
Check the `scalaVersion` setting:
sbt:Hello> scalaVersion
[info] helloCore / scalaVersion [info] 3.3.1 [info] scalaVersion [info] 3.3.1
This setting will go away after `reload`.
### Inspect the dist task
To find out more about `dist`, try `help` and `inspect`.
sbt:Hello> help dist
Creates the distribution packages.
sbt:Hello> inspect dist
To call inspect recursively on the dependency tasks use `inspect tree`.
sbt:Hello> inspect tree dist
[info] dist = Task[java.io.File] [info] +-Universal / dist = Task[java.io.File]….
### Batch mode
You can also run sbt in batch mode, passing sbt commands directly from the terminal.
$ sbt clean "testOnly HelloSuite"
**Note**: Running in batch mode requires JVM spinup and JIT each time, so **your build will run much slower**. For day-to-day coding, we recommend using the sbt shell or a continuous test like `~testQuick`.
### sbt new command
You can use the sbt `new` command to quickly setup a simple “Hello world” build.
$ sbt new scala/scala-seed.g8
….
A minimal Scala project.
name [My Something Project]: hello
Template applied in ./hello
When prompted for the project name, type `hello`.
This will create a new project under a directory named `hello`.
### Credits
This page is based on the Essential sbt tutorial written by William “Scala William” Narmontas.