示例#1
0
        public IEnumerator DragPreventFromStealing()
        {
            // Creates two groups
            Group group1 = CreateGroup("Group 1", 10, 10);
            Group group2 = CreateGroup("Group 2", 400, 400);

            group1.AddElement(m_Node1);

            // Select node1
            m_Node1.Select(graphView, false);

            // Allow one frame for the scope to be placed onto a layer and for the nodes to compute their layouts
            yield return(null);

            // Allow one frame for the scope to compute its geometry (position)
            yield return(null);

            // Allow one frame for the scope to update its layout
            yield return(null);

            Vector2 start = m_Node1.LocalToWorld(Vector2.zero);

            Vector2 centerOfGroup2ContentArea = group2.LocalToWorld(group2.containedElementsRect.center);

            // Drag node1 onto the content area of the group2.
            helpers.DragTo(start, centerOfGroup2ContentArea);

            // Ensure that node1 was not stolen by group2.
            Assert.AreEqual(group1, m_Node1.GetContainingScope());
        }
        public IEnumerator GroupSelectionIsRestoredWhenEnteringPlaymode_AddNodesAfterPersistence()
        {
            var group = new Group();

            graphView.AddElement(group);

            group.AddElement(node1);
            group.AddElement(node2);
            group.AddElement(node3);

            // Add two nodes to selection.
            graphView.AddToSelection(node1);
            graphView.AddToSelection(node3);

            Assert.True(node1.selected);
            Assert.False(node2.selected);
            Assert.True(node3.selected);

            // Allow 1 frame to let the persistent data get saved
            yield return(null);

            // This will re-create the window, flushing all temporary state
            yield return(new EnterPlayMode());

            // Allow 1 frame to let the persistence be restored
            yield return(null);

            node1 = CreateNodeWithoutAddingToGraphView(key1, new Vector2(200, 200), viewDataKey: key1);
            node2 = CreateNodeWithoutAddingToGraphView(key2, new Vector2(400, 400), viewDataKey: key2);
            node3 = CreateNodeWithoutAddingToGraphView(key3, new Vector2(600, 600), viewDataKey: key3);

            group = new Group();

            group.AddElement(node1);
            group.AddElement(node2);
            group.AddElement(node3);

            graphView.AddElement(group);

            graphView.AddElement(node1);
            graphView.AddElement(node2);
            graphView.AddElement(node3);

            Assert.True(node1.selected);
            Assert.False(node2.selected);
            Assert.True(node3.selected);
        }
示例#3
0
        public void PreventNestedGroup()
        {
            // Creates two groups
            Group group1 = CreateGroup("Group 1", 10, 10);
            Group group2 = CreateGroup("Group 2", 10, 10);

            ArgumentException ex = Assert.Throws <ArgumentException>(() => { group1.AddElement(group2); });

            Assert.AreEqual("Nested group is not supported yet.", ex.Message);
        }
示例#4
0
        public IEnumerator DragRemoveSelectionFromGroup()
        {
            // Creates a group and add node1, node2, node3
            Group group = CreateGroup("Group", 10, 10);

            group.AddElement(m_Node1);
            group.AddElement(m_Node2);
            group.AddElement(m_Node3);

            // Allow one frame for the scope to be placed onto a layer and for the nodes to compute their layouts
            yield return(null);

            // Allow one frame for the scope to compute its geometry (position)
            yield return(null);

            // Allow one frame for the scope to update its layout
            yield return(null);

            // Select node1 and node2
            m_Node1.Select(graphView, false);
            m_Node2.Select(graphView, true);

            // Drag selected nodes (starting from one of the nodes)
            Vector2 start        = m_Node1.worldBound.center;
            Vector2 outsideGroup = group.LocalToWorld(k_OutsidePosition);

            // Drag node1 and node2 away from the group holding Shift key
            helpers.MouseDownEvent(start, MouseButton.LeftMouse, EventModifiers.Shift);

            // Needed in order for the group to receive a drag event
            helpers.MouseDragEvent(start, start + Vector2.one, MouseButton.LeftMouse, EventModifiers.Shift);

            helpers.MouseDragEvent(start, outsideGroup, MouseButton.LeftMouse, EventModifiers.Shift);

            helpers.MouseUpEvent(outsideGroup);

            Assert.AreEqual(1, group.containedElements.Count());
            Assert.IsTrue(group.ContainsElement(m_Node3));
        }
