CWinCtrlRenderIcon¶
Script: RENDERICON
It is a control for the icon with using Render Texture.
It automatically cut out rectangle from the Render Texture area which you specify.
Multiple rendering result may be included within single Render Texture. After you render to the texture,it can render many icons at low cost.
For example ,it is effective to use that when you want to display the dress possible avatar icon on the listbox.
Callbacks arriving at :class:`CWindowBase<CWindowBase>`
void onClick(CWinCtrlBase cCtrl)
void onHold(CWinCtrlBase cCtrl)
void onBeginDrag(CWinCtrlBase cCtrl,Vector2 pos)
void onDrag(CWinCtrlBase cCtrl,Vector2 pos,Vector2 dragVelocity)
bool onDragRender(CWinCtrlBase cCtrl,Transform transform)
void onDrop(CWinCtrlBase cCtrl,CWindowBase cDragWindow,CWinCtrlBase cDragCtrl)
void onDropGround(CWinCtrlBase cCtrl)
bool onBeginRenderIcon(CWinCtrlRenderIcon icon)
It is started rendering on an icon.
Meaning of the return value of this function.
If you returns true, this control will render to the texture.
On the other hand, if you return a false, it does not render. And onEndRenderIcon is not called.
bool onEndRenderIcon(CWinCtrlRenderIcon icon)
It is called when the rendering has been completed
Meaning of the return value of this function.
If you return a true, rendering of the next frame is continued( onBeginRenderIcon is called at the next frame. ).
On the other hand, If you return a false, It is not rendered in the next frame.
If you want to resume the stopped rendering , you set the needToRender to true.
-
class CWinCtrlRenderIcon
¶ Functions / Properties
Assign a unique ID other than 0. Setting it to 0 frees the reserved render texture.Also, if you assign the same value as other controls, they share a render texture.
-
Camera
camera
{ get; }¶
you can get the camera to which the rendering texture is assigned. Access when you want to customize the camera position and angle.
-
WinColor
color1
{ get; set; }¶
It is assigned as the background color for rendering.
Default valus is (0,0,0,0).
Set to true when you want to restart rendering.
If you return a true, rendering of the next frame is continued( onBeginRenderIcon is called at the next frame. ).
-
CInput::e_State
state
{ get; }¶
Gets the state that the icon is depressed.
-
Camera
Example of use
In this example,you made objects active on onBeginRenderIcon.Next,you make them deactivated on onEndRenderIcon.
if you do not make these operations,All objects will be rendered to the same icon.
If the onBeginRenderIcon returns true, the Camera.Render() is called immediately. If you want to reflect an animation to objects, you must call the Animation.Sample().
When the control is not rendered correctly, try to check the following points.
Is the layer setting not wrong? / Do you not forget the setting of the layer?
Rendering targets are within the camera?
If objects are not in the camera, they are not rendered.
Did you set the regionId ?
If the regionId is 0, it is not performed rendering to render the texture.It is cut out a rectangular area from the render texture in the regionId the key, and then rendering.
override public bool onBeginRenderIcon(CWinCtrlRenderIcon icon) {
CWinCtrlListbox lbAvatar = lbAvatar = find(CWinCtrlListbox>(LISTBOX_Avatar);
int idx = lbAvatar.getContentsIndex(icon);
if (idx < 0) {
return false;
}
GameObject go = m_lstGameObject[idx];
if (go == null) {
return false;
}
go.SetActive(true);
Animation anim = go.GetComponent<Animation>();
anim.Sample();
return true;
}
override public bool onEndRenderIcon(CWinCtrlRenderIcon icon) {
CWinCtrlListbox lbAvatar = lbAvatar = find(CWinCtrlListbox>(LISTBOX_Avatar);
int idx = lbAvatar.getContentsIndex(icon);
GameObject go = m_lstGameObject[idx];
if (go == null) {
return false;
}
go.SetActive(false);
return false;
}
// click callback
override public void onClick(CWinCtrlBase cCtrl) {
switch (cCtrl.id) {
case RENDERICON_Avatar:
break;
}
}
// hold callback
override public void onHold(CWinCtrlBase cCtrl) {
switch (cCtrl.id) {
case RENDERICON_Avatar:
break;
}
}
The initial values of each layer
Camera.cullingMask = e_Layer.RenderIcon;
Please do not change it if not particularly necessary.
If the rendering, please be careful to layer settings.
The game object layer should set this value.
// If gameobjectAvatar is not multiple hierarchies, the following is sufficient.
gameobjectAvatar.layer = (int) e_LayerId.RenderIcon;
// If gameobjectAvatar is made up of multiple hierarchies, it must be recursively set using the following function:
Utility.setLayer(gameObjectAvatar,e_LayerId.RenderIcon);
gameobjectAvatar.SetActive(false);
Note
GameObject.layer set the layer only for a single hierarchy. It does not affect to the children of the hierarchy. To you set the layer in hierarchies of a game objects, you can use the Utility.setLayer. This function can be set recursively layer to root hierarchy and children hierarchies of the game object.
The main flow of rendering
RenderIcon is suitable to display models for each icon. However , the number of layers is limited , it is necessary to reuse a single layer.
This control is rendered by the following procedure in order to solve this problem .
Load models(Resources)
After you have finished loading , you deactivate the game object by SetActive (false).
You set RenderIcon to the layer.
You set a unique value to the regionId.
When OnBeginRenderIcon is called , you make game objects activate.
When OnEndRenderIcon is called , you make game objects deactivate.
You can limit game objects to be rendered in RenderIcon. The OnEndRenderIcon returns false. It is good for performance. If a OnEndRenderIcon returns true,it would be to continue rendering.
Timing onBeginRender is called .
You set a non-zero value to regionId.
Immediately after setting
regionId
to a unique non-zero value.onBeginRenderIcon
is called.It will continue to be called untilonBeginRenderIcon
returns true. If it returns false,onEndRenderIcon
will not be called.Using this mechanism, during an asynchronous import of a model it is possible to return false and render the model to texture when it is ready to be rendered (Don’t forget to set the layer).After the render texture is lost, it becomes necessary to regenerate it.
The reason for render texture is lost is the window minimized,the screen saver,etc.
After setting the true to needToRender
When the return value of onEndRenderIcon is true
If you want to every frame rendering , you can return value of this function to true. However , your application performance is lost.