Пример #1
0
        public Blendspace1DNodeInputPort CreateInputPort(float threshold)
        {
            Blendspace1DNodeInputPort port = new Blendspace1DNodeInputPort  {
                Node = this, Index = InputPorts.Count, Threshold = threshold
            };

            Playable.SetInputCount(Playable.GetInputCount() + 1);

            InputPorts.Add(port);

            RecalculateWeights();

            return(port);
        }
Пример #2
0
        private void RecalculateWeights()
        {
            Blendspace1DNodeInputPort previousPort;
            Blendspace1DNodeInputPort currentPort = null;
            Blendspace1DNodeInputPort nextPort    = (Blendspace1DNodeInputPort)InputPorts[0];

            for (int i = 0; i < InputPorts.Count; i++)
            {
                previousPort = currentPort;
                currentPort  = nextPort;
                nextPort     = (Blendspace1DNodeInputPort)(i == InputPorts.Count - 1 ? null : InputPorts[i + 1]);

                float parameterDistance = Parameter - currentPort.Threshold;

                if (parameterDistance == 0f)
                {
                    InputPorts[i].Weight = 1f;
                    break;
                }
                else if (parameterDistance < 0f)
                {
                    if (i == 0)
                    {
                        InputPorts[i].Weight = 1f;
                        break;
                    }
                    else
                    {
                        float previousDistance = previousPort.Threshold - currentPort.Threshold;

                        if (previousDistance == 0f)
                        {
                            InputPorts[i].Weight = 0f;
                            continue;
                        }

                        InputPorts[i].Weight = 1f - Mathf.Min(1f, parameterDistance / previousDistance);
                    }
                }
                else
                {
                    if (i == InputPorts.Count - 1)
                    {
                        InputPorts[i].Weight = 1f;
                        break;
                    }
                    else
                    {
                        float nextDistance = nextPort.Threshold - currentPort.Threshold;

                        if (nextDistance == 0f)
                        {
                            InputPorts[i].Weight = 0f;
                            continue;
                        }

                        InputPorts[i].Weight = 1f - Mathf.Min(1f, parameterDistance / nextDistance);
                    }
                }
            }
        }