Exemple #1
0
    protected override void OnUpdate()
    {
        List <Bridge.SelectorMatchRecord> l = new List <Bridge.SelectorMatchRecord>();

        Bridge.StyleMatchingContext ctx = new Bridge.StyleMatchingContext(null);
        //(element, info) => Debug.Log($"Matches: {element}"));
        Assert.IsTrue(GlobalObjectId.TryParse("GlobalObjectId_V1-1-e6e2a2a07016443409378c352d64f325-7433441132597879392-0", out var ssgoid));
        ctx.styleSheetStack = new List <StyleSheet> {
            (StyleSheet)GlobalObjectId.GlobalObjectIdentifierToObjectSlow(ssgoid)
        };

        var backgrounds = GetComponentDataFromEntity <Background>();

        Entities.ForEach((Entity e, ref UiRenderBounds bounds) =>
        {
            _eachEntity.Begin();
            l.Clear();
            ctx.currentElement = new UiEntity(e, PostUpdateCommands, backgrounds);
            _matchMarker.Begin();
            Bridge.StyleSelectorHelper.FindMatches(ctx, l);
            _matchMarker.End();
            if (l.Count > 0)
            {
//                string Rules(StyleRule info) => String.Join(",", info.properties.Select(p => $"{p.name}: {p.values}"));
//                Debug.Log(String.Join("\r\n", l.Select(x => $"{x.complexSelector} {Rules(x.complexSelector.rule)}")));
                _applyMatching.Begin();
                foreach (var record in l)
                {
                    Apply(ctx, record);
                }
                _applyMatching.End();
            }
            _eachEntity.End();
        });
    }
Exemple #2
0
        internal static IBuildStep Deserialize(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            if (GlobalObjectId.TryParse(json, out var id))
            {
                if (GlobalObjectId.GlobalObjectIdentifierToObjectSlow(id) is BuildPipeline pipeline)
                {
                    return(pipeline);
                }
            }
            else
            {
                var type = Type.GetType(json);
                if (TypeConstruction.TryConstruct <IBuildStep>(type, out var step))
                {
                    return(step);
                }
            }

            return(null);
        }
Exemple #3
0
            internal object TryConvert()
            {
                switch (type)
                {
                case ExportedType.Bool:
                    bool.TryParse(data, out var resultBool);
                    return(resultBool);

                case ExportedType.Number:
                    double.TryParse(data, out var resultDouble);
                    return(resultDouble);

                case ExportedType.String:
                    return(data);

                case ExportedType.ObjectReference:
                    var parts = data.Split(';');
                    if (parts.Length != 2)
                    {
                        return(null);
                    }
                    if (GlobalObjectId.TryParse(parts[0], out var id))
                    {
                        return(new ObjectValue(GlobalObjectId.GlobalObjectIdentifierToObjectSlow(id), parts[1]));
                    }
                    return(data);

                case ExportedType.Color:
                    ColorUtility.TryParseHtmlString(data, out var resultColor);
                    return(resultColor);
                }
                return(null);
            }
        public object Deserialize(SerializedValueView view)
        {
            var json = view.ToString();

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            if (GlobalObjectId.TryParse(json, out var id))
            {
                if (GlobalObjectId.GlobalObjectIdentifierToObjectSlow(id) is BuildPipeline pipeline)
                {
                    return(pipeline);
                }
            }
            else
            {
                if (TypeConstructionHelper.TryConstructFromAssemblyQualifiedTypeName <IBuildStep>(json, out var step))
                {
                    return(step);
                }
            }
            return(null);
        }
Exemple #5
0
        private static Object ToObject(SearchItem item, Type type)
        {
            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(null);
            }

            var obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid);

            if (obj)
            {
                if (type == null)
                {
                    return(obj);
                }
                var objType = obj.GetType();
                if (objType == type || objType.IsSubclassOf(type))
                {
                    return(obj);
                }

                if (obj is GameObject go)
                {
                    return(go.GetComponent(type));
                }
            }

            var assetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID.ToString());

            return(AssetDatabase.LoadMainAssetAtPath(assetPath));
        }
