示例#1
0
    void PutRunes(HexXY p)
    {
        if (!isInRuneDrawingMode)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            var existingRune = Level.S.GetEntities(p).OfType <Rune>().FirstOrDefault();
            if (existingRune != null)
            {
                var op = new Undos.RemoveEntity(existingRune, p);
                op.Remove();
                undos.Push(op);
                redos.Clear();
            }
        }
        else
        {
            foreach (var kvp in PlayerInput.runeKeys)
            {
                if (Input.GetKeyDown(kvp.Key))
                {
                    var existingRune = Level.S.GetEntities(p).OfType <Rune>().FirstOrDefault();
                    if (existingRune != null && existingRune.entityType != (uint)kvp.Value)
                    {
                        var op = new Undos.RemoveEntity(existingRune, p);
                        op.Remove();
                        undos.Push(op);
                        existingRune = null;
                        redos.Clear();
                    }

                    if (existingRune == null)
                    {
                        var rune = new Rune(0)
                        {
                            entityType = (uint)kvp.Value
                        };
                        var op = new Undos.AddEntity(rune, p);
                        op.Add();
                        undos.Push(op);
                        redos.Clear();
                    }
                    else if (existingRune.CanRotate)
                    {
                        var op = new Undos.RotateEntity(existingRune, p);
                        op.Rotate();
                        undos.Push(op);
                        redos.Clear();
                    }
                }
            }
        }
    }
示例#2
0
    void PutEntities(HexXY p)
    {
        if (!isInEntitySetMode)
        {
            return;
        }

        //Creating/selecting/rotating
        if (Input.GetMouseButtonDown(0))
        {
            if (Input.GetKey(KeyCode.LeftControl))
            {
                var ent = Level.S.GetEntities(p).FirstOrDefault();
                if (ent != null && ent is IRotatable && !(ent is Rune))
                {
                    var op = new Undos.RotateEntity(ent, p);
                    op.Rotate();
                    undos.Push(op);
                    redos.Clear();
                }
            }
            else
            {
                var existingEntity = Level.S.GetEntities(p).FirstOrDefault();
                if (existingEntity != null)
                {
                    Selection.activeGameObject = entities[existingEntity.graphicsHandle];
                    draggedEntity        = existingEntity;
                    draggedEntityOrigPos = draggedEntityCurrPos = existingEntity.pos;
                }
                else //TODO: make possible stacking entities with Alt or something?
                {
                    var prefab = Selection.activeGameObject;
                    if (prefab == null || PrefabUtility.GetPrefabType(prefab) == PrefabType.None)
                    {
                        return;
                    }
                    var gr = prefab.GetComponent <EntityGraphics>();
                    if (gr == null)
                    {
                        return;
                    }
                    var ent = gr.CreateEntity();
                    var op  = new Undos.AddEntity(ent, p);

                    op.Add();
                    undos.Push(op);
                    redos.Clear();
                }
            }
        }

        //Deleting
        if (Input.GetKeyDown(KeyCode.Space))
        {
            var ent = Level.S.GetEntities(p).FirstOrDefault();
            if (ent != null)
            {
                var op = new Undos.RemoveEntity(ent, p);
                op.Remove();
                undos.Push(op);
                redos.Clear();
            }
        }

        //Dragging
        if (draggedEntity != null)
        {
            if (Input.GetMouseButton(0))
            {
                //Drag
                if (p != draggedEntityCurrPos)
                {
                    var op = new Undos.MoveEntity(draggedEntity, draggedEntityCurrPos, p);
                    op.Move();
                    draggedEntityCurrPos = p;
                }
            }
            else
            {
                //Release
                if (draggedEntityCurrPos != draggedEntityOrigPos)
                {
                    var op = new Undos.MoveEntity(draggedEntity, draggedEntityOrigPos, draggedEntityCurrPos);
                    op.Move();
                    redos.Clear();
                    undos.Push(op);
                }
                draggedEntity = null;
            }
        }
    }