示例#5
0
    private void CreateDependencyNodes(AssetGroup assetGroup, string[] dependencies, Node parentNode, Group groupNode, int depth)
    {
        //Debug.Log(depth);

        foreach (string dependencyString in dependencies)
        {
            Object   dependencyAsset    = AssetDatabase.LoadMainAssetAtPath(dependencyString);
            string[] deeperDependencies = AssetDatabase.GetDependencies(dependencyString, false);

            var typeName = dependencyAsset.GetType().Name;

            //filter out selected asset types
            if (FilterType(typeName))
            {
                continue;
            }

            Node dependencyNode = CreateNode(assetGroup, dependencyAsset, AssetDatabase.GetAssetPath(dependencyAsset),
                                             false, deeperDependencies.Length);

            if (!assetGroup.m_AssetNodes.Contains(dependencyNode))
            {
                dependencyNode.userData = depth;
            }

            CreateDependencyNodes(assetGroup, deeperDependencies, dependencyNode, groupNode, depth + 1);

            if (!m_GraphView.Contains(dependencyNode))
            {
                m_GraphView.AddElement(dependencyNode);

                assetGroup.m_DependenciesForPlacement.Add(dependencyNode);
                groupNode.AddElement(dependencyNode);
            }

            //if (!assetGroup.m_AssetNodes.Contains(dependencyNode))
            //    groupNode.AddElement(dependencyNode);

            Edge edge = CreateEdge(dependencyNode, parentNode);

            edge.capabilities &= ~Capabilities.Deletable;
            assetGroup.m_AssetConnections.Add(edge);
            assetGroup.m_AssetNodes.Add(dependencyNode);

            //if (!assetGroup.m_DependenciesForPlacement.Contains(dependencyNode))
            //    assetGroup.m_DependenciesForPlacement.Add(dependencyNode);
        }
    }
    private void CreateDependencyNodes(string[] dependencies, Node parentNode, Group groupNode, int depth)
    {
        foreach (string dependencyString in dependencies)
        {
            Object   dependencyAsset    = AssetDatabase.LoadMainAssetAtPath(dependencyString);
            string[] deeperDependencies = AssetDatabase.GetDependencies(dependencyString, false);

            Node dependencyNode = CreateNode(dependencyAsset, AssetDatabase.GetAssetPath(dependencyAsset),
                                             false, deeperDependencies.Length > 0);

            if (!m_AssetElements.Contains(dependencyNode))
            {
                dependencyNode.userData = depth;
            }

            CreateDependencyNodes(deeperDependencies, dependencyNode, groupNode, depth + 1);

            if (!m_GraphView.Contains(dependencyNode))
            {
                m_GraphView.AddElement(dependencyNode);
            }

            Edge edge = new Edge
            {
                input  = dependencyNode.inputContainer[0] as Port,
                output = parentNode.outputContainer[0] as Port,
            };
            edge.input?.Connect(edge);
            edge.output?.Connect(edge);

            dependencyNode.RefreshPorts();
            m_GraphView.AddElement(edge);

            if (!m_AssetElements.Contains(dependencyNode))
            {
                groupNode.AddElement(dependencyNode);
            }

            edge.capabilities &= ~Capabilities.Deletable;
            m_AssetElements.Add(edge);
            m_AssetElements.Add(dependencyNode);

            if (!m_DependenciesForPlacement.Contains(dependencyNode))
            {
                m_DependenciesForPlacement.Add(dependencyNode);
            }
        }
    }
示例#7
0
        public override void SetUp()
        {
            base.SetUp();

            m_Node1     = CreateNode("Node 1", new Vector2(100, 100), 2, 2);
            m_Node2     = CreateNode("Node 2", new Vector2(200, 200), 2, 2);
            m_Node3     = CreateNode("Node 3", new Vector2(400, 400));
            m_Node4     = CreateNode("Node 4", new Vector2(500, 500));
            m_Group     = CreateGroup("Group", 500, 0);
            m_StackNode = CreateStackNode(300, 300);
            m_Edge1     = CreateEdge(m_Node2.outputContainer[0] as Port, m_Node1.inputContainer[0] as Port);
            m_Edge2     = CreateEdge(m_Node2.outputContainer[1] as Port, m_Node1.inputContainer[0] as Port);

            m_Group.AddElement(m_Node2);

            m_StackNode.AddElement(m_Node3);
            m_StackNode.AddElement(m_Node4);
        }
