예제 #1
0
        protected override Rect DrawSocket(Socket socket)
        {
            Rect socketRect = base.DrawSocket(socket);

            if (ZoomedBeyondSocketDrawThreshold)
            {
                return(socketRect);
            }
            if (socket.IsInput)
            {
                return(socketRect);
            }

            WeightedConnection socketValue = WeightedConnection.GetValue(socket);

            m_areaRect = new Rect(socket.GetX() + 24, socket.GetY(), socket.GetWidth() - 48, socket.GetHeight());

            float socketOpacity    = socket.IsConnected ? NodySettings.Instance.SocketConnectedOpacity : NodySettings.Instance.SocketNotConnectedOpacity;
            Color iconAndTextColor = (DGUI.Utility.IsProSkin ? Color.white.Darker() : Color.black.Lighter()).WithAlpha(socketOpacity);

            float chance = socket.IsConnected && TargetNode.MaxChance > 0
                               ? (float)socketValue.Weight / TargetNode.MaxChance
                               : 0f;

            string weightLabel = socketValue.Weight.ToString();
            string chanceLabel = Mathf.Round(chance * 100f) + "%";

            if (socket.IsConnected)
            {
                m_progressBarRect = new Rect(m_areaRect.x + kSocketIconSize + DGUI.Properties.Space(4), m_areaRect.yMax - DGUI.Properties.Space(2), m_areaRect.width - kSocketIconSize, DGUI.Properties.Space());
                DrawProgressBar(m_progressBarRect, chance, m_progressBarRect.height, false);
            }

            m_weightIconRect = new Rect(0, socket.GetHeight() / 2 - kSocketIconSize / 2, kSocketIconSize, kSocketIconSize);

            GUILayout.BeginArea(m_areaRect);
            {
                GUILayout.BeginHorizontal();
                {
                    DGUI.Icon.Draw(m_weightIconRect, SocketIcon, iconAndTextColor);
                    GUILayout.Space(DGUI.Properties.Space(2) + kSocketIconSize + DGUI.Properties.Space(2));
                    DGUI.Label.Draw(chanceLabel, DGUI.Colors.ColorTextOfGUIStyle(DGUI.Label.Style(Editor.Size.M, TextAlign.Left), iconAndTextColor), socket.GetHeight());
                    GUILayout.FlexibleSpace();
                    DGUI.Label.Draw(UILabels.Weight + ": " + weightLabel, DGUI.Colors.ColorTextOfGUIStyle(DGUI.Label.Style(Editor.Size.S, TextAlign.Left), iconAndTextColor.WithAlpha(0.6f)), socket.GetHeight());
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndArea();

            return(socket.GetRect());
        }
예제 #2
0
 public void UpdateMaxChance()
 {
     MaxChance = 0;
     foreach (Socket socket in OutputSockets)
     {
         if (!socket.IsConnected)
         {
             continue;
         }
         WeightedConnection connection = WeightedConnection.GetValue(socket);
         if (connection.Weight <= 0)
         {
             continue;
         }
         MaxChance += connection.Weight;
     }
 }
예제 #3
0
        private void SelectRandomOutputSocket()
        {
            m_selectChances.Clear();
            MaxChance = 0;
            foreach (Socket socket in OutputSockets)
            {
                if (!socket.IsConnected)
                {
                    continue;
                }

                WeightedConnection connection = WeightedConnection.GetValue(socket);
                if (connection.Weight <= 0)
                {
                    m_selectChances.Add(-1);
                }
                else
                {
                    MaxChance += connection.Weight;
                    m_selectChances.Add(MaxChance);
                }
            }

            int randomSocketIndex = 0;
            int randomChance      = Random.Range(0, MaxChance);

            for (int i = 0; i < m_selectChances.Count; i++)
            {
                if (m_selectChances[i] == -1)
                {
                    continue;
                }
                if (m_selectChances[i] < randomChance)
                {
                    continue;
                }
                randomSocketIndex = i;
                break;
            }

            ActiveGraph.SetActiveNodeByConnection(OutputSockets[randomSocketIndex].FirstConnection);
        }