コード例 #1
0
        private void AddButtonsToDisplayal(Exhibit e, GameObject displayal)
        {
            var genButtonPrefab = ObjectFactory.GetGenerationButtonPrefab();

            // Get IDs and potential reference.
            List <string> ids = new List <string>();

            if (e.Metadata.ContainsKey(GenerationMetadata.MemberIds.GetKey()))
            {
                var json          = e.Metadata[GenerationMetadata.MemberIds.GetKey()];
                var idDoublePairs = JsonConvert.DeserializeObject <List <IdDoublePair> >(json);
                idDoublePairs.ForEach(it => ids.Add(it.id));
            }

            var idConfig = displayal.AddComponent <IdListPair>();

            idConfig.associatedIds = ids;
            idConfig.originId      = e.Metadata[GenerationMetadata.ObjectId.GetKey()];

            List <GenerationMethod> types = GenerationMethodUtil.GetButtonTypes(ids.Count);

            var localScale      = displayal.transform.localScale;
            var offset          = -2.0f;
            var shift           = (types.Count - 1) / 2.0f;
            var xFactor         = 0.2f / localScale.x;
            var zFactor         = 0.2f / localScale.z;
            var displayalHeight = displayal.GetComponent <BoxCollider>().size.z;

            var parentGameObj = new GameObject("Button Wrapper");

            parentGameObj.transform.SetParent(displayal.transform.parent, false);
            parentGameObj.transform.localPosition = displayal.transform.localPosition;
            parentGameObj.transform.localRotation = displayal.transform.localRotation;
            parentGameObj.transform.localScale    = displayal.transform.localScale;

            var wrapperObj = parentGameObj.AddComponent <ButtonWrapper>();

            wrapperObj.displayal = displayal.GetComponent <Displayal>();

            for (var i = 0; i < types.Count; i++)
            {
                var method = types[i];

                var genButton = Instantiate(genButtonPrefab, parentGameObj.transform, false);
                genButton.name = "Generation Button (" + method.GetName() + ")";

                genButton.transform.localRotation = Quaternion.Euler(90.0f, 0.0f, 180.0f);
                genButton.transform.localPosition =
                    new Vector3(offset * (i - shift) * xFactor, 0.5f, 0.5f * displayalHeight + 0.75f * zFactor);
                genButton.transform.localScale = new Vector3(
                    0.75f * xFactor,
                    0.75f * zFactor, // Y/Z inverted due to different prefab orientation...
                    2.0f
                    );

                // Button.
                RoomReferences references = null;

                if (e.Metadata.ContainsKey(GenerationMetadata.References.GetKey()))
                {
                    var refJson = e.Metadata[GenerationMetadata.References.GetKey()];
                    references = JsonConvert.DeserializeObject <RoomReferences>(refJson);
                }

                GenerationButton genButtonComponent = genButton.GetComponent <GenerationButton>();
                genButtonComponent.type = method;
                if (references != null && references.References.ContainsKey(method.ToString()))
                {
                    // If a room was already generated from this button, link it.
                    genButtonComponent.targetRoomId = references.References[method.ToString()];
                }

                TextMesh genButtonText = genButton.GetComponentInChildren <TextMesh>();
                genButtonText.text = method.GetName();
            }
        }
コード例 #2
0
        void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (threadCheckBox.Checked)
            {
                cppClass.threadPreparingRules(firstKey, secondKey);
            }
            else
            {
                cppClass.preparingRules(firstKey, secondKey);
            }

            if (messageForm.InvokeRequired)
            {
                messageForm.Invoke(new MethodInvoker(
                                       delegate() { messageForm.Close(); }));
            }

            bitmap      = new Bitmap(imageLocation);
            percentage  = 0;
            numberCount = bitmap.Height * 3;

            if (threadCheckBox.Checked)
            {
                int numberThreads = Convert.ToInt32(Math.Round(threadNumericUpDown.Value, 0));
                int pieces        = Convert.ToInt32(Math.Round(spinBox.Value, 0));
                int currentThread = 0;

                Thread[] threads = new Thread[numberThreads];

                int piecesI = 0, piecesJ = 0;
                getFromPieces(ref piecesI, ref piecesJ, pieces);
                numberCount *= piecesJ;

                int startX = 0, startY = 0;
                int endX = 0, endY = 0;

                for (int i = 0; i < piecesI; i++)
                {
                    for (int j = 0; j < piecesJ; j++)
                    {
                        threads[currentThread] = new Thread(new ParameterizedThreadStart(this.threadScramblingPixels));
                        getXandY(ref startX, ref startY, ref endX, ref endY, i, j, piecesI, piecesJ);
                        threads[currentThread].Start(new ThreadParameters(startX, endX, startY, endY));

                        if (currentThread == numberThreads - 1)
                        {
                            for (int k = 0; k < numberThreads; k++)
                            {
                                threads[k].Join();
                            }
                            currentThread = 0;
                        }
                        else if (i == piecesI - 1 && j == piecesJ - 1)
                        {
                            for (int x = 0; x < currentThread + 1; x++)
                            {
                                threads[x].Join();
                            }
                        }
                        else
                        {
                            currentThread++;
                        }
                    }
                }

                for (int i = 0; i < bitmap.Height; i++)
                {
                    for (int j = 0; j < bitmap.Width; j++)
                    {
                        AlgorithmWrapper.WrapperPixel pixel = cppClass.getPixel(i, j);
                        Color color = Color.FromArgb(pixel.R, pixel.G, pixel.B);
                        bitmap.SetPixel(j, i, color);
                    }
                }
            }
            else
            {
                ScramblingPixels(0, bitmap.Height, 0, bitmap.Width);
            }

            if (trhreadTimer != null)
            {
                trhreadTimer.Dispose();
            }
            timer.Stop();

            if (saveButton.InvokeRequired)
            {
                saveButton.Invoke(new MethodInvoker(
                                      delegate(){ saveButton.Enabled = true; }));
            }

            if (saveKeysButton.InvokeRequired)
            {
                saveKeysButton.Invoke(new MethodInvoker(
                                          delegate() { saveKeysButton.Enabled = true; }));
            }

            if (loadButton.InvokeRequired)
            {
                loadButton.Invoke(new MethodInvoker(
                                      delegate() { loadButton.Enabled = true; }));
            }

            if (backButton.InvokeRequired)
            {
                backButton.Invoke(new MethodInvoker(
                                      delegate(){ backButton.Enabled = true; }));
            }

            if (EncryptButton.InvokeRequired)
            {
                EncryptButton.Invoke(new MethodInvoker(
                                         delegate() { EncryptButton.Enabled = false; }));
            }

            if (GenerationButton.InvokeRequired)
            {
                GenerationButton.Invoke(new MethodInvoker(
                                            delegate() { GenerationButton.Enabled = false; }));
            }

            Image1.Image = bitmap;
            MessageBox.Show("Picture was encrypted successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }