/// <summary> /// Show. /// </summary> public void Show() { if (mGameObject != null) { mGameObject.SetActive(true); if (mAnimator == null) { mAnimator = mGameObject.GetComponent <Animator>(); } if (mAnimator != null) { mAnimator.Play("Show"); } if (mButton == null) { mButton = mGameObject.GetComponent <MyUGUIButton>(); if (mButton == null) { mButton = mGameObject.AddComponent <MyUGUIButton>(); } } mButton.OnEventPointerClick.RemoveAllListeners(); mButton.OnEventPointerClick.AddListener(_OnClickClose); } }
/// <summary> /// Initialize. /// </summary> public void Initialize(GameObject gameObject) { mGameObject = gameObject; if (mGameObject != null) { GameObject tipsRoot = MyUtilities.FindObjectInFirstLayer(mGameObject, ELoadingType.Tips.ToString()); if (tipsRoot != null) { GameObject description = MyUtilities.FindObject(tipsRoot, "Description"); if (description != null) { mDescription = description.GetComponent <Text>(); } GameObject tips = MyUtilities.FindObject(tipsRoot, "Tips"); if (tips != null) { mTips = tips.GetComponent <Text>(); } GameObject cancel = MyUtilities.FindObject(tipsRoot, "ButtonCancel"); if (cancel != null) { mButtonCancel = cancel.GetComponent <MyUGUIButton>(); mButtonCancel.OnEventPointerClick.RemoveAllListeners(); mButtonCancel.OnEventPointerClick.AddListener(_OnClickCancel); } } } }
/// <summary> /// Create a template game object. /// </summary> public static GameObject CreateTemplate() { GameObject obj = new GameObject(PREFAB_NAME); #if UNITY_EDITOR Animator root_animator = obj.AddComponent <Animator>(); string[] paths = new string[] { "Assets/MyClasses", "Assets/Core/MyClasses", "Assets/Plugin/MyClasses", "Assets/Plugins/MyClasses", "Assets/Framework/MyClasses", "Assets/Frameworks/MyClasses" }; for (int i = 0; i < paths.Length; i++) { if (System.IO.File.Exists(paths[i] + "/Sources/Animations/my_animator_popup_overlay.controller")) { root_animator.runtimeAnimatorController = (RuntimeAnimatorController)UnityEditor.AssetDatabase.LoadAssetAtPath(paths[i] + "/Sources/Animations/my_animator_popup_overlay.controller", typeof(RuntimeAnimatorController)); Debug.LogError("[" + typeof(MyUGUIPopupOverlay).Name + "] CreateTemplate(): please setup \"my_animator_popup_overlay\" controller."); Debug.LogError("[" + typeof(MyUGUIPopupOverlay).Name + "] CreateTemplate(): mapping \"my_animation_popup_overlay_show\" motion for \"Show\" state."); Debug.LogError("[" + typeof(MyUGUIPopupOverlay).Name + "] CreateTemplate(): mapping \"my_animation_popup_overlay_hide\" motion for \"Hide\" state."); break; } } #endif RectTransform rect = obj.AddComponent <RectTransform>(); MyUtilities.Anchor(ref rect, MyUtilities.EAnchorPreset.DualStretch, MyUtilities.EAnchorPivot.MiddleCenter, Vector2.zero, Vector2.zero); obj.AddComponent <CanvasRenderer>(); Image image = obj.AddComponent <Image>(); image.color = new Color(0, 0, 0, 0.5f); image.raycastTarget = true; Button button = obj.AddComponent <Button>(); button.transition = Selectable.Transition.None; MyUGUIButton myButton = obj.AddComponent <MyUGUIButton>(); ColorBlock colorBlock = myButton.Button.colors; colorBlock.normalColor = Color.white; colorBlock.highlightedColor = Color.white; colorBlock.pressedColor = Color.white; colorBlock.disabledColor = Color.white; myButton.Button.colors = colorBlock; myButton.SoundResourcePath = string.Empty; myButton.PressAnimationType = MyUGUIButton.EAnimationType.None; myButton.ClickAnimationType = MyUGUIButton.EAnimationType.None; return(obj); }
/// <summary> /// OnEnable. /// </summary> void OnEnable() { mScript = (MyUGUIButton)target; mPressAnimationType = serializedObject.FindProperty("mPressAnimationType"); mPressAnimationScaleBy = serializedObject.FindProperty("mPressAnimationScaleBy"); mPressAnimationDelayTime = serializedObject.FindProperty("mPressAnimationDelayTime"); mPressAnimationDownDuration = serializedObject.FindProperty("mPressAnimationDownDuration"); mPressAnimationUpDuration = serializedObject.FindProperty("mPressAnimationUpDuration"); mPressAnimationUseExtraTouchZone = serializedObject.FindProperty("mPressAnimationUseExtraTouchZone"); mClickAnimationType = serializedObject.FindProperty("mClickAnimationType"); mClickAnimationScaleBy = serializedObject.FindProperty("mClickAnimationScaleBy"); mClickAnimationDelayTime = serializedObject.FindProperty("mClickAnimationDelayTime"); mClickAnimationDownDuration = serializedObject.FindProperty("mClickAnimationDownDuration"); mClickAnimationUpDuration = serializedObject.FindProperty("mClickAnimationUpDuration"); mClickSoundType = serializedObject.FindProperty("mClickSoundType"); mClickSoundResourcePath = serializedObject.FindProperty("mClickSoundResourcePath"); mClickSoundAudioClip = serializedObject.FindProperty("mClickSoundAudioClip"); mClickSoundDelayTime = serializedObject.FindProperty("mClickSoundDelayTime"); mClickSoundLocalVolume = serializedObject.FindProperty("mClickSoundLocalVolume"); mIsTriggerClickEventAfterAnimationComplete = serializedObject.FindProperty("mIsTriggerClickEventAfterAnimationComplete"); }
/// <summary> /// OnUGUIInit. /// </summary> public override void OnUGUIInit() { base.OnUGUIInit(); GameObject container = MyUtilities.FindObjectInAllLayers(GameObject, "Container"); mButtonLeft = MyUtilities.FindObjectInFirstLayer(container, "ButtonLeft").GetComponent <MyUGUIButton>(); mButtonRight = MyUtilities.FindObjectInFirstLayer(container, "ButtonRight").GetComponent <MyUGUIButton>(); GameObject title = MyUtilities.FindObjectInFirstLayer(container, "Title"); if (title != null) { mTitle = title.GetComponent <Text>(); #if USE_MY_UI_TMPRO if (mTitle == null) { mTitleTMPro = title.GetComponent <TextMeshProUGUI>(); } #endif } GameObject body = MyUtilities.FindObjectInFirstLayer(container, "Body"); if (body != null) { mBody = body.GetComponent <Text>(); #if USE_MY_UI_TMPRO if (mBody == null) { mBodyTMPro = body.GetComponent <TextMeshProUGUI>(); } #endif } GameObject close = MyUtilities.FindObjectInFirstLayer(container, "ButtonClose"); if (close != null) { mButtonClose = close.GetComponent <MyUGUIButton>(); } }