示例#1
0
        public static void AddAllNewGhosts(GhostCollectionConfig collectionConfigTarget)
        {
            var  list         = collectionConfigTarget.Ghosts;
            var  alreadyAdded = new HashSet <GhostAuthoringComponent>();
            bool hasEmpty     = false;

            foreach (var ghost in list)
            {
                if (ghost.prefab != null)
                {
                    alreadyAdded.Add(ghost.prefab);
                }
                else
                {
                    hasEmpty = true;
                }
            }

            if (hasEmpty)
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    if (list[i].prefab == null)
                    {
                        list.RemoveAt(i);
                        --i;
                        EditorUtility.SetDirty(collectionConfigTarget);
                    }
                }
            }

            var prefabGuids = AssetDatabase.FindAssets("t:" + typeof(GameObject).Name);

            foreach (var guid in prefabGuids)
            {
                var path  = AssetDatabase.GUIDToAssetPath(guid);
                var go    = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                var ghost = go.GetComponent <GhostAuthoringComponent>();
                if (ghost != null && !alreadyAdded.Contains(ghost))
                {
                    list.Add(new GhostCollectionConfig.Ghost {
                        prefab = ghost, enabled = true
                    });
                    EditorUtility.SetDirty(collectionConfigTarget);
                }
            }
        }
 private void Awake()
 {
     _authoring = GetComponent <GhostCollectionAuthoringComponent>();
     _config    = _authoring.ghostCollectionConfig;
 }