コード例 #1
0
 public static AniBoxCollider Lerp(AniBoxCollider left, AniBoxCollider right, float lerp)
 {
     AniBoxCollider m = new AniBoxCollider();
     m.mName = right.mName;
     m.mIndex = right.mIndex;
     m.mBoxType = right.mBoxType;
     m.mPosition = Vector3.Lerp(left.mPosition, right.mPosition, lerp);
     m.mSize = Vector3.Lerp(left.mSize, right.mSize, lerp);
     return m;
 }
コード例 #2
0
        void SetBoxAttribute(AniBoxCollider _box, GameObject _curBox = null)
        {
            if (_curBox != null)
            {
                _curBox.transform.localRotation = new Quaternion(0, 0, 0, 0);
            }
            _curBox.SetActive(true);
            //重新设置box的属性
            _curBox.gameObject.name = _box.mName;
            _curBox.layer           = LayerMask.NameToLayer(_box.mBoxType);
            //if (_curBox.transform.localPosition != _box.mPosition)
            //{
            _curBox.transform.localPosition = _box.mPosition;
            //}
            //计算scale
            var _colider = _curBox.GetComponent <BoxCollider>();

            _curBox.transform.localScale = new Vector3(_box.mSize.x / _colider.size.x, _box.mSize.y / _colider.size.y,
                                                       _box.mSize.z / _colider.size.z);


            if (IsShowBoxLine)
            {
                if (!_curBox.GetComponent <Collider_Vis>())
                {
                    _curBox.AddComponent <Collider_Vis>();
                }
                if (!_curBox.GetComponent <LineRenderer>())
                {
                    _curBox.AddComponent <LineRenderer>();
                }
                if (!_curBox.GetComponent <MeshRenderer>())
                {
                    _curBox.AddComponent <MeshRenderer>();
                }
                SetBoxColor(_curBox);

                //o.GetComponent<Collider_Vis>().updateColl();
            }
            else
            {
                if (_curBox.GetComponent <Collider_Vis>())
                {
                    DestroyImmediate(_curBox.GetComponent <Collider_Vis>());
                }
                if (_curBox.GetComponent <LineRenderer>())
                {
                    DestroyImmediate(_curBox.GetComponent <LineRenderer>());
                }
                if (_curBox.GetComponent <MeshRenderer>())
                {
                    DestroyImmediate(_curBox.GetComponent <MeshRenderer>());
                }
            }
        }
コード例 #3
0
        public static AniBoxCollider Lerp(AniBoxCollider left, AniBoxCollider right, float lerp)
        {
            AniBoxCollider m = new AniBoxCollider();

            m.mName     = right.mName;
            m.mIndex    = right.mIndex;
            m.mBoxType  = right.mBoxType;
            m.mPosition = Vector3.Lerp(left.mPosition, right.mPosition, lerp);
            m.mSize     = Vector3.Lerp(left.mSize, right.mSize, lerp);
            return(m);
        }
コード例 #4
0
        public void ResetBoxLerpFrameSegment(int frame)
        {
            //搜索开始与结束帧
            if (frames[frame].box_key)
            {
                return;
            }
            if (frame <= 0 || frame >= frames.Count - 1)
            {
                return;
            }

            int ibegin = frame;

            for (; ibegin >= 0; ibegin--)
            {
                if (frames[ibegin].box_key)
                {
                    break;
                }
            }
            if (ibegin == frame)
            {
                return;
            }
            int iend = frame;

            for (; iend < frames.Count; iend++)
            {
                if (frames[iend].box_key)
                {
                    break;
                }
            }
            if (iend == frame)
            {
                return;
            }
            //建立对位关系
            Dictionary <AniBoxCollider, AniBoxCollider> map = new Dictionary <AniBoxCollider, AniBoxCollider>();
            var leftlist  = frames[ibegin].boxesinfo;
            var rightlist = frames[iend].boxesinfo;

            for (int i = 0; i < leftlist.Count; i++)
            {
                //对位
                AniBoxCollider boxcollider = rightlist.Find(b => b.mIndex == leftlist[i].mIndex && b.mBoxType == leftlist[i].mBoxType);
                //
                map.Add(leftlist[i], boxcollider);
            }
            //找到两个Box关键帧之间插值
            for (int i = ibegin + 1; i < iend; i++)
            {
                float d1   = (i - ibegin);
                float d2   = (iend - i);
                float lerp = d1 / (d1 + d2);
                List <AniBoxCollider> colliderList = new List <AniBoxCollider>();
                foreach (var b in map.Keys)
                {
                    if (map[b] == null)
                    {
                        colliderList.Add(b);
                        continue;
                    }
                    else
                    {
                        colliderList.Add(AniBoxCollider.Lerp(b, map[b], lerp));
                    }
                }
                frames[i].boxesinfo = new List <AniBoxCollider>(colliderList);
            }
        }