Пример #1
0
        protected void Update()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                // Not allowed in play mode
                CWiz.ShowNotification("Cannot use OSA wizard during play mode", false, false);
                Close();
                return;
            }

            UpdateImplWithoutChecks();

            // Wait for scripts recompilation
            if (EditorApplication.isCompiling)
            {
                return;
            }

            // It's ok to delay the starting of updates until the gui resources are initialized, in order to have averything prepared
            if (_GUIResourcesInitialized)
            {
                UpdateImpl();
            }

            // SlowUpdate calling
            if (_CurrentFrameInSlowUpdateCycle % CWiz.SLOW_UPDATE_SKIPPED_FRAMES == 0)
            {
                _CurrentFrameInSlowUpdateCycle = 0;
                SlowUpdate();
            }
            else
            {
                ++_CurrentFrameInSlowUpdateCycle;
            }
        }
        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);             // 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));
        }
Пример #3
0
        static bool CheckForCreateOSAViaWizard()
        {
            string reasonIfNotValid;

            // Manually checking for validation, as this provides richer info about the case when creation is not possible
            if (!CreateOSAWindow.Validate(true, out reasonIfNotValid))
            {
                CWiz.ShowCouldNotExecuteCommandNotification(null);
                Debug.Log("OSA: Could not create ScrollView on the selected object: " + reasonIfNotValid);
                return(false);
            }

            return(true);
        }
Пример #4
0
        static void CreateOSA(MenuCommand menuCommand)
        {
            string reasonIfNotValid;

            // Manually checking for validation, as this provides richer info about the case when creation is not possible
            if (!CreateOSAWindow.Validate(true, out reasonIfNotValid))
            {
                CWiz.ShowCouldNotExecuteCommandNotification(null);
                Debug.Log("OSA: Could not create ScrollView on the selected object: " + reasonIfNotValid);
                return;
            }

            CreateOSAWindow.Open(new CreateOSAWindow.Parameters());
        }
Пример #5
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));
        }
Пример #6
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);
        }