/// <summary> /// Allows to set all rect transform values at once. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="pivotAndAnchor"></param> public void SetRTransformValues(float x, float y, float width, float height, Vector2 pivotAndAnchor) { RTransform.anchoredPosition = new Vector2(x, y); RTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); RTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); Pivot = AnchorMin = AnchorMax = pivotAndAnchor; }
public void UpdateUI() { Clear(); int buttonObjectCount = Mathf.Min(m_pageCount, m_maxPageBtnCount); // the rect width is prev btn width + next btn width + page btn width * page count float width = GetWidth(m_previousButton) + GetWidth(m_nextButton) + (GetWidth(m_pageButton) * buttonObjectCount); RTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); // calculate the range of the shown buttons int idealOffsetMin = Mathf.Max(0, m_selectedPage - m_maxPageBtnCount); int idealOffsetMax = Mathf.Max(0, Mathf.Min(m_pageCount - m_maxPageBtnCount, m_selectedPage - 1)); if (idealOffsetMin - 1 >= m_offset) { m_offset = idealOffsetMin; } else if (idealOffsetMax + 1 <= m_offset) { m_offset = idealOffsetMax; } // create page buttons SetText(m_pageButton, (1 + m_offset).ToString()); SetOnClick(m_pageButton, 1 + m_offset); for (int pageNumber = 2; pageNumber <= buttonObjectCount; pageNumber++) { Button pageBtn = (Button)Instantiate(m_pageButton); RectTransform rTransform = pageBtn.GetComponent <RectTransform>(); rTransform.SetParent(PageButtonTransform.parent, true); rTransform.localScale = PageButtonTransform.localScale; rTransform.localPosition = PageButtonTransform.localPosition + Vector3.right * (pageNumber - 1) * GetWidth(m_pageButton); SetText(pageBtn, (pageNumber + m_offset).ToString()); SetOnClick(pageBtn, pageNumber + m_offset); m_pageButtons.Add(pageBtn); } // highlight selected button for (int i = 0; i < m_pageButtons.Count; i++) { int pageNumber = i + 1 + m_offset; m_pageButtons[i].enabled = pageNumber != m_selectedPage; } // correct position of next button if (m_nextButton != null) { m_nextButton.GetComponent <RectTransform>().localPosition = PageButtonTransform.localPosition + Vector3.right * buttonObjectCount * GetWidth(m_pageButton); } }
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { var moduleCtx = context.Annotations.Get <CEContext>(context.CurrentModule, ConstantProtection.ContextKey); if (!parameters.Targets.Any() || moduleCtx == null) { return; } var ldc = new Dictionary <object, List <Tuple <MethodDef, Instruction> > >(); var ldInit = new Dictionary <byte[], List <Tuple <MethodDef, Instruction> > >(new ByteArrayComparer()); // Extract constants ExtractConstants(context, parameters, moduleCtx, ldc, ldInit); // Encode constants moduleCtx.ReferenceRepl = new Dictionary <MethodDef, List <Tuple <Instruction, uint, IMethod> > >(); moduleCtx.EncodedBuffer = new List <uint>(); foreach (var entry in ldInit.WithProgress(context.Logger)) // Ensure the array length haven't been encoded yet { EncodeInitializer(moduleCtx, entry.Key, entry.Value); context.CheckCancellation(); } foreach (var entry in ldc.WithProgress(context.Logger)) { if (entry.Key is string) { EncodeString(moduleCtx, (string)entry.Key, entry.Value); } else if (entry.Key is int) { EncodeConstant32(moduleCtx, (uint)(int)entry.Key, context.CurrentModule.CorLibTypes.Int32, entry.Value); } else if (entry.Key is long) { EncodeConstant64(moduleCtx, (uint)((long)entry.Key >> 32), (uint)(long)entry.Key, context.CurrentModule.CorLibTypes.Int64, entry.Value); } else if (entry.Key is float) { var t = new RTransform(); t.R4 = (float)entry.Key; EncodeConstant32(moduleCtx, t.Lo, context.CurrentModule.CorLibTypes.Single, entry.Value); } else if (entry.Key is double) { var t = new RTransform(); t.R8 = (double)entry.Key; EncodeConstant64(moduleCtx, t.Hi, t.Lo, context.CurrentModule.CorLibTypes.Double, entry.Value); } else { throw new UnreachableException(); } context.CheckCancellation(); } ReferenceReplacer.ReplaceReference(moduleCtx, parameters); // compress var encodedBuff = new byte[moduleCtx.EncodedBuffer.Count * 4]; int buffIndex = 0; foreach (uint dat in moduleCtx.EncodedBuffer) { encodedBuff[buffIndex++] = (byte)((dat >> 0) & 0xff); encodedBuff[buffIndex++] = (byte)((dat >> 8) & 0xff); encodedBuff[buffIndex++] = (byte)((dat >> 16) & 0xff); encodedBuff[buffIndex++] = (byte)((dat >> 24) & 0xff); } Debug.Assert(buffIndex == encodedBuff.Length); encodedBuff = context.Registry.GetService <ICompressionService>().Compress(encodedBuff); context.CheckCancellation(); uint compressedLen = (uint)(encodedBuff.Length + 3) / 4; compressedLen = (compressedLen + 0xfu) & ~0xfu; var compressedBuff = new uint[compressedLen]; Buffer.BlockCopy(encodedBuff, 0, compressedBuff, 0, encodedBuff.Length); Debug.Assert(compressedLen % 0x10 == 0); // encrypt uint keySeed = moduleCtx.Random.NextUInt32(); var key = new uint[0x10]; uint state = keySeed; for (int i = 0; i < 0x10; i++) { state ^= state >> 12; state ^= state << 25; state ^= state >> 27; key[i] = state; } var encryptedBuffer = new byte[compressedBuff.Length * 4]; buffIndex = 0; while (buffIndex < compressedBuff.Length) { uint[] enc = moduleCtx.ModeHandler.Encrypt(compressedBuff, buffIndex, key); for (int j = 0; j < 0x10; j++) { key[j] ^= compressedBuff[buffIndex + j]; } Buffer.BlockCopy(enc, 0, encryptedBuffer, buffIndex * 4, 0x40); buffIndex += 0x10; } Debug.Assert(buffIndex == compressedBuff.Length); moduleCtx.DataField.InitialValue = encryptedBuffer; moduleCtx.DataField.HasFieldRVA = true; moduleCtx.DataType.ClassLayout = new ClassLayoutUser(0, (uint)encryptedBuffer.Length); MutationHelper.InjectKeys(moduleCtx.InitMethod, new[] { 0, 1 }, new[] { encryptedBuffer.Length / 4, (int)keySeed }); MutationHelper.ReplacePlaceholder(moduleCtx.InitMethod, arg => { var repl = new List <Instruction>(); repl.AddRange(arg); repl.Add(Instruction.Create(OpCodes.Dup)); repl.Add(Instruction.Create(OpCodes.Ldtoken, moduleCtx.DataField)); repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import( typeof(RuntimeHelpers).GetMethod("InitializeArray")))); return(repl.ToArray()); }); }
/// <summary> /// Sets the width and height of the view. /// </summary> /// <param name="width"></param> /// <param name="height"></param> public void SetSize(float width, float height) { RTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); RTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); }
public void SetTextures(Texture2D[] p_textures, int p_selectedIndex) { if (m_texturePrefab != null) { m_textures = p_textures; // delete all existing texture instances Destroy(m_selectionInstance); for (int i = 0; i < m_instances.Length; i++) { Destroy(m_instances[i]); } // create new texture prefab instances m_instances = new GameObject[p_textures.Length]; float maxX = 0; for (int i = 0; i < p_textures.Length; i++) { // instantiate texture prefab m_instances[i] = (GameObject)Instantiate(m_texturePrefab); RectTransform instanceTransform = m_instances[i].GetComponent <RectTransform>(); m_elementSize = instanceTransform.rect.width; SetRectTransformPosition(instanceTransform, i, m_elementSize); // apply texture RawImage image = TryFindComponent <RawImage>(m_instances[i]); if (image != null) { image.texture = p_textures[i]; } else { Debug.LogError("uMyGUI_TexturePicker: SetTextures: TexturePrefab must have a RawImage component attached (can be in children)."); } // link button callback if (m_buttonCallback != null) { Button btn = TryFindComponent <Button>(m_instances[i]); if (btn != null) { int indexCopy = i; btn.onClick.AddListener(() => { m_buttonCallback(indexCopy); }); } } // calculate max x position to resize this rect transform maxX = instanceTransform.anchoredPosition.x + m_elementSize; // add selection prefab if needed if (i == p_selectedIndex) { if (m_selectionPrefab != null) { // instantiate selection prefab m_selectionInstance = (GameObject)Instantiate(m_selectionPrefab); SetRectTransformPosition(m_selectionInstance.GetComponent <RectTransform>(), i, m_elementSize); } else { Debug.LogError("uMyGUI_TexturePicker: SetTextures: you have passed a non negative selection index '" + p_selectedIndex + "', but the SelectionPrefab was not provided in the inspector or via script!"); } } } // resize rect transform (e.g. to allow scrolling if scroll rect is the parent) RTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, maxX - RTransform.rect.xMin + m_offsetEnd); } else { Debug.LogError("uMyGUI_TexturePicker: SetTextures: you must provide the TexturePrefab in the inspector or via script!"); } }