Ejemplo n.º 1
0
        protected override void OnSubmitClicked()
        {
            // Commented: this is already checked and if there's and error, the submit button is disabled
            //string reasonIfNotValid;
            //// Validate again, to make sure the hierarchy wasn't modified
            //if (!Validate(out reasonIfNotValid))
            //{
            //	C.ShowCouldNotExecuteCommandNotification(this);
            //	Debug.Log("SRIA: Could not create ScrollView on the selected object: " + reasonIfNotValid);
            //	return;
            //}
            var        parentGO = Selection.gameObjects[0];
            GameObject go       = new GameObject("SRIA", typeof(RectTransform));
            var        image    = go.AddComponent <Image>();
            var        c        = Color.white;

            c.a         = .13f;
            image.color = c;
            var scrollRect   = go.AddComponent <ScrollRect>();
            var scrollRectRT = scrollRect.transform as RectTransform;
            var parentRT     = parentGO.transform as RectTransform;

            scrollRectRT.anchorMin = new Vector2(Mathf.Clamp01(CWiz.SPACE_FOR_SCROLLBAR / parentRT.rect.width), Mathf.Clamp01(CWiz.SPACE_FOR_SCROLLBAR / parentRT.rect.height));
            scrollRectRT.anchorMax = Vector2.one - scrollRectRT.anchorMin;
            scrollRectRT.sizeDelta = Vector2.zero;

            GameObjectUtility.SetParentAndAlign(go, parentGO);
            var viewportRT = CreateRTAndSetParent("Viewport", go.transform);

            viewportRT.gameObject.AddComponent <Image>();
            viewportRT.gameObject.AddComponent <Mask>().showMaskGraphic = false;
            var contentRT = CreateRTAndSetParent("Content", viewportRT);

            scrollRect.content = contentRT;
#if SCROLLRECT_HAS_VIEWPORT
            scrollRect.viewport = viewportRT;
#endif
            Canvas.ForceUpdateCanvases();

            // Register the creation in the undo system
            Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
            Selection.activeObject = go;

            ConfigureScrollView(scrollRect, viewportRT);
            Close();

            var validationResult = InitSRIAWindow.Validate(false, scrollRect);             // checkForWindows=false, becase this windows is already opened
            if (!validationResult.isValid)
            {
                CWiz.ShowCouldNotExecuteCommandNotification(this);
                Debug.LogError("SRIA: Unexpected internal error while trying to initialize. Details(next line):\n" + validationResult.reasonIfNotValid + "\n" + validationResult.ToString());
                return;
            }

            InitSRIAWindow.Open(new InitSRIAWindow.Parameters(validationResult));
        }
Ejemplo n.º 2
0
        static void OptimizeSelectedScrollRectWithSRIA(MenuCommand command)
        {
            ScrollRect scrollRect       = (ScrollRect)command.context;
            var        validationResult = InitSRIAWindow.Validate(true, scrollRect);

            // Manually checking for validation, as this provides richer info about the case when initialization is not possible
            if (!validationResult.isValid)
            {
                CWiz.ShowCouldNotExecuteCommandNotification(null);
                Debug.Log("SRIA: Could not optimize '" + scrollRect.name + "': " + validationResult.reasonIfNotValid);
                return;
            }

            InitSRIAWindow.Open(new InitSRIAWindow.Parameters(validationResult));
        }