Пример #1
0
        Rect DrawSelectorCase(string name, PWColorSchemeName colorSchemeName, bool title = false)
        {
            if (title)
            {
                GUI.color = PWColorTheme.GetSelectorHeaderColor(colorSchemeName);
                GUILayout.Label(name, nodeSelectorTitleStyle);
                GUI.color = Color.white;
            }
            else
            {
                GUILayout.Label(name, nodeSelectorCaseStyle);
            }

            return(GUILayoutUtility.GetLastRect());
        }
Пример #2
0
    void    DrawSelectedBezier(Vector3 startPos, Vector3 endPos, Vector3 startTan, Vector3 endTan, PWColorSchemeName colorSchemeName, int width, PWLinkHighlight highlight)
    {
        switch (highlight)
        {
        case PWLinkHighlight.Selected:
            Handles.DrawBezier(startPos, endPos, startTan, endTan, PWColorTheme.selectedColor, null, width + 3);
            break;

        case PWLinkHighlight.Delete:
        case PWLinkHighlight.DeleteAndReset:
            Handles.DrawBezier(startPos, endPos, startTan, endTan, PWColorTheme.deletedColor, null, width + 2);
            break;
        }
        Color c = PWColorTheme.GetLinkColor(colorSchemeName);

        Handles.DrawBezier(startPos, endPos, startTan, endTan, c, null, width);
    }
Пример #3
0
    void RenderDecaledNode(int id, PWNode node)
    {
        //node grid snapping when pressing cmd/crtl
        if (node.isDragged && e.command)
        {
            Vector2 pos = node.rect.position;
            //aproximative grid cell size
            float snapPixels = 25.6f;

            pos.x = Mathf.RoundToInt(Mathf.RoundToInt(pos.x / snapPixels) * snapPixels);
            pos.y = Mathf.RoundToInt(Mathf.RoundToInt(pos.y / snapPixels) * snapPixels);
            node.rect.position = pos;
        }

        //move the node if panPosition changed:
        node.rect = PWUtils.DecalRect(node.rect, graph.panPosition);
        Rect decaledRect = GUILayout.Window(id, node.rect, node.OnWindowGUI, node.name, (node.isSelected) ? nodeSelectedStyle : nodeStyle, GUILayout.Height(node.viewHeight));

        node.visualRect = decaledRect;
        node.rect       = PWUtils.DecalRect(decaledRect, -graph.panPosition);

        //draw node header:
        //Draw the node header using the color scheme:
        if (e.type == EventType.Repaint)
        {
            float h = nodeStyle.border.top;
            float w = decaledRect.width - nodeStyle.border.right - nodeStyle.border.left;
            GUI.color = PWColorTheme.GetNodeColor(node.colorSchemeName);
            // GUI.DrawTexture(new Rect(0, 0, w, h), nodeHeaderStyle.normal.background);
            nodeHeaderStyle.Draw(new Rect(decaledRect.x, decaledRect.y, w, h), false, false, false, false);
            GUI.color = Color.white;
        }

        if (node.debug)
        {
            Rect debugRect = decaledRect;
            debugRect.y -= 20;
            EditorGUI.LabelField(debugRect, "id: " + node.id);
            debugRect.y -= 20;
            EditorGUI.LabelField(debugRect, "comp order: " + node.computeOrder + " | can work: " + node.canWork);
        }
    }
Пример #4
0
        void LoadFieldAttributes()
        {
            //get input variables
            System.Reflection.FieldInfo[] fInfos = GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            List <string> actualFields = new List <string>();

            foreach (var field in fInfos)
            {
                // reading field informations.

                actualFields.Add(field.Name);
                anchorFieldInfoMap[field.Name] = field;

                if (!anchorFieldDictionary.ContainsKey(field.Name))
                {
                    anchorFieldDictionary[field.Name] = CreateAnchorField();
                }

                PWAnchorField anchorField = anchorFieldDictionary[field.Name];

                //detect multi-anchor by checking for PWArray<T> type
                if (field.FieldType.IsGenericType)
                {
                    if (field.FieldType.GetGenericTypeDefinition() == typeof(PWArray <>))
                    {
                        anchorField.multiple = true;
                    }
                }

                System.Object[] attrs = field.GetCustomAttributes(true);
                foreach (var attr in attrs)
                {
                    PWInputAttribute       inputAttr       = attr as PWInputAttribute;
                    PWOutputAttribute      outputAttr      = attr as PWOutputAttribute;
                    PWColorAttribute       colorAttr       = attr as PWColorAttribute;
                    PWOffsetAttribute      offsetAttr      = attr as PWOffsetAttribute;
                    PWNotRequiredAttribute notRequiredAttr = attr as PWNotRequiredAttribute;

                    if (inputAttr != null)
                    {
                        anchorField.anchorType = PWAnchorType.Input;
                        if (inputAttr.name != null)
                        {
                            anchorField.name = inputAttr.name;
                        }
                    }
                    if (outputAttr != null)
                    {
                        anchorField.anchorType = PWAnchorType.Output;
                        if (outputAttr.name != null)
                        {
                            anchorField.name = outputAttr.name;
                        }
                    }
                    if (colorAttr != null)
                    {
                        anchorField.color = new SerializableColor(colorAttr.color);
                    }
                    if (offsetAttr != null)
                    {
                        anchorField.offset  = offsetAttr.offset;
                        anchorField.padding = offsetAttr.padding;
                    }
                    if (notRequiredAttr != null)
                    {
                        anchorField.required = false;
                    }
                }
                if (anchorField.anchorType == PWAnchorType.None)                 //field does not have a PW attribute
                {
                    anchorFieldDictionary.Remove(field.Name);
                }
                else
                {
                    //create anchor in this anchorField if there is not existing one
                    if (anchorField.anchors.Count == 0)
                    {
                        anchorField.CreateNewAnchor();
                    }

                    anchorField.colorSchemeName = PWColorTheme.GetAnchorColorSchemeName(field.FieldType);
                    anchorField.fieldName       = field.Name;
                    anchorField.fieldType       = (SerializableType)field.FieldType;
                    anchorField.fieldValue      = field.GetValue(this);
                    anchorField.nodeRef         = this;
                }
            }

            //remove inhexistants field dictionary entries (for renamed variables):
            var toRemoveKeys = new List <string>();

            foreach (var kp in anchorFieldDictionary)
            {
                if (!actualFields.Contains(kp.Key))
                {
                    toRemoveKeys.Add(kp.Key);
                }
            }

            //remove duplicate keys in the dictionary (yes it happends ...)
            HashSet <string> duplicateKeys = new HashSet <string>();

            foreach (var kp in anchorFieldDictionary)
            {
                // if (duplicateKeys.Contains(kp.Key))
                // toRemoveKeys.Add(kp.Key);
                duplicateKeys.Add(kp.Key);
            }

            foreach (var toRemoveKey in toRemoveKeys)
            {
                anchorFieldDictionary.Remove(toRemoveKey);
            }
        }