AnyPortrait > Scripting > Initialization, Basic Settings

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.

public bool Initialize()

​Description

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.

Return

bool : Returns false if it is initializing or has already finished, and returns true if initialization is successful.

public bool AsyncInitialize()

public bool AsyncInitialize(apPortrait.OnAsyncLinkCompleted onAsyncLinkCompleted)

public bool AsyncInitialize(int timePerYield)

public bool AsyncInitialize(int timePerYield, apPortrait.OnAsyncLinkCompleted onAsyncLinkCompleted)

​Description

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.)

Parameters

apPortrait.OnAsyncLinkCompleted onAsyncLinkCompleted : Callback event invoked when initialization is finished

int timePerYield : The timeout in milliseconds that yield is called during asynchronous processing.

Return

bool : Returns false if it is initializing or has already finished, and returns true if asynchronous initialization starts

public void ShowRootUnit()

​Description

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.

public void ShowRootUnit(apOptRootUnit targetOptRootUnit)

​Description

Sets the root unit to be rendered.

Target the root unit specified by the parameter.

Other root units are automatically hidden.

Parameters

apOptRootUnit targetOptRootUnit : The root unit to be rendered.

public void HideRootUnits()

​Description

Hide all root units.

public void Show()

​Description

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().

public void Hide()

​Description

Hide all root units.

Same as HideRootUnits().

public void SetImportant(bool isImportant)

​Description

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.

Parameters

bool isImportant : Important Property

public void SetFPSForNotImportant(int fps)

​Description

(This applies from v1.2.3.)

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.

Parameters

int fps : Fixed FPS value applied when the character's animation is executed. Valid only if the "Important" attribute is off.

public apOptRootUnit GetOptRootUnit(int rootUnitIndex)

​Description

Returns the root unit of the requested index.

Parameters

int rootUnitIndex : Root Unit Index (Default is 0)

Return

apOptRootUnit : The root unit corresponding to the index. Return null if not

public void CleanUpMeshesCommandBuffers()

​Description

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.

public void ResetMeshesCommandBuffers(bool isOnlyActiveRootUnit)

public void ResetMeshCommandBuffer(apOptRootUnit targetOptRootUnit, bool isRegistToCamera)

​Description

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.

Parameters

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.

public void SetSortingLayer(string sortingLayerName)

public void SetSortingLayer(apOptTransform optTransform, string sortingLayerName)

public void SetSortingLayer(string transformName, string sortingLayerName)

public void SetSortingLayer(int rootUnitIndex, string transformName, string sortingLayerName)

​Description

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.

(This function applies from version 1.0.2.)

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.

(Three functions that change the Sorting Layer of the apOptTransform will be applied from version 1.1.6.)

Parameters

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

public void SetSortingOrder(int sortingOrder)

public void SetSortingOrder(apOptTransform optTransform, int sortingOrder)

public void SetSortingOrder(string transformName, int sortingOrder)

public void SetSortingOrder(int rootUnitIndex, string transformName, int sortingOrder)

​Description

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.

(This function applies from version 1.0.2.)

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.

(Three functions that change the Sorting Order of the apOptTransform will be applied from version 1.1.6.)

Parameters

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

public string GetSortingLayerName()

​Description

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.

(This function applies from version 1.0.2.)

Return

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".

public int GetSortingOrder()

​Description

Returns the currently applied Sorting Order value.

The larger this value is, the more the front of the screen is rendered.

(This function applies from version 1.0.2.)

Return

int : The current rendering order.

public void SetSortingOrderChangedAutomatically(bool isEnabled)

​Description

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.

(This function applies from version 1.1.8.)

Parameters

bool isEnabled : If true, the Sorting Order is changed automatically.

public void FindRenderingCamerasAutomatically()

​Description

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.

(This function applies from version 1.2.0.)

public int SetRenderingCameras(params Camera[] cameras)

​Description

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.

(This function applies from version 1.2.0.)

Parameters

params Camera[] cameras : Specify one or more cameras.

Return

int : The number of cameras that can actually render the character.

using UnityEngine;
using AnyPortrait;

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");

           }
}