Example #1
0
        public void Initialize(TreeGraphView graphView)
        {
            this.graphView = graphView;
            RecreateSearchTree();

            graphView.editorWindow.OnTargetContextChangedMethods += RecreateSearchTree;
        }
Example #2
0
        public virtual void Initialize(TreeGraphView graphView, NodeInfo info)
        {
            Info      = info;
            GraphView = graphView;

            title = Info.displayedName;

            //Generate parent port
            if (HasParent)
            {
                ParentPort = InstantiatePort(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(bool));

                ParentPort.portName = "Parent";
                ParentPort.AddManipulator(GraphView.GetNewEdgeConnector());

                inputContainer.Add(ParentPort);
            }

            //Generate child port
            if (MaxChildCount > 0)
            {
                if (MaxChildCount == 1)
                {
                    ChildrenPort          = InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Single, typeof(int));
                    ChildrenPort.portName = "Child";
                }
                else
                {
                    ChildrenPort          = InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(float));
                    ChildrenPort.portName = "Children";
                }

                ChildrenPort.AddManipulator(GraphView.GetNewEdgeConnector());
                outputContainer.Add(ChildrenPort);
            }

            //Generate order display
            if (HasParent)
            {
                orderLabel = new Label {
                    name = "title-label"
                };                                                             //Use the same style as the title
                orderLabel.AddToClassList("unity-text-element");
                orderLabel.AddToClassList("unity-label");

                titleContainer.Insert(1, orderLabel);                 //The first position is the title, the second is the button, so we insert the label in between
                RecalculateOrder();
            }
        }
 public TreeGraphSerializer(TreeGraphEditorWindow editorWindow, TreeGraphView graphView)
 {
     this.editorWindow = editorWindow;
     this.graphView    = graphView;
 }
Example #4
0
 public override void Initialize(TreeGraphView graphView, NodeInfo info)
 {
     base.Initialize(graphView, info);
     GenerateParameterControl(Parameters[0], "Success");
 }
Example #5
0
 public override void Initialize(TreeGraphView graphView, NodeInfo info)
 {
     base.Initialize(graphView, info);
     GenerateParameterControl(Parameters[0], "Chance", parameter => parameter.Float1Value = Mathf.Clamp01(parameter.Float1Value));
 }
Example #6
0
        public override void Initialize(TreeGraphView graphView, NodeInfo info)
        {
            base.Initialize(graphView, info);

            contextSelector = new PopupField <SerializableMethod>(
                "Target Context", representativeMethods, 0,
                method =>
            {
                if (representativeMethods.Count != 1)
                {
                    GraphView.editorWindow.SetTargetContextType(contextSelector?.value);
                }
                return("Select");
            },
                method =>
            {
                if (method == null)
                {
                    return("Select");
                }
                if (method.Method == null)
                {
                    return("Missing");
                }

                return(method.TargetContextType.ToString());
            }
                );
            typeLabel = new Label("None");

            {
                // Because the choices property in PopupField is internal, which according to https://forum.unity.com/threads/maskfield-choices-internal.672670/
                // is a bug. So we will use reflection to set it for now

                var property = contextSelector.GetType().GetProperty("choices", BindingFlags.Instance | BindingFlags.NonPublic);
                if (property == null)
                {
                    throw new Exception("Reflection not working!!!");
                }

                //Should be contextSelector.choices = representativeActions
                property.SetValue(contextSelector, representativeMethods);
            }

            VisualElement parameterContainer = TryGetParameterContainer();
            var           labelStyle         = contextSelector.Q <Label>().style;

            labelStyle.paddingTop   = 0f;
            labelStyle.paddingLeft  = 4f;
            labelStyle.paddingRight = 7f;

            contextSelector[1].style.paddingBottom = 0f;             //Set selector bottom padding to 0
            typeLabel.style.minWidth     = labelStyle.minWidth = 64f;
            typeLabel.style.paddingRight = typeLabel.style.paddingLeft = 8f;

            inputContainer.style.justifyContent = Justify.Center;

            inputContainer.Add(contextSelector);
            parameterContainer.Add(typeLabel);

            GraphView.editorWindow.OnTargetContextChangedMethods += RecalculateTargetContext;
            RecalculateTargetContext();
        }
 public EdgeConnectorListener(TreeGraphView graphView) => this.graphView = graphView;
Example #8
0
 public void Initialize(TreeGraphView graphView) => this.graphView = graphView;