예제 #1
0
        /// <summary>
        /// Fetches every ConnectionPortStyle, ConnectionKnobStyle or ValueConnectionType declaration in the script assemblies to provide the framework with custom connection port styles
        /// </summary>
        public static void FetchConnectionPortStyles()
        {
            connectionPortStyles = new Dictionary <string, ConnectionPortStyle> ();
            connectionValueTypes = new Dictionary <string, ValueConnectionType> ();
            foreach (Type type in ReflectionUtility.getSubTypes(typeof(ConnectionPortStyle)))
            {
                ConnectionPortStyle portStyle = (ConnectionPortStyle)Activator.CreateInstance(type);
                if (portStyle == null)
                {
                    throw new UnityException("Error with Connection Port Style Declaration " + type.FullName);
                }
                if (!portStyle.isValid())
                {
                    throw new Exception(type.BaseType.Name + " declaration " + portStyle.Identifier + " is invalid!");
                }
                if (connectionPortStyles.ContainsKey(portStyle.Identifier))
                {
                    throw new Exception("Duplicate ConnectionPortStyle declaration " + portStyle.Identifier + "!");
                }

                connectionPortStyles.Add(portStyle.Identifier, portStyle);
                if (type.IsSubclassOf(typeof(ValueConnectionType)))
                {
                    connectionValueTypes.Add(portStyle.Identifier, (ValueConnectionType)portStyle);
                }
                if (!portStyle.isValid())
                {
                    LogMgr.LogError("Style " + portStyle.Identifier + " is invalid!");
                }
            }
        }
예제 #2
0
        public static void InitSystem(out Dictionary <string, ConnectionPortStyle> ports,
                                      out Dictionary <string, ValueConnectionType> values)
        {
            ports  = new Dictionary <string, ConnectionPortStyle>();
            values = new Dictionary <string, ValueConnectionType>();
            foreach (Type type in ReflectionUtility.getSubTypes(typeof(ConnectionPortStyle)))
            {
                ConnectionPortStyle portStyle = (ConnectionPortStyle)Activator.CreateInstance(type);
                if (portStyle == null)
                {
                    throw new UnityException("Error with Connection Port Style Declaration " + type.FullName);
                }
                if (ports.ContainsKey(portStyle.Identifier))
                {
                    throw new Exception("Duplicate ConnectionPortStyle declaration " + portStyle.Identifier + "!");
                }

                ports.Add(portStyle.Identifier, portStyle);
                if (type.IsSubclassOf(typeof(ValueConnectionType)))
                {
                    values.Add(portStyle.Identifier, (ValueConnectionType)portStyle);
                }
            }

            connectionPortStyles = ports;
            connectionValueTypes = values;
        }
예제 #3
0
 /// <summary>
 /// Checks and fetches the connection style declaration specified by the styleID
 /// </summary>
 protected void CheckConnectionStyle()
 {
     if (_connectionStyle == null || !_connectionStyle.isValid())
     {
         _connectionStyle = ConnectionPortStyles.GetPortStyle(styleID, styleBaseClass);
         if (_connectionStyle == null || !_connectionStyle.isValid())
         {
             color = NodeEditorGUI.RandomColorHSV(styleID.GetHashCode(), 0, 1, 0.6f, 0.8f, 0.8f, 1.4f);
         }
         else
         {
             color = _connectionStyle.Color;
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Checks and fetches the connection style declaration specified by the styleID
        /// </summary>
        protected void CheckConnectionStyle()
        {
            if (_connectionStyle == null || !_connectionStyle.isValid())
            {
                _connectionStyle = ConnectionPortStyles.GetPortStyle(styleID, styleBaseClass);
                if (_connectionStyle == null || !_connectionStyle.isValid())
                {                 // Generate consistent color for a type - using string because it delivers greater variety of colors than type hashcode
#if UNITY_5_4_OR_NEWER
                    UnityEngine.Random.InitState(styleID.GetHashCode());
#endif
                    color = UnityEngine.Random.ColorHSV(0, 1, 0.6f, 0.8f, 0.8f, 1.4f);
                }
                else
                {
                    color = _connectionStyle.Color;
                }
            }
        }