Exemple #6
0
        protected override void InternalValidate()
        {
            this.itemId   = null;
            this.objectId = null;
            LocalizedString?localizedString = null;

            TaskLogger.LogEnter();
            base.InternalValidate();
            if (!string.IsNullOrEmpty(this.MeetingID))
            {
                try
                {
                    this.itemId = StoreObjectId.Deserialize(this.MeetingID);
                }
                catch (Exception)
                {
                    if (!GlobalObjectId.TryParse(this.MeetingID, out this.objectId))
                    {
                        base.WriteError(new ManagementObjectNotFoundException(localizedString ?? base.GetErrorMessageObjectNotFound(this.Identity.ToString(), typeof(MailboxIdParameter).ToString(), (base.DataSession != null) ? base.DataSession.Source : null)), ErrorCategory.InvalidData, null);
                    }
                }
            }
            this.logSourceUser = base.GetDataObjects(this.Identity, base.OptionalIdentityData, out localizedString).FirstOrDefault <ADUser>();
            if (this.logSourceUser == null || base.HasErrors)
            {
                base.WriteError(new ManagementObjectNotFoundException(localizedString ?? base.GetErrorMessageObjectNotFound(this.Identity.ToString(), typeof(MailboxIdParameter).ToString(), (base.DataSession != null) ? base.DataSession.Source : null)), ErrorCategory.InvalidData, null);
            }
            if (this.LogMailbox != null)
            {
                this.outputMailboxUser = base.GetDataObjects(this.LogMailbox, base.OptionalIdentityData, out localizedString).FirstOrDefault <ADUser>();
            }
            TaskLogger.LogExit();
        }
 public override void OnClicked(int index)
 {
     if (GlobalObjectId.TryParse(guids[index], out var gid))
     {
         var containerPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID);
         EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <Object>(containerPath));
     }
 }
 private string ToPath(SearchItem item)
 {
     if (GlobalObjectId.TryParse(item.id, out var gid))
     {
         return(AssetDatabase.GUIDToAssetPath(gid.assetGUID));
     }
     return(item.id);
 }
Exemple #9
0
        private static Texture2D FetchThumbnail(SearchItem item)
        {
            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(null);
            }
            var sourceAssetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID.ToString());

            return(Utils.GetAssetPreviewFromPath(sourceAssetPath, k_PreviewSize, FetchPreviewOptions.Preview2D));
        }
Exemple #10
0
        private static Texture2D FetchThumbnail(SearchItem item)
        {
            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(null);
            }
            var sourceAssetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID.ToString());

            return(AssetDatabase.GetCachedIcon(sourceAssetPath) as Texture2D);
        }
Exemple #11
0
 protected override void OnCreate()
 {
     mesh          = CreateQuad();
     m_RenderQuery = GetEntityQuery(
         ComponentType.ReadOnly <UiRenderBounds>()
         );
     GlobalObjectId.TryParse(UIMaterialGOID, out var goid);
     material         = (Material)GlobalObjectId.GlobalObjectIdentifierToObjectSlow(goid);
     _colorPropertyId = Shader.PropertyToID("_Color");
     _gen             = new TextGenerator();
 }
Exemple #12
0
        internal static object GlobalObjectIdDeserializer(PropertyDatabaseDeserializationArgs args)
        {
            var symbol = args.value.int32_0;
            var str    = args.stringTableView.GetString(symbol);

            if (GlobalObjectId.TryParse(str, out var goid))
            {
                return(goid);
            }
            return(null);
        }
