Exemple #1
0
        public static HighlighterCollection Create(GameObject obj, HighlighterSet set)
        {
            GameObject highlighterCollectionObj = Instantiate(Resources.Load <GameObject>(COLLECTION_PREFAB_PATH));

            var prefabs = GetPrefabs(set);

            Component[] components = obj.GetComponentsInChildren <Component>();
            Dictionary <Component, IEnumerable <IHighlighter> > highlighters = new Dictionary <Component, IEnumerable <IHighlighter> >();

            foreach (Component component in components)
            {
                List <IHighlighter> list = new List <IHighlighter>();

                var caches = prefabs.Where(x => x.GetCache().GetComponent <IHighlighter>().CanHighlight(component.GetType()));
                foreach (var cache in caches)
                {
                    GameObject highlighterObj = cache.Instantiate();
                    highlighterObj.transform.position = Vector3.zero;
                    highlighterObj.transform.SetParent(highlighterCollectionObj.transform, false);

                    list.Add(highlighterObj.GetComponent <IHighlighter>());
                }

                highlighters.Add(component, list);
            }

            HighlighterCollection highlighterCollection = highlighterCollectionObj.GetComponent <HighlighterCollection>();

            highlighterCollection.Init(highlighters);
            return(highlighterCollection);
        }
Exemple #2
0
 private static IEnumerable <IContentCachedPrefab> GetPrefabs(HighlighterSet set)
 {
     if (_highlighterPrefabs == null)
     {
         _highlighterPrefabs = ContentSystem.Content.GetAll(PREFAB_PATH, typeof(IContentCachedPrefab)).Cast <IContentCachedPrefab>().ToArray();
     }
     return(_highlighterPrefabs.Where(x => set.Contains(x.GetCache().GetComponent <IHighlighter>().Identifier)));
 }