Exemplo n.º 1
0
        public static Hash128 GetHash(string guid, BuildTarget target)
        {
            LiveLinkBuildPipeline.RemapBuildInAssetGuid(ref guid);

            // TODO: GetArtifactHash needs to take BuildTarget so we can get Artifacts for other than the ActiveBuildTarget
            return(AssetDatabaseExperimental.GetArtifactHash(guid, typeof(LiveLinkBuildImporter), AssetDatabaseExperimental.ImportSyncMode.Block));
        }
Exemplo n.º 2
0
 private void OnGUIFooter()
 {
     using (new EditorGUIUtility.IconSizeScope(s_IconSize))
     {
         if (AssetDatabaseExperimental.IsCacheServerEnabled())
         {
             // Bad IP:Port. Direct the user to fix in Project Preferences.
             if (!AssetDatabaseExperimental.CanConnectToCacheServer(AssetDatabaseExperimental.GetCacheServerAddress(), AssetDatabaseExperimental.GetCacheServerPort()))
             {
                 if (GUILayout.Button(m_CacheCannotConnectButtonContent, GUILayout.Width(k_ConnectionButtonWidth), GUILayout.Height(k_ConnectionButtonHeight)))
                 {
                     OpenProjectSettings();
                 }
             }
             // Give the option to 'reconnect' as the user may have changed the IP or Port within Project Preferences.
             else
             {
                 if (GUILayout.Button(m_CacheCanReconnectButtonContent, GUILayout.Width(k_ConnectionButtonWidth), GUILayout.Height(k_ConnectionButtonHeight)))
                 {
                     AssetDatabaseExperimental.RefreshSettings();
                 }
             }
         }
         else
         {
             if (GUILayout.Button(m_CacheDisabledButtonContent, GUILayout.Width(k_ConnectionButtonWidth), GUILayout.Height(k_ConnectionButtonHeight)))
             {
                 OpenProjectSettings();
             }
         }
     }
 }
