예제 #1
0
        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;
        }
        internal static UIPartActionResourceEditorImproved CreateTemplate(UIPartActionResourceEditor oldEditor)
        {
            GameObject editGo = (GameObject)Instantiate(oldEditor.gameObject);

            Destroy(editGo.GetComponent <UIPartActionResourceEditor>());
            UIPartActionResourceEditorImproved edit = editGo.AddTaggedComponent <UIPartActionResourceEditorImproved>();

            editGo.SetActive(false);
            edit.transform.parent        = oldEditor.transform.parent;
            edit.transform.localPosition = oldEditor.transform.localPosition;

            // Find all the bits.
            edit.slider       = editGo.transform.Find("Slider").GetComponent <UIProgressSlider>();
            edit.resourceAmnt = editGo.transform.Find("amnt").GetComponent <SpriteText>();
            edit.resourceName = editGo.transform.Find("name").GetComponent <SpriteText>();
            edit.resourceMax  = editGo.transform.Find("total").GetComponent <SpriteText>();
            edit.flowBtn      = editGo.transform.Find("StateBtn").GetComponent <UIStateToggleBtn>();

            return(edit);
        }