Beispiel #1
0
    private void Awake()
    {
        #region Classify Situation Data by Difficulty, Major Challenge, Length and Attribute

        UnityEngine.Object[] situationData = Resources.LoadAll("Situation Data", typeof(SituationData));

        for (int i = 0; i < 3; i++)
        {
            situations.Add(new List <List <List <List <SituationData> > > >());
            backup.Add(new List <List <List <List <SituationData> > > >());

            for (int j = 0; j < 3; j++)
            {
                situations[i].Add(new List <List <List <SituationData> > >());
                backup[i].Add(new List <List <List <SituationData> > >());

                for (int k = 0; k < numberOfAttributes; k++)
                {
                    situations[i][j].Add(new List <List <SituationData> >());
                    backup[i][j].Add(new List <List <SituationData> >());

                    for (int l = 0; l < 2; l++)
                    {
                        situations[i][j][k].Add(new List <SituationData>());
                        backup[i][j][k].Add(new List <SituationData>());
                    }
                }
            }
        }

        foreach (SituationData data in situationData)
        {
            int attribute = data.attributeInt;

            if (attribute == numberOfAttributes)
            {
                for (int i = 0; i < numberOfAttributes; i++)
                {
                    situations[data.Difficulty][data.challengeInt][i][data.Length].Add(data);
                    backup[data.Difficulty][data.challengeInt][i][data.Length].Add(data);
                }
            }
            else
            {
                situations[data.Difficulty][data.challengeInt][attribute][data.Length].Add(data);
                backup[data.Difficulty][data.challengeInt][attribute][data.Length].Add(data);
            }
        }

        #endregion


        #region Instantiate all Elements

        UnityEngine.Object[] elementData = Resources.LoadAll("Element Data", typeof(ElementData));
        int length = elementData.Length;

        indexes = new int[length];

        ElementData[] eData = new ElementData[length];

        elements = new Scorable[length, maxIndex];

        int e = 0;
        foreach (ElementData ed in elementData)
        {
            eData[e] = ed;
            for (int j = 0; j < maxIndex; j++)
            {
                elements[e, j] = Instantiate(ed.Element);
                elements[e, j].gameObject.SetActive(false);
            }
            e++;
        }

        for (int i = 0; i < length; i++)
        {
            foreach (SituationData data in situationData)
            {
                for (int k = 0; k < data.Elements.Length; k++)
                {
                    if (data.Elements[k].element == eData[i])
                    {
                        data.Elements[k].element.setIndex(i);
                    }
                }
            }

            indexes[i] = 0;
        }

        #endregion


        #region Classify Fields by Attribute

        List <List <FieldData> > fieldDatas = new List <List <FieldData> >();

        for (int i = 0; i < numberOfAttributes; i++)
        {
            fieldDatas.Add(new List <FieldData>());
        }

        UnityEngine.Object[] fieldData = Resources.LoadAll("Field Data", typeof(FieldData));

        foreach (FieldData data in fieldData)
        {
            fieldDatas[data.attributeInt].Add(data);
        }

        #endregion


        #region Classify Transitions by Attribute In and Out

        List <List <List <TransitionData> > > transitionDatas = new List <List <List <TransitionData> > >();

        for (int i = 0; i < numberOfAttributes; i++)
        {
            transitionDatas.Add(new List <List <TransitionData> >());

            for (int j = 0; j < numberOfAttributes; j++)
            {
                transitionDatas[i].Add(new List <TransitionData>());
            }
        }

        UnityEngine.Object[] transitionData = Resources.LoadAll("Transition Data", typeof(TransitionData));

        foreach (TransitionData data in transitionData)
        {
            transitionDatas[data.InAttribute][data.OutAttribute].Add(data);
        }

        #endregion


        #region Set Field Indexes (which Field will appear when) and Transition Indexes

        attributes = new int[numberOfFields];

        int[] iterations = new int[numberOfAttributes];

        int currentAttribute = UnityEngine.Random.Range(0, numberOfAttributes);
        attributes[0] = currentAttribute;
        iterations[currentAttribute]++;

        int currentIndex = UnityEngine.Random.Range(0, fieldDatas[currentAttribute].Count);

        List <int[]> fieldIndexes = new List <int[]>();
        fieldIndexes.Add(new int[] { currentAttribute, currentIndex });

        List <int[]> transitionIndexes = new List <int[]>();

        for (int i = 1; i < numberOfFields; i++)
        {
            float random = UnityEngine.Random.Range(0, 100);
            int   repeat = Mathf.Clamp(firstChancesToRepeatAttribute - repeatCount * chanceDecreaseToRepeatAttribute, 0, 100);

            List <int> types = new List <int>();

            for (int j = 0; j < 3; j++)
            {
                types.Add(j);
            }
            types.Remove(currentAttribute);

            int otherOne = types[0];
            int otherTwo = types[1];


            int newAttribute = currentAttribute;


            if (random >= repeat)
            {
                float rapport;

                if (iterations[otherOne] == 0)
                {
                    if (iterations[otherTwo] == 0)
                    {
                        rapport = .5f;
                    }
                    else
                    {
                        rapport = 1;
                    }
                }
                else
                {
                    if (otherTwo == 0)
                    {
                        rapport = 0;
                    }
                    else
                    {
                        rapport = (float)iterations[otherOne] / iterations[otherTwo];
                    }
                }

                if (random < repeat + (100f - repeat) * rapport)
                {
                    newAttribute = otherOne;
                    repeatCount  = 0;
                }
                else
                {
                    newAttribute = otherTwo;
                    repeatCount  = 0;
                }
            }
            else
            {
                repeatCount++;
            }

            attributes[i] = newAttribute;
            iterations[newAttribute]++;

            int newIndex = UnityEngine.Random.Range(0, fieldDatas[newAttribute].Count);

            int[] fIndex = new int[2] {
                newAttribute, newIndex
            };

            while (AreIntsEqual(fieldIndexes[i - 1], fIndex))
            {
                newIndex = UnityEngine.Random.Range(0, fieldDatas[newAttribute].Count);

                fIndex[1] = newIndex;
            }


            #region Set Transition

            int TIndex = UnityEngine.Random.Range(0, transitionDatas[currentAttribute][newAttribute].Count);

            int[] tIndex = new int[4] {
                currentAttribute, newAttribute, TIndex, transitionDatas[currentAttribute][newAttribute][TIndex].OutDirection
            };

            if (i > 1)
            {
                while (AreIntsEqual(transitionIndexes[i - 2], tIndex))
                {
                    TIndex = UnityEngine.Random.Range(0, transitionDatas[currentAttribute][newAttribute].Count);

                    tIndex[2] = TIndex;
                    tIndex[3] = transitionDatas[currentAttribute][newAttribute][TIndex].OutDirection;
                }
            }

            transitionIndexes.Add(tIndex);

            #endregion


            currentIndex     = newIndex;
            currentAttribute = newAttribute;

            fieldIndexes.Add(fIndex);
        }

        #endregion


        #region Instantiate needed Fields and Transitions

        fields      = new Transform[numberOfFields];
        transitions = new Transform[numberOfFields - 1];

        for (int i = 0; i < numberOfFields; i++)
        {
            int index = FieldIndex(i, fieldIndexes);

            if (i > 0 && index != i)
            {
                fields[i] = fields[index];
            }
            else
            {
                fields[i] = Instantiate(
                    fieldDatas
                    [fieldIndexes[i][0]]
                    [fieldIndexes[i][1]]
                    .Field.transform
                    );
                fields[i].gameObject.SetActive(false);
            }

            if (i < numberOfFields - 1)
            {
                index = FieldIndex(i, transitionIndexes);
                if (i > 0 && index != i)
                {
                    transitions[i] = transitions[index];
                }
                else
                {
                    transitions[i] = Instantiate(
                        transitionDatas
                        [transitionIndexes[i][0]]
                        [transitionIndexes[i][1]]
                        [transitionIndexes[i][2]]
                        .Transition.transform
                        );
                    transitions[i].gameObject.SetActive(false);
                }
            }
        }

        #endregion


        #region Set Position && Rotation of Fields and Transitions

        fieldPositions      = new Vector3[numberOfFields];
        transitionPositions = new Vector3[numberOfFields];
        directions          = new int[numberOfFields];
        int direction = 0;
        directions[0] = direction;

        Vector3 position = Vector3.zero;
        fieldPositions[0] = position;

        for (int i = 1; i < numberOfFields; i++)
        {
            position += TransitionPosition(direction);
            transitionPositions[i - 1] = position;

            int lastDirection = direction;
            if (transitionIndexes[i - 1][3] == 0)
            {
                direction = (direction + 3) % 4;
            }
            else
            {
                direction = (direction + 1) % 4;
            }
            position         += FieldPosition(direction, lastDirection);
            fieldPositions[i] = position;
            directions[i]     = direction;
        }

        position += TransitionPosition(direction);
        transitionPositions[numberOfFields - 1] = position;

        #endregion


        #region Set Major Challenges

        int   chalRandom = UnityEngine.Random.Range(0, chances.Length);
        int[] chal       = chances[chalRandom].chances;
        for (int i = 0; i < 3; i++)
        {
            chal[i] = Mathf.RoundToInt(chal[i] * (float)numberOfFields / 100);
        }

        List <int> chalInt    = new List <int>();
        List <int> chalBackup = new List <int>();
        for (int i = 0; i < 3; i++)
        {
            chalBackup.Add(i);

            for (int j = 0; j < chal[i]; j++)
            {
                chalInt.Add(i);
            }
        }

        List <int> majorChal = new List <int>();
        for (int i = 0; i < numberOfFields; i++)
        {
            if (chalInt.Count == 0)
            {
                int count = chalBackup.Count;
                if (count == 0)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        chalBackup.Add(i);
                    }
                }

                chalRandom = UnityEngine.Random.Range(0, chalBackup.Count);
                majorChal.Add(chalBackup[chalRandom]);
                chalBackup.Remove(chalBackup[chalRandom]);
            }
            else
            {
                chalRandom = UnityEngine.Random.Range(0, chalInt.Count);
                majorChal.Add(chalInt[chalRandom]);
                chalInt.Remove(chalInt[chalRandom]);
            }
        }

        majorChallenges = majorChal.ToArray();

        #endregion


        trigger = FindObjectOfType <StudioParameterTrigger>();
        player  = FindObjectOfType <PathMovement>().PathToFollow;
        sm      = FindObjectOfType <ScoreManager>();
        GetComponent <Collider>().isTrigger = true;
        SetFieldActive(0);
    }
Beispiel #2
0
 public void SetParameters(float performance, int gameClear, int corrupion, int progression, StudioParameterTrigger sp)
 {
     if (performance != -999)
     {
         sp.TriggerParameters(AudioParameters.Performance, performance);
     }
     if (gameClear != -999)
     {
         sp.TriggerParameters(AudioParameters.GameClear, gameClear);
     }
     if (corrupion != -999)
     {
         sp.TriggerParameters(AudioParameters.Corruption, corrupion);
     }
     if (progression != -999)
     {
         sp.TriggerParameters(AudioParameters.Progression, progression);
     }
 }