File size: 3,228 Bytes
18a519f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System.Linq;

namespace Unity.VisualScripting
{
    [Descriptor(typeof(FlowStateTransition))]
    public class FlowStateTransitionDescriptor : NesterStateTransitionDescriptor<FlowStateTransition>
    {
        public FlowStateTransitionDescriptor(FlowStateTransition transition) : base(transition) { }

        public override string Title()
        {
            var graph = transition.nest.graph;

            if (graph != null)
            {
                if (!StringUtility.IsNullOrWhiteSpace(graph.title))
                {
                    return graph.title;
                }

                using (var recursion = Recursion.New(1))
                {
                    var events = graph.GetUnitsRecursive(recursion).OfType<IEventUnit>().ToList();

                    if (events.Count == 0)
                    {
                        return "(No Event)";
                    }
                    else if (events.Count == 1)
                    {
                        return events[0].Description().title;
                    }
                    else // if (events.Count > 1)
                    {
                        return "(Multiple Events)";
                    }
                }
            }
            else
            {
                return "(No Transition)";
            }
        }

        public override string Summary()
        {
            var graph = transition.nest.graph;

            if (graph != null)
            {
                if (!StringUtility.IsNullOrWhiteSpace(graph.summary))
                {
                    return graph.summary;
                }

                using (var recursion = Recursion.New(1))
                {
                    var events = graph.GetUnitsRecursive(recursion).OfType<IEventUnit>().ToList();

                    if (events.Count == 0)
                    {
                        return "Open the transition graph to add an event.";
                    }
                    else if (events.Count == 1)
                    {
                        return events[0].Description().summary;
                    }
                    else // if (events.Count > 1)
                    {
                        return "Open the transition graph to see the full transition.";
                    }
                }
            }
            else
            {
                return "Choose a source in the graph inspector.";
            }
        }

        public override EditorTexture Icon()
        {
            var graph = transition.nest.graph;

            using (var recursion = Recursion.New(1))
            {
                if (graph != null)
                {
                    var events = graph.GetUnitsRecursive(recursion).OfType<IEventUnit>().ToList();

                    if (events.Count == 1)
                    {
                        return events[0].Description().icon;
                    }
                    else
                    {
                        return typeof(IStateTransition).Icon();
                    }
                }
                else
                {
                    return typeof(IStateTransition).Icon();
                }
            }
        }
    }
}