Exemple #13
0
        private Object GetContextObject(ref RunItemContext ctx)
        {
            var item = ctx.item;
            var guid = guids[item.index];

            if (GlobalObjectId.TryParse(guid, out var globalId))
            {
                // Try loading the object
                // TODO: Upcoming changes to GlobalObjectIdentifierToObjectSlow will allow it
                //       to return direct references to prefabs and their children.
                //       Once that change happens there are several items which should be adjusted.
                var obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(globalId);

                // If the object was not loaded, it is probably part of an unopened scene;
                // if so, then the solution is to first load the scene here.
                var objIsInSceneOrPrefab = globalId.identifierType == 2; // 2 is IdentifierType.kSceneObject
                if (!obj &&
                    objIsInSceneOrPrefab)
                {
                    // Open the Containing Scene Asset in the Hierarchy so the Object can be manipulated
                    var mainAssetPath = AssetDatabase.GUIDToAssetPath(globalId.assetGUID);
                    var mainAsset     = AssetDatabase.LoadAssetAtPath <Object>(mainAssetPath);
                    AssetDatabase.OpenAsset(mainAsset);

                    // If a prefab stage was opened, then mainAsset is the root of the
                    // prefab that contains the target object, so reference that for now,
                    // until GlobalObjectIdentifierToObjectSlow is updated
                    if (PrefabStageUtility.GetCurrentPrefabStage() != null)
                    {
                        obj = mainAsset;
                    }

                    // Reload object if it is still null (because it's in a previously unopened scene)
                    if (!obj)
                    {
                        obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(globalId);
                        if (!obj)
                        {
                            ctx.didFail = true;
                            ctx.info    = $"Object {globalId.assetGUID} failed to load...";
                        }
                    }
                }

                return(obj);
            }

            ctx.didFail = true;
            ctx.info    = $"Failed to parse Global ID {item.descriptor.info}...";

            return(null);
        }
Exemple #14
0
        private static Object ToObject(SearchItem item, Type type)
        {
            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(null);
            }

            var assetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID.ToString());

            return(ToObjectType(GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid), type) ??
                   ToObjectType(AssetDatabase.LoadAssetAtPath(assetPath, type), type) ??
                   ToObjectType(AssetDatabase.LoadMainAssetAtPath(assetPath), type));
        }
        public void OnAfterDeserialize()
        {
            var ids = new GlobalObjectId[_objectIds.Length];

            globalObjectIdSet.Clear();
            activeObjects.Clear();
            for (var i = 0; i < _objectIds.Length; i++)
            {
                if (GlobalObjectId.TryParse(_objectIds[i], out ids[i]))
                {
                    globalObjectIdSet.Add(ids[i]);
                }
            }
            EditorApplication.delayCall += ConvertGlobalObjectIdsToSceneObjects;
        }
        private Object LoadObject(ref RunItemContext ctx)
        {
            var item = ctx.item;
            var guid = guids[item.index];

            if (GlobalObjectId.TryParse(guid, out var gid))
            {
                var obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid);
                if (!obj)
                {
                    // Open container scene
                    if (gid.identifierType == (int)IdentifierType.kSceneObject)
                    {
                        var containerPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID);

                        var mainInstanceID = AssetDatabase.LoadAssetAtPath <Object>(containerPath);
                        AssetDatabase.OpenAsset(mainInstanceID);

                        // if we have a prefab open, then we already have the object we need to update
                        var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
                        if (prefabStage != null)
                        {
                            obj = mainInstanceID;
                        }

                        // Reload object if it is still null
                        if (obj == null)
                        {
                            obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid);
                            if (!obj)
                            {
                                ctx.didFail = true;
                                ctx.info    = $"Object {gid.assetGUID} failed to load...";
                            }
                        }
                    }
                }

                return(obj);
            }

            ctx.didFail = true;
            ctx.info    = $"Failed to parse Global ID {item.descriptor.info}...";

            return(null);
        }
Exemple #17
0
        internal static object DrawObjectReference(Rect rect, object value)
        {
            if (value is UnityEngine.Object obj)
            {
                DrawObjectField(rect, obj);
            }
            else if (value is string s && GlobalObjectId.TryParse(s, out var gid))
            {
                obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid);
                if (obj)
                {
                    DrawObjectField(rect, obj);
                }
            }

            return(value?.ToString());
        }
Exemple #18
0
        private static bool SelectObjectbyId(string id, out string guid)
        {
            guid = null;
            if (!GlobalObjectId.TryParse(id, out var gid))
            {
                return(false);
            }
            guid = gid.assetGUID.ToString();
            var obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid);

            if (obj)
            {
                Utils.SelectObject(obj);
                return(true);
            }
            return(false);
        }
