Unity basic learning nineteen, guide the design of the module

1. What is Bootstrapping

Each game has a novice education period due to various issues such as themes and gameplay. The role of the novice guide is to pass the rules and gameplay of the game to users in a short period of time in a simple form.

2. Why there is a bootstrap framework

Novice guidance is closely related to the business logic of the game. In order to reduce the coupling of the code and make the planning operable based on configuration, there is a novice guidance framework.

3. Guide program

3.1 Nodes and steps

The novice guide module is composed of many nodes , and these nodes can be sequential or independent of each other. During initialization, we use the binary number returned by the server to determine which has been completed and which has not been completed, so as to understand the player's novice guidance progress.

Each node is composed of multiple bootstrap steps, each step is configured by curation, and the steps can also be ordered and unordered. Since the first step of a node cannot be automatically triggered, the trigger only pays attention to the first step of the node during initialization, and then traverses the steps of the entire node after the first step is completed. If it is ordered, listen to the next node. If there are disordered ones, they will be monitored at the same time. Regardless of order or disorder, each node has only one final step. After completing this step, the node is complete.

3.2 Fault Tolerance

Fault tolerance is an important part of the onboarding framework. Due to various reasons such as network, configuration, and code errors, the boot module may be interrupted, especially if the forced boot is interrupted, the user interface may be stuck.

The fault tolerance types of this framework are divided into:

  1. Illegal interface fault tolerance : Illegal interface appears during forced boot or dependent interface is closed. When the framework is initialized, the UI interface display and close events are registered. When the trigger of the step is triggered, the monitoring state is set to true and then detected. If it is forced to guide and the current interface and the guided ignore interface do not match the dependent interface, fault-tolerant processing is performed. . Sets the listen state to false after the node completes
  2. Force guide focus size to 0 or off-screen : Force guide that there is no clickable area on the current screen. After the guidance interface of the current step is displayed, it is set to the detection state. Firstly, obtain the mandatory guiding rectangle click area (this function is implemented in the logic of the mandatory guiding interface). If the width and height of the click area are less than 5 or the area is not within the UI camera and the requirement is not met after 5s, fault-tolerant processing will be performed.

  3. Mandatory boot time timeout : The time spent on the transition interface after the boot is completed exceeds the limit time. Detect when completion logic is executed for the current step. If the current step is completed but the current page is not closed within the set time (the default time in the frame is 30s), perform fault tolerance.
  4. Lua error: Lua code error occurred when executing the callback function in the configuration table. Use AddListeningLuaException to listen when the framework is initialized

  5. Custom fault tolerance: Custom errors in the logic of the boot interface. An error occurs when executing the logic of the boot interface. If it occurs, it will be directly fault-tolerant.

Fault-tolerant mode: skip the current step, skip the current node, and do nothing.

3.3 Modules

a. Trigger

Trigger the boot process. Detection types are:

  1. Auto: trigger automatically
  2. Event: event trigger
  3. OpenUI: Open the specified UI trigger
  4. RecvMsg: Triggered by receiving a specified message

It is detected according to the trigger type every time it is triggered, if the conditions are met, and there is no problem with fault tolerance. Execute the current step.

b. to execute

Used to execute bootstrap steps. If BeforeExecute is configured, it will be executed first. If OverrideExecute is defined, it will be executed after the boot interface is displayed.

c. to finish

End the current step. Detection types are:

  1. Auto: complete automatically
  2. CloseUI: Close the specified UI
  3. Click: Click the specified button to complete
  4. Event: Accept the specified event to complete
  5. RecvMsg: Receive the specified server message completed

After triggering, the detection is done according to the type. If a delay is set, it will be delayed according to the set parameters. If the current step is the first step, all steps of the current node will be traversed. If they are all ordered, the trigger will only monitor the next step, otherwise it will monitor all non-ordered steps. If the current step is the last step, complete the current node.

d. Planning configuration table

