コード例 #1
0
        private async Task CreateDecal(Vector3 origin)
        {
            var gameData = await Document.Environment.GetGameData();

            if (gameData == null)
            {
                return;
            }

            var gd = gameData.Classes.FirstOrDefault(x => x.Name == "infodecal");

            if (gd == null)
            {
                return;
            }

            var texture = Document.Map.Data.GetOne <ActiveTexture>()?.Name;

            if (String.IsNullOrWhiteSpace(texture))
            {
                return;
            }

            var tc = await Document.Environment.GetTextureCollection();

            if (tc == null)
            {
                return;
            }

            if (!tc.HasTexture(texture))
            {
                return;
            }

            var decal = new Primitives.MapObjects.Entity(Document.Map.NumberGenerator.Next("MapObject"))
            {
                Data =
                {
                    new EntityData
                    {
                        Name       = gd.Name,
                        Properties ={                  { "texture", texture } }
                    },
                    new ObjectColor(Colour.GetRandomBrushColour()),
                    new Origin(origin)
                }
            };

            await MapDocumentOperation.Perform(Document, new Attach(Document.Map.Root.ID, decal));
        }
コード例 #2
0
ファイル: EntityTool.cs プロジェクト: tomast1337/sledge
        private async Task CreateEntity(MapDocument document, Vector3 origin, string gd = null)
        {
            if (gd == null)
            {
                gd = _activeEntity;
            }
            if (gd == null)
            {
                return;
            }

            var colour = Colour.GetDefaultEntityColour();
            var data   = await document.Environment.GetGameData();

            if (data != null)
            {
                var cls = data.Classes.FirstOrDefault(x => String.Equals(x.Name, gd, StringComparison.InvariantCultureIgnoreCase));
                if (cls != null)
                {
                    var col = cls.Behaviours.Where(x => x.Name == "color").ToArray();
                    if (col.Any())
                    {
                        colour = col[0].GetColour(0);
                    }
                }
            }

            var entity = new Primitives.MapObjects.Entity(document.Map.NumberGenerator.Next("MapObject"))
            {
                Data =
                {
                    new EntityData {
                        Name = gd
                    },
                    new ObjectColor(colour),
                    new Origin(origin),
                }
            };

            var transaction = new Transaction();

            transaction.Add(new Attach(document.Map.Root.ID, entity));

            if (_selectCreatedEntity)
            {
                transaction.Add(new Deselect(document.Selection));
                transaction.Add(new Select(entity.FindAll()));
            }

            await MapDocumentOperation.Perform(document, transaction);

            if (_switchToSelectAfterCreation)
            {
                Oy.Publish("ActivateTool", "SelectTool");
            }

            if (_resetEntityTypeOnCreation)
            {
                Oy.Publish("EntityTool:ResetEntityType", this);
            }
        }