Exemple #19
0
    /// <summary>
    /// Do not call this in OnBeforeSerialize/OnAfterDeserialize or you will crash!
    /// </summary>
    /// <returns></returns>
    public T Load <T>() where T : Object
    {
        if (string.IsNullOrEmpty(_guid))
        {
            return(null);
        }

#if UNITY_EDITOR
        var str = $"GlobalObjectId_V1-{_typeId}-{_guid}-{(ulong)_localId}-{(ulong)_prefabId}";

        if (GlobalObjectId.TryParse(str, out var id))
        {
            var obj = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(id);
            Debug.Assert(Type == obj.GetType());
            return(obj as T);
        }

        return(default);
Exemple #20
0
        private static string FetchDescription(SearchItem item)
        {
            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(null);
            }

            var go = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid) as GameObject;

            if (go)
            {
                return(item.description = $"Source: {SearchUtils.GetHierarchyPath(go)}");
            }

            var sourceAssetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID.ToString());

            return(item.description = $"Source: {GetAssetDescription(sourceAssetPath)}");
        }
        static string[] GatherDependenciesFromSourceFile(string assetPath)
        {
            var dependencies = new List <string>();

            try
            {
                using (var reader = new SerializedObjectReader(assetPath))
                {
                    var root = reader.ReadObject();
                    if (!root.TryGetMember(nameof(BuildConfiguration.Dependencies), out var member))
                    {
                        return(Array.Empty <string>());
                    }

                    var valueView = member.Value();
                    if (valueView.Type != TokenType.Array)
                    {
                        return(Array.Empty <string>());
                    }

                    var arrayView = valueView.AsArrayView();
                    foreach (var value in arrayView)
                    {
                        if (!GlobalObjectId.TryParse(value.AsStringView().ToString(), out var id))
                        {
                            continue;
                        }

                        var dependencyPath = AssetDatabase.GUIDToAssetPath(id.assetGUID.ToString());
                        if (string.IsNullOrEmpty(dependencyPath))
                        {
                            continue;
                        }

                        dependencies.Add(dependencyPath);
                    }
                }
            }
            catch
            {
                return(Array.Empty <string>());
            }
            return(dependencies.ToArray());
        }
Exemple #22
0
        private static Texture2D FetchPreview(SearchItem item, FetchPreviewOptions options)
        {
            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(null);
            }

            if (options.HasFlag(FetchPreviewOptions.Large))
            {
                var go = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid) as GameObject;
                if (go)
                {
                    return(AssetPreview.GetAssetPreview(go));
                }
            }

            var sourceAssetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID.ToString());

            return(AssetDatabase.GetCachedIcon(sourceAssetPath) as Texture2D);
        }
Exemple #23
0
        private static string FetchDescription(SearchItem item)
        {
            if (item.options.HasFlag(SearchItemOptions.Compacted))
            {
                return(FetchLabel(item));
            }

            if (!String.IsNullOrEmpty(item.description))
            {
                return(item.description);
            }

            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(null);
            }

            var sourceAssetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID.ToString());

            return(item.description = $"Source: {GetAssetDescription(sourceAssetPath)}");
        }
Exemple #24
0
        private void AddSearchItemsAsConverterAssetEntries(ISearchList searchItems, InitializeConverterContext context)
        {
            foreach (var searchItem in searchItems)
            {
                if (searchItem == null || !GlobalObjectId.TryParse(searchItem.id, out var globalId))
                {
                    continue;
                }

                var description = searchItem.provider.fetchDescription(searchItem, searchItem.context);

                var item = new ConverterItemDescriptor()
                {
                    name = description.Split('/').Last().Split('.').First(),
                    info = $"{ReturnType(globalId)}",
                };

                guids.Add(globalId.ToString());
                context.AddAssetToConvert(item);
            }
        }
        static bool TryGetScenePath(SearchItem item, out string path)
        {
            path = item.data as string;
            if (!string.IsNullOrEmpty(path))
            {
                return(true);
            }

            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(false);
            }

            var scenePath = AssetDatabase.GUIDToAssetPath(gid.assetGUID);

            if (string.IsNullOrEmpty(scenePath))
            {
                return(false);
            }

            item.data = path = scenePath;
            return(true);
        }
        public override void OnInitialize(InitializeConverterContext ctx, Action callback)
        {
            var context = Search.SearchService.CreateContext("asset", "urp:convert-readonly");

            Search.SearchService.Request(context, (c, items) =>
            {
                // we're going to do this step twice in order to get them ordered, but it should be fast
                var orderedRequest = items.OrderBy(req =>
                {
                    GlobalObjectId.TryParse(req.id, out var gid);
                    return(gid.assetGUID);
                });

                foreach (var r in orderedRequest)
                {
                    if (r == null || !GlobalObjectId.TryParse(r.id, out var gid))
                    {
                        continue;
                    }

                    var label       = r.provider.fetchLabel(r, r.context);
                    var description = r.provider.fetchDescription(r, r.context);

                    var item = new ConverterItemDescriptor()
                    {
                        name = description.Split('/').Last().Split('.').First(),
                        info = $"{label}",
                    };
                    guids.Add(gid.ToString());

                    ctx.AddAssetToConvert(item);
                }

                callback.Invoke();
            });
            context?.Dispose();
        }
