コード例 #1
0
        protected override void Update()
        {
            float deltaTime = this.IsAffectedByTimeScaling ? Time.deltaTime : Time.unscaledDeltaTime;

            if (this.IsFadeDelayRunning)
            {
                _fadeDelay -= deltaTime;
                if (_fadeDelay <= 0)
                {
                    _fadeDelay = null;
                    this.BeginFading();
                }
            }
            else if (this.IsFading)
            {
                _currentFadeTime += deltaTime;
                _alpha            = FlaiMath.Min(1, _currentFadeTime / this.CurrentFade.Time);
                _alpha            = this.IsFadingIn ? _alpha : (1 - _alpha);
                if (_currentFadeTime >= this.CurrentFade.Time)
                {
                    _currentFadeTime = 0;
                    this.OnFadeCompleted();
                }
            }
        }
コード例 #2
0
ファイル: Bag.cs プロジェクト: ly774508966/Flai.Unity
        // does this work right?
        public void TrimExcess()
        {
            if (this.Count >= this.Capacity * 0.9)
            {
                return;
            }

            int newCapacity = FlaiMath.Max(4, this.Count);

            Array.Resize(ref _items, newCapacity); // not 100% if works, but I think it does
        }
コード例 #3
0
            public T Interpolate(Snapshot <T> other, double currentTimeStamp)
            {
                Ensure.True(this.Timestamp <= other.Timestamp);
                if (FlaiMath.EqualsApproximately(this.Timestamp, other.Timestamp))
                {
                    return(this.Value);
                }

                return(this.Value.Interpolate(other.Value,
                                              (float)FlaiMath.Scale(currentTimeStamp, this.Timestamp, other.Timestamp, 0, 1)));
            }
コード例 #4
0
        public void AddLast(ref T value)
        {
            if (++_headIndex == _buffer.Length)
            {
                _headIndex = 0;
            }

            _buffer[_headIndex] = value;
            if (_size == _buffer.Length)
            {
                if (++_tailIndex == _buffer.Length)
                {
                    _tailIndex = 0;
                }
            }
            _size = FlaiMath.Min(_size + 1, _buffer.Length);
        }
コード例 #5
0
        private void Follow(float?delta = null)
        {
            float   deltaTime = delta ?? ((Time.deltaTime + Time.smoothDeltaTime) * 0.5f);
            Vector3 current   = this.Position;
            Vector3 target    = this.Target.GetPosition() + this.Offset;
            float   amount    = FlaiMath.Clamp(deltaTime * this.Power, 0, 1);

            if (this.X)
            {
                current.x = FlaiMath.Lerp(this.LerpType, current.x, target.x, amount);
            }

            if (this.Y)
            {
                current.y = FlaiMath.Lerp(this.LerpType, current.y, target.y, amount);
            }

            if (this.Z)
            {
                current.z = FlaiMath.Lerp(this.LerpType, current.z, target.z, amount);
            }

            this.Position = current;
        }
コード例 #6
0
        protected override void LateUpdate()
        {
            if (!this.IsRunningParameter.IsNullOrWhiteSpace())
            {
                this.Animator.SetBool(this.IsRunningParameter, this.Controller.IsOnGround && FlaiMath.Abs(this.Controller.Velocity.X) > 0.01f);
            }

            if (!this.IsOnGroundParameter.IsNullOrWhiteSpace())
            {
                this.Animator.SetBool(this.IsOnGroundParameter, this.Controller.IsOnGround);
            }

            if (!this.HorizontalVelocity.IsNullOrWhiteSpace())
            {
                this.Animator.SetFloat(this.HorizontalVelocity, this.Controller.Velocity.X);
            }

            if (!this.VerticalVelocity.IsNullOrWhiteSpace())
            {
                this.Animator.SetFloat(this.VerticalVelocity, this.Controller.Velocity.Y);
            }
        }
