Unity3d Highlighting System v4.2.1插件的使用(PS:5.0新功能)

4.2.1

1. 改变点击的颜色设置,不使用它自带的基本点击色

 private bool isok = true;

 if (Input.GetButtonDown(buttonFire1))
            {
                if (!targetTransform.GetComponent<HighlighterFlashing>())
                    targetTransform.gameObject.AddComponent<HighlighterFlashing>();
                Highlighter ht = targetTransform.GetComponentInParent<Highlighter>();
                // ht.FlashingOn(new Color(1, 0, 0, 1), new Color(1, 0, 0, 1), 0);

            isok = !isok;
                if (isok)
                {
                    ht.FlashingOn();//重载,startcolor,endcolor, fre以及延迟
                }
                else
                {
                    ht.FlashingOff();
                }
            }

也可以直接在HighlighterFlashing这个脚本中直接修改初始的颜色值,

2.    Highlighter ht = targetTransform.GetComponentInParent<Highlighter>();
         ht.FlashingOn(new Color(1, 0, 0, 1), new Color(1, 0, 0, 1), 0);

     当程序运行时,如果想修改初始的闪烁色值,这时修改HighlighterFlashing里的颜色值时是没有用的,只能修改脚本Highlighter 里的 ht.FlashingOn(new Color(1, 0, 0, 1), new Color(1, 0, 0, 1), 0);才能改变自身的闪烁的颜色

5.0

5.0版本的功能感觉更加完美和理解,更加一目了然,

下面修改了一点代码是相机RaycastController的点击颜色切换

 private Stack<Highlighter> OnMouseClickHighlihter = new Stack<Highlighter>();
        private void PerformRaycast(UpdateEvent currentEvent)
        {
            if (currentEvent != updateEvent) { return; }

            if (cam == null) { return; }

            if (onHover == null) { return; }
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }
            else
            { 
                RaycastHit hitInfo;

                // Create a ray from mouse coords
                Ray ray = cam.ScreenPointToRay(Input.mousePosition);

                // Targeting raycast
                if (Physics.Raycast(ray, out hitInfo, rayLength >= 0f ? rayLength : Mathf.Infinity, layerMask.value))
                {
                  
                    if (!hitInfo.collider.transform.GetComponent<Highlighter>())

                        hitInfo.collider.gameObject.AddComponent<Highlighter>().tweenGradient.SetKeys(new GradientColorKey[] {
                        new GradientColorKey { color=new Color(1,1,0),time=0.5f}, new GradientColorKey { color=new Color(0,1,0),time=1}}, new GradientAlphaKey[] {new GradientAlphaKey{alpha=255},new GradientAlphaKey{alpha=255,time=1f}
                        });
                    hitInfo.collider.transform.GetComponent<Highlighter>().overlay = true;
                    OnMouseEnterOrExit.OnMouseEnter(hitInfo.collider.gameObject);
                    if (Input.GetMouseButtonDown(0))
                    {
                       if (OnMouseClickHighlihter.Count != 0)
                        {
                            //Debug.Log("ssss");
                            for (int i = 0; i < OnMouseClickHighlihter.Count; i++)
                            {
                                if (OnMouseClickHighlihter.Peek())
                                {
                                    OnMouseClickHighlihter.Pop().GetComponent<Highlighter>().Off();
                                }
                            }
                        }
                        OnMouseClickHighlihter.Push(hitInfo.collider.transform.GetComponent<Highlighter>());
                    }
                    onHover.Invoke(hitInfo);
                }
            }
        }

//setkey设置颜色值以及区间值  ,overlay 开启时物体点击色能够渲染在相机最前面

hitInfo.collider.gameObject.AddComponent<Highlighter>().tweenGradient.SetKeys(new GradientColorKey[] {
                        new GradientColorKey { color=new Color(1,1,0),time=0.5f}, new GradientColorKey { color=new Color(0,1,0),time=1}}, new GradientAlphaKey[] {new GradientAlphaKey{alpha=255},new GradientAlphaKey{alpha=255,time=1f}
                        });
                    hitInfo.collider.transform.GetComponent<Highlighter>().overlay = true;

开启或者关闭颜色 highlighter.tween = !highlighter.tween;

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值