internal static UIPartActionLabelImproved CreateTemplate(UIPartActionLabel oldLabel) { GameObject labelGo = (GameObject)Instantiate(oldLabel.gameObject); Destroy(labelGo.GetComponent <UIPartActionLabel>()); UIPartActionLabelImproved label = labelGo.AddTaggedComponent <UIPartActionLabelImproved>(); labelGo.SetActive(false); label.transform.parent = oldLabel.transform.parent; label.transform.localPosition = oldLabel.transform.localPosition; return(label); }
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; }