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; }
public static UIPartActionScaleEdit CreateTemplate() { // Create the control GameObject editGo = new GameObject("UIPartActionScaleEdit", SystemUtils.VersionTaggedType(typeof(UIPartActionScaleEdit))); UIPartActionScaleEdit edit = editGo.GetTaggedComponent <UIPartActionScaleEdit>(); 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.65f, 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(40, -8, 0); edit.fieldName = fieldNameGo.GetComponent <SpriteText>(); GameObject fieldValueGo = (GameObject)Instantiate(srcTextGo); fieldValueGo.transform.parent = editGo.transform; fieldValueGo.transform.localPosition = new Vector3(110, -8, 0); edit.fieldValue = fieldValueGo.GetComponent <SpriteText>(); GameObject incLargeDownGo = (GameObject)Instantiate(srcButtonGo); incLargeDownGo.transform.parent = edit.transform; incLargeDownGo.transform.localScale = new Vector3(0.45f, 1.1f, 1f); incLargeDownGo.transform.localPosition = new Vector3(11.5f, -9, 0); //>11 edit.incLargeDown = incLargeDownGo.GetComponent <UIButton>(); GameObject incLargeDownLabelGo = (GameObject)Instantiate(srcTextGo); incLargeDownLabelGo.transform.parent = editGo.transform; incLargeDownLabelGo.transform.localPosition = new Vector3(5.5f, -7, 0); // <6 edit.incLargeDownLabel = incLargeDownLabelGo.GetComponent <SpriteText>(); edit.incLargeDownLabel.Text = "<<"; GameObject incLargeUpGo = (GameObject)Instantiate(srcButtonGo); incLargeUpGo.transform.parent = edit.transform; incLargeUpGo.transform.localScale = new Vector3(0.45f, 1.1f, 1f); incLargeUpGo.transform.localPosition = new Vector3(187.5f, -9, 0); // >187 edit.incLargeUp = incLargeUpGo.GetComponent <UIButton>(); GameObject incLargeUpLabelGo = (GameObject)Instantiate(srcTextGo); incLargeUpLabelGo.transform.parent = editGo.transform; incLargeUpLabelGo.transform.localPosition = new Vector3(181.5f, -7, 0); //<182 edit.incLargeUpLabel = incLargeUpLabelGo.GetComponent <SpriteText>(); edit.incLargeUpLabel.Text = ">>"; return(edit); }