Exemplo n.º 3
0
        private static Hash128 ProduceArtifact(GUID guid, Type importerType, ImportMode mode, out OnDemandState state)
        {
            state = OnDemandState.Unavailable;
            switch (mode)
            {
                #if UNITY_2020_2_OR_NEWER
            case ImportMode.Asynchronous:
                return(AssetDatabaseExperimental.ProduceArtifactAsync(new ArtifactKey(guid, importerType)).value);

            case ImportMode.Synchronous:
                return(AssetDatabaseExperimental.ProduceArtifact(new ArtifactKey(guid, importerType)).value);

            case ImportMode.NoImport:
                var akey = new ArtifactKey(guid, importerType);
                var id   = AssetDatabaseExperimental.LookupArtifact(akey).value;
                if (!id.isValid)
                {
                    state = AssetDatabaseExperimental.GetOnDemandArtifactProgress(akey).state;
                }
                return(id);
                #else
            case ImportMode.Asynchronous:
                return(AssetDatabaseExperimental.GetArtifactHash(guid.ToString(), importerType, AssetDatabaseExperimental.ImportSyncMode.Queue));

            case ImportMode.Synchronous:
                return(AssetDatabaseExperimental.GetArtifactHash(guid.ToString(), importerType));

            case ImportMode.NoImport:
                return(AssetDatabaseExperimental.GetArtifactHash(guid.ToString(), importerType, AssetDatabaseExperimental.ImportSyncMode.Poll));
                #endif
            }

            return(default);
Exemplo n.º 4
0
        internal static Hash128 GetArtifactHash(string guid, Type importerType, ImportMode mode)
        {
            switch (mode)
            {
#if UNITY_2020_2_OR_NEWER
            case ImportMode.Asynchronous:
                return(AssetDatabaseExperimental.ProduceArtifactAsync(new ArtifactKey(new GUID(guid), importerType)).value);

            case ImportMode.Synchronous:
                return(AssetDatabaseExperimental.ProduceArtifact(new ArtifactKey(new GUID(guid), importerType)).value);

            case ImportMode.NoImport:
                return(AssetDatabaseExperimental.LookupArtifact(new ArtifactKey(new GUID(guid), importerType)).value);
#else
            case ImportMode.Asynchronous:
                return(AssetDatabaseExperimental.GetArtifactHash(guid, importerType, AssetDatabaseExperimental.ImportSyncMode.Queue));

            case ImportMode.Synchronous:
                return(AssetDatabaseExperimental.GetArtifactHash(guid, importerType));

            case ImportMode.NoImport:
                return(AssetDatabaseExperimental.GetArtifactHash(guid, importerType, AssetDatabaseExperimental.ImportSyncMode.Poll));
#endif
            }

            return(default);
        private static void OnPreferencesReadGUI()
        {
            bool shouldTryConnect = s_ConnectionState == ConnectionState.Unknown &&
                                    (AssetDatabase.IsV1Enabled() ? s_CacheServerMode != CacheServerMode.Disabled : s_CacheServer2Mode != CacheServer2Mode.Disabled);

            if (shouldTryConnect)
            {
                var canConnect = false;
                if (AssetDatabase.IsV1Enabled())
                {
                    canConnect = InternalEditorUtility.CanConnectToCacheServer();
                }
                else
                {
                    canConnect = AssetDatabaseExperimental.IsConnectedToCacheServer();
                }

                if (canConnect)
                {
                    s_ConnectionState = ConnectionState.Success;
                }
                else
                {
                    s_ConnectionState = ConnectionState.Failure;
                }
            }
        }
Exemplo n.º 6
0
        public static void WritePreferences()
        {
            // Don't change anything if there's a command line override
            if (GetCommandLineRemoteAddressOverride() != null)
            {
                return;
            }

            CacheServerMode oldMode       = (CacheServerMode)EditorPrefs.GetInt(kModeKey);
            var             oldPath       = EditorPrefs.GetString(LocalCacheServer.PathKey);
            var             oldCustomPath = EditorPrefs.GetBool(LocalCacheServer.CustomPathKey);
            bool            changedDir    = false;

            if (oldMode != s_CacheServerMode && oldMode == CacheServerMode.Local)
            {
                changedDir = true;
            }
            if (s_EnableCustomPath && oldPath != s_CachePath)
            {
                changedDir = true;
            }
            if (s_EnableCustomPath != oldCustomPath && s_CachePath != LocalCacheServer.GetCacheLocation() && s_CachePath != "")
            {
                changedDir = true;
            }
            if (changedDir)
            {
                s_LocalCacheServerUsedSize = -1;
                var message = s_CacheServerMode == CacheServerMode.Local ?
                              "You have changed the location of the local cache storage." :
                              "You have disabled the local cache.";
                message += " Do you want to delete the old locally cached data at " + LocalCacheServer.GetCacheLocation() + "?";
                if (EditorUtility.DisplayDialog("Delete old Cache", message, "Delete", "Don't Delete"))
                {
                    LocalCacheServer.Clear();
                    s_LocalCacheServerUsedSize = -1;
                }
            }

            EditorPrefs.SetInt(kAssetPipelineVersionForNewProjects, (int)s_AssetPipelineVersionForNewProjects);
            EditorPrefs.SetString(kIPAddress2Key, s_CacheServer2IPAddress);
            EditorPrefs.SetInt(kMode2Key, (int)s_CacheServer2Mode);
            EditorPrefs.SetString(kIPAddressKey, s_CacheServerIPAddress);
            EditorPrefs.SetInt(kModeKey, (int)s_CacheServerMode);
            EditorPrefs.SetInt(LocalCacheServer.SizeKey, s_LocalCacheServerSize);
            EditorPrefs.SetString(LocalCacheServer.PathKey, s_CachePath);
            EditorPrefs.SetBool(LocalCacheServer.CustomPathKey, s_EnableCustomPath);
            LocalCacheServer.Setup();

            if (AssetDatabase.IsV2Enabled())
            {
                AssetDatabaseExperimental.RefreshConnectionToCacheServer();
            }

            if (changedDir)
            {
                //Call ExitGUI after bringing up a dialog to avoid an exception
                EditorGUIUtility.ExitGUI();
            }
        }
Exemplo n.º 7
0
        static void CacheServerVersion2GUI(bool allowCacheServerChanges, string overrideAddress)
        {
            GUILayout.Space(5);

            bool changeStateBeforeControls = GUI.changed;

            s_CacheServer2Mode = (CacheServer2Mode)EditorGUILayout.EnumPopup(Properties.cacheServerDefaultMode, s_CacheServer2Mode);

            s_CacheServer2IPAddress = EditorGUILayout.TextField(Properties.cacheServerIPLabel, s_CacheServer2IPAddress);

            if (GUI.changed != changeStateBeforeControls)
            {
                s_ConnectionState = ConnectionState.Unknown;
            }

            GUILayout.Space(5);

            using (new EditorGUI.DisabledScope(AssetDatabase.IsV1Enabled()))
            {
                if (GUILayout.Button("Check Connection", GUILayout.Width(150)))
                {
                    var    address = s_CacheServer2IPAddress.Split(':');
                    var    ip      = address[0];
                    UInt16 port    = 0;
                    if (address.Length == 2)
                    {
                        port = Convert.ToUInt16(address[1]);
                    }

                    if (AssetDatabaseExperimental.CanConnectToCacheServer(ip, port))
                    {
                        s_ConnectionState = ConnectionState.Success;
                    }
                    else
                    {
                        s_ConnectionState = ConnectionState.Failure;
                    }
                }
            }

            GUILayout.Space(-25);

            var s = AssetDatabase.IsV2Enabled() ? s_ConnectionState : ConnectionState.Unknown;

            switch (s)
            {
            case ConnectionState.Success:
                EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
                break;

            case ConnectionState.Failure:
                EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
                break;

            case ConnectionState.Unknown:
                GUILayout.Space(44);
                break;
            }
        }
Exemplo n.º 8
0
        public override Vector2 GetWindowSize()
        {
            int lines                 = AssetDatabaseExperimental.IsCacheServerEnabled() ? 3 : 2;
            int heightOfLines         = (int)Math.Ceiling(EditorGUI.kSingleLineHeight * lines);
            int heightOfWindowPadding = m_WindowStyle.padding.top + m_WindowStyle.padding.bottom;

            return(new Vector2(250, heightOfLines + heightOfWindowPadding));
        }
Exemplo n.º 9
0
        public static Hash128 GetHash(string guid, BuildTarget target, AssetDatabaseExperimental.ImportSyncMode syncMode)
        {
            LiveLinkBuildPipeline.RemapBuildInAssetGuid(ref guid);
            AssetBundleTypeCache.RegisterMonoScripts();

            // TODO: GetArtifactHash needs to take BuildTarget so we can get Artifacts for other than the ActiveBuildTarget
            return(AssetDatabaseExperimental.GetArtifactHash(guid, typeof(LiveLinkBuildImporter), syncMode));
        }
        private static Hash128 ProduceArtifact(GUID guid, Type importerType, ImportMode mode, out OnDemandState state)
        {
            var akey = new ArtifactKey(guid, importerType);

            state = AssetDatabaseExperimental.GetOnDemandArtifactProgress(akey).state;

            if (state == OnDemandState.Failed)
            {
                return(default);
 public void OnDisable()
 {
     DevDeviceList.Changed -= OnDeviceListChanged;
     if (AssetDatabase.IsV2Enabled())
     {
         AssetDatabaseExperimental.RefreshCacheServerNamespacePrefix();
         AssetDatabaseExperimental.RefreshConnectionToCacheServer();
     }
 }
Exemplo n.º 12
0
        public static string GetLibraryFullPath(string guid)
        {
            if (String.IsNullOrEmpty(guid))
            {
                return(null);
            }

            string path = AssetDatabase.GUIDToAssetPath(guid);

            if (Path.GetExtension(path).Equals(".asset"))
            {
                return(path);
            }

#if UNITY_2019_2_OR_NEWER
            if (EditorSettings.assetPipelineMode == AssetPipelineMode.Version1)
            {
                return(GetAssetDatabaseVersion1LibraryDataPath(guid));
            }
            else
            {
#if UNITY_2020_2_OR_NEWER
                Hash128 artifactHash = AssetDatabaseExperimental.LookupArtifact(new ArtifactKey(new GUID(guid))).value;
#else
                Hash128 artifactHash = AssetDatabaseExperimental.GetArtifactHash(guid);
#endif

                if (!artifactHash.isValid)
                {
                    return(null);
                }

#if UNITY_2020_2_OR_NEWER
                ArtifactID artifactID = new ArtifactID();
                artifactID.value = artifactHash;
                AssetDatabaseExperimental.GetArtifactPaths(artifactID, out string[] paths);
#else
                AssetDatabaseExperimental.GetArtifactPaths(artifactHash, out string[] paths);
#endif

                foreach (string artifactPath in paths)
                {
                    if (artifactPath.EndsWith(".info"))
                    {
                        continue;
                    }

                    return(Path.GetFullPath(artifactPath));
                }
            }
#else // For older unity versions that dont have asset database V2 yet
            return(return GetAssetDatabaseVersion1LibraryDataPath(guid));
#endif

            return(null);
        }
Exemplo n.º 13
0
        public override void OnGUI(Rect rect)
        {
            var exit = false;

            GUILayout.BeginArea(rect, m_WindowStyle);
            GUILayout.BeginHorizontal();
            GUILayout.Label(m_WindowTitleContent, EditorStyles.boldLabel);
            if (GUILayout.Button(GUIContent.none, m_CacheServerOverflowMenuButtonStyle))
            {
                var menu = new GenericMenu();
                menu.AddItem(m_WindowOverflowMenuPreferencesButtonContent, false, () =>
                {
                    OpenPreferences();
                });
                menu.AddItem(m_WindowOverflowMenuProjectSettingsButtonContent, false, () =>
                {
                    OpenProjectSettings();
                });
                menu.ShowAsContext();
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(k_Header_footer_vertical_padding);

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(k_StatusText, ConnectionStatusText());
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(k_EndpointText, AssetDatabaseExperimental.GetCacheServerAddress());
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(k_NamespaceText, AssetDatabaseExperimental.GetCacheServerNamespacePrefix());
            GUILayout.EndHorizontal();

            GUILayout.Space(k_Header_footer_vertical_padding);

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            OnGUIFooter();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndArea();

            exit |= Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape;

            if (exit)
            {
                editorWindow.Close();
                GUIUtility.ExitGUI();
            }
        }
Exemplo n.º 14
0
        public override void OnGUI(Rect rect)
        {
            var exit = false;

            GUILayout.BeginArea(rect, m_WindowStyle);
            if (AssetDatabaseExperimental.IsCacheServerEnabled())
            {
                var iconPosition = new Rect();
                iconPosition.x      = rect.width - m_RefreshIcon.image.width - m_WindowStyle.padding.right;
                iconPosition.y      = m_WindowStyle.padding.top;
                iconPosition.width  = m_RefreshIcon.image.width;
                iconPosition.height = m_RefreshIcon.image.height;
                GUIStyle helpIconStyle = EditorStyles.iconButton;
                if (GUI.Button(iconPosition, m_RefreshIcon, helpIconStyle))
                {
                    AssetDatabaseExperimental.RefreshSettings();
                }

                GUILayout.BeginHorizontal();
                var style = new GUIStyle();
                style.fontStyle        = FontStyle.Bold;
                style.normal.textColor = EditorStyles.boldLabel.normal.textColor;
                if (!AssetDatabaseExperimental.IsConnectedToCacheServer())
                {
                    style.normal.textColor = new Color(0.97f, 0.32f, 0.31f);
                }
                EditorGUILayout.LabelField(AssetDatabaseExperimental.GetCacheServerAddress(), style);
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            var statusTextStyle = new GUIStyle()
            {
                normal = { textColor = Color.grey }
            };

            EditorGUILayout.LabelField(ConnectionStatusText(), statusTextStyle);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(m_OpenProjectSettings, "ControlLabel"))
            {
                OpenProjectSettings();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            exit |= Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape;
            if (exit)
            {
                editorWindow.Close();
                GUIUtility.ExitGUI();
            }
        }
Exemplo n.º 15
0
 static void HandleNotImportedAssetsInSafeModeOverlay(string guid, Rect drawRect)
 {
     if (EditorUtility.isInSafeMode)
     {
         GUID lookupGUID = new GUID(guid);
         var  hash       = AssetDatabaseExperimental.LookupArtifact(new ArtifactKey(lookupGUID));
         if (!hash.isValid)
         {
             GUI.Label(drawRect, s_NotImportedAssetTooltip);
         }
     }
 }
Exemplo n.º 16
0
        // This function is responsible for providing all the subscenes to the build.
        //
        // The way these files get generated is that we have a SceneWithBuildConfiguration file, (which is a bit of a hack to work around the inability for scriptable importers to take arguments, so
        // instead we create a different file that points to the scene we want to import, and points to the buildconfiguration we want to import it for).   The SubsceneImporter will import this file,
        // and it will make 3 (relevant) kind of files:
        // - headerfile
        // - entitybinaryformat file (the actual entities payloads)
        // - a SerializedFile that has an array of UnityEngine.Object PPtrs that are used by this entity file.
        //
        // The first two we deal with very simply: they just need to be copied into the build, and we're done.
        // the third one, we will feed as input to the Scriptable build pipeline (which is actually about creating assetbundles), and create an assetbundle that
        // has all those objects in it that the 3rd file referred to.  We do this with a batch api, first we loop through all subscenes, and register with this batch
        // api which assetbundles we'd like to see produced, and then at the end, we say "okay make them please".  this assetbundle creation api has a caching system
        // that is separate from the assetpipeline caching system, so if all goes well, the call to produce these assetbundles will return very fast and did nothing.
        //
        // The reason for the strange looking api, where a two callbacks get passed in is to make integration of the new incremental buildpipeline easier, as this code
        // needs to be compatible both with the current buildpipeline in the dots-repo, as well as with the incremental buildpipeline.  When that is merged, we can simplify this.

        public static void PrepareAdditionalFiles(string buildConfigurationGuid, Func <Type, IBuildComponent> getRequiredComponent, Action <string, string> RegisterFileCopy, string outputStreamingAssetsDirectory, string buildWorkingDirectory)
        {
            T GetRequiredComponent <T>() => (T)getRequiredComponent(typeof(T));

            var profile = GetRequiredComponent <ClassicBuildProfile>();

            if (profile.Target == BuildTarget.NoTarget)
            {
                throw new InvalidOperationException($"Invalid build target '{profile.Target.ToString()}'.");
            }

            if (profile.Target != EditorUserBuildSettings.activeBuildTarget)
            {
                throw new InvalidOperationException($"ActiveBuildTarget must be switched before the {nameof(SubSceneBuildCode)} runs.");
            }

            var content       = new BundleBuildContent(new AssetBundleBuild[0]);
            var sceneList     = GetRequiredComponent <SceneList>();
            var bundleNames   = new List <string>();
            var subSceneGuids = sceneList.GetScenePathsForBuild().SelectMany(scenePath => SceneMetaDataImporter.GetSubSceneGuids(AssetDatabase.AssetPathToGUID(scenePath))).Distinct().ToList();

            foreach (var subSceneGuid in subSceneGuids)
            {
                var hash128Guid = SceneWithBuildConfigurationGUIDs.EnsureExistsFor(subSceneGuid, new Hash128(buildConfigurationGuid));

                var hash = AssetDatabaseExperimental.GetArtifactHash(hash128Guid.ToString(), typeof(SubSceneImporter));
                AssetDatabaseExperimental.GetArtifactPaths(hash, out var artifactPaths);

                foreach (var artifactPath in artifactPaths)
                {
                    var ext = Path.GetExtension(artifactPath).Replace(".", "");
                    if (ext == EntityScenesPaths.GetExtension(EntityScenesPaths.PathType.EntitiesHeader))
                    {
                        var destinationFile = outputStreamingAssetsDirectory + "/" + EntityScenesPaths.RelativePathInStreamingAssetsFolderFor(subSceneGuid, EntityScenesPaths.PathType.EntitiesHeader, -1);
                        RegisterFileCopy(artifactPath, destinationFile);
                    }

                    if (ext == EntityScenesPaths.GetExtension(EntityScenesPaths.PathType.EntitiesBinary))
                    {
                        var destinationFile = outputStreamingAssetsDirectory + "/" + EntityScenesPaths.RelativePathInStreamingAssetsFolderFor(subSceneGuid, EntityScenesPaths.PathType.EntitiesBinary, EntityScenesPaths.GetSectionIndexFromPath(artifactPath));
                        RegisterFileCopy(artifactPath, destinationFile);
                    }

                    if (ext == EntityScenesPaths.GetExtension(EntityScenesPaths.PathType.EntitiesUnityObjectReferences))
                    {
                        content.CustomAssets.Add(new CustomContent
                        {
                            Asset     = hash128Guid,
                            Processor = (guid, processor) =>
                            {
                                var sectionIndex = EntityScenesPaths.GetSectionIndexFromPath(artifactPath);
                                processor.GetObjectIdentifiersAndTypesForSerializedFile(artifactPath, out ObjectIdentifier[] objectIds, out Type[] types);
Exemplo n.º 17
0
 public static string GetBundlePath(string guid, BuildTarget target)
 {
     try
     {
         AssetDatabaseExperimental.GetArtifactPaths(GetHash(guid, target), out string[] paths);
         return(paths.First(o => o.EndsWith(k_BundleExtension)));
     }
     catch (Exception e)
     {
         UnityEngine.Debug.LogError($"Exception thrown getting bundle path for '{guid}'.\n{e.Message}");
     }
     return("");
 }
Exemplo n.º 18
0
        static void HandleOndemandProgressOverlay(string guid, Rect drawRect, Action repaintAction)
        {
            if (AssetDatabaseExperimental.ActiveOnDemandMode == AssetDatabaseExperimental.OnDemandMode.Off)
            {
                return;
            }

            var now = EditorApplication.timeSinceStartup;

            if (repaintAction != null)
            {
                GUID lookupGUID = new GUID(guid);
                var  hash       = AssetDatabaseExperimental.LookupArtifact(new ArtifactKey(lookupGUID));
                if (!hash.isValid)
                {
                    if (s_ProgressRepainters.IndexOf(repaintAction) == -1)
                    {
                        s_ProgressRepainters.Add(repaintAction);
                    }

                    s_LastInvalidArtifactHashTime = now;

                    if (!s_CallbackController.active)
                    {
                        s_CallbackController.Start();
                    }

                    var texture = InternalEditorUtility.animatedProgressImage.image;
                    var xOffset = (drawRect.width - texture.width) / 2.0f;
                    if (xOffset < 0)
                    {
                        xOffset = 0;
                    }
                    var yOffset = (drawRect.height - texture.height) / 2.0f;
                    if (yOffset < 0)
                    {
                        yOffset = 0;
                    }
                    var width  = texture.width <= drawRect.width ? texture.width : drawRect.width;
                    var height = texture.height <= drawRect.height ? texture.height : drawRect.height;
                    var rect   = new Rect(drawRect.x + xOffset, drawRect.y + yOffset, width, height);
                    GUI.DrawTexture(rect, texture);
                }
            }

            if (s_CallbackController.active && (s_LastInvalidArtifactHashTime + k_AnimatedProgressImageTimeout) < now)
            {
                s_CallbackController.Stop();
                s_ProgressRepainters.Clear();
            }
        }
Exemplo n.º 19
0
        private GUIContent ConnectionStatusText()
        {
            GUIContent status = m_StatusMessageConnected;

            if (!AssetDatabaseExperimental.IsCacheServerEnabled())
            {
                status = m_StatusMessageDisabled;
            }
            else if (!AssetDatabaseExperimental.IsConnectedToCacheServer())
            {
                status = m_StatusMessageError;
            }
            return(status);
        }
Exemplo n.º 20
0
        private GUIContent GetStatusContent()
        {
            if (!AssetDatabaseExperimental.IsCacheServerEnabled())
            {
                return(m_CacheServerNotEnabledContent);
            }

            if (!AssetDatabaseExperimental.IsConnectedToCacheServer())
            {
                return(m_CacheServerDisconnectedContent);
            }

            return(m_CacheServerConnectedContent);
        }
Exemplo n.º 21
0
        private string ConnectionStatusText()
        {
            string status = k_StatusConnectedText;

            if (!AssetDatabaseExperimental.IsCacheServerEnabled())
            {
                status = k_StatusDisabledText;
            }
            else if (!AssetDatabaseExperimental.IsConnectedToCacheServer())
            {
                status = k_StatusDisconnectedText;
            }
            return(status);
        }
Exemplo n.º 22
0
    public unsafe static Hash128[] GetSubSceneGuids(string guid)
    {
        var hash = AssetDatabaseExperimental.GetArtifactHash(guid, typeof(SceneMetaDataImporter), AssetDatabaseExperimental.ImportSyncMode.Block);

        AssetDatabaseExperimental.GetArtifactPaths(hash, out string[] paths);

        var metaPath = paths.First(o => o.EndsWith("scenemeta"));

        BlobAssetReference <SceneMetaData> sceneMetaDataRef;

        if (!BlobAssetReference <SceneMetaData> .TryRead(metaPath, SceneMetaDataImporter.CurrentFileFormatVersion, out sceneMetaDataRef))
        {
            return(new Hash128[0]);
        }

        Hash128[] guids = sceneMetaDataRef.Value.SubScenes.ToArray();
        sceneMetaDataRef.Dispose();
        return(guids);
    }
Exemplo n.º 23
0
        private void DrawImporterSelectionPopup()
        {
            if (m_AvailableImporterTypesOptions.Length < 2)
            {
                return;
            }
            var mixed = EditorGUI.showMixedValue;

            EditorGUI.showMixedValue = m_SelectedImporterType == k_MultipleSelectedImporterTypes;
            GUILayout.Label(Styles.ImporterSelection);
            var newSelection = EditorGUILayout.Popup(m_SelectedImporterType, m_AvailableImporterTypesOptions);

            if (newSelection != m_SelectedImporterType)
            {
                if (CheckForApplyOnClose(false))
                {
                    // TODO : this should probably be handled by the AssetDatabase code when restoring selection?
                    m_SelectedAssetsPath         = assetTargets.Select(AssetDatabase.GetAssetPath).ToList();
                    EditorApplication.delayCall += () =>
                    {
                        var loaded = m_SelectedAssetsPath.Select(AssetDatabase.LoadMainAssetAtPath);
                        if (m_HasInspectorBeenSeenLocked)
                        {
                            m_Inspector.SetObjectsLocked(loaded.ToList());
                        }
                        else
                        {
                            Selection.objects = loaded.ToArray();
                        }
                    };
                    AssetDatabase.StartAssetEditing();
                    foreach (var importer in targets.Cast <AssetImporter>())
                    {
                        Undo.RegisterImporterUndo(importer.assetPath, string.Empty);
                        AssetDatabaseExperimental.SetImporterOverrideInternal(importer.assetPath, m_AvailableImporterTypes[newSelection]);
                    }
                    AssetDatabase.StopAssetEditing();
                    GUIUtility.ExitGUI();
                }
            }
            EditorGUI.showMixedValue = mixed;
        }
        //TODO: There is too much code duplication here, refactor this to send general artifacts to the editor
        unsafe void SendSubScene(Unity.Entities.Hash128 subSceneGuid, Unity.Entities.Hash128 buildSettingsGuid, int playerId)
        {
            LiveLinkMsg.LogInfo($"Sending SubScene: 'GUID: {subSceneGuid}' with 'BuildSettings: {buildSettingsGuid}' to playerId: {playerId}");

            var hash = EntityScenesPaths.GetSubSceneArtifactHash(subSceneGuid, buildSettingsGuid, AssetDatabaseExperimental.ImportSyncMode.Block);

            AssetDatabaseExperimental.GetArtifactPaths(hash, out var paths);
            var sceneHeaderPath = EntityScenesPaths.GetLoadPathFromArtifactPaths(paths, EntityScenesPaths.PathType.EntitiesHeader);

            if (!File.Exists(sceneHeaderPath))
            {
                Debug.LogError("Send Entity Scene failed because the entity header file could not be found: " + sceneHeaderPath);
                return;
            }

            if (!BlobAssetReference <SceneMetaData> .TryRead(sceneHeaderPath, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef))
            {
                Debug.LogError("Send Entity Scene failed because the entity header file was an old version: " + sceneHeaderPath);
                return;
            }

            ref var sceneMetaData = ref sceneMetaDataRef.Value;
Exemplo n.º 25
0
        // Recursive until new SBP APIs land in 2020.1
        public unsafe static Hash128[] GetDependencies(string guid, BuildTarget target)
        {
            try
            {
                AssetDatabaseExperimental.GetArtifactPaths(GetHash(guid, target), out string[] paths);
                var metaPath = paths.First(o => o.EndsWith(k_DependenciesExtension));

                BlobAssetReference <BuildMetaData> buildMetaData;
                if (!BlobAssetReference <BuildMetaData> .TryRead(metaPath, k_CurrentFileFormatVersion, out buildMetaData))
                {
                    return(new Hash128[0]);
                }

                Hash128[] guids = buildMetaData.Value.Dependencies.ToArray();
                buildMetaData.Dispose();
                return(guids);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError($"Exception thrown getting dependencies for '{guid}'.\n{e.Message}");
            }
            return(new Hash128[0]);
        }
Exemplo n.º 26
0
        public static void RegisterMonoScripts()
        {
            if (AssetDatabaseExperimental.IsAssetImportWorkerProcess() || s_Initialized)
            {
                return;
            }
            s_Initialized = true;

            AssetDatabaseExperimental.UnregisterCustomDependencyPrefixFilter("UnityEngineType/");

            var behaviours = TypeCache.GetTypesDerivedFrom <UnityEngine.MonoBehaviour>();
            var scripts    = TypeCache.GetTypesDerivedFrom <UnityEngine.ScriptableObject>();

            for (int i = 0; i != behaviours.Count; i++)
            {
                var type = behaviours[i];
                if (type.IsGenericType)
                {
                    continue;
                }
                var hash = TypeHash.CalculateStableTypeHash(type);
                AssetDatabaseExperimental.RegisterCustomDependency(TypeString(type),
                                                                   new UnityEngine.Hash128(hash, hash));
            }

            for (int i = 0; i != scripts.Count; i++)
            {
                var type = scripts[i];
                if (type.IsGenericType)
                {
                    continue;
                }
                var hash = TypeHash.CalculateStableTypeHash(type);
                AssetDatabaseExperimental.RegisterCustomDependency(TypeString(type),
                                                                   new UnityEngine.Hash128(hash, hash));
            }
        }
Exemplo n.º 27
0
        private IndexArtifact[] ProduceArtifacts(IList <string> assetPaths)
        {
            var artifacts         = InitializeIndexArtifacts(assetPaths);
            var indexImporterType = SearchIndexEntryImporter.GetIndexImporterType(settings.type, settings.options.GetHashCode());

            #if UNITY_2020_2_OR_NEWER
            var artifactIds = AssetDatabaseExperimental.ProduceArtifactsAsync(artifacts.Select(a => new GUID(a.guid)).ToArray(), indexImporterType);
            for (int i = 0; i < artifactIds.Length; ++i)
            {
                artifacts[i].key = artifactIds[i].value;
            }
            #else
            for (int i = 0; i < artifacts.Length; ++i)
            {
                if (String.IsNullOrEmpty(artifacts[i].guid))
                {
                    continue;
                }
                artifacts[i].key = ProduceArtifact(artifacts[i].guid, indexImporterType, ImportMode.Asynchronous);
            }
            #endif

            return(artifacts);
        }
        private void DoCacheServerSettings()
        {
            GUILayout.Space(10);
            GUILayout.Label(Content.cacheServer, EditorStyles.boldLabel);

            var overrideAddress = CacheServerPreferences.GetCommandLineRemoteAddressOverride();

            if (overrideAddress != null)
            {
                EditorGUILayout.HelpBox("Cache Server remote address forced via command line argument. To use the cache server address specified here please restart Unity without the -CacheServerIPAddress command line argument.", MessageType.Info, true);
            }

            int index = Mathf.Clamp((int)EditorSettings.cacheServerMode, 0, cacheServerModePopupList.Length - 1);

            CreatePopupMenu(Content.mode.text, cacheServerModePopupList, index, SetCacheServerMode);

            if (index != (int)CacheServerMode.Disabled)
            {
                bool isCacheServerEnabled = true;

                if (index == (int)CacheServerMode.AsPreferences)
                {
                    if (CacheServerPreferences.IsCacheServerV2Enabled)
                    {
                        var cacheServerIP = CacheServerPreferences.CachesServerV2Address;
                        cacheServerIP = string.IsNullOrEmpty(cacheServerIP) ? "Not set in preferences" : cacheServerIP;
                        EditorGUILayout.HelpBox(cacheServerIP, MessageType.None, false);
                    }
                    else
                    {
                        isCacheServerEnabled = false;
                        EditorGUILayout.HelpBox("Disabled", MessageType.None, false);
                    }
                }

                if (isCacheServerEnabled)
                {
                    var oldEndpoint = EditorSettings.cacheServerEndpoint;
                    var newEndpoint = EditorGUILayout.TextField(Content.cacheServerIPLabel, oldEndpoint);
                    if (newEndpoint != oldEndpoint)
                    {
                        EditorSettings.cacheServerEndpoint = newEndpoint;
                    }

                    EditorGUILayout.BeginHorizontal();

                    if (GUILayout.Button("Check Connection", GUILayout.Width(150)))
                    {
                        if (AssetDatabase.IsV2Enabled())
                        {
                            var    address = EditorSettings.cacheServerEndpoint.Split(':');
                            var    ip      = address[0];
                            UInt16 port    = 0; // If 0, will use the default set port
                            if (address.Length == 2)
                            {
                                port = Convert.ToUInt16(address[1]);
                            }

                            if (AssetDatabaseExperimental.CanConnectToCacheServer(ip, port))
                            {
                                m_CacheServerConnectionState = CacheServerConnectionState.Success;
                            }
                            else
                            {
                                m_CacheServerConnectionState = CacheServerConnectionState.Failure;
                            }
                        }
                        else
                        {
                            if (InternalEditorUtility.CanConnectToCacheServer())
                            {
                                m_CacheServerConnectionState = CacheServerConnectionState.Success;
                            }
                            else
                            {
                                m_CacheServerConnectionState = CacheServerConnectionState.Failure;
                            }
                        }
                    }

                    GUILayout.Space(25);

                    switch (m_CacheServerConnectionState)
                    {
                    case CacheServerConnectionState.Success:
                        EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, true);
                        break;

                    case CacheServerConnectionState.Failure:
                        EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, true);
                        break;

                    case CacheServerConnectionState.Unknown:
                        GUILayout.Space(44);
                        break;
                    }

                    EditorGUILayout.EndHorizontal();

                    var old      = EditorSettings.cacheServerNamespacePrefix;
                    var newvalue = EditorGUILayout.TextField(Content.cacheServerNamespacePrefixLabel, old);
                    if (newvalue != old)
                    {
                        EditorSettings.cacheServerNamespacePrefix = newvalue;
                    }

                    EditorGUI.BeginChangeCheck();
                    bool enableDownload = EditorSettings.cacheServerEnableDownload;
                    enableDownload = EditorGUILayout.Toggle(Content.cacheServerEnableDownloadLabel, enableDownload);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorSettings.cacheServerEnableDownload = enableDownload;
                    }

                    EditorGUI.BeginChangeCheck();
                    bool enableUpload = EditorSettings.cacheServerEnableUpload;
                    enableUpload = EditorGUILayout.Toggle(Content.cacheServerEnableUploadLabel, enableUpload);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorSettings.cacheServerEnableUpload = enableUpload;
                    }

                    bool enableAuth = EditorSettings.cacheServerEnableAuth;
                    using (new EditorGUI.DisabledScope(enableAuth))
                    {
                        EditorGUI.BeginChangeCheck();
                        bool enableTls = EditorSettings.cacheServerEnableTls;
                        enableTls = EditorGUILayout.Toggle(Content.cacheServerEnableTlsLabel, enableTls);
                        if (EditorGUI.EndChangeCheck())
                        {
                            EditorSettings.cacheServerEnableTls = enableTls;
                        }
                    }

                    EditorGUI.BeginChangeCheck();
                    enableAuth = EditorGUILayout.Toggle(Content.cacheServerEnableAuthLabel, enableAuth);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorSettings.cacheServerEnableAuth = enableAuth;
                        if (enableAuth)
                        {
                            EditorSettings.cacheServerEnableTls = true;
                        }
                    }

                    EditorGUI.indentLevel++;
                    using (new EditorGUI.DisabledScope(!enableAuth))
                    {
                        int authModeIndex = Convert.ToInt32(EditorUserSettings.GetConfigValue("cacheServerAuthMode"));
                        CreatePopupMenu(Content.mode.text, cacheServerAuthMode, authModeIndex, SetCacheServerAuthMode);

                        string oldUserVal = EditorUserSettings.GetConfigValue("cacheServerAuthUser");
                        var    newUserVal = EditorGUILayout.TextField(Content.cacheServerAuthUserLabel, oldUserVal);
                        if (newUserVal != oldUserVal)
                        {
                            EditorUserSettings.SetConfigValue("cacheServerAuthUser", newUserVal);
                        }

                        var oldPasswordVal = EditorUserSettings.GetConfigValue("cacheServerAuthPassword");
                        var newPasswordVal = EditorGUILayout.PasswordField(Content.cacheServerAuthPasswordLabel, oldPasswordVal);
                        if (newPasswordVal != oldPasswordVal)
                        {
                            EditorUserSettings.SetPrivateConfigValue("cacheServerAuthPassword", newPasswordVal);
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }
        }
Exemplo n.º 29
0
 public void OnDisable()
 {
     DevDeviceList.Changed -= OnDeviceListChanged;
     AssetDatabaseExperimental.RefreshSettings();
 }
Exemplo n.º 30
0
        static void UpdateBuildTaget(BuildTarget target)
        {
            var hash = Hash128.Compute(target.ToString());

            AssetDatabaseExperimental.RegisterCustomDependency("HLODSystemPlatform", hash);
        }