//------------------------------------------------------------ // Game Framework // Copyright © 2013-2021 loyalsoft. All rights reserved. // Homepage: http://www.game7000.com/ // Feedback: http://www.game7000.com/ //------------------------------------------------------------ using System.Collections.Generic; using System.Linq; namespace UnityGameFramework.Editor.ResourceTools { public sealed partial class ResourceAnalyzerController { private sealed class CircularDependencyChecker { private readonly Stamp[] m_Stamps; public CircularDependencyChecker(Stamp[] stamps) { m_Stamps = stamps; } public string[][] Check() { HashSet hosts = new HashSet(); foreach (Stamp stamp in m_Stamps) { hosts.Add(stamp.HostAssetName); } List results = new List(); foreach (string host in hosts) { LinkedList route = new LinkedList(); HashSet visited = new HashSet(); if (Check(host, route, visited)) { results.Add(route.ToArray()); } } return results.ToArray(); } private bool Check(string host, LinkedList route, HashSet visited) { visited.Add(host); route.AddLast(host); foreach (Stamp stamp in m_Stamps) { if (host != stamp.HostAssetName) { continue; } if (visited.Contains(stamp.DependencyAssetName)) { route.AddLast(stamp.DependencyAssetName); return true; } if (Check(stamp.DependencyAssetName, route, visited)) { return true; } } route.RemoveLast(); visited.Remove(host); return false; } } } }