Exemplo n.º 1
0
        protected override void Draw()
        {
            UnityEditor.EditorGUIUtility.fieldWidth = 25;
            UnityEditor.EditorGUIUtility.labelWidth = 100;
            firstScoreWins.DisplayLayout(firstScoreWins.GetCachedValue() ? new GUIContent("First wins", "First score greater than 0 will be selected") : new GUIContent("Higher wins", "Highest value greather than 0 will be selected"));
            checkContinually.DisplayLayout("Test Continually");

            UnityEditor.EditorGUIUtility.labelWidth = 25;
            Color originalColor = GUI.color;

            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            for (int i = 0; i < scoreInputs.Length; i++)
            {
                if (lastWinner == i)
                {
                    GUI.color = Color.green;
                }
                GUILayout.BeginHorizontal();
                scoreInputs[i].DisplayLayout(i.ToString());
                if (GUILayout.Button("-"))
                {
                    scoreInputs[i].OnDelete();
                    scoreOutputs[i].OnDelete();
                    this.RemoveAt("scoreInputs", i);
                    this.RemoveAt("scoreOutputs", i);
                }
                GUILayout.EndHorizontal();
                if (lastWinner == i)
                {
                    GUI.color = originalColor;
                }
            }
            if (GUILayout.Button("+"))
            {
                this.Add("scoreInputs", CreateIO <Input_System_Single>());
                this.Add("scoreOutputs", CreateTreeOutput());
            }
            GUILayout.EndVertical();

            Rect graphRect = GUILayoutUtility.GetRect(64, 50);

            if (isVisible && Event.current.type == EventType.Repaint)
            {
                if (graph == null)
                {
                    graph = new GraphDrawer <int>(64);
                }
                graph.Draw(graphRect);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            for (int i = 0; i < scoreOutputs.Length; i++)
            {
                scoreOutputs[i].DisplayLayout(i.ToString());
            }
            GUILayout.EndHorizontal();
        }
Exemplo n.º 2
0
        private int GetWinner()
        {
#if UNITY_EDITOR
            if (graph == null)
            {
                graph = new GraphDrawer <int>(64);
            }
            newValues.Clear();
            for (int i = 0; i < scoreInputs.Length; i++)
            {
                newValues.Add(new KeyValuePair <int, float>(i, scoreInputs[i].GetValue()));
            }
            graph.UpdateHistory(newValues);
#endif
            if (firstScoreWins.GetValue())
            {
                for (int i = 0; i < scoreInputs.Length; i++)
                {
                    if (scoreInputs[i].GetValue() > 0)
                    {
                        return(i);
                    }
                }
            }
            else
            {
                int   winner      = -1;
                float winnerScore = 0;
                for (int i = 0; i < scoreInputs.Length; i++)
                {
                    float score = scoreInputs[i].GetValue();
                    if (winnerScore < score)
                    {
                        winnerScore = score;
                        winner      = i;
                    }
                }
                if (winnerScore > 0)
                {
                    return(winner);
                }
            }

            return(-1);
        }