private void CalcSteering(long delta)
 {
     if (!_arrive)
     {
         float   passtime       = delta * 0.001f;
         float   maxSpeed       = model.speed * cpx.maxSpeed;
         Vector3 desireVelocity = (_destiny - _calcPos).normalized * maxSpeed - _steer.velocity;
         _steer.force += desireVelocity;
         VectorMath.Truncate(ref _steer.force, cpx.maxForce);
         _steer.force    /= cpx.mass;
         _steer.velocity += _steer.force * passtime;
         VectorMath.Truncate(ref _steer.velocity, maxSpeed);
         Vector3 v = _steer.velocity * passtime;
         _calcPos += v;
         _position = _calcPos;
         float lerp = (_calcPos - _start).magnitude / (_destiny - _start).magnitude;
         lerp        = lerp > 1 ? 1 : lerp;
         _position.y = _start.y + (_destiny.y - _start.y) * lerp;
         model.MoveTo(_position);
         model.orientation = VectorMath.CalcOrientation(_steer.velocity);
         if ((_calcPos - _destiny).magnitude < cpx.arriveThreshold)
         {
             _arrive = true;
         }
     }
     else if (_isLast)
     {
         _status = CompStatus.COMPLETE;
     }
 }
示例#2
0
            protected override void OnUpdate(long now)
            {
                float   delta    = (now - _prevUpdate) * 0.001f;
                float   max      = model.speed * cpx.maxSpeed * delta;
                Vector3 diff     = (_destiny - _position);
                Vector3 velocity = diff * cpx.elastic;

                VectorMath.Truncate(ref velocity, max);
                _position += velocity;
                model.MoveTo(_position);
                model.orientation = VectorMath.CalcOrientation(velocity);
                _prevUpdate       = now;
            }
            private void CalcElastic(long delta)
            {
                float   max      = model.speed * delta;
                Vector3 diff     = (_destiny - _position);
                Vector3 velocity = diff * cpx.lastElasity;

                VectorMath.Truncate(ref velocity, max);
                _position += velocity;
                model.MoveTo(_position);
                model.orientation = VectorMath.CalcOrientation(velocity);
                if (velocity.magnitude < 0.2f)
                {
                    _status = CompStatus.COMPLETE;
                }
            }
示例#4
0
        private IEnumerator Create()
        {
            string file;

            if (!AssetUtils.ParseFile(prefab, out file))
            {
                yield break;
            }
            IEnumerator e = AssetUtils.Load(AssetType.Prefab, file);

            while (e.MoveNext())
            {
                yield return(null);
            }
            e = AssetUtils.PickAsyn <GameObject>(AssetType.Prefab, file);
            while (e.MoveNext())
            {
                yield return(null);
            }
            GameObject p = AssetUtils.Pick <GameObject>(AssetType.Prefab, file);

            if (!p)
            {
                GlobalLogger.LogError(string.Format("prefab read error at {0}", file));
                yield break;
            }
            _model = GameObjectPool.Get(p, GameObjectPool.LifeMode.SceneLife);
            Transform t = _model.transform;

            t.SetParent(CanvasManager.sceneCanvas);
            t.position = from;
            _model.SetActive(true);
            Transform child  = t.GetChild(0);
            float     orient = VectorMath.CalcOrientation(to - from);

            t.eulerAngles = new Vector3(0, orient, 0);
            Text3D_Dll t3 = child.GetComponent <Text3D_Dll>();

            if (t3)
            {
                t3.text = text;
                e       = t3.DoAnimation();
                while (e.MoveNext())
                {
                    yield return(null);
                }
            }
        }