Пример #1
0
    void ClearScene()
    {
        foreach (Transform child in transform)
        {
            Destroy(child.gameObject);
        }

        selectedPacketRenderer = null;
        containers             = new Dictionary <int, GridContainer>();
        gameSet = false;
        successReminder.SetActive(false);
    }
Пример #2
0
    public Instruction.Result TryPack(Packet packer)
    {
        List <Packet> toPack = new List <Packet>();

        foreach (var packet in packets)
        {
            if (packet.type != Packet.Type.Ant && packet.type != Packet.Type.Box)
            {
                return(Instruction.Result.ERROR);
            }
            toPack.Add(packet);
        }
        Packet         box      = new Packet(Packet.Type.Box, this);
        PacketRenderer renderer = Manager.CreatePacketRenderer(box, this);

        foreach (var packet in toPack)
        {
            Release(packet);
            box.Contain(packet);
        }
        return(Instruction.Result.SUCCEED);
    }
Пример #3
0
    void LoadDemo()
    {
        foreach (GridContainer container in gameObject.GetComponentsInChildren <GridContainer>())
        {
            container.Init(this, container.InitLocation);
            containers.Add(HashLocation(container.Location), container);
            // moved to container.Init()
            // container.transform.position = LocationToPos(container.Location);
        }

        foreach (PacketRenderer renderer in gameObject.GetComponentsInChildren <PacketRenderer>())
        {
            GridContainer container = null;
            var           result    = QueryContainer(renderer.InitLocation, ref container);
            if (result == Instruction.Result.SUCCEED)
            {
                renderer.Init(this, container);
            }
            if (renderer.name == "Character")
            {
                selectedPacketRenderer = renderer;
            }
        }
    }
Пример #4
0
 public void UpdateSelectedPacket(PacketRenderer renderer)
 {
     selectedPacketRenderer = renderer;
 }
Пример #5
0
    void LoadLevel(string levelName)
    {
        ClearScene();
        if (levelName == "")
        {
            levelName = "level_demo";
        }

        string filepath = Application.streamingAssetsPath + "/Levels/" + levelName + ".csv";
        var    data     = CSVTool.Read(filepath, Encoding.UTF8);

        int width = 0;

        foreach (var line in data)
        {
            width = Mathf.Max(width, line.Count);
        }
        int height = data.Count;

        for (int i = 0; i < data.Count; ++i)
        {
            for (int j = 0; j < data[i].Count; ++j)
            {
                string element = data[i][j];
                if (element == "")
                {
                    continue;
                }
                GameObject obj = Instantiate(gridPrefab);
                obj.transform.parent = transform;
                GridContainer container = obj.GetComponent <GridContainer>();
                Vector2       location  = new Vector2(j - width / 2, height / 2 - i);
                container.Init(this, location);
                containers.Add(HashLocation(container.Location), container);

                Packet.Type packetType = Packet.Type.Unk;
                Packet      packet     = null;

                if (element.StartsWith("ant"))
                {
                    // ant related info
                    bool        packable = false, unpackable = false;
                    Orientation antOri = Orientation.NONE;
                    packetType = Packet.Type.Ant;
                    string antInfo = element.Substring(3);
                    if (antInfo.StartsWith("P"))
                    {
                        packable = true;
                        antInfo  = antInfo.Substring(1);
                    }
                    else if (antInfo.StartsWith("U"))
                    {
                        unpackable = true;
                        antInfo    = antInfo.Substring(1);
                    }
                    if (antInfo.Length >= 2)
                    {
                        switch (antInfo[1])
                        {
                        case 'r': antOri = Orientation.RIGHT; break;

                        case 'l': antOri = Orientation.LEFT; break;

                        case 'u': antOri = Orientation.UP;   break;

                        case 'd': antOri = Orientation.DOWN; break;
                        }
                    }
                    // not safe here
                    packet = new Packet(packetType, container);
                    packet.AntInit(packable, unpackable, antOri);
                }
                else
                {
                    switch (element)
                    {
                    case "tar":
                        packetType = Packet.Type.Target;
                        break;

                    case "pack":
                        packetType = Packet.Type.Box;
                        break;

                    case "wall":
                        packetType = Packet.Type.Wall;
                        break;

                    case "hole":
                        packetType = Packet.Type.Hole;
                        break;

                    default:
                        break;
                    }
                    if (packetType != Packet.Type.Unk)
                    {
                        packet = new Packet(packetType, container);
                    }
                }

                if (packetType != Packet.Type.Unk)
                {
                    GameObject pack = Instantiate(packetPrefab);
                    pack.transform.parent = transform;
                    var renderer = pack.GetComponent <PacketRenderer>();
                    renderer.Init(this, packet);
                    if (packet.type == Packet.Type.Ant)
                    {
                        selectedPacketRenderer = renderer;
                    }
                }
            }
        }
    }