Exemplo n.º 1
0
        private static void CheckAndFixCraftingCrossLinks()
        {
            // thank unity we have no better way to see variants (heirs) of game objects.
            // This dictionary contains pairs of values:
            // <Parent, List<parent's heirs>> or something like that. Heirs can also have its heirs, so they also
            // can be parents and should be presented in this dictionary with the matching key.
            Dictionary <GameObject, HashSet <GameObject> > parentsAndChilds =
                FindUtils.BuildAndGetInheritanceDictionaryOfPrefabs(new List <Type> {
                typeof(CraftingIngredient)
            });

            string[] recipeGuids = AssetDatabase.FindAssets("t:CraftingRecipe");

            if (recipeGuids.Length == 0)
            {
                return;
            }

            foreach (string recipeGuid in recipeGuids)
            {
                CraftingRecipe recipe = AssetDatabase.LoadAssetAtPath <CraftingRecipe>(
                    AssetDatabase.GUIDToAssetPath(recipeGuid)
                    );
                for (int i = 0; i < recipe.RequiredIngredients.Count; i++)
                {
                    CheckAndFixCraftingCrossLinks(
                        recipe,
                        i,
                        recipe.RequiredIngredients[i].RequiredItem,
                        parentsAndChilds
                        );
                }
            }
        }
Exemplo n.º 2
0
 public static void _CallAllClientSpawnHooksInScene()
 {
     //client side, just call the hooks
     foreach (var clientSpawn in FindUtils.FindInterfaceImplementersInScene <IClientSpawn>())
     {
         clientSpawn.OnSpawnClient(ClientSpawnInfo.Default());
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Populates the <see cref="Masters"/> and <see cref="Slaves"/> device lists with the relevant devices from the active scene.
        /// </summary>
        /// <param name="type">The multitool connection otype the device must support</param>
        public static void InitDeviceLists(MultitoolConnectionType type, bool forceRefresh = false)
        {
            currentConType = type;

            if (forceRefresh == false &&
                masters.TryGetValue(type, out var master) && master != null &&
                slaves.TryGetValue(type, out var slave) && slave != null)
            {
                return;
            }

            masters[type] = FindUtils.FindInterfacesOfType <IMultitoolMasterable>().Where(master => master.ConType == type).ToList();
            slaves[type]  = FindUtils.FindInterfacesOfType <IMultitoolSlaveable>().Where(master => master.ConType == type).ToList();
        }
Exemplo n.º 4
0
        public void CheckIngredientCrossLinks()
        {
            StringBuilder report = new StringBuilder();
            // thank unity we have no better way to see variants (heirs) of game objects.
            // This dictionary contains pairs of values:
            // <Parent, List<parent's heirs>> or something like that. Heirs can also have its heirs, so they also
            // can be parents and should be presented in this dictionary with the matching key.
            Dictionary <GameObject, HashSet <GameObject> > parentsAndChilds =
                FindUtils.BuildAndGetInheritanceDictionaryOfPrefabs(new List <Type> {
                typeof(CraftingIngredient)
            });

            // yes we can search without this recipesPath but i don't wanna make this test run for 5 minutes
            string[] recipeGuids = AssetDatabase.FindAssets("t:CraftingRecipe", new[] { recipesPath });

            if (recipeGuids.Length == 0)
            {
                report
                .AppendLine()
                .Append("Recipe directory path was probably changed - can't find any recipe at path: ")
                .Append($"{recipesPath}.");
            }

            foreach (string recipeGuid in recipeGuids)
            {
                CraftingRecipe recipe = AssetDatabase.LoadAssetAtPath <CraftingRecipe>(
                    AssetDatabase.GUIDToAssetPath(recipeGuid)
                    );
                for (int i = 0; i < recipe.RequiredIngredients.Count; i++)
                {
                    CheckIngredientsCrossLinks(
                        recipe,
                        i,
                        recipe.RequiredIngredients[i].RequiredItem,
                        parentsAndChilds,
                        report
                        );
                }
            }

            Logger.Log(report.ToString(), Category.Tests);
            Assert.IsEmpty(report.ToString());
        }
Exemplo n.º 5
0
 private IEnumerator WaitToFireHooks()
 {
     //we have to wait to fire hooks until the root objects in the scene are active,
     //otherwise our attempt to find the hooks to call will always return 0.
     //TODO: Find a better way to do this, maybe there is a hook for this
     while (FindUtils.FindInterfaceImplementersInScene <IServerSpawn>().Count == 0)
     {
         yield return(WaitFor.Seconds(1));
     }
     if (CustomNetworkManager.Instance._isServer)
     {
         //invoke all server + client side hooks on all objects that have them
         foreach (var serverSpawn in FindUtils.FindInterfaceImplementersInScene <IServerSpawn>())
         {
             serverSpawn.OnSpawnServer(SpawnInfo.Mapped(((Component)serverSpawn).gameObject));
         }
         Spawn._CallAllClientSpawnHooksInScene();
     }
     else
     {
         Spawn._CallAllClientSpawnHooksInScene();
     }
 }