Ejemplo n.º 1
0
        public static void OnCustomEnabledControlClicked(IComponentDrawer drawer, Event inputEvent)
        {
            DrawGUI.Use(inputEvent);

            var targets = drawer.Components;

            var firstBehaviour = targets[0] as Behaviour;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(firstBehaviour != null, "createCustomEnabledFlag was true but target was not a Behaviour");
                        #endif

            bool setEnabled = !firstBehaviour.enabled;

            var changed = targets;
            for (int n = targets.Length - 1; n >= 1; n--)
            {
                if (((Behaviour)targets[n]).enabled == setEnabled)
                {
                    changed = changed.RemoveAt(n);
                }
            }

            UndoHandler.RegisterUndoableAction(changed, changed.Length == 1 ? (setEnabled ? "Enable Component" : "Disable Component") : (setEnabled ? "Enable Components" : "Disable Components"));

            firstBehaviour.enabled = setEnabled;
            for (int n = targets.Length - 1; n >= 1; n--)
            {
                ((Behaviour)targets[n]).enabled = setEnabled;
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public override void AddComponentMember(int memberIndex, [NotNull] IComponentDrawer componentDrawer)
        {
            var category = ComponentCategories.Get(componentDrawer.Component);

                        #if DEV_MODE
            Debug.Log("AddComponentMember(" + memberIndex + ", " + componentDrawer.GetType().Name + ") category=\"" + category + "\", members.Length=" + members.Length);
                        #endif

            var categoryDrawer = GetOrCreateCategoryDrawer(category);

            if (categoryDrawer == null)
            {
                var setMembers = members;

                if (memberIndex == -1)
                {
                    memberIndex = setMembers.Length - LastCollectionMemberCountOffset + 1;
                }
                DrawerArrayPool.InsertAt(ref setMembers, memberIndex, componentDrawer, false);
                SetMembers(setMembers);
                return;
            }

            var setCategoryMembers = categoryDrawer.Members;
            DrawerArrayPool.InsertAt(ref setCategoryMembers, setCategoryMembers.Length, componentDrawer, false);
            categoryDrawer.SetMembers(setCategoryMembers);
        }
Ejemplo n.º 3
0
        private void ReadNetworkLocation_OnClick(object sender, RoutedEventArgs e)
        {
            var filename = GetPathFromDialog();

            try
            {
                var locations = _networkLocationMapRetriever.Read(filename);

                _nodeDrawer    = new SmartNodeDrawer(_network, locations);
                _networkDrawer = new NetworkDrawer(_nodeDrawer, _channelDrawer);

                NetworkArea.Children.Remove(GeneratedCanvas);

                _networkDrawer.DrawComponents(NetworkArea);

                MessageBox.Show("File loaded!", "OK", MessageBoxButton.OK, MessageBoxImage.Information,
                                MessageBoxResult.OK,
                                MessageBoxOptions.None);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error,
                                MessageBoxResult.OK,
                                MessageBoxOptions.None);
            }
        }
Ejemplo n.º 4
0
        public static void DrawCustomEnabledField(IComponentDrawer drawer, Rect position)
        {
            var  components = drawer.Components;
            bool wasEnabled = ((Behaviour)components[0]).enabled;
            bool mixed      = false;

            for (int n = components.Length - 1; n >= 1; n--)
            {
                bool enabled = ((Behaviour)components[n]).enabled;
                if (enabled != wasEnabled)
                {
                    mixed = true;
                    break;
                }
            }

            if (mixed)
            {
                DrawGUI.Active.ShowMixedValue = true;
            }

            GUI.Toggle(position, wasEnabled, GUIContent.none);

            if (mixed)
            {
                DrawGUI.Active.ShowMixedValue = false;
            }
        }
        public void Setup()
        {
            _panel = new Canvas
            {
                Width  = 700,
                Height = 700
            };
            _networkMock = new Mock <INetworkHandler>();

            _wideAreaNetworkNodeDrawer = new WideAreaNetworkNodeDrawer(_networkMock.Object);

            const int nodesCount = 5;

            var nodes = Enumerable
                        .Range(0, nodesCount)
                        .Select(i => new Node
            {
                Id                   = (uint)i,
                LinkedNodesId        = new SortedSet <uint>(),
                MessageQueueHandlers = new List <MessageQueueHandler>()
            })
                        .ToArray();

            _networkMock.Setup(n => n.Nodes)
            .Returns(nodes);

            _networkMock.Setup(n => n.GetNodeById(It.IsAny <uint>()))
            .Returns((uint nodeId) => nodes.FirstOrDefault(n => n.Id == nodeId));
        }
Ejemplo n.º 6
0
        public void Setup()
        {
            _panel = new Canvas()
            {
                Width  = 700,
                Height = 700
            };

            _networkMock = new Mock <INetworkHandler>();

            _nodeDrawerMock    = new Mock <IComponentDrawer>();
            _channelDrawerMock = new Mock <IComponentDrawer>();

            _networkDrawer = new NetworkDrawer(_nodeDrawerMock.Object, _channelDrawerMock.Object);

            const int nodeCount = 5;
            var       nodes     = Enumerable
                                  .Range(0, nodeCount)
                                  .Select(n => new Node {
                Id = (uint)n
            })
                                  .ToArray();

            _networkMock.Setup(n => n.Nodes)
            .Returns(nodes);
        }
Ejemplo n.º 7
0
        public static void NameByType([NotNull] IComponentDrawer componentDrawer)
        {
            var goDrawer = componentDrawer.Parent;

            if (goDrawer != null)
            {
                NameByType(goDrawer.GetValues() as GameObject[], componentDrawer.GetValues() as Component[]);
            }
        }
Ejemplo n.º 8
0
        static EntityInspectorEditor()
        {
            m_TypeDrawers = DrawerCollector.CollectTypeDrawers();

            m_ComponentDrawers = DrawerCollector.CollectComponentDrawers(m_TypeDrawers);

            m_DefaultComponentDrawer = new DefaultComponentDrawer(m_TypeDrawers);

            InspectorUtility.Setup(m_TypeDrawers);
        }
Ejemplo n.º 9
0
 public BackgroundWorker(IMessageExchanger messageExchanger, IMessageGenerator messageGenerator,
                         IComponentDrawer networkDrawer, IMessageCreator messageCreator,
                         IMessageRegistrator messageRegistrator, IMessageViewUpdater messageViewUpdated,
                         int updatePeriod)
 {
     _messageExchanger   = messageExchanger;
     _messageGenerator   = messageGenerator;
     _networkDrawer      = networkDrawer;
     _messageCreator     = messageCreator;
     _messageRegistrator = messageRegistrator;
     _updatePeriod       = updatePeriod;
     _messageViewUpdated = messageViewUpdated;
     _locker             = new Mutex();
 }
Ejemplo n.º 10
0
        public static void SelectPreviousOfType([NotNull] IComponentDrawer subject)
        {
            var inspector = InspectorUtility.ActiveInspector;

            var selected          = inspector.FocusedDrawer;
            var selectedIndexPath = selected == null ? null : selected.GenerateMemberIndexPath(subject);

            Component component;

            if (!HierarchyUtility.TryGetPreviousOfType(subject.Component, out component))
            {
                if (component == null)
                {
                    inspector.Message("No instances to select found in scene.");
                }
                else
                {
                    inspector.Message("No additional instances found in scene.");
                }
                return;
            }

            if (component.gameObject != subject.gameObject)
            {
                // UPDATE: New test to preserve selected path
                // TO DO: Support custom editors
                inspector.OnNextInspectedChanged(() =>
                {
                    if (selectedIndexPath == null)
                    {
                        inspector.SelectAndShow(component, ReasonSelectionChanged.SelectPrevOfType);
                    }
                    else
                    {
                        var componentDrawer = inspector.State.drawers.FindDrawer(component);
                        componentDrawer.SelectMemberAtIndexPath(selectedIndexPath, ReasonSelectionChanged.SelectPrevOfType);
                    }
                });
                inspector.Select(component);
            }
            else
            {
                inspector.SelectAndShow(component, ReasonSelectionChanged.SelectPrevOfType);
            }
        }
Ejemplo n.º 11
0
        public void Setup()
        {
            _panel = new Canvas()
            {
                Width  = 700,
                Height = 700
            };
            _networkMock   = new Mock <INetworkHandler>();
            _channelDrawer = new ChannelDrawer(_networkMock.Object);

            const int nodesCount = 5;

            var nodes = Enumerable
                        .Range(0, nodesCount)
                        .Select(i => new Node {
                Id = (uint)i
            })
                        .ToArray();

            _networkMock.Setup(n => n.Nodes)
            .Returns(nodes);

            var channels = new[]
            {
                new Channel
                {
                    Id           = Guid.NewGuid(),
                    FirstNodeId  = 0,
                    SecondNodeId = 1,
                },
                new Channel
                {
                    Id           = Guid.NewGuid(),
                    FirstNodeId  = 3,
                    SecondNodeId = 2
                }
            };

            _networkMock.Setup(n => n.Channels)
            .Returns(channels);
        }
Ejemplo n.º 12
0
        public void Setup()
        {
            _panel = new Canvas
            {
                Width  = 700,
                Height = 700
            };
            _networkMock = new Mock <INetworkHandler>();

            const int nodesCount = 5;

            var nodes = Enumerable
                        .Range(0, nodesCount)
                        .Select(i => new Node
            {
                Id = (uint)i,
                MessageQueueHandlers = new List <MessageQueueHandler>()
            })
                        .ToArray();

            _locationsMap = new[]
            {
                new NodeLocationMapDto
                {
                    Id = 0,
                    X  = 20,
                    Y  = 30
                }
            };

            _nodeDrawer = new SmartNodeDrawer(_networkMock.Object, _locationsMap);


            _networkMock.Setup(n => n.Nodes)
            .Returns(nodes);
        }
Ejemplo n.º 13
0
        public static void SelectNextOfType([NotNull] IComponentDrawer subject)
        {
            var inspector = InspectorUtility.ActiveInspector;

            var selected          = inspector.FocusedDrawer;
            var selectedIndexPath = selected == null ? null : selected.GenerateMemberIndexPath(subject);

            Component component;

            if (!HierarchyUtility.TryGetNextOfType(subject.Component, out component))
            {
                if (component == null)
                {
                    inspector.Message("No instances to select found in scene");
                }
                else
                {
                    inspector.Message("No additional instances found in scene");
                }
                return;
            }

            if (component.gameObject != subject.gameObject)
            {
                                #if DEV_MODE
                Debug.Log("Selecting " + component.GetType().Name + " on " + component.name + " during OnNextInspectedChanged.");
                                #endif

                //UPDATE: New test to preserve selected path
                // TO DO: Support custom editors
                inspector.OnNextInspectedChanged(() =>
                {
                    if (selectedIndexPath == null)
                    {
                        inspector.SelectAndShow(component, ReasonSelectionChanged.SelectNextOfType);
                    }
                    else
                    {
                        var componentDrawer = inspector.State.drawers.FindDrawer(component);
                        componentDrawer.SelectMemberAtIndexPath(selectedIndexPath, ReasonSelectionChanged.SelectNextOfType);
                    }
                });
                inspector.Select(component.gameObject);
            }
            else
            {
                                #if DEV_MODE
                Debug.Log("Component " + component.GetType().Name + " found on same GameObject " + component.name + ".");
                                #endif

                if (selectedIndexPath == null)
                {
                    inspector.SelectAndShow(component, ReasonSelectionChanged.SelectNextOfType);
                }
                else
                {
                    var componentDrawer = inspector.State.drawers.FindDrawer(component);
                    componentDrawer.SelectMemberAtIndexPath(selectedIndexPath, ReasonSelectionChanged.SelectNextOfType);
                }
            }
        }
Ejemplo n.º 14
0
 private void InitializeDrawers()
 {
     _nodeDrawer    = new WideAreaNetworkNodeDrawer(_network);
     _channelDrawer = new ChannelDrawer(_network);
     _networkDrawer = new NetworkDrawer(_nodeDrawer, _channelDrawer);
 }
Ejemplo n.º 15
0
 public NetworkDrawer(IComponentDrawer nodeDrawer, IComponentDrawer channelDrawer)
 {
     _nodeDrawer    = nodeDrawer;
     _channelDrawer = channelDrawer;
 }