Skip to content
TheChatArchiveThe Chat Archive
grok-3-preview-02-24· xAIHugging Face LMArena Human Preference 140K

unity, c#, using System.Threading; using System.Threading.Tasks; using UnityEngine;…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-5-sonnet-20241022’s answer.
  1. User

    unity, c#,

    using System.Threading; using System.Threading.Tasks; using UnityEngine; using AdxUnityPlugin; using R3; using VContainer;

    namespace Ncroquis.Backend {

    public class AdxBackendProvider : IBackendProvider
    {
    
        public ProviderKey providerKey => ProviderKey.ADX;
        
    

    #if UNITY_ANDROID private readonly string _adxAppId = "61ee18cecb8c670001000023"; //TEST #elif UNITY_IPHONE private readonly string _adxAppId = "6200fea42a918d0001000001"; //TEST #endif private readonly GdprType _gdprType = GdprType.POPUP_DEBUG;

        private readonly ReactiveProperty<bool> _isInitialized = new(false);
        public ReadOnlyReactiveProperty<bool> IsInitialized => _isInitialized.ToReadOnlyReactiveProperty();
    
    
        private TaskCompletionSource<bool> _initializeTcs;
    
    
        public Task InitializeAsync(CancellationToken cancellation = default)
        {
            if (_isInitialized.Value)
            {
                Debug.LogWarning("[ADX Backend Provider] ADX SDK는 이미 초기화되었습니다.");
                return Task.CompletedTask;
            }
    
            if (_initializeTcs != null && !_initializeTcs.Task.IsCompleted)
            {
                Debug.LogWarning("[ADX Backend Provider] ADX SDK 초기화가 이미 진행 중입니다.");
                return _initializeTcs.Task;
            }
    
            cancellation.ThrowIfCancellationRequested();
    
            _initializeTcs = new TaskCompletionSource<bool>();
    
            cancellation.Register(() =>
            {
                _initializeTcs.TrySetCanceled(cancellation);
            });
    
            AdxSDK.SetLogEnable(true);
    
            var adxConfiguration = new ADXConfiguration.Builder()
                .SetAppId(_adxAppId)
                .SetGdprType(_gdprType)
                .Build();
    
            AdxSDK.Initialize(adxConfiguration, OnADXConsentCompleted);
    
            return _initializeTcs.Task;
        }
    
        private void OnADXConsentCompleted(string s)
        {
            Debug.LogFormat("[ADX Backend Provider] ADX 동의 완료: {0}", s);
    
            _isInitialized.Value = true;
            _initializeTcs?.TrySetResult(true);
        }
    }
    

    }

    InitializeAsync 에서 UnityEditor 모드 일때는 초기화 된걸로 처리하고 넘어가줘

  2. Assistant

    UnityEditor 모드에서 초기화를 생략하고 바로 초기화된 것으로 처리하려면, InitializeAsync 메서드에서 UnityEditor 환경인지 확인한 후 초기화 로직을 우회하도록 수정할 수 있습니다. 아래는 수정된 코드입니다.

    using System.Threading;
    using System.Threading.Tasks;
    using UnityEngine;
    using AdxUnityPlugin;
    using R3;
    using VContainer;
    
    namespace Ncroquis.Backend
    {
        public class AdxBackendProvider : IBackendProvider
        {
            public ProviderKey providerKey => ProviderKey.ADX;
    
    #if UNITY_ANDROID
            private readonly string _adxAppId = "61ee18cecb8c670001000023"; //TEST
    #elif UNITY_IPHONE
            private readonly string _adxAppId = "6200fea42a918d0001000001"; //TEST
    #endif
            private readonly GdprType _gdprType = GdprType.POPUP_DEBUG;
    
            private readonly ReactiveProperty<bool> _isInitialized = new(false);
            public ReadOnlyReactiveProperty<bool> IsInitialized => _isInitialized.ToReadOnlyReactiveProperty();
    
            private TaskCompletionSource<bool> _initializeTcs;
    
            public Task InitializeAsync(CancellationToken cancellation = default)
            {
                if (_isInitialized.Value)
                {
                    Debug.LogWarning("[ADX Backend Provider] ADX SDK는 이미 초기화되었습니다.");
                    return Task.CompletedTask;
                }
    
                if (_initializeTcs != null && !_initializeTcs.Task.IsCompleted)
                {
                    Debug.LogWarning("[ADX Backend Provider] ADX SDK 초기화가 이미 진행 중입니다.");
                    return _initializeTcs.Task;
                }
    
                cancellation.ThrowIfCancellationRequested();
    
                _initializeTcs = new TaskCompletionSource<bool>();
    
                cancellation.Register(() =>
                {
                    _initializeTcs.TrySetCanceled(cancellation);
                });
    
                // UnityEditor 모드에서는 초기화를 생략하고 바로 완료로 처리
    #if UNITY_EDITOR
                Debug.Log("[ADX Backend Provider] UnityEditor 모드에서는 초기화를 생략합니다.");
                _isInitialized.Value = true;
                _initializeTcs.TrySetResult(true);
                return _initializeTcs.Task;
    #else
                // 실제 디바이스에서는 기존 초기화 로직 수행
                AdxSDK.SetLogEnable(true);
    
                var adxConfiguration = new ADXConfiguration.Builder()
                    .SetAppId(_adxAppId)
                    .SetGdprType(_gdprType)
                    .Build();
    
                AdxSDK.Initialize(adxConfiguration, OnADXConsentCompleted);
    
                return _initializeTcs.Task;
    #endif
            }
    
            private void OnADXConsentCompleted(string s)
            {
                Debug.LogFormat("[ADX Backend Provider] ADX 동의 완료: {0}", s);
    
                _isInitialized.Value = true;
                _initializeTcs?.TrySetResult(true);
            }
        }
    }
    

    주요 변경 사항

    1. #if UNITY_EDITOR 조건문 추가:

      • UnityEditor 환경에서는 초기화 로직을 실행하지 않고, 바로 _isInitialized.Value를 true로 설정하고 _initializeTcs.TrySetResult(true)를 호출하여 초기화가 완료된 것으로 처리합니다.
      • 이를 통해 UnityEditor에서 불필요한 초기화 과정을 생략할 수 있습니다.
    2. #else 블록:

      • 실제 디바이스 환경에서는 기존 초기화 로직이 그대로 실행됩니다.
    3. 로그 추가:

      • UnityEditor 모드에서 초기화가 생략되었음을 알리는 로그를 추가하여 디버깅 시 혼란을 방지했습니다.

    사용 시 주의사항

    • UnityEditor에서 초기화를 생략하면, 실제 디바이스에서만 초기화가 이루어지므로, UnityEditor 환경에서 테스트할 때는 초기화가 필요한 기능(예: 광고 로드 등)이 동작하지 않을 수 있습니다. 이를 감안하여 테스트 계획을 세우세요.
    • UNITY_EDITOR 전처리 지시문은 Unity에서 제공하는 기본 전처리 지시문이므로 별도의 설정 없이 사용할 수 있습니다.

    이제 UnityEditor 모드에서는 초기화가 생략되고, 실제 디바이스에서는 정상적으로 초기화가 진행됩니다.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.