Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions manual/scripting/advanced/curve.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
# Curve

Engine API contains **BezierCurve<T>** and **LinearCurve<T>** types that can be very useful for animations driven via game code. For instance, you can expose the curve, edit it in the editor and then use to perform smooth animation.
Curves are a nice way to represent a value over a certain time. They have a lot of use cases, which include easing harsh transitions, defining different output values for different input values or a really fine tuned jump arc.

Here is sa sample script that shows how to use a curves:
## Curve types

Flax engine provides the [`BezierCurve<T>`](https://docs.flaxengine.com/api/FlaxEngine.BezierCurve-1.html) and [`LinearCurve<T>`](https://docs.flaxengine.com/api/FlaxEngine.LinearCurve-1.html) classes to represent a **bezier-** or **linear curve**. Both come with an extensive API and editor, that allows you to quickly create, modify and utilize curves in your game.

Both curve classes have a *type wildcard* `<T>`, which you can use to make a curve represent different types, like for example `int`s, `float`s or even more complex ones like `Vector3` or `Color`. The curve editor will adapt based on which type the curve has.

## Curve editor

The curve editor provides an easy and intuitive way to edit and visualize a curve.

### Adding and editing curve points

You can pan the editor by moving the mouse while the right mouse button is pressed down. Double click anywhere in the curve editor to create a new curve point. To move a point, click and drag on it. You can double click an existing point to edit its values, like the time, value, or in the case of a bezier curve, the easing.

To bring up a menu with more edit options, right click anywhere in the curve editor. It allows you to copy and paste a point, edit multiple curve points at once, reset the view or show the whole curve. The latter one can also be done by pressing *F* on your keyboard.

### Curve presets

It is also possible to apply a preset to your curve: Simply bring up the right click menu, go to "*Apply Preset*" and chose the preset you want to apply.

### Resizing

The curve editor can be resized horizontally by dragging on the bottom bar, right below its horizontal scrollbar.

![Curve editor in use](media/curve-editor.gif)

## Example

This sample script will show you how to use curves:

```cs
public class CustomCurve : Script
Expand All @@ -25,11 +53,12 @@ public class CustomCurve : Script
{
var time = (Time.GameTime - start) * speed;

FloatCurve.Evaluate(out var floatValue, time);
Vector2Curve.Evaluate(out var vector2Curve, time);
Vector3Curve.Evaluate(out var vector3Curve, time);
// Access the curve's data
FloatCurve.Evaluate(out float floatValue, time);
Vector2Curve.Evaluate(out Vector2 vector2value, time);
Vector3Curve.Evaluate(out Vector3 vector3value, time);

Debug.Log(string.Format("At {0}: float: {1}, vec2: {2}, vec3: {3}", time, floatValue, vector2Curve, vector3Curve));
Debug.Log($"At {time}: float: {floatValue}, vec2: {vector2value}, vec3: {vector3value}")
}
}
```
Expand Down
Binary file added manual/scripting/advanced/media/curve-editor.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified manual/scripting/advanced/media/tags-editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 26 additions & 8 deletions manual/scripting/advanced/tags.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
# Tags

Gameplay tag that represents a hierarchical name of the form `X.Y.Z` (namespaces separated with a dot). Tags are defined in project [LayersAndTagsSettings](../../editor/game-settings/layers-and-tags-settings.md) asset but can be also created from code.
Flax has the concept of **tags**, which are can be used to mark an actor as part of a group (not to be confused with [Static Flags](https://docs.flaxengine.com/api/FlaxEngine.StaticFlags.html) or [Layers](https://docs.flaxengine.com/manual/editor/game-settings/layers-and-tags-settings.html)) or to track state by using the **tags** as a way to represent booleans.

Scripting API contains the structure `Tag` which holds index of the tag in a global `Tags.List` array. Tags comparison is very fast (`int32` compare), also single tag uses very little memory (4 bytes). Scripting API `Tags` contains utilities for using tag lists such as `HasTag`/`HasTagExact`/`HasAny`/`HasAnyExact`/`HasAll`/`HasAllExact` which use an array of tags (`Tag[]` in C#, `Array<Tag>` in C++).
## Tags in Flax Engine

In case you are not familiar with what a **tag** is in the context of Flax Engine, similar terms you might recognize are "*label*", "*keyword*", "*marker*" or "*identifier*".

They are represented in a hierarchical form as `X.Y.Z` (**tags** separated with a dot) and can be defined in a Flax project's [LayersAndTagsSettings](../../editor/game-settings/layers-and-tags-settings.md) settings, or be created from code.

As mentioned before, they are most commonly used to tag actors, but it is also possible to have an array of **tags** anywhere in your code, without the need for an *Actor* that holds the **tags**.

## Actor Tags

Every actor contains list of tags (`Actor.Tags`) and various utilities for quick checking for a tag (`Actor.HasTag`). Actors can be marked with specific tags to be used by different gameplay systems. For example, player rigidbody and collider can be marked with a tag `Player` to distinguish them when processing collision events or when calculating hit damage in a shooter game.
Every *Actor* contains a list of **tags** ([`Actor.Tags`](https://docs.flaxengine.com/api/FlaxEngine.Actor.html#FlaxEngine_Actor_Tags)) and an utility method for quick checking for a **tag** on the *Actor* with [`Actor.HasTag`](https://docs.flaxengine.com/api/FlaxEngine.Actor.html#FlaxEngine_Actor_HasTag).

These can be edited in the *Properties Panel* under the *General/Tags* section by clicking the three dot button (`...`).

Actors can be marked with specific **tags** to be used by different gameplay systems. A common use case is to distinguish between objects on the same *Layer* when processing a physics result, like for example a raycast or collision.

## Tag Editor

[`Tag`](https://docs.flaxengine.com/api-cpp/Tag.html) and `Tag[]` are represented in the *Properties Panel* by a dedicated editor, which allows to edit and visualize them in a tree hierarchy.

**Tags** can be added or removed by ticking or unticking the **tag**'s checkbox. Each **tag** has a plus (`+`) button on the right side which can be used to add a **sub-tag** to the current **tag**. Utility buttons on the top of the editor provide quick access to frequently used actions and the search field allows to filter **tags** by their name. It is also possible to quickly add a new **tag** in the format of `X.Y.Z` via the *Add Tag* section.

The **tag** editor will display all of the selected tags in a list next to the `...` button.

![Tags Editor](media/tags-editor.png)

`Tag` and `Tag[]` are displayed in the properties panel with the ability to edit them via tree hierarchy. Each tag can contain nested child nodes. Tags can be selected via checkboxes. Each node has a plus (`+`) button on the right side which can be used to add a sub-tag to the list. Utility buttons on the top can help to edit tags, and the search field allows filtering tags by name.
## Tags in the Scripting API

The scripting API contains the struct [`Tag`](https://docs.flaxengine.com/api-cpp/Tag.html), which holds the index of the tag in a global `Tags.List` array. The [`Tags`](https://docs.flaxengine.com/api-cpp/Tags.html) class contains utilities for comparing two arrays of [`Tag`](https://docs.flaxengine.com/api-cpp/Tag.html)s, like checking the array has a specific tag ([`HasTag()`](https://docs.flaxengine.com/api-cpp/Tags.html#Tags_HasTag_const_Array_Tag____const_Tag_)) or to check if the first array has any of the [`Tag`](https://docs.flaxengine.com/api-cpp/Tag.html)s from the second array ([`HasAny()`](https://docs.flaxengine.com/api-cpp/Tags.html#Tags_HasAny_const_Array_Tag____const_Array_Tag____)).

**Tag** comparison is very fast (`int32` comparison) and memory usage is only 4 bytes per **tag**.

## Scripting
## Code Example

Follow code examples below to use tags in your gameplay code:
Follow these code examples to use **tags** in your gameplay code:

# [C#](#tab/code-csharp)
```cs
Expand All @@ -28,15 +48,13 @@ public class MyScript : Script
public Tag PlayerTag = Tags.Get("Player");
public Tag[] EnemyTags;

/// <inheritdoc />
public override void OnEnable()
{
_trigger = Level.FindActor(Tags.Get("ObjectDetector")) as BoxCollider;
if (_trigger)
_trigger.TriggerEnter += OnTriggerEnter;
}

/// <inheritdoc />
public override void OnDisable()
{
if (_trigger)
Expand Down
38 changes: 38 additions & 0 deletions manual/scripting/code-examples/event-examples-script.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using FlaxEngine;

public class EventExamples : Script
{
public override void OnEnable()
{
Debug.Log("Script is now enabled");
}

public override void OnDisable()
{
Debug.Log("Script is now disabled");
}

public override void OnStart()
{
// Init the position to (0, 0, 0) once after the script is created
Actor.Position = Vector3.Zero;
}

public override void OnUpdate()
{
// Adjusts the actors rotation to look at the world origin every frame
Actor.LookAt(Vector3.Zero);
}

public override void OnFixedUpdate()
{
// Move the actor up by 10 centimeters every fixed framerate frame
Actor.Position += new Vector3(0f, 10f, 0);
}

public override void OnDebugDraw()
{
// Draw the actors bounds using DebugDraw
DebugDraw.DrawWireBox(Actor.Box, Color.Red, 0f);
}
}
29 changes: 29 additions & 0 deletions manual/scripting/code-examples/event-examples-ui-control.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using FlaxEngine;
using FlaxEngine.GUI;

public class ControlExample : Control
{
private bool outlineBlack;



public override void Draw()
{
// Draw the control using Render2D
Rectangle rect = new Rectangle(Float2.Zero, Width, Height);
Render2D.FillRectangle(rect, IsMouseOver ? Color.Green : Color.Red);
Render2D.DrawRectangle(rect, outlineBlack ? Color.Black : Color.White);
}

public override bool OnKeyDown(KeyboardKeys key)
{
// Check if the pressed key was the C key
if (key == KeyboardKeys.C)
{
outlineBlack = !outlineBlack;
return true;
}

return false;
}
}
24 changes: 0 additions & 24 deletions manual/scripting/code-examples/events.cs

This file was deleted.

2 changes: 1 addition & 1 deletion manual/scripting/code-examples/properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class MyScript : Script
{
public float Field1 = 11;
public Color Field2 = Color.Yellow;
public Color Field2 = Color.LightBlue;
public DirectionalLight Field3 { get; set; }
}
2 changes: 1 addition & 1 deletion manual/scripting/code-examples/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ API_CLASS() class GAME_API MyScript : public Script
DECLARE_SCRIPTING_TYPE(MyScript);

API_FIELD() float Field1 = 11;
API_FIELD() Color Field2 = Color::Yellow;
API_FIELD() Color Field2 = Color::LightBlue;
API_FIELD() ScriptingObjectReference<DirectionalLight> Field3;

// [Script]
Expand Down
2 changes: 1 addition & 1 deletion manual/scripting/empty-actor.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Empty Actor

**Empty Actor** is an actor type that does not contain any dedicated role or in-build behavior. Instead of, it can be used to build a scene hierarchy, transform child objects or to implement a custom actor types using C# scripts (attached as components). Using Empty Actor can be very useful when working on larger projects.
**Empty Actor** is an actor type that does not have any dedicated role and contains no in-build behavior. It can be used as an empty object/ actor in the scene hierarchy, transform child actors or to implement a custom actor type using attached C# scripts.
13 changes: 6 additions & 7 deletions manual/scripting/engine-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
Scripting API list for gameplay programming (available in both C++, C# and Visual Scripting):
* `Engine` - global engine API
* `Content` - assets loading and content management
* `Audio` - audio effects and music playback
* `Audio` - audio effects and playback
* `DebugDraw` - debug shapes drawing
* `DebugLog` - debug log messages sending
* `Debug` - info, warning and error messages
* `Globals` - global engine variables container
* `Screen` - utility for game viewport management
* `Time` - game ticking and time management
* `Graphics` - rendering quality and management
* `Input` - user input reading, access and processing
* `Level` - scene manager for actors and scene object lifetime handling
* `Navigation` - pathfinding and navigation utilities for AI
* `Physics` - physical simulation manager
* `Physics` - physics simulation manager
* `Platform` - low-level runtime platform implementation (memory access, system info, etc.)
* `Clipboard` - system clipboard
* `MessageBox` - native platform message box popup utility
Expand All @@ -24,15 +24,14 @@ Scripting API list for gameplay programming (available in both C++, C# and Visua

## Objects Hierarchy

The diagram with a hierarchy of the main object types used in Flax.
This diagram shows the hierarchy of the main object types used in Flax.

In C# and Visual Scripting API `FlaxEngine.Object` type is mapped into `ScriptingObject`.
In the C# and Visual Scripting API, the `FlaxEngine.Object` type is mapped into `ScriptingObject`.

![Flax Object Hierarchy Diagram](media/objects-hierarchy.png)

## Engine Architecture

The diagram below shows the simplified architecture of the engine and editor.
The diagram below shows the simplified architecture of the engine and the editor.

![Flax Engine Architecture](media/engine-architecture.png)

Loading
Loading