예제 #1
0
 public void CreateNewBlock()
 {
     blockColor = colorPicker.GetBlockColor();
     newBlock   = (GameObject)Instantiate(blocks[blockIndex], transform.position, Quaternion.identity);
     newBlock.transform.parent = transform;
     block = newBlock.GetComponent <Block>() as BlockHierarchy;
     block.SetColor(blockColor, SetMaterial(blockColor));
     block.SetStackObject(stackBlock);
     block.transform.name = block.GetRows() + "x" + block.GetColumns() + "_Block_" + count++;
     size = newBlock.transform.localScale;
     newBlock.transform.localScale = Vector3.zero;
     StartCoroutine("Grow");
 }
예제 #2
0
        private static BlockHierarchy ReadBlockHierarchy(BinaryReaderEx br)
        {
            long currentPosition = br.BaseStream.Position;
            var  rootFolderBlock = br.ReadStruct <LIFFBlock>();

            if (rootFolderBlock.BlockType != 3)
            {
                throw new IOException("The file is not a valid LIF. Root folder block type is not '3'.");
            }

            var rootFolder = new BlockHierarchy(rootFolderBlock, currentPosition);

            ReadFolderBlocks(br, rootFolder);
            return(rootFolder);
        }
예제 #3
0
        private static void ReadFolderBlocks(BinaryReaderEx br, BlockHierarchy folderHierarchy)
        {
            int remainingSize = folderHierarchy.Block.BlockSize - LIFFBLOCK_SIZE;

            //if (folderHierarchy.Block.Spacing1 != 0)
            //    Trace.WriteLine($"Unexpected folder block spacing 1 '{folderHierarchy.Block.Spacing1}'");
            //if (folderHierarchy.Block.Spacing2 != 0)
            //    Trace.WriteLine($"Unexpected folder block spacing 2 '{folderHierarchy.Block.Spacing2}'");
            //if (folderHierarchy.Block.Spacing3 != 0)
            //    Trace.WriteLine($"Unexpected folder block spacing 3 '{folderHierarchy.Block.Spacing3}'");

            while (remainingSize > 0)
            {
                long currentPosition = br.BaseStream.Position;

                var childBlock = br.ReadStruct <LIFFBlock>();
                remainingSize -= childBlock.BlockSize;

                if (childBlock.BlockType < 3 || childBlock.BlockType > 4)
                {
                    throw new IOException($"Unexpected block type '{childBlock.BlockType}'.");
                }

                var block = new BlockHierarchy(childBlock, currentPosition);
                folderHierarchy.Childs.Add(block);

                if (childBlock.BlockType == 3)
                {
                    ReadFolderBlocks(br, block);
                }
                else if (childBlock.BlockType == 4)
                {
                    //if (childBlock.Spacing1 != 0)
                    //    Trace.WriteLine($"Unexpected file block spacing 1 '{childBlock.Spacing1}'");
                    //if (childBlock.Spacing2 != 1)
                    //    Trace.WriteLine($"Unexpected file block spacing 2 '{childBlock.Spacing2}'");
                    //if (childBlock.Spacing3 != 0)
                    //    Trace.WriteLine($"Unexpected file block spacing 3 '{childBlock.Spacing3}'");
                    br.BaseStream.Skip(childBlock.BlockSize - LIFFBLOCK_SIZE);//skip over file content
                }
            }
        }
예제 #4
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Keypad1))
        {
            howMany = 1;
        }
        else if (Input.GetKeyDown(KeyCode.Keypad2))
        {
            howMany = 2;
        }
        else if (Input.GetKeyDown(KeyCode.Keypad3))
        {
            howMany = 3;
        }
        else if (Input.GetKeyDown(KeyCode.Keypad4))
        {
            howMany = 4;
        }
        else if (Input.GetKeyDown(KeyCode.Keypad5))
        {
            howMany = 5;
        }
        else if (Input.GetKeyDown(KeyCode.Keypad6))
        {
            howMany = 6;
        }

        if (Input.GetKeyDown(KeyCode.I))
        {
            newBlock = BuildBlock(howMany);
            newBlock.transform.parent = transform;
            block = newBlock.GetComponent <Block>() as BlockHierarchy;
            block.SetStackObject(stackBlock);
            block.InitializeBuild();
        }
    }
예제 #5
0
        private static void PopulateFolderFileHierarchy(BinaryReaderEx br, FolderEntry parentFolder, BlockHierarchy hierarchy, LIFFFolderEntry folderEntry)
        {
            if (hierarchy.ChildCount != folderEntry.EntryCount)
            {
                throw new IOException("The file is not a valid LIF. Entry count mismatch.");
            }

            for (int i = 0; i < folderEntry.EntryCount; i++)
            {
                var   expectedBlock = hierarchy.Childs[i];
                short entryType     = br.ReadInt16();
                br.BaseStream.Skip(-2);

                LifEntry entry;
                if (entryType == 1)
                {
                    var folderInfo = br.ReadStruct <LIFFFolderEntry>();
                    entry = new FolderEntry(folderInfo.Filename);
                    PopulateFolderFileHierarchy(br, (FolderEntry)entry, expectedBlock, folderInfo);
                }
                else if (entryType == 2)
                {
                    var fileInfo   = br.ReadStruct <LIFFFileEntry>();
                    var dataStream = new StreamPortion(br.BaseStream, expectedBlock.PositionInStream + LIFFBLOCK_SIZE, fileInfo.FileSize - LIFFBLOCK_SIZE);
                    entry = new FileEntry(dataStream, fileInfo.Filename);
                    ((FileEntry)entry).SetFileAttributes(
                        DateTime.FromFileTime(fileInfo.Created),
                        DateTime.FromFileTime(fileInfo.Modified),
                        DateTime.FromFileTime(fileInfo.Accessed));
                }
                else
                {
                    throw new IOException("The file is not a valid LIF.");
                }

                parentFolder.Entries.Add(entry);
            }
        }