Esempio n. 1
0
        public static UIPartActionSubtypeSelector CreatePrefab()
        {
            GameObject partActionVariantSelectorPrefabGameObject = UIPartActionController.Instance.fieldPrefabs.OfType <UIPartActionVariantSelector>().FirstOrDefault()?.gameObject;

            if (partActionVariantSelectorPrefabGameObject.IsNull())
            {
                throw new Exception("Could not find FieldVariantSelector prefab");
            }

            GameObject partActionSubtypeSelectorGameObject = Instantiate(partActionVariantSelectorPrefabGameObject);

            DontDestroyOnLoad(partActionSubtypeSelectorGameObject);

            UIPartActionVariantSelector partActionVariantSelector = partActionSubtypeSelectorGameObject.GetComponent <UIPartActionVariantSelector>();
            UIPartActionSubtypeSelector partActionSubtypeSelector = partActionSubtypeSelectorGameObject.AddComponent <UIPartActionSubtypeSelector>();

            partActionSubtypeSelector.buttonPrevious   = partActionVariantSelector.buttonPrevious;
            partActionSubtypeSelector.buttonNext       = partActionVariantSelector.buttonNext;
            partActionSubtypeSelector.scrollMain       = partActionVariantSelector.scrollMain;
            partActionSubtypeSelector.subtypeTitleText = partActionVariantSelector.variantName;
            partActionSubtypeSelector.buttonPreviousTooltipController = partActionSubtypeSelector.buttonPrevious.gameObject.AddComponent <TooltipController_TitleAndText>();
            partActionSubtypeSelector.buttonNextTooltipController     = partActionSubtypeSelector.buttonNext.gameObject.AddComponent <TooltipController_TitleAndText>();

            partActionSubtypeSelector.switcherDescriptionText = partActionSubtypeSelectorGameObject.GetChild("Label_Variants").GetComponent <TMPro.TextMeshProUGUI>();

            partActionSubtypeSelector.subtypeTitleText.alignment = TMPro.TextAlignmentOptions.Right;

            RectTransform switcherDescriptionRectTransform = (RectTransform)partActionSubtypeSelector.switcherDescriptionText.gameObject.transform;

            switcherDescriptionRectTransform.anchorMin        = new Vector2(0, 1);
            switcherDescriptionRectTransform.anchorMax        = new Vector2(0, 1);
            switcherDescriptionRectTransform.pivot            = new Vector2(0, 0.5f);
            switcherDescriptionRectTransform.anchoredPosition = new Vector2(0, -5);
            switcherDescriptionRectTransform.sizeDelta       += new Vector2(45, 0);

            RectTransform subypeTitleRectTransform = (RectTransform)partActionSubtypeSelector.subtypeTitleText.gameObject.transform;

            subypeTitleRectTransform.pivot            = new Vector2(1, 0.5f);
            subypeTitleRectTransform.anchoredPosition = new Vector2(0, -5);
            subypeTitleRectTransform.sizeDelta       -= new Vector2(20, 0);

            partActionSubtypeSelector.prefabVariantButton = UIPartActionSubtypeButton.CreatePrefab(partActionVariantSelector.prefabVariantButton);

            Destroy(partActionVariantSelector);

            return(partActionSubtypeSelector);
        }
Esempio n. 2
0
        private void Start()
        {
            if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight)
            {
                try
                {
                    UIPartActionSubtypeSelector.EnsurePrefab();
                }
                catch (Exception ex)
                {
                    FatalErrorHandler.HandleFatalError(ex);
                    Debug.LogException(ex);
                }
            }

            Destroy(gameObject);
        }
Esempio n. 3
0
        public static void EnsurePrefab()
        {
            if (UIPartActionController.Instance.IsNull())
            {
                throw new InvalidOperationException("UIPartActionController.Instance is null");
            }

            if (partActionSubtypeSelectorPrefab.IsNull())
            {
                partActionSubtypeSelectorPrefab = CreatePrefab();
            }
            else if (UIPartActionController.Instance.fieldPrefabs.Contains(partActionSubtypeSelectorPrefab))
            {
                return;
            }

            UIPartActionController.Instance.fieldPrefabs.Add(partActionSubtypeSelectorPrefab);
            Log.info("[UI.UIPartActionSubtypeSelector] added prefab to UIPartActionController");
        }