“This is the 29th day of my participation in the Gwen Challenge in November. See details of the event: The Last Gwen Challenge in 2021”

👉 About the author

As we all know, life is a long process of constantly overcoming difficulties and reflecting on progress. In this process, there will be a lot of questions and thoughts about life, so I decided to share my thoughts, experiences and stories to find resonance!!

Focus on Android/Unity and various game development tips, as well as various resource sharing (websites, tools, materials, source code, games, etc.)

Welcome to pay attention to the public account [Mr. Empty name] for more resources and communication!

👉 premise

During this period of time, I learned a Unity framework and prepared to apply it to the actual project, but it was difficult for me to learn because the author could not see the end of the framework and did not have any detailed documents. Fortunately, the author opened all the contents of the framework and recorded the learning process again.

👉 Practice

How do I use 😜?

Project catalog and functions are as follows:

  • Libraries Store the gameFramework.dll core framework and some third-party Libraries necessary for the framework (currently only one open source ZIP compression algorithm library).
  • Prefabs houses the GameFramework.prefab, which is used to quickly create a game frame startup scene
  • Scripts contains all Runtime and Editor code for the UnityGameFramework
  • Example.unity is an empty scene with gameFramework. prefab as the scene to start the game
  • Procedureexample.cs is a sample process code file that the sample will use as the startup process.

After running the project, you notice that the Game scene has a small floating window, which is the debugger window provided by the framework

  • The Console TAB at run time (on mobile devices, of course) defaults to displaying the most recent log in different log colors for different log types. Click on a log to view the log and stack details
  • The Information TAB displays device hardware Information, game version and resource Information, input Information, sensors, and more
  • The Profiler TAB displays performance debugging information, memory, object pool, network, and more
  • The Other TAB can be used to configure resizing of the debugger window (which is not normally modified), perform memory reclamation, or restart the game, etc

The author’s English is not very good, in order to use it quickly translated part of the English into Chinese, it seems to be much delayed, ha ha

😜 Log management tool

In any programming language, logging is the primary tool for logical analysis, so learning to use the framework’s logging tools is a top priority.

The first is the basic Log (pictured), which is printed to the Unity editor console as the system’s

For released products, you are advised to disable all logs or enable only logs at the error or higher levels. You can enable the log level during development and debugging.

In addition to printing on the console, we use the framework more likely to save logs to files.

Customize a class that inherits DefaultLogHelper

using GameFramework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityGameFramework.Runtime;
 
internal class FileLogHelper : DefaultLogHelper
{
// Set the path for saving log files - you can customize it or use the system's
private readonly string CurrentLogPath = Utility.Path.GetRegularPath(Path.Combine(Application.persistentDataPath, "current.log"));
private readonly string PreviousLogPath = Utility.Path.GetRegularPath(Path.Combine(Application.persistentDataPath, "previous.log"));
public FileLogHelper()
{
    Application.logMessageReceived += OnLogMessageReceived;
    try
    {
        // Replace the log every time it runs, just like a queue
        if (File.Exists(PreviousLogPath))
        {
            File.Delete(PreviousLogPath);
        }
        if (File.Exists(CurrentLogPath))
        {
            File.Move(CurrentLogPath, PreviousLogPath);
        }
    }
    catch
    {
    }
}
 
    private void OnLogMessageReceived(string logMessage, string stackTrace, LogType logType)
    {
        string log = Utility.Text.Format("[{0}] [{1}] {2} {4} {3} {4}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), logType.ToString(), logMessage ?? "<Empty Message>", stackTrace ?? "<Empty StackTrace>", Environment.NewLine);
        try
        {
            File.AppendAllText(CurrentLogPath, log, Encoding.UTF8);
        }
        catch
        {
        }
    }
}
Copy the code

Then select the object in which the Base script is attached, it’s as simple as that!

Each path location can also be found in the debugger window at run time.

👉 other

📢 author: Kom and Kom in Kom

📢 reprint instructions – be sure to specify the source: Zhim Granular’s personal home page – column – Nuggets (juejin. Cn)

📢 welcome to like 👍 collect 🌟 message 📝