AnyPortrait > Script > Initialization, Basic Settings
It guides you through the functions that should be called when using a GameObject with apPortrait and the functions that should be referenced by default.
Initialization function that is automatically executed just before the first update.
If you load and use the Prefab in real time, you must call the Initialize() or AsyncInitialize() function.
A function that takes a long execution time when there is a lot of data. It is recommended that you use the AsyncInitialize() function.
bool : Returns false if it is initializing or has already finished, and returns true if initialization is successful.
Initialization function that performs the same function as Initialize().
If the Prefab is loaded in real time, you must call the Initialize() or AsyncInitialize() function.
Use asynchronous processing to reduce execution time load using coroutine.
Callback event is received as a parameter and is called on exit.
If timePerYield, which is a unit of ms, is used as a parameter, it calculates the coroutine processing time as a timer, so that the load on the CPU is reduced.
Instead, the initialization time may take a little longer in this case.
(Processing with timePerYield will work from v1.1.7.)
apPortrait.OnAsyncLinkCompleted onAsyncLinkCompleted : Callback event invoked when initialization is finished
int timePerYield : The timeout in milliseconds that yield is called during asynchronous processing
bool : Returns false if it is initializing or has already finished, and returns true if asynchronous initialization starts
Sets the root unit to be rendered.
It targets the root unit with the "animation clip started automatically" or the root unit with index 0.
Other root units are automatically hidden.
apOptRootUnit targetOptRootUnit : The root unit to be rendered.
Hide all root units.
Sets the root unit to be rendered.
It targets the root unit with the "animation clip started automatically" or the root unit with index 0.
Other root units are automatically hidden.
Same as ShowRootUnit().
Hide all root units.
Same as HideRootUnits().
Set the "Important" property.
If the "Important" property is True, this object is updated every frame.
If the "Important" attribute is False, the editor will update according to the FPS specified.
bool isImportant : Important Property
If "Important" property is off, the character will run with a fixed FPS. (Depending on the game's FPS, it may run at fewer FPS.)
You can change the value of the fixed FPS set in "Bake step" by script.
int fps : Fixed FPS value applied when the character's animation is executed. Valid only if the "Important" attribute is off.
Returns the root unit of the requested index.
int rootUnitIndex : Root Unit Index (Default is 0)
apOptRootUnit : The root unit corresponding to the index. Return null if not
Returns the currently playing root unit.
apOptRootUnit : The currently playing root unit. If not, return null
Returns the index of the currently playing root unit.
int : The index of the currently playing root unit. If not, return -1
If there is a mesh with a clipping mask applied, it automatically works with one camera for rendering.
Calling this function removes and initializes the information associated with the current camera.
When re-rendering, it automatically tries to re-link.
Re-link with the camera for all or some of the meshes with clipping masks.
Depending on arguments, you can also hold back the camera and re-create the render texture (RenderTexture) only.
bool isOnlyActiveRootUnit : Entering true will reset the current root unit only. If false, it will target the entire root unit.
apOptRootUnit targetOptRootUnit : The root unit to be reset
bool isRegistToCamera : If it is true, it will re-link with the camera. If false, re-create the render texture (RenderTexure) and wait for the next frame.
Sets the Sorting Layer used when calculating the order in which GameObjects are rendered.
The rendering order is calculated by grouping Game Objects on the same layer.
The Sorting Layer can be configured in Unity's Project Settings > Tags and Layers.
If you enter a name that is not set, processing will fail with an error message.
If you only want to change the Sorting Layer of a specific apOptTransform,
you can specify the apOptTransform object directly or enter its name as an argument.
string sortingLayerName : Name of the Sorting Layer to set
apOptTransform optTransform : The object whose Sorting Layer is to be changed
string transformName : The name of the optTransform for which you want to change the Sorting Layer
int rootUnitIndex : The index of the root unit to which the optTransform to change the Sorting Layer belongs to
Sets the Sorting Order used when calculating the order in which GameObjects are rendered.
A GameObject with a large value in the same sorting layer is rendered on the front of the screen.
If you only want to change the Sorting Order of a specific apOptTransform,
you can specify the apOptTransform object directly or enter its name as an argument.
int sortingOrder : Rendering order. Larger values render in front of the screen.
apOptTransform optTransform : The object whose Sorting Order is to be changed
string transformName : The name of the optTransform for which you want to change the Sorting Order
int rootUnitIndex : The index of the root unit to which the optTransform to change the Sorting Order belongs to
Returns the name of the currently applied Sorting Layer.
The name of the Sorting Layer must be registered in Project Settings > Tags and Layers.
It is not recommended to call this function frequently because it queries the settings of the project every time this function is called.
string : Name of the applied Sorting Layer. If it has a sorting layer value that does not match the project settings, it returns "Unknown Layer".
Returns the currently applied Sorting Order value.
The larger this value is, the more the front of the screen is rendered.
int : The current rendering order.
Returns the current Sorting Order value for a specific apOptTransform.
apOptTransform optTransform : Target apOptTransform
int : Current rendering Sorting Order.
This is the function used when the Sorting Order Option of apPortrait is "Depth To Order" or "Reverse Depth To Order".
This function determines whether the "Sorting Order" value of meshes will be changed automatically by changing the depth.
If you want to control the Sorting Order with a script, you must enter False to prevent the Sorting Order from being changed automatically.
The default value is True.
bool isEnabled : If true, the Sorting Order is changed automatically.
Set to recognize the cameras in the scene automatically while simultaneously checking the current cameras to determine how to render.
Even if this function is not called, it is set to recognize the cameras in the scene in run time.
You can specify the cameras to render the character.
After this function is called, it will not automatically check for cameras in the scene until the FindRenderingCamerasAutomatically() function is called.
params Camera[] cameras : Specify one or more cameras.
int : The number of cameras that can actually render the character.
Synchronizes the values of animation or control parameters to the target character.
When this function is called, the corresponding character is updated depending on the target character.
Examples of using this function can be found on the following pages.
- Synchronize with other characters
- Synchronize bones to change costumes
apPortrait targetPortrait : The apPortrait to be synchronized.
bool syncAnimation : Whether to sync animations.
bool syncControlParam : Whether to synchronize control parameters.
bool syncRootUnit : Whether to synchronize Root Units. The number of Root Units of apPortrait to be synchronized must be 2 or more and they must be the same. If the animation is synchronized, this request will be ignored.
bool syncBones : Whether to synchronize the movement of the bones.
SYNC_BONE_OPTION syncBoneOption : When synchronizing the movements of the bones, you can choose how to synchronize them. If you enter MatchFromRoot, the structure must be the same from the root bone, which is the topmost. If you enter MatchFromSubBones, the root bone of the character being synchronized will be synchronized even if it is not the root bone of the target character. If syncBones is false, this option is ignored, so you can enter any value.
bool : Synchronization processing result. Returns false if processing fails, such as if the synchronization target is invalid or already synchronized.
Turns off synchronization.
Determines which time value in Unity to use when the character is updated.
Depending on this option, you can set whether the game speed will be affected and time multiplier.
It does not apply when using Mecanim.
You can learn the example using this functions at the related page.
bool useUnscaleDeltaTime : If this value is true, it is updated by Unity's Time.unscaledDeltaTime, and if false, it is updated by Time.deltaTime. (The default is false .)
float multiplier : You can set the update speed. If not entered, it is set to the default speed of 1x.
When a character is updated, you can use a callback function to control the playback speed.
It does not apply when using Mecanim.
You can learn the example using this functions at the related page.
OnDeltaTimeRequested onDeltaTimeRequested : A callback function that returns the time of the current frame. You can modify the update time. The format of the callback function is "float OnDeltaTimeRequested(object savedObject)" .
object savedObject : It is a value that can be used for purposes such as identifying which object is calling when a callback function is called. There is no restriction on the type, and null is possible.
Set the meshes to be updated every frame.
A description of this option can be found in the related page.
Set the meshes to be updated at regular time intervals according to the FPS option.
A description of this option can be found in the related page.
int fps : Set the frequency as FPS. Up to 30 FPS.
bool isSyncUpdate : Whether mesh update timing should be synchronized with other characters with the same options.
public class PrefabTest : MonoBehaviour
{
void Start () { }
void Update ()
{
if(Input.GetKeyUp(KeyCode.P))
{
GameObject swordGirl = Resources.Load<GameObject>("TestPrefab/SwordGirl");
swordGirl = Instantiate<GameObject>(swordGirl);
apPortrait swordGirlPortrait = swordGirl.GetComponent<apPortrait>();
swordGirlPortrait.transform.parent = this.transform;
swordGirlPortrait.transform.localPosition = Vector3.zero;
swordGirlPortrait.AsyncInitialize(OnPortraitLoadAsync);
}
}
void OnPortraitLoadAsync(apPortrait portrait)
{
portrait.Play("Idle");
}
}