Exemplo n.º 1
0
        public void Merge(IEnumerable <AssetIdentifierTuple> entries)
        {
            var types = entries.SelectMany(x => new[] { x.source.assetType, x.destination.assetType });

            if (types.Where(x => !string.IsNullOrEmpty(x)).Distinct().Count() > 1)
            {
                Debug.LogError("Attempting to map entries of multiple types! This is not allowed.");
                return;
            }

            var arr = entries as AssetIdentifierTuple[] ?? entries.ToArray();
            var src = arr.Where(x => AssetId.IsValid(x.source) && !AssetId.IsValid(x.destination)).ToArray();
            var dst = arr.Where(x => AssetId.IsValid(x.destination)).ToArray();

            if (dst.Count() != 1)
            {
                Debug.LogError("Merging AssetId entries requires only one valid destination entry be selected.");
                return;
            }

            var d = dst.First().destination;

            foreach (var s in src)
            {
                map.Add(new AssetIdentifierTuple(new AssetId(s.source), new AssetId(d)));
            }

            map.RemoveAll(src.Contains);
            map.RemoveAll(x => dst.Contains(x) && !AssetId.IsValid(x.source));
        }
Exemplo n.º 2
0
 public bool AssetEquals(AssetIdentifierTuple other)
 {
     return(AssetId.IsValid(source) == AssetId.IsValid(other.source) &&
            source.AssetEquals(other.source) &&
            AssetId.IsValid(destination) == AssetId.IsValid(other.destination) &&
            destination.AssetEquals(other.destination));
 }
        void GetRemapSource(string directory)
        {
            if (string.IsNullOrEmpty(directory) || !Directory.Exists(directory))
            {
                Debug.LogWarning("No source directory selected.");
                return;
            }

            var remapObject = GetGuidRemapObject();

            string localDirectory = directory.Replace("\\", "/").Replace(Application.dataPath, "Assets") + "/";

            if (!remapObject.sourceDirectory.Contains(localDirectory))
            {
                remapObject.sourceDirectory.Add(localDirectory);
            }

            List <AssetIdentifierTuple> map = remapObject.map;

            foreach (var id in GetAssetIdentifiersInDirectory(localDirectory, k_DirectoryExcludeFilter))
            {
                id.SetPathRelativeTo(localDirectory);

                if (map.Any(x => x.source != null && x.source.Equals(id)))
                {
                    continue;
                }

                // the only time where a destination can exist with a null source is when a single destination is in the
                // map, so it's okay to grab the first and not bother searching for more dangling destination entries
                AssetIdentifierTuple matchingDestination =
                    map.FirstOrDefault(x =>
                {
                    return(x.destination != null &&
                           x.destination.AssetEquals(id));
                });

                if (matchingDestination != null)
                {
                    if (AssetId.IsValid(matchingDestination.source))
                    {
                        map.Add(new AssetIdentifierTuple(id, matchingDestination.destination));
                    }
                    else
                    {
                        matchingDestination.source = id;
                    }
                }
                else
                {
                    map.Add(new AssetIdentifierTuple(id, null));
                }
            }

            m_TreeView.isDirty = true;
        }
Exemplo n.º 4
0
        public void Clear(Origin origin)
        {
            switch (origin)
            {
            case Origin.Source:
                sourceDirectory.Clear();
                for (int i = 0, c = map.Count; i < c; i++)
                {
                    map[i].source.Clear();
                }
                break;

            case Origin.Destination:
                destinationDirectory = "";
                for (int i = 0, c = map.Count; i < c; i++)
                {
                    map[i].destination.Clear();
                }
                break;
            }

            map = map.Where(x => AssetId.IsValid(x.source) || AssetId.IsValid(x.destination)).ToList();
        }