コード例 #7
0
 public void MoveRight()
 {
     _moveDirection = FlaiMath.Clamp(_moveDirection + 1, -1, 1);
 }
コード例 #8
0
 public void MoveLeft()
 {
     _moveDirection = FlaiMath.Clamp(_moveDirection - 1, -1, 1);
 }
コード例 #9
0
        protected virtual void SetGroundDirection()
        {
            int multiplier = (this.GroundDirection == VerticalDirection.Down) ? 1 : -1;

            this.Scale2D = new Vector2f(this.Scale2D.X, FlaiMath.Abs(this.Scale2D.Y) * multiplier);
        }
コード例 #10
0
 public static Color32 MultiplyAlpha(this Color32 color, float alpha)
 {
     return(new Color32(color.r, color.g, color.b, (byte)FlaiMath.Clamp(color.a * alpha, 0, 255)));
 }
コード例 #11
0
        public static bool GetDrawFunction(Type type, MemberReference memberReference, ShowInInspectorAttribute attribute, out DrawFunction drawFunction)
        {
            if (_drawFunctions.TryGetValue(type, out drawFunction))
            {
                return(true);
            }

            DrawFunctionGenerator generator;

            if (_drawFunctionGenerators.TryGetValue(type, out generator))
            {
                drawFunction = generator(memberReference, attribute);
                return(true);
            }

            if (type.IsEnum)
            {
                drawFunction = (n, v, o) => EditorGUILayout.EnumPopup(n, (Enum)v, o);
                return(true);
            }
            else if (typeof(UnityObject).IsAssignableFrom(type))
            {
                drawFunction = (n, v, o) => EditorGUILayout.ObjectField(n, (UnityObject)v, type, true, o);
                return(true);
            }
            else if (type.IsArray)
            {
                Type         elementType = type.GetElementType();
                DrawFunction elementDrawFunction;
                if (InternalPropertyDrawer.GetDrawFunction(elementType, out elementDrawFunction))
                {
                    drawFunction = (label, value, parameters) =>
                    {
                        const int IndentationAmount = 20;
                        Array     array             = (Array)value;

                        // draw the name of the array
                        EditorGUILayout.LabelField(label, EditorStyles.boldLabel);

                        // draw the length (and '+' & '-' buttons)
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(IndentationAmount);
                        int newLength = EditorGUILayout.IntField("Length", array.Length);
                        if (GUILayout.Button("+", GUILayout.Width(24)))
                        {
                            newLength++;
                        }
                        else if (GUILayout.Button("-", GUILayout.Width(24)))
                        {
                            newLength = FlaiMath.Max(0, newLength - 1);
                        }
                        EditorGUILayout.EndHorizontal();

                        // if the size has been changed, then update it
                        if (newLength != array.Length && newLength > 0)
                        {
                            Array newArray = (Array)Activator.CreateInstance(array.GetType(), newLength);
                            if (array.Length > 0)
                            {
                                for (int i = 0; i < newArray.Length; i++)
                                {
                                    var elementValue = (i >= array.Length) ? array.GetValue(array.Length - 1) : array.GetValue(i);
                                    newArray.SetValue(elementValue, i);
                                }
                            }

                            array = newArray;
                        }

                        // draw all the elements
                        for (int i = 0; i < array.Length; i++)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(IndentationAmount);
                            array.SetValue(elementDrawFunction("Element " + i, array.GetValue(i), null), i);
                            EditorGUILayout.EndHorizontal();
                        }

                        return(array);
                    };

                    return(true);
                }
            }

            return(false);
        }
コード例 #12
0
 private void OnGUI()
 {
     GUI.Label(new Rect(this.Position.X, this.Position.Y, 90, 20), "Current: " + FlaiMath.Round(1f / Time.unscaledDeltaTime).ToString());
     GUI.Label(new Rect(this.Position.X, this.Position.Y + 28, 90, 20), _avgFpsString);
 }