All steps of bootstrapping are done by curating configuration. Mainly configure the parameters of each boot step module, and the sequence relationship between nodes is also configured here. Each step may include:

  1. Tag: basic attributes
  2. view: Boot interface configuration
  3. Trigger: trigger configuration
  4. JumpCheck: jump detection
  5. Execute: execute boot
  6. Comp: Completed related configuration
  7. Error: fault-tolerant configuration

See SysGuideTest for details

4. Source code implementation

4.1 Framework Execution Process

  1. initialization

    1. After receiving the server message, judge which unfinished nodes are based on the binary number sent by the server. If the order is in order, the trigger will monitor the first step of the first node, and if the order is out of order, it will monitor multiple nodes at the same time.
    2. Call fault-tolerant listening to enable all fault-tolerant listening.
    3. Initialize the behavior, which may include the camera, the position of the character, etc. depending on the project
  2. trigger

    1. Some actions on the interface trigger the trigger of a certain step. Trigger detection by type
    2. If the current step is the first step, then traverse all the steps of the node, listen to the ordered first step and all unordered steps
    3. Perform jump detection, and decide which step to jump to according to the OverridFunc and ExFunc configured in the configuration table
    4. If there is no jump, fault-tolerant detection is performed.
    5. To start the guide step, call GuideMgr.Playing.
  3. implement

    1. Configured BeforeExecute, execute and display the GuidePanel guide interface first, and execute the logic in the guide interface if there is OverrideExecute
  4. The Comp that registers this step joins the listener

  5. Finish

    1. Trigger the Comp callback of a certain step, perform detection, and if the condition is met. Enter the CompStep method to start the completion logic
    2. If delayComp is set, the corresponding time will be delayed, and the callback will be executed after the time is up
    3. Fault-tolerant detection in the callback function
    4. Send buried information
    5. Execute if ExFunc is configured
    6. It is the last step to complete the node. If it is a sequence, the trigger listens to the next step.
  6. Implementation of Forced Guidance 

    When the step type is set to Force and the View.ForceAttri property is set, the step is a forced bootstrap step.

    Use a full-screen mask to cover all elements of the page, and put a button mask on the mask. The color, size effect, position, picture, etc. of the button mask can be configured through the configuration file. The click event of the button is implemented by View.clickHandler. Passed by GuideGlue glue. If the configuration is a function, it is directly assigned to the click event of the button. If it is a string, use this name to find the dependent interface element and assign the corresponding click event to the mask.

4.2 UML diagrams

 

5. Key points, important nodes, intractable disease scenarios

If an error occurs during the boot process, send the protocol directly to complete the boot.

5.1 Fault tolerance processing - Lua throws an exception

There is a list of exceptionHandlers exception functions in Main.lua. As long as an exception is thrown, all the exception reporting functions in this list will be executed once. When the boot is started, an exception report is registered in the exception list . The purpose is that once an abnormal error occurs, it will tell the developer that the error is reported when the boot is running .

5.2 Fault-tolerant processing - pop-up illegal interface

Monitor the opening event of the interface. Once an interface is opened, check whether it is the interface bound to this guide, and report an error if it is not

5.3 Fault Tolerance - Forced boot without valid focus

Detect whether the range of the rect that needs to be clicked for guidance is within the range of the Camera.

5.4 Fault Tolerance - Continuous Forced Boot Transition Timeout

If it fails for more than 30s, an error will be reported.

5.5 Fault-tolerant processing - RecvMsg cannot be triggered after disconnection and reconnection

If the bootstrap is waiting for the return of the RecvMsg protocol and disconnects and reconnects at this time, the RecvMsg will not return. At this time, perform a jumpCheck to skip this waiting stage and throw an error.

5.6 Fault Tolerance - Custom Errors

If you need to throw errors in other guidance places, use this custom name to throw GuideDef.ErrorCode.UserDefine

Guess you like

Origin blog.csdn.net/u013617851/article/details/124859284