circle-loader
0
by
0/ 40/ /0

This time we will share several technical topics which are related to Program development. It is recommended to read for 15 minutes. Any unique insights or discoveries, please feel free to contact us or discuss.

UWA Q&A Community:answer.uwa4d.com


UI

Q1: In the case of overlapping buttons, how to realize that clicking the button above can also execute on the button below? I just hope that my touch monitor can penetrate through the button without stopping. What should I do on UGUI?

To realize it, we put a script on the control which needs to do this kind of processing, and don’t modify the source code of EventSystem. According to your needs, a full-screen UI may be made to specifically detect the sliding time.

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Collections.Generic;

namespace KEngine.UI
{
    public class TouchPenetrate : MonoBehaviour, IPointerClickHandler
    {
        public bool PenetrateOneLayer = true;

        //Monitor click
        public void OnPointerClick(PointerEventData eventData)
        {
            //PassEvent(eventData, ExecuteEvents.submitHandler);
            PassEvent(eventData, ExecuteEvents.pointerClickHandler);
        }


        //Pass on the incident
        public void PassEvent<T>(PointerEventData data, ExecuteEvents.EventFunction<T> function)
            where T : IEventSystemHandler
        {
            List<RaycastResult> results = new List<RaycastResult>();
            EventSystem.current.RaycastAll(data, results);
            GameObject current = data.pointerCurrentRaycast.gameObject;
            for (int i = 0; i < results.Count; i++)
            {
                if (current != results[i].gameObject)
                {
                    ExecuteEvents.Execute(results[i].gameObject, data, function);
                    if (PenetrateOneLayer)
                    {
                        //Only trigger one layer of events
                        break;
                    }
                }
            }
        }
    }
}

Thanks to Jia Weihao for providing the answer above.


Editor

Q2: Now we want to clean up some resources in our project, and remove some unnecessary Mesh. Therefore, we need to get all the paths in FBX where the Meshes locate which are used in all Prefabs. Then we return to the modeling software from FBX to delete the Mesh which will not be used any more. Now we can get FBX by name where the Mesh locates used in Prefab, but if there is a Mesh with the same name in FBX, how to know which Mesh is used?

It is not possible to directly obtain the path in FBX by name where the Mesh locates, but you can find out which Mesh is in FBX by comparison, and then find the path:

private static string GetMeshPath(string modelPath, MeshFilter prefabFilter) {
    GameObject model = AssetDatabase.LoadAssetAtPath<GameObject>(modelPath);

    if (!model) {
        Debug.LogWarning("No game object found at " + modelPath, prefabFilter);
        return null;
    }

    MeshFilter modelFilter = null;

    foreach (MeshFilter filter in model.GetComponentsInChildren<MeshFilter>(true)) {
        if (filter.sharedMesh == prefabFilter.sharedMesh) {
            modelFilter = filter;
            break;
        }
    }

    if (!modelFilter) {
        Debug.LogWarning("No game object found for " + prefabFilter, prefabFilter);
        return null;
    }

    Transform transform = modelFilter.transform;
    string path = transform.name;

    while (transform.parent) {
        transform = transform.parent;
        path = transform.name + "/" + path;
    }

    return path;
}

This answer is provided by UWA.


IL2CPP

Q3: Does Mono memory still exist after using IL2CPP, and after using it, what kind of memory is the Manage Object (for example: Int32 []) obtained through Profiler?

It can be simply considered that IL2CPP just replaces virtual machine implementation of Mono, so the mono memory will still be allocated as before (maybe some details are different).

 

The biggest difference between IL2CPP and Mono in terms of mono memory allocation is that the Reserved Total of IL2CPP can decrease, but Reserved Total of Mono will only increase.

This answer is provided by UWA.


Mesh

Q4: The Prefab contains multiple Sub Meshes. When the Prefab is initialized in the scene, these Sub Meshes are merged. How to avoid it?

Uncheck the option “Weld Vertices” in “Import Settings”. This option will automatically merge vertices with the same position, and it is turned on by default.

This answer is provided by UWA.


UGUI

Q5: After reading some articles about UGUI optimization, it is all mentioned in these articles that the attribute “Best Fit” should not be checked in TEXT. However, I don’t find the relevant consumption value of Text_OnPopulateMesh in Frame Debugger in Profiler. Does it mean that “Best Fit” checked in current UI does not cause too much performance consumption? Or where can I find the consumption related to Best Fit in UI?

 

By the way, there is no corresponding change in terms of memory.

The main function of Best Fit is that the font size in the text box will automatically adapt to the size of the text box. Generally speaking, it will bring two problems:

 

1. The font size in the game is not unified, for example, 21, 22, 23, 24 are all possible, because the newly generated words under each font size will occupy the size of a word on the corresponding Font Texture, so Font Texture is easy to occupy too much memory usage;

 

2. The extra overhead caused by dynamically modifying the size of the text box during operation. In some projects, it’s possible to dynamically adjust the size of the text box (such as text animation). If this type of text check the option “Best Fit”, there will be an additional CPU time consumption.

 

The size of Font Texture will be affected by the font type, size, and text content. If there is no change, it may be that the content has not exceeded the range of 512 x 1024, or you can check if another Font Texture has been generated? The main influence of BestFit is that the font size is not unified. If this option is checked but the font size has not changed, it will not cause an impact.

This answer is provided by UWA.


This is the 58th UWA Technology Sharing for Unity Development. As we all know, Our life has a limit but knowledge has none. These problems are only the tip of the iceberg and there are more technical problems during our program development which deserve to discuss. Welcome to join UWA Q&A community, let‘s explore and share knowledge together!

UWA website:en.uwa4d.com

UWA Blog:blog.en.uwa4d.com

UWA Q&A community:answer.uwa4d.com

Post a Reply