示例#1
0
文件: AddNode.cs 项目: q8f13/BigMarch
        public override BlendData GetResult()
        {
            for (int i = 0; i < UpstreamList.Count; i++)
            {
                BlendData data = UpstreamList[i].GetResult();
                if (_cached == null)
                {
                    _cached = (BlendData)Activator.CreateInstance(data.GetType());
                }

                if (i == 0)
                {
                    _cached.CopyFrom(data);
                }
                else
                {
                    _cached.CaculateAdd(_cached, data);
                }
            }
            if (_cached == null)
            {
                throw new Exception("can not get blend data, upstream count is 0");
            }
            return(_cached);
        }
示例#2
0
        public override BlendData GetResult()
        {
            for (int i = 0; i < UpstreamList.Count; i++)
            {
                //如果循环到了最后一个,那么直接使用最后一个的结果。因为最后一个,之后,没有可以跟它混合的了。
                if (i == UpstreamList.Count - 1)
                {
                    BlendData data = UpstreamList[UpstreamList.Count - 1].Node.GetResult();
                    if (_cached == null)
                    {
                        _cached = (BlendData)Activator.CreateInstance(data.GetType());
                    }
                    _cached.CopyFrom(data);

                    return(_cached);
                }

                // 除了最后一个之外,都使用,当前的和下一个,做混合。
                Pair currentPair = UpstreamList[i];
                Pair nextPair    = UpstreamList[i + 1];

                if (BlendParameter >= currentPair.Threshold && BlendParameter < nextPair.Threshold)
                {
                    // lerp在 0~1之间。
                    float lerp = (BlendParameter - currentPair.Threshold) /
                                 (nextPair.Threshold - currentPair.Threshold);

                    BlendData currentBlendData = currentPair.Node.GetResult();
                    BlendData nextBlendData    = nextPair.Node.GetResult();
                    if (_cached == null)
                    {
                        _cached = (BlendData)Activator.CreateInstance(currentBlendData.GetType());
                    }
                    _cached.CaculateLerp(currentBlendData, nextBlendData, lerp);
                    return(_cached);
                }
            }
            throw new Exception(string.Format("can not get blend data, current weight{0}", BlendParameter));
        }