public void FixedUpdate() { // If section modifier exists and is not completed, run modifiers if (sectionModifier == null || sectionModifier.IsSectionComplete()) { // New section! sentenceDataHolder = cFGGenerator.GetSentence(); // If null try getting sentence next call if (sentenceDataHolder != null) { CreateNewModifiers(); afterInit = true; } } else if (afterInit) { // Call once after initializing new modifiers afterInit = false; // First off stop any coroutines running at this moment StopAllCoroutines(); // Start coroutines once to run each modifier once per frame foreach (var modifierEnumerator in modifierEnumerators) { StartCoroutine(modifierEnumerator); } } }
private float CalcDistance(SentenceDataHolder orig, SentenceDataHolder toCompare) { //return 5; if (orig == null) { // Default return(1); } var origColors = GetColors(orig); var compareColors = GetColors(toCompare); // Calc the differences float distance = 0; for (int i = 0; i < origColors.Length; i++) { // Add distance between each color in the palette, but modify distance by color weight distance += Mathf.Abs(origColors[i] - compareColors[i]); // Adds square so that the distance will not linearly affect weight //distance += Mathf.Sqrt(Mathf.Abs(origColors[i] - compareColors[i])); } return(distance); }
private float[] GetColors(SentenceDataHolder dataHolder) { try { return(dataHolder.ColorScheme().Split(' ').Select(color => Helpers.FromText(color).Sum()).ToArray()); } catch (Exception e) { Debug.LogError(e.Message); Debug.LogError("Colors: " + dataHolder.ColorScheme()); Debug.LogError("Color Index: " + dataHolder.ColorIndex()); return(null); } }
private void EnqueueNewSentence() { SentenceDataHolder lastSentence = list.Last; // Debug.Log("Last sentence colors: " + ((lastSentence != null) ? (lastSentence.ColorScheme()) : ("NULL"))); Sentence[] sentences = new Sentence[NUM_OF_SENTENCES_PER_RUN]; for (int i = 0; i < sentences.Length; i++) { SentenceDataHolder sentenceData = GenerateNewSentence(); float weight = CalcDistance(lastSentence, sentenceData); Sentence s = new Sentence(); s.Weight = weight; s.SentenceData = sentenceData; // Debug.Log("Color: " + sentenceData.ColorScheme() + " Weight: " + weight.ToString()); sentences[i] = s; } // Sort the sentences by weight Array.Sort(sentences); // The first element should have the minimal distance //list.Enqueue(sentences[0].SentenceData); list.Enqueue(WeightedRandomization.Choose(sentences).SentenceData); }