예제 #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))
            //{
            //	DemosUtil.ShowCouldNotExecuteCommandNotification(this);
            //	Debug.Log("OSA: Could not create ScrollView on the selected object: " + reasonIfNotValid);
            //	return;
            //}
            var        parentGO = Selection.gameObjects[0];
            GameObject go       = new GameObject("OSA", 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 = InitOSAWindow.Validate(false, scrollRect, false);             // checkForWindows=false, becase this windows is already opened
            if (!validationResult.isValid)
            {
                CWiz.ShowCouldNotExecuteCommandNotification(this);
                Debug.LogError("OSA: Unexpected internal error while trying to initialize. Details(next line):\n" + validationResult.reasonIfNotValid + "\n" + validationResult.ToString());
                return;
            }

            InitOSAWindow.Open(InitOSAWindow.Parameters.Create(validationResult, false, true, true, true));
        }
예제 #2
0
        static void OptimizeSelectedScrollRectWithOSA(MenuCommand command)
        {
            ScrollRect scrollRect       = (ScrollRect)command.context;
            var        validationResult = InitOSAWindow.Validate(true, scrollRect, false);

            // 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("OSA: Could not optimize '" + scrollRect.name + "': " + validationResult.reasonIfNotValid);
                return;
            }

            InitOSAWindow.Open(InitOSAWindow.Parameters.Create(validationResult, false, true, true, false));
        }
예제 #3
0
        static void CreateTableViewOSA(MenuCommand menuCommand)
        {
            if (CWiz.GetTypeFromAllAssemblies(CWiz.TV.TABLE_ADAPTER_INTERFACE_FULL_NAME) == null)
            {
                CWiz.ShowCouldNotExecuteCommandNotification(null);
                Debug.Log("OSA: Import the TableView.unitypackage first");
                return;
            }
#if OSA_TV_TMPRO
            if (Resources.Load <GameObject>(CWiz.TV.Paths.INPUT__FLOATING_DROPDOWN) == null)
            {
                CWiz.ShowCouldNotExecuteCommandNotification(null);
                Debug.Log("OSA: Found 'OSA_TV_TMPRO' scripting define, but package 'TMPro/TableViewTMProSupport.unitypackage' wasn't imported. Please import the package");
                return;
            }
#endif

            if (!CheckForCreateOSAViaWizard())
            {
                return;
            }

            var resPath  = CWiz.TV.Paths.SCROLL_VIEW;
            var tvPrefab = Resources.Load <GameObject>(resPath);
            var go       = UnityEngine.Object.Instantiate(tvPrefab);
            go.name = go.name.Replace("(Clone)", "");
            Canvas.ForceUpdateCanvases();

            // Register the creation in the undo system
            Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
            Selection.activeObject = go;
            GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);

            // Adding this just so the validation will pass, but we don't need it
            var scrollRect = go.AddComponent <ScrollRect>();
            scrollRect.horizontal = false;
            scrollRect.vertical   = true;
            scrollRect.viewport   = go.transform.Find("Viewport") as RectTransform;
            scrollRect.content    = scrollRect.viewport.Find("Content") as RectTransform;

            var validationResult = InitOSAWindow.Validate(true, scrollRect, true);
            // 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("OSA: Could not configure instantiated TableView '" + scrollRect.name + "': " + validationResult.reasonIfNotValid);
                return;
            }

            InitOSAWindow.Parameters p = InitOSAWindow.Parameters.Create(
                validationResult,
                true,
                false,
                false,
                true,
                false,
                CWiz.TV.IMPLEMENTATION_TEMPLATE_NAME,
                CWiz.GetTypeFromAllAssemblies(CWiz.TV.TABLE_ADAPTER_INTERFACE_FULL_NAME)
                );
            InitOSAWindow.Open(p);
        }
예제 #4
0
        public static bool Validate(bool forOpeningWindow, out string reasonIfNotValid)
        {
            if (!BaseValidate(out reasonIfNotValid))
            {
                return(false);
            }

            if (forOpeningWindow)
            {
                // Commented: it's safe to re-open the create window
                //if (IsOpen())
                //{
                //	reasonIfNotValid = "Creation window already opened";
                //	return false;
                //}
                if (InitOSAWindow.IsOpen())
                {
                    reasonIfNotValid = "Initialization window already opened";
                    return(false);
                }
            }

            if (Selection.gameObjects.Length != 1)
            {
                reasonIfNotValid = "One UI Game Object needs to be selected";
                return(false);
            }

            var asRT = Selection.gameObjects[0].transform as RectTransform;

            if (!asRT)
            {
                reasonIfNotValid = "The selected Game Object doesn't have a RectTransform component";
                return(false);
            }

            if (asRT.rect.height <= 0f)
            {
                reasonIfNotValid = "The selected Game Object has an invalid height";
                return(false);
            }

            if (asRT.rect.width <= 0f)
            {
                reasonIfNotValid = "The selected Game Object has an invalid width";
                return(false);
            }

            if (!GameObject.FindObjectOfType <EventSystem>())
            {
                reasonIfNotValid = "No EventSystem was found in the scene. Please add one";
                return(false);
            }

            reasonIfNotValid = null;
            var tr = asRT as Transform;

            while (tr)
            {
                if (!(tr is RectTransform))
                {
                    reasonIfNotValid =
                        "Found a non-RectTransform intermediary parent before first Canvas ancestor. " +
                        "Your hierarchy may be something like: ...Canvas->...->Transform->...-><SelectedObject>. " +
                        "There should only be RectTransforms between the selected object and its most close Canvas ancestor";
                    return(false);
                }

                var c = tr.GetComponent <Canvas>();
                if (c)
                {
                    return(true);
                }

                tr = tr.parent;
            }

            reasonIfNotValid = "Couldn't find a Canvas in the parents of the selected Game Object";
            return(false);
        }