Пример #1
0
        private static bool LookForObjectsReferencesInHierarchy(Object[] objects, List <HierarchyReferenceItem> results)
        {
            var foundReferences   = new Dictionary <int, Dictionary <ExactReferenceData, List <ExactReferenceData> > >(objects.Length);
            var objectInstanceIds = CSObjectTools.GetObjectsInstanceIDs(objects);

            var canceled = HierarchyEntryFinder.FillHierarchyReferenceEntries(objects, (lookAt, lookForInstanceId, settings) =>
            {
                for (var i = 0; i < objectInstanceIds.Length; i++)
                {
                    var instanceId = objectInstanceIds[i];
                    if (instanceId == lookForInstanceId)
                    {
                        ExactReferenceData referenced;

                        if (!foundReferences.ContainsKey(instanceId))
                        {
                            foundReferences.Add(instanceId, new Dictionary <ExactReferenceData, List <ExactReferenceData> >());
                            referenced = ObjectToReferencingEntry(objects[i]);
                            foundReferences[instanceId].Add(referenced, new List <ExactReferenceData>());
                        }
                        else
                        {
                            referenced = foundReferences[instanceId].Keys.First();
                        }

                        var assetPath = CSObjectTools.TryGetObjectAssetPath(lookAt);
                        var reference = EntryGenerator.CreateNewReferenceEntry(EntryFinder.currentLocation, lookAt,
                                                                               lookAt as GameObject, settings);

                        var referenceData = new ExactReferenceData
                        {
                            assetPath = assetPath,
                            reference = reference
                        };

                        foundReferences[instanceId][referenced].Add(referenceData);
                    }
                }
            });

            if (!canceled && foundReferences.Count > 0)
            {
                BuildTree(foundReferences, results);
            }

            if (canceled)
            {
                HierarchyReferencesTab.AutoSelectHierarchyReference = null;
            }

            return(canceled);
        }
Пример #2
0
        protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
        {
            var objectReferences = DragAndDrop.objectReferences;

            if (objectReferences == null || objectReferences.Length == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            for (var i = 0; i < objectReferences.Length; i++)
            {
                var monoBehaviour = objectReferences[i] as MonoBehaviour;
                if (monoBehaviour == null)
                {
                    continue;
                }

                var monoScript = MonoScript.FromMonoBehaviour(monoBehaviour);
                if (monoScript == null)
                {
                    continue;
                }

                objectReferences[i] = monoScript;
            }

            var ids         = CSObjectTools.GetObjectsInstanceIDs(objectReferences);
            var assetsPaths = ProjectScopeReferencesFinder.GetAssetsFromInstances(ids);

            if (assetsPaths.Length == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            if (Event.current.type == EventType.DragPerform)
            {
                EditorApplication.delayCall += () => { ReferencesFinder.FindAssetsReferences(assetsPaths.ToArray()); };
                DragAndDrop.AcceptDrag();
            }

            return(DragAndDropVisualMode.Generic);
        }