Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Changing Play Mode Script through code

Discussion in 'Asset Bundles' started by stevencoull, Feb 12, 2019.

  1. stevencoull

    stevencoull

    Joined:
    Sep 15, 2016
    Posts:
    15
    I'm developing a continuous integration platform with Jenkins but hit a wall when it comes to Asset Bundles. Generally we set our play mode to Fast during development/test builds, then Packed for releases only. I'd like to make it possible to choose between which play mode to use when building through Jenkins, but I can't find any documentation that would allow me to change the play mode through the UnityEditor API. Hopefully I'm just overlooking something - any help would be appreciated.
     
  2. huoqingling

    huoqingling

    Joined:
    Jul 25, 2019
    Posts:
    1
    For Example

    Code (CSharp):
    1. [MenuItem("Tools/change Play Mode Script")]
    2. public static void SetPlayModeScript()
    3. {
    4.     int modeIndex = 0;
    5.     for (int i = 0; i < AddressableAssetSettingsDefaultObject.Settings.DataBuilders.Count; i++)
    6.     {
    7.         var m = AddressableAssetSettingsDefaultObject.Settings.GetDataBuilder(i);
    8.         //if (m.CanBuildData<UnityEditor.AddressableAssets.Build.AddressablesPlayModeBuildResult>())
    9.         {
    10.             //if(m.Name== "Fast Mode")
    11.             //{
    12.             //    modeIndex = i;
    13.             //    break;
    14.             //}
    15.             //if (m.Name == "Virtual Mode")
    16.             //{
    17.             //    modeIndex = i;
    18.             //    break;
    19.             //}
    20.             if (m.Name == "Packed Play Mode")
    21.             {
    22.                 modeIndex = i;
    23.                 break;
    24.             }
    25.         }
    26.     }
    27.     AddressableAssetSettingsDefaultObject.Settings.ActivePlayModeDataBuilderIndex = modeIndex;
    28. UnityEditor.AssetDatabase.SaveAssets();
    29. }
     
unityunity