public void SetGreed(int idx, int greed) { Assert.IsTrue(spawnedSpecies.ContainsKey(idx), "idx not spawned"); Species s = spawnedSpecies[idx]; s.Greediness = greed; OnGreedSet?.Invoke(idx, greedTrait.NormaliseValue(greed)); factory.RegenerateSpecies(s.GObject, s.BodySize, s.Greediness, s.RandomSeed); if (inspected == s) { sizeTrait.SetValueWithoutCallback(s.BodySize); greedTrait.SetValueWithoutCallback(s.Greediness); } s.Status.SetGreed(sizeTrait.PositivifyValue(greed)); }
void SetGreedFromSlider(int prevValue, int newValue) { Assert.IsTrue(incubated != null || inspected != null, "nothing inspected or incubated"); Assert.IsFalse(incubated != null && inspected != null, "both inspecting and incubating"); Species toSet = incubated != null? incubated : inspected; toSet.Greediness = newValue; toSet.Status?.SetGreed(greedTrait.PositivifyValue(toSet.Greediness)); factory.RegenerateSpecies(toSet.GObject, sizeTrait.NormaliseValue(toSet.BodySize), greedTrait.NormaliseValue(toSet.Greediness), toSet.RandomSeed); SetNameIfNotUser(toSet); if (inspected != null) // only call events on spawned species { OnGreedSet?.Invoke(toSet.Idx, greedTrait.NormaliseValue(newValue)); OnUserGreedSet?.Invoke(toSet.Idx, prevValue, newValue); } }
private void SpawnWithNonUserEvents(Species toSpawn) { if (graveyard.ContainsKey(toSpawn.Idx)) { // toSpawn.GObject.SetActive(true); graveyard.Remove(toSpawn.Idx); } spawnedSpecies[toSpawn.Idx] = toSpawn; if (toSpawn.Status == null) { toSpawn.Status = Instantiate(statusPrefab, statusCanvas.transform); toSpawn.Status.FollowSpecies(toSpawn.GObject); toSpawn.Status.SetSize(sizeTrait.PositivifyValue(toSpawn.BodySize)); toSpawn.Status.SetGreed(greedTrait.PositivifyValue(toSpawn.Greediness)); toSpawn.Status.ShowHealth(); } // must be invoked first so that nodelink focuses after adding OnSpawned?.Invoke(toSpawn.Idx, toSpawn.IsProducer, toSpawn.GObject); OnSizeSet?.Invoke(toSpawn.Idx, sizeTrait.NormaliseValue(toSpawn.BodySize)); OnGreedSet?.Invoke(toSpawn.Idx, greedTrait.NormaliseValue(toSpawn.Greediness)); }