示例#8
0
        public frmGroup()
        {
            InitializeComponent();

            Model model = diagram1.Model;

            diagram1.Paging.Enabled = false;
            diagram1.Model.SetSize(new Size(1000, 1000));

            Shape shape = new Shape();

            shape.Location    = new PointF(320, 320);
            shape.BorderColor = Color.Green;
            model.Shapes.Add(shape);


            Shape shape2 = new Shape();

            shape2.Location    = new PointF(20, 20);
            shape2.BorderColor = Color.Blue;
            model.Shapes.Add(shape2);

            Shape shape3 = new Shape();

            shape3.Location    = new PointF(200, 100);
            shape3.BorderColor = Color.Red;
            model.Shapes.Add(shape3);

            Group group = new Group();

            //group.AddElement(shape);

            group.Expanded = true;

            model.Shapes.Add(group);

            group.AddElement(shape2);

            diagram1.Refresh();
        }
    private void ExploreAsset()
    {
        Object obj       = Selection.activeObject;
        string assetPath = AssetDatabase.GetAssetPath(obj);

        // assetPath will be empty if obj is null or isn't an asset (a scene object)
        if (obj == null || string.IsNullOrEmpty(assetPath))
        {
            return;
        }

        Group groupNode = new Group {
            title = obj.name
        };
        Object mainObject = AssetDatabase.LoadMainAssetAtPath(assetPath);

        string[] dependencies    = AssetDatabase.GetDependencies(assetPath, false);
        bool     hasDependencies = dependencies.Length > 0;

        Node mainNode = CreateNode(mainObject, assetPath, true, hasDependencies);

        mainNode.userData = 0;

        mainNode.SetPosition(new Rect(0, 0, 0, 0));
        m_GraphView.AddElement(groupNode);
        m_GraphView.AddElement(mainNode);

        groupNode.AddElement(mainNode);

        CreateDependencyNodes(dependencies, mainNode, groupNode, 1);

        m_AssetElements.Add(mainNode);
        m_AssetElements.Add(groupNode);
        groupNode.capabilities &= ~Capabilities.Deletable;

        groupNode.Focus();

        mainNode.RegisterCallback <GeometryChangedEvent>(UpdateDependencyNodePlacement);
    }
    private void CreateDependencyNodes(AssetGroup assetGroup, string[] dependencies, Node parentNode, Group groupNode, int depth)
    {
        //Debug.Log(depth);

        foreach (string dependencyString in dependencies)
        {
            Object   dependencyAsset    = AssetDatabase.LoadMainAssetAtPath(dependencyString);
            string[] deeperDependencies = AssetDatabase.GetDependencies(dependencyString, false);

            var typeName = dependencyAsset.GetType().Name;

            //filter out selected asset types
            if (FilterType(typeName))
            {
                continue;
            }

            Node dependencyNode = CreateNode(assetGroup, dependencyAsset, AssetDatabase.GetAssetPath(dependencyAsset),
                                             false, deeperDependencies.Length);

            if (!assetGroup.m_AssetNodes.Contains(dependencyNode))
            {
                dependencyNode.userData = depth;
            }

            CreateDependencyNodes(assetGroup, deeperDependencies, dependencyNode, groupNode, depth + 1);

            //if the node doesnt exists yet, put it in the group
            if (!m_GraphView.Contains(dependencyNode))
            {
                m_GraphView.AddElement(dependencyNode);

                assetGroup.m_DependenciesForPlacement.Add(dependencyNode);
                groupNode.AddElement(dependencyNode);
            }
            else
            {
                //TODO: if it already exists, put it in a separate group for shared assets
                //Check if the dependencyNode is in the same group or not
                //if it's a different group move it to a new shared group

                /*
                 * if (SharedToggle.value) {
                 *  if (!assetGroup.m_AssetNodes.Contains(dependencyNode)) {
                 *      if (assetGroup.SharedGroup == null) {
                 *          assetGroup.SharedGroup = new AssetGroup();
                 *
                 *          AssetGroups.Add(assetGroup.SharedGroup);
                 *          assetGroup.SharedGroup.assetPath = assetGroup.assetPath;
                 *
                 *          assetGroup.SharedGroup.groupNode = new Group { title = "Shared Group" };
                 *
                 *          assetGroup.SharedGroup.mainNode = dependencyNode;
                 *          assetGroup.SharedGroup.mainNode.userData = 0;
                 *      }
                 *
                 *      if (!m_GraphView.Contains(assetGroup.SharedGroup.groupNode)) {
                 *          m_GraphView.AddElement(assetGroup.SharedGroup.groupNode);
                 *      }
                 *
                 *      //add the node to the group and remove it from the previous group
                 *      assetGroup.m_AssetNodes.Remove(dependencyNode);
                 *      //assetGroup.groupNode.RemoveElement(dependencyNode);
                 *      assetGroup.m_DependenciesForPlacement.Remove(dependencyNode);
                 *
                 *      assetGroup.SharedGroup.m_DependenciesForPlacement.Add(dependencyNode);
                 *
                 *      if (!assetGroup.SharedGroup.groupNode.ContainsElement(dependencyNode)) {
                 *          assetGroup.SharedGroup.groupNode.AddElement(dependencyNode);
                 *      }
                 *
                 *      assetGroup.SharedGroup.m_AssetNodes.Add(dependencyNode);
                 *  }
                 * }*/
            }

            Edge edge = CreateEdge(dependencyNode, parentNode);

            assetGroup.m_AssetConnections.Add(edge);
            assetGroup.m_AssetNodes.Add(dependencyNode);
        }
    }
