예제 #1
0
        //********初期化********//
        public virtual void Init(AdvGraphicLayer layer, AdvGraphicInfo graphic)
        {
            this.layer         = layer;
            this.rectTransform = this.transform as RectTransform;
            this.rectTransform.SetStretch();

            if (graphic.RenderTextureSetting.EnableRenderTexture)
            {
                InitRenderTextureImage(graphic);
            }
            else
            {
                GameObject child = this.transform.AddChildGameObject(graphic.Key);
                this.TargetObject = this.RenderObject = child.AddComponent(graphic.GetComponentType()) as AdvGraphicBase;
                this.TargetObject.Init(this);
            }

            //リップシンクのキャラクターラベルを設定
            LipSynchBase lipSync = TargetObject.GetComponentInChildren <LipSynchBase>();

            if (lipSync != null)
            {
                lipSync.CharacterLabel = this.gameObject.name;
                lipSync.OnCheckTextLipSync.AddListener(
                    (x) =>
                {
                    x.EnableTextLipSync = (x.CharacterLabel == Engine.Page.CharacterLabel && Engine.Page.IsSendChar);
                });
            }

            this.FadeTimer   = this.gameObject.AddComponent <Timer>();
            this.effectColor = this.GetComponentCreateIfMissing <AdvEffectColor>();
            this.effectColor.OnValueChanged.AddListener(RenderObject.OnEffectColorsChange);
        }
예제 #2
0
        /// <summary>
        /// 拷贝指引的目标控件
        /// </summary>
        public void CopyTargetObj()
        {
            if (TargetObject == null)
            {
                return;
            }

            CopyObj = UnityEngine.GameObject.Instantiate(TargetObject) as GameObject;


            var toggle = CopyObj.GetComponent <Toggle>();

            if (toggle != null)
            {
                toggle.group = null;
            }

            CopyTrans = CopyObj.transform;

            // 需要特殊处理的MonoBehaviour
            var spec_list = SGameEngine.Pool <MonoBehaviour> .List.New();

            // 把非UI控件的MonoBehaviour销毁掉
            var remove_list = SGameEngine.Pool <MonoBehaviour> .List.New();

            var db_guide_copy_behavior = DBManager.Instance.GetDB <DBGuideCopyBehavior>();

            foreach (var com in CopyObj.GetComponentsInChildren <MonoBehaviour>(true))
            {
                // 处理特殊的组件
                TargetModelInfo target_model_info = com as TargetModelInfo;
                if (target_model_info != null)
                {
                    spec_list.Add(target_model_info);
                    continue;
                }

                // 因为UIItemNewSlot采用了延迟加载图标,直接拷贝会图标丢失,需要把UIItemNewSlot也拷贝进来并进行加载工作
                UIItemNewSlot slot = com as UIItemNewSlot;
                if (slot != null)
                {
                    UIItemNewSlot source_slot = TargetObject.GetComponentInChildren <UIItemNewSlot>();

                    if (source_slot != null)
                    {
                        slot.ItemInfo = source_slot.ItemInfo;
                        slot.SetUI();
                        if (slot.ItemInfo != null && GoodsHelper.GetGoodsType(slot.ItemInfo.type_idx) == GameConst.GIVE_TYPE_SOUL)
                        {
                            slot.CanShowCircleBkg = true;
                            slot.SetColor(false);
                            slot.SetBgImageVisiable(false);
                            slot.SetEffectRootVisiable(false);
                        }
                    }

                    continue;
                }

                // ui控件的基类
                if (com == null || com is ICanvasElement || com is Selectable)
                {
                    continue;
                }

                // 其他需要添加的组件
                string class_name = com.GetType().Name;
                if (db_guide_copy_behavior.ContainType(class_name))
                {
                    continue;
                }

                //有Alpha渐变时直接设为不透明
                TweenAlpha tween = com as TweenAlpha;
                if (tween != null)
                {
                    tween.value = 1;
                }

                // 剩余的组件添加到remove_list
                remove_list.Add(com);
            }

            for (int i = remove_list.Count - 1; i >= 0; i--)
            {
                //包含序列帧特效的GameObject直接删掉,因为有特效重叠不同步的问题,物品除外
                if (remove_list[i] is UGUIFrameAnimation)
                {
                    if (remove_list[i].transform.parent != null && remove_list[i].transform.parent.parent != null)
                    {
                        if (remove_list[i].transform.parent.parent.GetComponent <UIItemNewSlot>() == null)
                        {
                            UnityEngine.Object.DestroyImmediate(remove_list[i].gameObject);
                        }
                    }
                }
                else
                {
                    UnityEngine.Object.DestroyImmediate(remove_list[i]);
                }
            }
            SGameEngine.Pool <MonoBehaviour> .List.Free(remove_list);

            var canvas = CopyObj.GetComponent <Canvas>();

            if (canvas != null)
            {
                UnityEngine.Object.DestroyImmediate(canvas);
            }

            CopyObj.SetActive(false);
            CopyTrans.SetParent(Wnd.TargetTmpRoot);

            var local_pos = CopyTrans.localPosition;

            local_pos.z             = 0f;
            CopyTrans.localPosition = local_pos;
            RectTransform copy_trans   = CopyTrans.GetComponent <RectTransform>();
            RectTransform traget_trans = TargetObject.GetComponent <RectTransform>();

            UGUIMath.SetWidgetSize(copy_trans, traget_trans);
            CopyObj.SetActive(true);

            // 可能traget_trans的父亲节点有缩放
            var rect_corner = new Vector3[4];

            copy_trans.GetWorldCorners(rect_corner);
            float copy_rect_size_x = rect_corner[2].x - rect_corner[0].x;

            traget_trans.GetWorldCorners(rect_corner);
            float target_size_x = rect_corner[2].x - rect_corner[0].x;

            float scale = 1;

            if (copy_rect_size_x != 0)
            {
                scale = target_size_x / copy_rect_size_x;
            }
            Vector3 ori_scale = CopyTrans.localScale;

            CopyTrans.localScale = new Vector3(ori_scale.x * scale, ori_scale.y * scale, ori_scale.z * scale);

            for (int i = spec_list.Count - 1; i >= 0; i--)
            {
                var com = spec_list[i];

                //StartLoadModel 函数中播放模型动作在object隐藏时会不生效,需延后调用
                TargetModelInfo target_model_info = com as TargetModelInfo;
                if (target_model_info != null)
                {
                    target_model_info.StartLoadModel();
                }
            }

            SGameEngine.Pool <MonoBehaviour> .List.Free(spec_list);
        }