internal IEnumerator Register() { UIPartActionController controller; while ((controller = UIPartActionController.Instance) == null) { yield return(false); } FieldInfo typesField = (from fld in controller.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance) where fld.FieldType == typeof(List <Type>) select fld).First(); List <Type> fieldPrefabTypes; while ((fieldPrefabTypes = (List <Type>)typesField.GetValue(controller)) == null || fieldPrefabTypes.Count == 0 || !UIPartActionController.Instance.fieldPrefabs.Find(cls => cls.GetType() == typeof(UIPartActionFloatRange))) { yield return(false); } Debug.Log("[KAE] Registering field prefabs for version " + Assembly.GetExecutingAssembly().GetName().Version + (isLatestVersion?" (latest)":"")); // Register prefabs. This needs to be done for every version of the assembly. (the types might be called the same, but they aren't the same) controller.fieldPrefabs.Add(UIPartActionFloatEdit.CreateTemplate()); fieldPrefabTypes.Add(typeof(UI_FloatEdit)); controller.fieldPrefabs.Add(UIPartActionScaleEdit.CreateTemplate()); fieldPrefabTypes.Add(typeof(UI_ScaleEdit)); controller.fieldPrefabs.Add(UIPartActionChooseOption.CreateTemplate()); fieldPrefabTypes.Add(typeof(UI_ChooseOption)); // Register the label and resource editor fields. This should only be done by the most recent version. if (isLatestVersion && GameSceneFilter.AnyEditor.IsLoaded()) { int idx = controller.fieldPrefabs.FindIndex(item => item.GetType() == typeof(UIPartActionLabel)); controller.fieldPrefabs[idx] = UIPartActionLabelImproved.CreateTemplate((UIPartActionLabel)controller.fieldPrefabs[idx]); controller.resourceItemEditorPrefab = UIPartActionResourceEditorImproved.CreateTemplate(controller.resourceItemEditorPrefab); } isRunning = false; }
//private string selectedValue; public static UIPartActionChooseOption CreateTemplate() { // Create the control GameObject editGo = new GameObject("UIPartActionChooseOption", SystemUtils.VersionTaggedType(typeof(UIPartActionChooseOption))); UIPartActionChooseOption edit = editGo.GetTaggedComponent <UIPartActionChooseOption>(); editGo.SetActive(false); // TODO: since I don'type have access to EZE GUI, I'm copying out bits from other existing GUIs // if someone does have access, they could do this better although really it works pretty well. UIPartActionButton evtp = UIPartActionController.Instance.eventItemPrefab; GameObject srcTextGo = evtp.transform.Find("Text").gameObject; GameObject srcBackgroundGo = evtp.transform.Find("Background").gameObject; GameObject srcButtonGo = evtp.transform.Find("Btn").gameObject; UIPartActionFloatRange paFlt = (UIPartActionFloatRange)UIPartActionController.Instance.fieldPrefabs.Find(cls => cls.GetType() == typeof(UIPartActionFloatRange)); GameObject srcSliderGo = paFlt.transform.Find("Slider").gameObject; // Start building our control GameObject backgroundGo = (GameObject)Instantiate(srcBackgroundGo); backgroundGo.transform.parent = editGo.transform; GameObject sliderGo = (GameObject)Instantiate(srcSliderGo); sliderGo.transform.parent = editGo.transform; sliderGo.transform.localScale = new Vector3(0.81f, 1, 1); edit.slider = sliderGo.GetComponent <UIProgressSlider>(); edit.slider.ignoreDefault = true; GameObject fieldNameGo = (GameObject)Instantiate(srcTextGo); fieldNameGo.transform.parent = editGo.transform; fieldNameGo.transform.localPosition = new Vector3(24, -8, 0); edit.fieldName = fieldNameGo.GetComponent <SpriteText>(); GameObject incDownGo = (GameObject)Instantiate(srcButtonGo); incDownGo.transform.parent = edit.transform; incDownGo.transform.localScale = new Vector3(0.45f, 1.1f, 1f); incDownGo.transform.localPosition = new Vector3(11.5f, -9, 0); //>11 edit.incDown = incDownGo.GetComponent <UIButton>(); GameObject incDownLabelGo = (GameObject)Instantiate(srcTextGo); incDownLabelGo.transform.parent = editGo.transform; incDownLabelGo.transform.localPosition = new Vector3(5.5f, -7, 0); // <6 SpriteText incDownLabel = incDownLabelGo.GetComponent <SpriteText>(); incDownLabel.Text = "<<"; GameObject incUpGo = (GameObject)Instantiate(srcButtonGo); incUpGo.transform.parent = edit.transform; incUpGo.transform.localScale = new Vector3(0.45f, 1.1f, 1f); incUpGo.transform.localPosition = new Vector3(187.5f, -9, 0); // >187 edit.incUp = incUpGo.GetComponent <UIButton>(); GameObject incUpLabelGo = (GameObject)Instantiate(srcTextGo); incUpLabelGo.transform.parent = editGo.transform; incUpLabelGo.transform.localPosition = new Vector3(181.5f, -7, 0); //<182 SpriteText incUpLabel = incUpLabelGo.GetComponent <SpriteText>(); incUpLabel.Text = ">>"; return(edit); }