-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCycleRep.cs
More file actions
53 lines (46 loc) · 1.46 KB
/
Copy pathCycleRep.cs
File metadata and controls
53 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections.Generic;
using UnityEngine;
using RelationsInspector.Extensions;
using System.Linq;
namespace RelationsInspector.Backend.AssetDependency
{
// object representing a cycle in the dependency graph
public class CycleRep : ScriptableObject
{
public HashSet<Object> members; // objects that are part of the cycle
public GameObject gameObject;
public static CycleRep Create( IEnumerable<Object> members )
{
var instance = CreateInstance<CycleRep>();
instance.hideFlags = HideFlags.HideAndDontSave;
instance.members = members.ToHashSet();
instance.gameObject = instance.GetGameObject();
instance.name = instance.gameObject == null ? "Cycle Rep" : instance.gameObject.name;
return instance;
}
public override string ToString()
{
return "rep named {" + name + "} members: " + members.ToDelimitedString();
}
public bool EqualMembers( CycleRep other )
{
return other != null && other.members.SetEquals( this.members );
}
// returns the represented gameobject, if there is one
// that is: if one member is a gameobject, and all others are components of it
private GameObject GetGameObject()
{
var gos = members.OfType<GameObject>();
if( gos.Count() != 1)
return null;
var go = gos.First();
foreach ( var obj in members.Except( new[] { go } ) )
{
var asComponent = obj as Component;
if ( asComponent == null || asComponent.gameObject != go )
return null;
}
return go;
}
}
}