#Development and production offline and online scenes

6 messages · Page 1 of 1 (latest)

heavy brook
#

Is it possible to specify the offline and online scene at runtime? For my use case, the offline and online scene would always match on client and server but they would be specified in Awake() of NetworkManager so as to specify different scenes for either development or production.

#

Do I understand correctly that I can just use any scene string (as AssetDatabase.GetAssetPath(scene))?

#

Basically:

CustomNetworkManaager: NetworkManager {
    public SceneAsset offlineSceneDevelopment;
    public SceneAsset onlineSceneDevelopment;
    public SceneAsset offlineSceneProduction;
    public SceneAsset onlineSceneProduction;

    public override void Awake()
    {
        base.Awake();
        singleton = this;
#if DEVELOPMENT
        offlineScene = AssetDatabase.GetAssetPath(offlineSceneDevelopment);
        onlineScene = AssetDatabase.GetAssetPath(onlineSceneDevelopment);
#elif XPRODUCTION
        offlineScene = AssetDatabase.GetAssetPath(offlineSceneProduction);
        onlineScene = AssetDatabase.GetAssetPath(onlineSceneProduction);
#endif
    }
...
heavy brook
#

SceneAttribute source:

namespace Mirror
{
    [CustomPropertyDrawer(typeof(SceneAttribute))]
    public class SceneDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType == SerializedPropertyType.String)
            {
                SceneAsset sceneObject = AssetDatabase.LoadAssetAtPath<SceneAsset>(property.stringValue);

                if (sceneObject == null && !string.IsNullOrWhiteSpace(property.stringValue))
                {
                    // try to load it from the build settings for legacy compatibility
                    sceneObject = GetBuildSettingsSceneObject(property.stringValue);
                }
                if (sceneObject == null && !string.IsNullOrWhiteSpace(property.stringValue))
                {
                    Debug.LogError($"Could not find scene {property.stringValue} in {property.propertyPath}, assign the proper scenes in your NetworkManager");
                }
                SceneAsset scene = (SceneAsset)EditorGUI.ObjectField(position, label, sceneObject, typeof(SceneAsset), true);

                property.stringValue = AssetDatabase.GetAssetPath(scene);
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use [Scene] with strings.");
            }
        }

        protected SceneAsset GetBuildSettingsSceneObject(string sceneName)
        {
            foreach (EditorBuildSettingsScene buildScene in EditorBuildSettings.scenes)
            {
                SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath<SceneAsset>(buildScene.path);
                if (sceneAsset!= null && sceneAsset.name == sceneName)
                {
                    return sceneAsset;
                }
            }
            return null;
        }
    }
}
heavy brook
#

It seems to be working. Waiting for some OGs like Gadget to look at this. Maybe this gives has some hidden unexpected behaviour down the road.

broken pivot