Exemple #27
0
        internal static IBuildStep Deserialize(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            if (GlobalObjectId.TryParse(json, out var id))
            {
                if (GlobalObjectId.GlobalObjectIdentifierToObjectSlow(id) is BuildPipeline pipeline)
                {
                    return(pipeline);
                }
            }
            else
            {
                if (TypeConstruction.TryConstructFromAssemblyQualifiedTypeName <IBuildStep>(json, out var step))
                {
                    return(step);
                }
            }

            return(null);
        }
Exemple #28
0
        private bool Validate()
        {
            // Validate should return whether the popup is alive.
            // If not, it should try reinitializing it from serialized data, if possible.
            // If it returns false, the popup may have been closed by Validate, and the caller should abort.

            // If we're already alive, no need to do anything, just return true.
            var isAlive = editor != null &&
                          editor.targets.All(t => t != null) &&
                          editor.serializedObject != null &&
                          editor.serializedObject.targetObject != null &&
                          editor.serializedObject.targetObjects.All(t => t != null);

            if (isAlive)
            {
                return(true);
            }

            // If we don't have initialization data and we're not alive, we close and abort.
            // Normally though, this shouldn't happen, since this gets set in Initialize() then serialized.

            var isInitializable = initializationTargets != null
#if UNITY_2019_2_OR_NEWER
                                  && initializationTargetIdData != null &&
                                  initializationTargets.Length == initializationTargetIdData.Length
#endif
            ;

            if (!isInitializable)
            {
                Close();
                return(false);
            }

            // We wait for the plugin container to be initialized, but don't close yet if it isn't.
            if (!PluginContainer.initialized)
            {
                return(false);
            }

            // Check that we do want persistent editors. Currently an experimental feature.
            if (!PeekPlugin.Configuration.persistentPinnedEditors)
            {
                Close();
                return(false);
            }

            // The strategy will be to try to use the serialized object reference if available,
            // then otherwise parse and return the GOID. Normally we should be able to rely on
            // the GOID alone, but there's a bug (TODO: REPORT) in the UnityEditor.GUID.TryParse
            // function which will return false for zero values, the case for objects within
            // unsaved scenes.

            var targets = new List <UnityObject>();

            for (var i = 0; i < initializationTargets.Length; i++)
            {
                var initializationTarget = initializationTargets[i];

                // We have a direct alive reference, keep that
                if (initializationTarget != null)
                {
                    targets.Add(initializationTarget);
                    continue;
                }

#if UNITY_2019_2_OR_NEWER
                // Fallback to parsing the GOID

                var initializationTargetIdDatum = initializationTargetIdData[i];

                if (!GlobalObjectId.TryParse(initializationTargetIdDatum, out var initializationTargetId))
                {
                    continue;
                }

                var target = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(initializationTargetId);

                if (target == null)
                {
                    continue;
                }

                targets.Add(target);
#endif
            }

            // If we couldn't find any initialization target that's still alive, we have nothing to display,
            // so we close and abort.
            if (targets.Count == 0)
            {
                Close();
                return(false);
            }

            // If we did find alive targets to reinitialize, we use those to reinitialize the popup and return true.
            Initialize(targets.ToArray());
            return(true);
        }