예제 #1
0
 private void Validate()
 {
     if (!ValueUtility.IsSupportDistance <TValue>())
     {
         throw new System.NotImplementedException($"distance operation must be implemented for type {typeof(TValue)}");
     }
 }
예제 #2
0
 public bool NextSeq()
 {
     if (seqIndex >= values.Count - 2)
     {
         return(false);
     }
     seqIndex++;
     seqStartDis = seqEndDis;
     seqEndDis   = seqStartDis + ValueUtility.Distance(seqFrom, seqTo);
     return(true);
 }
예제 #3
0
 public bool PreSeq()
 {
     if (seqIndex == 0)
     {
         return(false);
     }
     seqIndex--;
     seqEndDis   = seqStartDis;
     seqStartDis = seqEndDis - ValueUtility.Distance(seqFrom, seqTo);
     return(true);
 }
예제 #4
0
            private static void OnStart(ref State state)
            {
                state.seqIndex    = 0;
                state.seqStartDis = 0;
                state.seqEndDis   = state.seqStartDis + ValueUtility.Distance(state.seqFrom, state.seqTo);
                var totalDis = 0f;

                for (var index = 0; index < state.values.Count - 1; index++)
                {
                    totalDis += ValueUtility.Distance(state.values[index], state.values[index + 1]);
                }
                state.totalDis = totalDis;
            }
예제 #5
0
 /// <summary>
 /// 创建一个属性,代表与目标对象的距离. 其中TValue必须支持距离运算符
 /// </summary>
 public static PropertyAccesser <TObject, float> Distance <TObject, TValue>(TObject target, PropertyAccesser <TObject, TValue> property)
 {
     return(new PropertyAccesser <TObject, float>(
                setter: (source, value) => {
         var from = property.Get(source);
         var to = property.Get(target);
         var dis = ValueUtility.Distance(from, to);
         var resultValue = ValueUtility.Lerp(from, to, 1 - value / dis);
         property.Set(source, resultValue);
     },
                getter: (source) => {
         var from = property.Get(source);
         var to = property.Get(target);
         return ValueUtility.Distance(from, to);
     }
                ));
 }
예제 #6
0
            private static void OnUpdate(ActionState actionState, ref State state)
            {
                var targetDis = state.totalDis * actionState.interpolatedTime;

                while (targetDis > state.seqEndDis)
                {
                    if (!state.NextSeq())
                    {
                        break;
                    }
                }
                while (targetDis < state.seqStartDis)
                {
                    if (!state.PreSeq())
                    {
                        break;
                    }
                }
                var t     = (targetDis - state.seqStartDis) / (state.seqEndDis - state.seqStartDis);
                var value = ValueUtility.Lerp(state.seqFrom, state.seqTo, t);

                state.property.UnsafeSet(state.target, value);
            }
예제 #7
0
파일: By.cs 프로젝트: wlgys8/UniTweenAsync
            private static void OnUpdate(ActionState actionState, ref State state)
            {
                var value = ValueUtility.Lerp(state.from, state.to, actionState.interpolatedTime);

                state.property.UnsafeSet(state.target, value);
            }
예제 #8
0
파일: By.cs 프로젝트: wlgys8/UniTweenAsync
 private static void OnStart(ref State state)
 {
     state.from = state.property.UnsafeGet(state.target);
     state.to   = ValueUtility.Add(state.from, state.delta);
 }