示例#11
0
        public override void Load()
        {
            #region Initialisation de la population (en cas de mode entrainement IA)
            IATrainingMode = MainGame.IATrainingMode;
            if (IATrainingMode)
            {
                if (File.Exists("Population.json"))
                {
                    Population = Population.OpenFromFile("Population");
                }
                else
                {
                    Population = new Population();
                    Population.MutationRate = 0.05f;
                }
                Population.OnGenomesDeletion += Population_OnGenomesDeletion;
                Population.OnGenomesChanged  += Population_OnGenomesChanged;
            }
            #endregion

            #region Démarrage des musiques
            sndMusic = AssetManager.mscGameplay;
            MediaPlayer.Play(sndMusic);
            MediaPlayer.Volume      = 0.5f;
            MediaPlayer.IsRepeating = true;
            #endregion

            #region Ajout des bruitages
            _sndexplosion = AssetManager.sndExplosion;
            #endregion

            #region Création du ciel
            _skyTexture = new Texture2D(MainGame.spriteBatch.GraphicsDevice, (int)MapSize.X, _skyHeight);
            Color[] skyData = new Color[_skyTexture.Width * _skyTexture.Height];
            int     skyH    = _skyTexture.Height;
            int     skyW    = _skyTexture.Width;
            for (int y = 0; y < skyH; y++)
            {
                Color skyColor = Color.Lerp(Color.Black, new Color(119, 181, 254), (float)y / skyH);
                for (int x = 0; x < skyW; x++)
                {
                    skyData[x + y * skyW] = skyColor;
                }
            }
            _skyTexture.SetData(skyData);
            #endregion

            #region Création de la map et relevé des points d'eau pour le réseau de neurone
            WaterPosition = new List <Rectangle>();
            bool beginWater         = false;
            int  beginWaterPosition = 0;
            _perlinNoise = PerlinNoise.Generate1DMap((int)MapSize.X, 550f);
            _mapTexture  = new Texture2D(MainGame.spriteBatch.GraphicsDevice, (int)MapSize.X, (int)MapSize.Y);
            MapData      = new byte[(int)(MapSize.X * MapSize.Y)];
            MapColors    = new Color[MapData.Length];

            Color[] colors = new Color[5];
            colors[0] = Color.White;
            colors[1] = Color.Green;
            colors[2] = Color.DarkGreen;
            colors[4] = new Color(132, 73, 44);
            colors[3] = new Color(62, 28, 0);

            for (ushort i = 0; i < _perlinNoise.Length; i++)
            {
                float  noiseVal = _perlinNoise[i];
                ushort x        = (ushort)(i % MapSize.X);
                ushort h        = (ushort)Math.Floor((noiseVal + 1) * MapSize.Y * 0.5f);
                h = (ushort)MathHelper.Clamp(h, 0, WaterLevel + 1);
                int min = (int)Math.Floor((_perlinNoise.Min() + 1) * MapSize.Y * 0.5f);
                int dif = (int)MapSize.Y - min;
                for (ushort y = h; y < MapSize.Y; y++)
                {
                    uint index = (uint)(x + y * MapSize.X);
                    if (y <= WaterLevel)
                    {
                        float pourcent = (float)(y - min) / dif;
                        float p1       = 0.25f;
                        float p2       = 0.5f;
                        float p3       = 0.75f;
                        float p4       = 1f;
                        if (pourcent < p1)
                        {
                            MapColors[index] = Color.Lerp(colors[0], colors[1], pourcent / p1);
                        }
                        else if (pourcent < p2)
                        {
                            MapColors[index] = Color.Lerp(colors[1], colors[2], (pourcent - p1) / (p2 - p1));
                        }
                        else if (pourcent < p3)
                        {
                            MapColors[index] = Color.Lerp(colors[2], colors[3], (pourcent - p2) / (p3 - p2));
                        }
                        else if (pourcent < p4)
                        {
                            MapColors[index] = Color.Lerp(colors[3], colors[4], (pourcent - p3) / (p4 - p3));
                        }
                        MapData[index] = 1;
                    }
                    else
                    {
                        MapColors[index] = Color.Brown;
                    }
                }
                if (!IsSolid(new Vector2(x, WaterLevel - 1)))
                {
                    if (!beginWater)
                    {
                        beginWater         = true;
                        beginWaterPosition = x;
                    }
                }
                else
                {
                    if (beginWater)
                    {
                        beginWater = false;
                        WaterPosition.Add(new Rectangle(beginWaterPosition, WaterLevel, x - beginWaterPosition, (int)MapSize.Y - WaterLevel));
                    }
                }
            }
            _mapTexture.SetData(MapColors);
            #endregion

            #region Création de l'eau
            Vector2 p = new Vector2(0, WaterLevel);
            WaterHeight = (int)(MapSize - p).Y;
            Vector2 s = new Vector2(MapSize.X, WaterHeight);
            _water = new Water(this, p, s);
            #endregion

            #region Paramétrage de la Caméra
            Camera c = MainGame.Camera;
            c.CameraSize   = new Vector3(MapSize.X, MapSize.Y, 0);
            c.CameraOffset = new Vector3(0, MapSize.Y - MainGame.Screen.Height, 0);
            c.Enable       = true;
            c.Speed        = 10;
            #endregion

            #region Création d'un timer de tours
            _timerSecond           = new Timer(1000);
            _timerSecond.Elapsed  += OnTimerElapsed;
            _timerSecond.AutoReset = true;
            _timerSecond.Enabled   = true;
            _counter = TIME_BETWEEN_TOUR;
            #endregion

            #region Création des éléments de GUI
            GUIGroup = new Group();
            Texture2D texture = AssetManager.GameBottomBar;
            _gameBarImage        = new Image(texture, new Vector2(MainGame.Screen.Width / 2, MainGame.Screen.Height - texture.Height / 2));
            _gameBarImage.Layer -= 0.1f;
            _gameBarImage.SetOriginToCenter();
            GUIGroup.AddElement(_gameBarImage);

            texture      = AssetManager.Cursor;
            _cursorImage = new Image(texture, new Vector2(_gameBarImage.Position.X - _gameBarImage.Origin.X + (_gameBarImage.Position.X / MapSize.X), _gameBarImage.Position.Y - texture.Height * 0.75f));
            _cursorImage.SetOriginToCenter();
            GUIGroup.AddElement(_cursorImage);

            Viewport   screen = MainGame.Screen;
            SpriteFont font   = AssetManager.MenuFont;
            _bigTimerTextBox = new Textbox(new Vector2((screen.Width - font.MeasureString("3").X) / 2, (screen.Height - font.MeasureString("3").Y) / 2), font, "3");
            _bigTimerTextBox.ApplyColor(Color.White, Color.Black);
            _bigTimerTextBox.Visible = false;
            _bigTimerTextBox.Layer  += 0.2f;
            GUIGroup.AddElement(_bigTimerTextBox);

            font          = AssetManager.MainFont;
            _timerTextBox = new Textbox(new Vector2(382, 725), font, TIME_BETWEEN_TOUR.ToString() + "sec");
            _timerTextBox.ApplyColor(Color.Red, Color.Black);
            GUIGroup.AddElement(_timerTextBox);

            _currentTeamTextBox = new Textbox(new Vector2(25, 725), font, "Equipe des rouges");
            GUIGroup.AddElement(_currentTeamTextBox);

            _currentTankTextBox = new Textbox(new Vector2(196, 725), font, ".");
            _currentTankTextBox.ApplyColor(Color.Yellow, Color.Black);
            GUIGroup.AddElement(_currentTankTextBox);

            _infoBulle = new Textbox(new Vector2(925, 725), font, "InfoBulle :");
            _infoBulle.ApplyColor(Color.Yellow, Color.Black);
            GUIGroup.AddElement(_infoBulle);

            if (IATrainingMode)
            {
                _fittingScoreTextBox = new Textbox(Vector2.One, font, "Fitness Score : 0 Generation : " + Population.Generation);
                _fittingScoreTextBox.ApplyColor(Color.Yellow, Color.Black);
                GUIGroup.AddElement(_fittingScoreTextBox);
            }

            GUIGroupButtons = new GroupSelection();
            for (int i = 0; i < Enum.GetValues(typeof(Action.eActions)).Length; i++)
            {
                ButtonAction btn;
                if (i == 0)
                {
                    btn = new ButtonAction(this, (Action.eActions)i, Vector2.Zero, Vector2.Zero, AssetManager.MainFont, string.Empty);
                }
                else
                {
                    btn = new ButtonAction(this, (Action.eActions)i, new Vector2(442 + 37 * (i - 1), 725), Vector2.Zero, AssetManager.MainFont, string.Empty);
                }
                GUIGroupButtons.AddElement((IIntegrableMenu)btn);
                btn.OnHover += OnButtonHover;
                btn.OnClick += OnButtonClicked;
            }
            c.OnPositionChange += OnCameraPositionChange;
            #endregion

            #region Remplissage du sac à loot
            _lootBag = new List <Action.eActions>();
            FillLootBag();
            #endregion

            #region Création des équipes
            Teams = new List <Team>();
            Texture2D img = AssetManager.TanksSpriteSheet;
            Team      t;
            int       numberOfTeam        = MainGame.NumberOfTeam;
            int       numberOfTankPerTeam = MainGame.NumberOfTank;
            Random    rnd = new Random();

            for (byte i = 0; i < numberOfTeam; i++)
            {
                eControlType controlType;
                if (IATrainingMode)
                {
                    controlType = eControlType.NeuralNetwork;
                }
                else
                {
                    //if (i < 1)
                    controlType = eControlType.Player;     // MainGame.ControlTypes[i];
                    //else
                    //controlType = eControlType.NeuralNetwork;
                }
                t = new Team(this, img, numberOfTankPerTeam, i, rnd, controlType);
                Teams.Add(t);
                if (IATrainingMode)
                {
                    NeuralNetworkControl nn = (NeuralNetworkControl)t.Control;
                    if (Population.Genomes.Count > i)
                    {
                        nn.Genome = Population.Genomes[i % Population.Genomes.Count];
                        nn.Genome.OnFitnessScoreChange += Genome_OnFitnessScoreChange;
                    }
                    else
                    {
                        Population.Genomes.Add(nn.Genome);
                        nn.Genome.OnFitnessScoreChange += Genome_OnFitnessScoreChange;
                    }
                }
                t.OnTankSelectionChange += OnTankSelectionChange;
            }
            t = Teams[IndexTeam];
            t.RefreshCameraOnSelection();
            _currentTeamTextBox.ApplyColor(t.TeamColor, Color.Black);
            _currentTankTextBox.Text = t.Tanks[t.IndexTank].Name;
            RefreshActionButtonInventory();
            #endregion

            base.Load();
        }