public void SetupDeviceFrame(eSafeAreaType _type)
    {
        // Get prefab name and path
        string prefabName = "TA Deco";
        string prefabPath = _type.ToString() + "/" + prefabName;

        // Make and setup deco game object
        GameObject prefab = Resources.Load(prefabPath) as GameObject;

        this.frameDeco = MonoBehaviour.Instantiate(prefab) as GameObject;
        frameDeco.name = prefabName;

        RectTransform frameDecoRectTransform = frameDeco.GetComponent <RectTransform>();

        frameDecoRectTransform.SetParent(this.transform);

        frameDecoRectTransform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
        frameDecoRectTransform.offsetMin  = new Vector2(0.0f, 0.0f);
        frameDecoRectTransform.offsetMax  = new Vector2(0.0f, 0.0f);

        // Setup Scale (because canvas base scale)
        Vector3 scaleFactor = this.GetComponent <RectTransform>().localScale;

        foreach (Transform tr in frameDeco.transform)
        {
            RectTransform temp = tr.GetComponent <RectTransform>();
            temp.localScale = new Vector3(temp.localScale.x / scaleFactor.x, temp.localScale.y / scaleFactor.y, temp.localScale.z / scaleFactor.z);
        }
    }
// =================================================================
//      Functions 4 Editor
// =================================================================
    public void ShowSafeAreaFrame(eSafeAreaType _type)
    {
        // Listing SafeArea Device
        if (_type == eSafeAreaType.IPHONE_X_TALL)
        {
            UpdateSafeArea(new Rect(0, 102, 1125, 2202), new Vector2(1125.0f, 2436.0f));
        }
        if (_type == eSafeAreaType.IPHONE_X_WIDE)
        {
            UpdateSafeArea(new Rect(132, 0, 2202, 1125), new Vector2(2436.0f, 1125.0f));
        }
    }
Esempio n. 3
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        SafeAreaController saController = target as SafeAreaController;

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Safe-Area Test in Editor");

        testType = (eSafeAreaType)EditorGUILayout.EnumPopup("Test Device Type:", testType);

        if (!saController.isSafeAreaOn)
        {
            if (GUILayout.Button("Show Safe-Area"))
            {
                if (saController)
                {
                    saController.ShowSafeAreaFrame(testType);
                    saController.SetupDeviceFrame(testType);
                    saController.isSafeAreaOn = true;
                }
            }
        }
        else
        {
            if (GUILayout.Button("Hide Safe-Area"))
            {
                if (saController)
                {
                    saController.HideSafeAreaFrame(testType);
                    saController.DeleteDeviceFrame();
                    saController.isSafeAreaOn = false;
                }
            }
        }

        EditorGUILayout.Space();
    }
 public void HideSafeAreaFrame(eSafeAreaType _type)
 {
     UpdateSafeArea(new Rect(0, 0, 1, 1), new Vector2(1, 1));
 }