Beispiel #1
0
        private static void UpgradeAllTextObjects()
        {
            if (
                !EditorUtility.DisplayDialog(
                    "Upgrade All UI Text?",
                    string.Format(
                        "This option will scan your project for all {0} instances and replace them with {1} objects. " +
                        "All references to objects and serialized values will remain intact.",
                        typeof(UnityEngine.UI.Text).FullName, typeof(HyperText).FullName
                        ), "Yes", "No"
                    )
                )
            {
                return;
            }
            HyperText  ht     = new GameObject("DELETE THIS", typeof(HyperText)).GetComponent <HyperText>();
            MonoScript script = MonoScript.FromMonoBehaviour(ht);

            AssetDatabaseX.ModifyAllComponentsInProject <UnityEngine.UI.Text>(
                delegate(UnityEngine.UI.Text text, string assetPath)
            {
                if (text is HyperText)
                {
                    return;
                }
                SerializedObject so = new SerializedObject(text);
                so.FindProperty("m_Script").objectReferenceValue = script;
                so.ApplyModifiedProperties();
            }
                );
            if (ht != null)
            {
                Object.DestroyImmediate(ht.gameObject);
            }
        }
Beispiel #2
0
        private static void CleanUpQuads()
        {
#pragma warning disable 612
            AssetDatabaseX.ModifyAllComponentsInProject <HyperTextQuad>(
                (quad, assetPath) => Undo.DestroyObjectImmediate(quad), "Clean Up HyperText Quads in Prefabs"
                );
#pragma warning restore 612
        }
Beispiel #3
0
        private static void ValidateRaycastTargets()
        {
            if (
                !EditorUtility.DisplayDialog(
                    "Validate HyperText Raycast Targets?",
                    string.Format(
                        "This option will scan your project for all {0} instances that are children of {1} or {2} " +
                        "objects (such as e.g., Buttons) but also have the raycastTarget property enabled and have " +
                        "links defined. Links on these instances will block input events. Results will be logged to " +
                        "the console.\n\nDo you wish to proceed?",
                        typeof(HyperText).Name,
                        typeof(UnityEngine.EventSystems.IPointerClickHandler).Name,
                        typeof(UnityEngine.EventSystems.IPointerDownHandler).Name

                        ), "Yes", "No"
                    )
                )
            {
                return;
            }
            System.Type logEntries =
                ReflectionX.AllTypes.FirstOrDefault(t => t.FullName == "UnityEditorInternal.LogEntries");
            if (logEntries != null)
            {
                System.Reflection.MethodInfo clear = logEntries.GetStaticMethod("Clear");
                if (clear != null)
                {
                    clear.Invoke(null, null);
                }
            }
            bool isSilent = HyperText.IsSilent;

            HyperText.IsSilent = true;
            string undoName = "Validate HyperText Raycast Targets";

            System.Reflection.MethodInfo getWarningMessage =
                typeof(HyperText).GetInstanceMethod("GetInputBlockingWarningMessage");
            AssetDatabaseX.ModifyAssetCallback <HyperText> validateRaycastTarget =
                delegate(HyperText hyperText, string assetPath)
            {
                if (!hyperText.raycastTarget)
                {
                    return;
                }
#if UNITY_4_6 || UNITY_4_7
                s_ClickHandlers.Clear();
                s_DownHandlers.Clear();
                s_ClickHandlers.AddRange(
                    hyperText.GetComponentsInParent(
                        typeof(UnityEngine.EventSystems.IPointerClickHandler), true
                        ).Cast <UnityEngine.EventSystems.IPointerClickHandler>()
                    );
                s_DownHandlers.AddRange(
                    hyperText.GetComponentsInParent(
                        typeof(UnityEngine.EventSystems.IPointerDownHandler), true
                        ).Cast <UnityEngine.EventSystems.IPointerDownHandler>()
                    );
#else
                hyperText.GetComponentsInParent(true, s_ClickHandlers);
                hyperText.GetComponentsInParent(true, s_DownHandlers);
#endif
                s_ClickHandlers.Remove(hyperText);
                s_DownHandlers.Remove(hyperText);
                if (s_ClickHandlers.Count > 0 || s_DownHandlers.Count > 0)
                {
                    using (ListPool <HyperText.LinkInfo> .Scope links = new ListPool <HyperText.LinkInfo> .Scope())
                    {
                        if (hyperText.GetLinks(links.List) > 0)
                        {
                            string warningMessage = getWarningMessage.Invoke(hyperText, null) as string;
                            if (!string.IsNullOrEmpty(warningMessage))
                            {
                                Debug.LogWarning(
                                    string.Format(
                                        "{0}\n<b>{1}</b> at {2}\n", warningMessage, hyperText.name, assetPath
                                        ), hyperText
                                    );
                            }
                        }
                    }
                }
            };
            AssetDatabaseX.ModifyAllComponentsInProject(validateRaycastTarget, undoName);
            HyperText.IsSilent = isSilent;
        }