static public GameObject AddGlass(GameObject parent, bool zoom, bool horizontal) { if (zoom) { GameObject glassBg = new GameObject("GlassBg"); GameObjectUtility.SetParentAndAlign(glassBg, parent); DontTouchImage bgImage = glassBg.AddComponent <DontTouchImage>(); bgImage.sprite = (Sprite)AssetDatabase.LoadAssetAtPath(!horizontal ? CanvasSpritePath : CanvasRotateSpritePath, typeof(Sprite)); bgImage.type = Image.Type.Sliced; RectTransform bgRect = glassBg.GetComponent <RectTransform>(); if (!horizontal) { bgRect.anchorMin = new Vector2(0, 0.5f); bgRect.anchorMax = new Vector2(1, 0.5f); bgRect.sizeDelta = new Vector2(-20, 18); } else { bgRect.anchorMin = new Vector2(0.5f, 0); bgRect.anchorMax = new Vector2(0.5f, 1); bgRect.sizeDelta = new Vector2(18, -20); } } GameObject glass = new GameObject("Glass"); GameObjectUtility.SetParentAndAlign(glass, parent); DontTouchImage image = glass.AddComponent <DontTouchImage>(); image.color = new Color(1, 1, 1, 0.75f); image.sprite = (Sprite)AssetDatabase.LoadAssetAtPath(!horizontal ? CursorSpritePath : CursorRotateSpritePath, typeof(Sprite)); image.type = Image.Type.Sliced; RectTransform rect = glass.GetComponent <RectTransform>(); if (!horizontal) { rect.anchorMin = new Vector2(0, 0.5f); rect.anchorMax = new Vector2(1, 0.5f); rect.sizeDelta = new Vector2(-20, 20); } else { rect.anchorMin = new Vector2(0.5f, 0); rect.anchorMax = new Vector2(0.5f, 1); rect.sizeDelta = new Vector2(20, -22); } if (zoom) { Mask glassMask = glass.AddComponent <Mask>(); glassMask.showMaskGraphic = true; } return(glass); }
static public void AddFrame(GameObject parent) { GameObject frame = new GameObject("Frame"); GameObjectUtility.SetParentAndAlign(frame, parent); DontTouchImage image = frame.AddComponent <DontTouchImage>(); image.fillCenter = false; image.sprite = (Sprite)AssetDatabase.LoadAssetAtPath(FrameSpritePath, typeof(Sprite)); image.type = Image.Type.Sliced; RectTransform rect = frame.GetComponent <RectTransform>(); rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.one; rect.pivot = new Vector2(0.5f, 0.5f); rect.sizeDelta = Vector2.zero; }