coolishbee / universal-sdk-unity

The Universal SDK for Unity provides a modern way of implementing Social Login APIs.
45 stars 11 forks source link

Fix iOS settings incorrect during build #25

Closed dlorddd closed 1 year ago

dlorddd commented 1 year ago

Problem Description

When building sometimes the .plist file was missing the Universal SDK properties. The root of the problem is in UniversalSDKSettings.cs because this property is used by PlistUpdating.cs:

public static UniversalSDKSettings Instance
{
    get
    {
        if (ReferenceEquals(instance, null))
        {
            // this can not find the settings object in the Assets/Editor/UniversalSDK folder
            instance = Resources.Load(settingsAssetName) as UniversalSDKSettings;
            if (ReferenceEquals(instance, null))
            {
                // as a fallback here a temporary object is created
                instance = CreateInstance<UniversalSDKSettings>();
            }
        }
        return instance;
    }
}

Why does it sometimes work? Because opening the settings object in the inspector updates the temporary instance in UniversalSDKSettingsEditor.cs:

string fullPath = Path.Combine(Path.Combine(UnityAssetFolder, UniversalSDKSettings.settingsPath), UniversalSDKSettings.settingsAssetName + UniversalSDKSettings.settingsAssetExtension);
UniversalSDKSettings instance = AssetDatabase.LoadAssetAtPath(fullPath, typeof(UniversalSDKSettings)) as UniversalSDKSettings;

Fix Description

Moving the Settings from Assets/Editor/UniversalSDK to Assets/Editor/UniversalSDK/Resources fixes the problem. Now Resources.Load() can find the settings asset.

Also the folder creation got a slight rework which is still not ideal but a bit more robust I think.

coolishbee commented 1 year ago

Thank you very much!

dlorddd commented 1 year ago

You are very welcome. I hope to make more contributions on the Unity side in the future.