Is there a callback function that detects changes to Build Settings in Unity?

Asked 2 years ago, Updated 2 years ago, 85 views

In Unity 3D,
Could you tell me if there is a callback that detects changes made to Build Settings?
If it does not exist, please let me know how to implement it.
Thank you for your cooperation.

unity3d build

2022-09-30 21:39

2 Answers

It appears that only changes to the target platform are currently supported.
There seems to be no detection or notification of changes to the individual contents of Build Settings.

Chapter 13 Callback for Various Events
13.6 EditorUserBuildSettings.activeBuildTargetChanged

Callback that is invoked when a platform is changed by the Build Settings window or EditorUserBuildSettings.SwitchActiveBuildTarget.Different platform configurations, such as BundleIdentifier changes, or changes to the contents of StreamingAsets and Resources folders.

You will probably set up a callback to register with this variable.
EditorUserBuildSettings.activeBuildTargetChanged

public static var activeBuildTargetChanged:Action;

Description
Configure the callback that is invoked immediately after a platform change in SwitchActiveBuildTarget

See Also: System.Action.

This is the related method.
EditorUserBuildSettings.SwitchActiveBuildTarget

public static function SwitchActiveBuildTarget (target:BuildTarget):bool;

Description
Change Build Target

Note: This method is not available when starting the editor in batch mode.

If you want to know the details other than changing the target platform, I'm afraid
Wouldn't it be possible to register this callback?
13.13 EditorApplication.globalEventHandler

Callback that occurs when an event occurs throughout the Unity editor.This has not been officially published, but it is useful for identifying key events and mouse locations.
The code below is a wrapper class that makes globalEventHandler easy to use.
  Note) Diagram omitted.
Figure 13.9: Pressing the key at the appropriate time will display the log.
  Note) code omitted
Note, however, that it does not work in game views or in some other windows.

It seems that there is a description like this.Is this better suited for proprietary callback implementations?
13.11 EditorApplication.update

Callback called at the Unity editor update timing.The editor also has a certain update timing, such as MonoBehavior Update.It is called approximately 200 times per second and is performed before the drawing system process.*4
[*4] There are reports of bugs running 200 times per second.The document says 100 times per second.
For example, WWW communications can also be used.
  Note) code omitted
You can also use it to implement your own callback.
The code below creates a callback that is invoked every time the focused EditorWindow changes.
  Note) I omit the code, but this is an example implementation:See where to find it

These are the variables for the above configuration.
EditorApplication.update

public static var update:CallbackFunction;

Description
Deligate for UnityEditor update processing

Adds a callback to this delivery that is called approximately 100 times per second. See Also: EditorApplication.CallbackFunction.


2022-09-30 21:39

using UnityEditor;
using UnityEngine;

public class SceneListChangedMonitor:MonoBehavior
{
    Initialize OnLoadMethod
    static void initialize()
    {
        Debug.Log ("Start Monitoring Scene List");
        EditorBuildSettings.sceneListChanged+=()=>
        {
            // Get scene name and state from scene list
            foreach (varscene in EditorBuildSettings.scenes)
            {
                Debug.Log($"Scene={scene.path}is{scene.enabled}");
            }
        };
    }
}

This is how the code that displays the scene list in the console log when there is a change in the scene list in Build Settings is implemented.


2022-09-30 21:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.