public override void update(float t)
        {
            float newT = 0;

            if (FloatUtils.EQ(t, 0) || FloatUtils.EQ(t, 1))
            {
                newT = t;
            }

            else
            {
                float s = _period / 4;
                t    = t - 1;
                newT = -Mathf.Pow(2, 10 * t) * Mathf.Sin((t - s) * (Mathf.PI * 2) / _period);
            }
            _inner.update(newT);
        }
        public override void update(float t)
        {
            // prevents rouding errors
            if (!FloatUtils.EQ(t, 1) && !FloatUtils.EQ(t, 0))
            {
                t *= 2;
                if (FloatUtils.Small(t, 1))
                {
                    t = 0.5f * Mathf.Pow(2, 10 * (t - 1));
                }
                else
                {
                    t = 0.5f * (-Mathf.Pow(2, -10 * (t - 1)) + 2);
                }
            }

            _inner.update(t);
        }
Exemplo n.º 3
0
        protected float bounceTime(float t)
        {
            if (FloatUtils.Small(t, 1 / 2.75f))
            {
                return(7.5625f * t * t);
            }
            else if (FloatUtils.Small(t, 2 / 2.75f))
            {
                t -= 1.5f / 2.75f;
                return(7.5625f * t * t + 0.75f);
            }
            else if (FloatUtils.Small(t, 2.5f / 2.75f))
            {
                t -= 2.25f / 2.75f;
                return(7.5625f * t * t + 0.9375f);
            }

            t -= 2.625f / 2.75f;
            return(7.5625f * t * t + 0.984375f);
        }
Exemplo n.º 4
0
        public static CGAffineTransform Invert(CGAffineTransform xform)
        {
            CGAffineTransform result;
            float             determinant;

            determinant = xform.a * xform.d - xform.c * xform.b;
            if (FloatUtils.EQ(determinant, 0))
            {
                return(xform);
            }

            result.a  = xform.d / determinant;
            result.b  = -xform.b / determinant;
            result.c  = -xform.c / determinant;
            result.d  = xform.a / determinant;
            result.tx = (-xform.d * xform.tx + xform.c * xform.ty) / determinant;
            result.ty = (xform.b * xform.tx - xform.a * xform.ty) / determinant;

            return(result);
        }
Exemplo n.º 5
0
        // Needed for BridgeSupport
        public override void update(float t)
        {
            if (FloatUtils.Small(t, 0.5f))
            {
                t = Mathf.Pow(t * _intersetValue, _polynomialOrder);
            }
            else
            {
                if (_hasInflection)
                {
                    t = Mathf.Pow((t - 1.0f) * _intersetValue, _polynomialOrder) + 1.0f;
                }
                else
                {
                    t = -Mathf.Pow((t - 1.0f) * _intersetValue, _polynomialOrder) + 1.0f;
                }
            }

            _inner.update(t);
        }
Exemplo n.º 6
0
        public override void update(float t)
        {
            float newT;

            // prevents possible rounding errors
            if (FloatUtils.EQ(t, 0) || FloatUtils.EQ(t, 1))
            {
                newT = t;
            }
            else if (FloatUtils.Small(t, 0.5f))
            {
                t    = t * 2;
                newT = (1 - bounceTime(1 - t)) * 0.5f;
            }
            else
            {
                newT = bounceTime(t * 2 - 1) * 0.5f + 0.5f;
            }

            _inner.update(newT);
        }
        public void playAnimation(string anmName, int start)
        {
            NSUtils.Assert(start >= 0, "{0}#playAnimation start frame should not be {1}.", GetType().Name, start);
            AnimationClip clip = getAnimationClip(anmName);

            NSUtils.Assert(clip != null, "{0}#playAnimation {1} not found.", GetType().Name, anmName);
            int totalFrames = getTotalFrames(anmName);

            NSUtils.Assert(start < totalFrames, "{0}#playAnimation start frame {1} should not bigger than {2}.", GetType().Name, start, totalFrames);

            float startTime = Mathf.Clamp01(1f * start / totalFrames);

            if (FloatUtils.ES(_transitionDuration, 0))
            {
                _fbxAnimator.Play(anmName, 0, startTime);
            }
            else
            {
                _fbxAnimator.CrossFadeInFixedTime(anmName, _transitionDuration, 0, startTime * clip.length);
            }
        }
Exemplo n.º 8
0
        public virtual void updateTransform()
        {
            if (_isUpdateTransformDirty)
            {
                //position
                Vector2 pInParentAR = _position;
                if (_parent != null)
                {
                    if (_parent.ignoreAnchorPointForPosition)
                    {
                        if (FloatUtils.NEQ(_parent.scaleX, 0) && FloatUtils.NEQ(_parent.scaleY, 0))
                        {
                            pInParentAR += new Vector2(_parent.anchorPointInPixels.x * (1 / _parent.scaleX - 1), _parent.anchorPointInPixels.y * (1 / _parent.scaleY - 1));
                        }
                    }
                    else
                    {
                        pInParentAR -= _parent.anchorPointInPixels;
                    }
                }
                Vector2 uPInParentAR = ccUtils.PixelsToUnits(pInParentAR);
                Vector3 pos          = transform.localPosition;
                pos.x = uPInParentAR.x;
                pos.y = uPInParentAR.y;
                pos.z = 0;
                transform.localPosition = pos;


                //rotation
                Vector3 rotation = calculateRotation();
                transform.localEulerAngles = Vector3.zero;
                transform.Rotate(rotation.x, 0, 0);
                transform.Rotate(0, rotation.y, 0);
                transform.Rotate(0, 0, rotation.z);

                //scale
                transform.localScale    = new Vector3(Mathf.Abs(_scaleX), Mathf.Abs(_scaleY), transform.localScale.z);
                _isUpdateTransformDirty = false;
            }
        }
Exemplo n.º 9
0
        // issue #80. Instead of hooking step:, hook update: since it can be called by any
        // container action like CCRepeat, CCSequence, CCEase, etc..
        public override void update(float dt)
        {
            if (FloatUtils.EB(dt, _nextDt))
            {
                while (FloatUtils.Big(dt, _nextDt) && _total < _times)
                {
                    _innerAction.update(1.0f);
                    _total++;

                    _innerAction.stop();
                    _innerAction.startWithTarget(_target);
                    _nextDt += _innerAction.duration / _duration;
                }

                // fix for issue #1288, incorrect end value of repeat
                if (FloatUtils.EB(dt, 1.0f) && _total < _times)
                {
                    _total++;
                }

                // don't set a instantaction back or update it, it has no use because it has no duration
                if (!_isActionInstant)
                {
                    if (_total == _times)
                    {
                        _innerAction.update(1);
                        _innerAction.stop();
                    }
                    else
                    {
                        // issue #390 prevent jerk, use right update
                        _innerAction.update(dt - (_nextDt - _innerAction.duration / _duration));
                    }
                }
            }
            else
            {
                _innerAction.update((dt * _times) % 1.0f);
            }
        }
        public void SendEvent(AnimationEvent evt)
        {
            if (_eventHandler != null)
            {
                AnimatorStateInfo evtInfo  = evt.animatorStateInfo;
                AnimatorStateInfo curInfo  = _animator.GetCurrentAnimatorStateInfo(0);
                AnimatorStateInfo nextInfo = _animator.GetNextAnimatorStateInfo(0);
                bool isInTransition        = _animator.IsInTransition(0);

                //skip previous events
                if (isInTransition)
                {
                    if (evtInfo.fullPathHash != nextInfo.fullPathHash)
                    {
                        return;
                    }

                    //skip previous events when curState == nextStateInfo and real time < evt time.
                    //it might has bug here
                    if (curInfo.fullPathHash == nextInfo.fullPathHash)
                    {
                        float evtSupposedTime = evt.time / evtInfo.length;
                        float evtRealTime     = (evtInfo.normalizedTime) % 1;
                        if (FloatUtils.Small(evtRealTime, evtSupposedTime))
                        {
                            return;
                        }
                    }
                }
                else
                {
                    if (evtInfo.fullPathHash != curInfo.fullPathHash)
                    {
                        return;
                    }
                }

                _eventHandler(evt);
            }
        }
Exemplo n.º 11
0
        public void initWithAction(CCActionFiniteTime one, CCActionFiniteTime two)
        {
            NSUtils.Assert(one != null && two != null, "Sequence: arguments must be non-nil");
            NSUtils.Assert(one != _one && one != _two, "Spawn: reinit using same parameters is not supported");
            NSUtils.Assert(two != _two && two != _one, "Spawn: reinit using same parameters is not supported");

            float d1 = one.duration;
            float d2 = two.duration;

            base.initWithDuration(Mathf.Max(d1, d2));
            _one = one;
            _two = two;

            if (FloatUtils.Big(d1, d2))
            {
                _two = CCSequence.Actions(two, new CCDelayTime(d1 - d2));
            }
            else if (d1 < d2)
            {
                _one = CCSequence.Actions(one, new CCDelayTime(d2 - d1));
            }
        }
 public override void update(float t)
 {
     _inner.update(FloatUtils.EQ(t, 1) ? 1 : (-Mathf.Pow(2, -10 * t / 1) + 1));
 }
 public override void update(float t)
 {
     _inner.update(FloatUtils.EQ(t, 0) ? 0 : Mathf.Pow(2, 10 * (t / 1 - 1)) /* - 1 * 0.001f */);
 }
Exemplo n.º 14
0
 /** returns YES if the action has finished */
 public override bool isDone()
 {
     return(FloatUtils.EB(_elapsed, _duration));
 }
Exemplo n.º 15
0
        public override void ccTouchMoved(UITouch touch)
        {
            if (scrollTouch_ != touch)
            {
                return;
            }

            Vector2 touchPoint = this.convertTouchToNodeSpace(touch);

            touchPoint = this.convertToWorldSpace(touchPoint);


            // If finger is dragged for more distance then minimum - start sliding and cancel pressed buttons.
            // Of course only if we not already in sliding mode
            if ((state_ != kCCScrollLayerState.Sliding) &&
                (Mathf.Abs(touchPoint.x - startSwipe_) >= this.minimumTouchLengthToSlide))
            {
                state_ = kCCScrollLayerState.Sliding;

                // Avoid jerk after state change.
                startSwipe_ = touchPoint.x;

                if (this.stealTouches)
                {
                    this.claimTouch(touch);
                }
                if (this.delegate_ != null)
                {
                    this.delegate_.scrollLayerDraging(this);
                }
            }

            if (state_ == kCCScrollLayerState.Sliding)
            {
                float desiredX = (-currentScreen_ * (this.contentSize.x - this.pagesWidthOffset)) + touchPoint.x - startSwipe_;
                int   page     = this.pageNumberForPosition(new Vector2(desiredX, 0));
                float offset   = desiredX - this.positionForPageWithNumber(page).x;
                if ((page == 0 && FloatUtils.Big(offset, 0)) || (page == layers_.Count - 1 && FloatUtils.Small(offset, 0)))
                {
                    offset -= marginOffset_ * offset / CCDirector.sharedDirector.winSize.x;
                }
                else
                {
                    offset = 0;
                }
                this.position = new Vector2(desiredX - offset, 0);
            }
        }
Exemplo n.º 16
0
        public static CCTMXMap Parse(string file, NSDictionary tilesetCaches = null)
        {
            string      text   = LoadText(file);
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(text);
            XmlNodeList nodeList = xmlDoc.DocumentElement.ChildNodes;

            // get mapWidth, mapHeight, tileWidth, tileHeight
            XmlNode mapNode = xmlDoc.DocumentElement;

            float version = float.Parse(mapNode.Attributes["version"].InnerText);

            if (!FloatUtils.EQ(version, 1.0f))
            {
                CCDebug.Warning("cocos2d:CCTMXMap: Found {0} tmx file, but only 1.0 version was tested.", version);
            }

            string dir = file.Replace(Path.GetFileName(file), "");

            CCTMXMap map = new CCTMXMap();

            map.fileName   = file;
            map.cols       = int.Parse(mapNode.Attributes["width"].InnerText);
            map.rows       = int.Parse(mapNode.Attributes["height"].InnerText);
            map.tileWidth  = int.Parse(mapNode.Attributes["tilewidth"].InnerText);
            map.tileHeight = int.Parse(mapNode.Attributes["tileheight"].InnerText);

            Dictionary <int, string> gidToFiles = new Dictionary <int, string> (256);
            Dictionary <int, Dictionary <string, string> > gidToTileProperties = new Dictionary <int, Dictionary <string, string> > (256);
            List <CCTMXLayer> layers = new List <CCTMXLayer> (8);


            var enumerator = nodeList.GetEnumerator();

            while (enumerator.MoveNext())
            {
                XmlNode nodeData = (XmlNode)enumerator.Current;
                if (nodeData.Name == "tileset")
                {
                    ParseTileset(nodeData, gidToFiles, gidToTileProperties, dir, tilesetCaches);
                }
                else if (nodeData.Name == "layer")
                {
                    CCTMXLayer layer = ParseLayer(nodeData, map.cols, map.rows, gidToFiles, gidToTileProperties);
                    layers.Add(layer);
                }
                else if (nodeData.Name == "objectgroup")
                {
                    CCTMXLayer layer = ParseObjectGroup(nodeData, map.cols, map.rows, map.tileWidth, map.tileHeight, gidToFiles, gidToTileProperties);
                    layers.Add(layer);
                }
                else if (nodeData.Name == "properties")
                {
                    if (map.properties == null)
                    {
                        map.properties = new Dictionary <string, string>();
                    }
                    ParseProperties(nodeData, map.properties);
                }
            }
            map.gidToFiles          = gidToFiles;
            map.gidToTileProperties = gidToTileProperties;
            map.layers = layers.ToArray();
            return(map);
        }
Exemplo n.º 17
0
        // Helper
        protected void updateTexture()
        {
            if (string.IsNullOrEmpty(_text))
            {
                _content.mesh.text = _text;
                return;
            }
            if (FloatUtils.EQ(_dimensions.x, 0))
            {
                _content.mesh.text = _text;
                Bounds  localBounds = getLocalbounds();
                Vector2 textSize    = ccUtils.UnitsToPixels(localBounds.size);
                this.contentSize = textSize;
            }
            else
            {
                StringBuilder finalText         = new StringBuilder();
                string        originalText      = _text;
                int           preEmptyCharIndex = -1;
                for (int i = 1; i <= originalText.Length; i++)
                {
                    char c = originalText[i - 1];
                    if (char.IsWhiteSpace(c))
                    {
                        preEmptyCharIndex = i - 1;
                    }
                    string tmpStr = originalText.Substring(0, i);
                    if (c == '\n')
                    {
                        finalText.Append(tmpStr);
                        originalText      = originalText.Substring(i);
                        i                 = 0;
                        preEmptyCharIndex = -1;
                    }

                    _content.mesh.text = tmpStr;
                    Bounds  localBounds = getLocalbounds();
                    Vector2 csize       = ccUtils.UnitsToPixels(localBounds.size);
                    if (FloatUtils.Big(csize.x, _dimensions.x))
                    {
                        if (preEmptyCharIndex == -1)
                        {
                            tmpStr = originalText.Substring(0, --i);
                        }
                        else
                        {
                            tmpStr            = originalText.Substring(0, preEmptyCharIndex);
                            i                 = preEmptyCharIndex + 1;
                            preEmptyCharIndex = -1;
                        }
                        finalText.Append(tmpStr);
                        if (i < originalText.Length)
                        {
                            finalText.Append("\n");
                            originalText = originalText.Substring(i);
                            i            = 0;
                        }
                    }
                    else if (i == originalText.Length)
                    {
                        tmpStr = originalText.Substring(0, i);
                        finalText.Append(tmpStr);
                        break;
                    }

//					string tmpStr = originalText.Substring(0, i);
//					_content.mesh.text = tmpStr;
//					Vector2 csize = _content.renderer.bounds.size;
//					csize = ccUtils.UnitsToPixels(csize);
//					if(FloatUtils.Small(csize.x , _dimensions.x) || i==1){
//						tmpStr = originalText.Substring(0, i);
//						finalText += tmpStr;
//						if(i<originalText.Length){
//							finalText += "\n";
//							originalText = originalText.Substring(i);
//							i = originalText.Length+1;
//						}else{
//							break;
//						}
//					}
                }
                _content.mesh.text = finalText.ToString();
                Bounds  bounds   = getLocalbounds();
                Vector2 textSize = ccUtils.UnitsToPixels(bounds.size);
                this.contentSize = textSize;
            }
            _isContentDirty = true;
        }
Exemplo n.º 18
0
 protected override CCAction reverseImpl()
 {
     return(new CCShake(this.duration, amplitude, dampening, FloatUtils.EQ(shakeInterval, 0) ? 0 : Mathf.RoundToInt(1 / shakeInterval)));
 }
Exemplo n.º 19
0
        public override void updateTransform()
        {
            if (_isUpdateTransformDirty)
            {
                //position
                Vector2 pInParentAR = _position;
                if (_parent != null)
                {
                    if (_parent.ignoreAnchorPointForPosition)
                    {
                        if (FloatUtils.NEQ(_parent.scaleX, 0) && FloatUtils.NEQ(_parent.scaleY, 0))
                        {
                            pInParentAR += new Vector2(_parent.anchorPointInPixels.x * (1 / _parent.scaleX - 1), _parent.anchorPointInPixels.y * (1 / _parent.scaleY - 1));
                        }
                    }
                    else
                    {
                        pInParentAR -= _parent.anchorPointInPixels;
                    }
                }
                Vector2 uPInParentAR = ccUtils.PixelsToUnits(pInParentAR);
                Vector3 pos          = transform.localPosition;
                pos.x = uPInParentAR.x;
                pos.y = uPInParentAR.y;
                pos.z = _positionZ / UIWindow.PIXEL_PER_UNIT;
                transform.localPosition = pos;

                //rotation
                transform.localPosition    = pos;
                transform.localEulerAngles = Vector3.zero;
                switch (_rotationSortingOrder)
                {
                case kRotationSortingOrder.XYZ:
                    transform.Rotate(-_rotationX, 0, 0);
                    transform.Rotate(0, -_rotationY, 0);
                    transform.Rotate(0, 0, -_rotation);
                    break;

                case kRotationSortingOrder.XZY:
                    transform.Rotate(-_rotationX, 0, 0);
                    transform.Rotate(0, 0, -_rotation);
                    transform.Rotate(0, -_rotationY, 0);
                    break;

                case kRotationSortingOrder.YXZ:
                    transform.Rotate(0, -_rotationY, 0);
                    transform.Rotate(-_rotationX, 0, 0);
                    transform.Rotate(0, 0, -_rotation);
                    break;

                case kRotationSortingOrder.YZX:
                    transform.Rotate(0, -_rotationY, 0);
                    transform.Rotate(0, 0, -_rotation);
                    transform.Rotate(-_rotationX, 0, 0);
                    break;

                case kRotationSortingOrder.ZXY:
                    transform.Rotate(0, 0, -_rotation);
                    transform.Rotate(-_rotationX, 0, 0);
                    transform.Rotate(0, -_rotationY, 0);
                    break;

                case kRotationSortingOrder.ZYX:
                    transform.Rotate(0, 0, -_rotation);
                    transform.Rotate(0, -_rotationY, 0);
                    transform.Rotate(-_rotationX, 0, 0);
                    break;
                }
                //scale
                transform.localScale = new Vector3(_scaleX, _scaleY, _scaleZ);

                _isUpdateTransformDirty = false;
            }
        }
Exemplo n.º 20
0
        public override void startWithTarget(object aTarget)
        {
            NSUtils.Assert(aTarget is CC3Node, "CC3Rotate only supports with CC3Node, and target is {0}.", aTarget);
            base.startWithTarget(aTarget);

            //Calculate angle
            CC3Node node = (CC3Node)_target;

            _startAngle = new Vector3(node.rotationX, node.rotationY, node.rotation);

            if (FloatUtils.Big(_startAngle.x, 0))
            {
                _startAngle.x = _startAngle.x % 360.0f;
            }
            else
            {
                _startAngle.x = _startAngle.x % -360.0f;
            }

            if (FloatUtils.Big(_startAngle.y, 0))
            {
                _startAngle.y = _startAngle.y % 360.0f;
            }
            else
            {
                _startAngle.y = _startAngle.y % -360.0f;
            }

            if (FloatUtils.Big(_startAngle.z, 0))
            {
                _startAngle.z = _startAngle.z % 360.0f;
            }
            else
            {
                _startAngle.z = _startAngle.z % -360.0f;
            }



            _diffAngle = _dstAngle - _startAngle;
            if (FloatUtils.Big(_diffAngle.x, 180))
            {
                _diffAngle.x -= 360;
            }
            if (FloatUtils.Small(_diffAngle.x, -180))
            {
                _diffAngle.x += 360;
            }

            if (FloatUtils.Big(_diffAngle.y, 180))
            {
                _diffAngle.y -= 360;
            }
            if (FloatUtils.Small(_diffAngle.y, -180))
            {
                _diffAngle.y += 360;
            }

            if (FloatUtils.Big(_diffAngle.z, 180))
            {
                _diffAngle.z -= 360;
            }
            if (FloatUtils.Small(_diffAngle.z, -180))
            {
                _diffAngle.z += 360;
            }
        }
Exemplo n.º 21
0
        static void CheckSemiTransparentSprite(NSDictionary dictionary, Texture2D texture)
        {
            NSDictionary metadataDict = dictionary.objectForKey <NSDictionary>("metadata");
            NSDictionary framesDict   = dictionary.objectForKey <NSDictionary>("frames");

            // get the format
            int format = 0;

            if (metadataDict != null)
            {
                format = metadataDict.objectForKey <int> ("format");
            }

            // get texture size
            Vector2 textureSize = new Vector2(texture.width, texture.height);

            // check the format
            NSUtils.Assert(format >= 0 && format <= 3, @"cocos2d: WARNING: format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:texture:");

            // SpriteFrame info
            Rect rect           = new Rect();
            bool textureRotated = false;

            // add real frames
            var enumerator = framesDict.GetEnumerator();

            while (enumerator.MoveNext())
            {
                KeyValuePair <object, object> frameDictKeyValue = enumerator.Current;
                NSDictionary frameDict = (NSDictionary)frameDictKeyValue.Value;
                if (format == 0)
                {
                    float x  = frameDict.objectForKey <float>("x");
                    float y  = frameDict.objectForKey <float>("y");
                    float w  = frameDict.objectForKey <float>("width");
                    float h  = frameDict.objectForKey <float>("height");
                    int   ow = frameDict.objectForKey <int>("originalWidth");
                    int   oh = frameDict.objectForKey <int>("originalHeight");
                    // check ow/oh
                    if (ow == 0 || oh == 0)
                    {
                        CCDebug.Warning("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist");
                    }

                    // abs ow/oh
                    ow = Math.Abs(ow);
                    oh = Math.Abs(oh);

                    // set frame info
                    rect           = new Rect(x, y, w, h);
                    textureRotated = false;
                }
                else if (format == 1 || format == 2)
                {
                    Rect frame   = ccUtils.RectFromString(frameDict.objectForKey <string>("frame"));
                    bool rotated = false;

                    // rotation
                    if (format == 2)
                    {
                        rotated = frameDict.objectForKey <bool>("rotated");
                    }

                    // set frame info
                    rect           = frame;
                    textureRotated = rotated;
                }
                else if (format == 3)
                {
                    // get values
                    Vector2 spriteSize      = ccUtils.PointFromString(frameDict.objectForKey <string>("spriteSize"));
                    Rect    textureRect     = ccUtils.RectFromString(frameDict.objectForKey <string>("textureRect"));
                    bool    textureRotated_ = frameDict.objectForKey <bool>("textureRotated");


                    // set frame info
                    rect           = new Rect(textureRect.position.x, textureRect.position.y, spriteSize.x, spriteSize.y);
                    textureRotated = textureRotated_;
                }
                if (textureRotated)
                {
                    rect.size = new Vector2(rect.size.y, rect.size.x);
                }
                rect.y = textureSize.y - rect.y - rect.height;

                // add sprite frame
                int  rectX  = Mathf.RoundToInt(rect.xMin);
                int  rectY  = Mathf.RoundToInt(rect.yMin);
                int  rectW  = Mathf.RoundToInt(rect.width);
                int  rectH  = Mathf.RoundToInt(rect.height);
                bool isSemi = false;
                for (int x = 0; x < rectW; x++)
                {
                    for (int y = 0; y < rectH; y++)
                    {
                        Color color = texture.GetPixel(rectX + x, rectY + y);
                        if (FloatUtils.Big(color.a, 0) && FloatUtils.Small(color.a, 1))
                        {
                            isSemi = true;
                            break;
                        }
                    }
                    if (isSemi)
                    {
                        break;
                    }
                }
                frameDict.Add("semi", isSemi);
            }
        }
Exemplo n.º 22
0
        //-------------update------------

        /** 'update' the scheduler.
         * You should NEVER call this method, unless you know what you are doing.
         */
        public void update(float dt)
        {
            if (_paused)
            {
                return;
            }
            updateHashLocked = true;
            if (!FloatUtils.EQ(_timeScale, 1.0f))
            {
                dt *= _timeScale;
            }

            // Iterate all over the Updates selectors
            // updates with priority < 0
            {
                for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next)
                {
                    utNode <tListEntry> entry = tmp;
                    if (!entry.obj.paused && !entry.obj.markedForDeletion)
                    {
                        entry.obj.impMethod.Invoke(dt);
                    }
                }
            }
            // updates with priority == 0
            {
                for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next)
                {
                    utNode <tListEntry> entry = tmp;
                    if (!entry.obj.paused && !entry.obj.markedForDeletion)
                    {
                        entry.obj.impMethod.Invoke(dt);
                    }
                }
            }
            // updates with priority > 0
            {
                for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next)
                {
                    utNode <tListEntry> entry = tmp;
                    if (!entry.obj.paused && !entry.obj.markedForDeletion)
                    {
                        entry.obj.impMethod.Invoke(dt);
                    }
                }
            }

//			 Iterate all over the custom selectors (CCTimers)
            if (hashForTimers.Any())
            {
                var enumerator = new Dictionary <int, tHashTimerEntry>(hashForTimers).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    var elt = enumerator.Current.Value;
                    currentTarget         = elt;
                    currentTargetSalvaged = false;
                    if (!currentTarget.paused)
                    {
                        for (elt.timerIndex = 0; elt.timerIndex < elt.timers.Count; elt.timerIndex++)
                        {
                            elt.currentTimer         = elt.timers[elt.timerIndex];
                            elt.currentTimerSalvaged = false;
                            elt.currentTimer.update(dt);
                            elt.currentTimer = null;
                        }
                    }
                    if (currentTargetSalvaged && currentTarget.timers.Count == 0)
                    {
                        removeHashElement(currentTarget);
                    }
                }
            }


            for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next)
            {
                utNode <tListEntry> entry = tmp;
                if (entry.obj.markedForDeletion)
                {
                    removeUpdatesFromHash(entry);
                }
            }

            for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next)
            {
                utNode <tListEntry> entry = tmp;
                if (entry.obj.markedForDeletion)
                {
                    removeUpdatesFromHash(entry);
                }
            }


            for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next)
            {
                utNode <tListEntry> entry = tmp;
                if (entry.obj.markedForDeletion)
                {
                    removeUpdatesFromHash(entry);
                }
            }
            updateHashLocked = false;
            currentTarget    = null;
        }
Exemplo n.º 23
0
        public void OnUpdate(CADisplayLink sender)
        {
            bool hasTouchesBegan     = false;
            bool hasTouchesMoved     = false;
            bool hasTouchesEnded     = false;
            bool hasTouchesCancelled = false;
            int  touchCount          = Input.touchCount;

            if (touchCount > 0)
            {
                int count = Input.touches.Length;
                for (int i = 0; i < count; i++)
                {
                    Touch   touch   = Input.touches [i];
                    UITouch uiTouch = new UITouch();
                    uiTouch.fingerId = touch.fingerId;
                    uiTouch.phase    = touch.phase;
                    Vector3 p = touch.position;
                    p.z = -Camera.main.transform.position.z;
                    uiTouch.location  = Camera.main.ScreenToWorldPoint(p) * PIXEL_PER_UNIT;
                    uiTouch.tapCount  = touch.tapCount;
                    uiTouch.timestamp = DateTime.Now;
                    if (touch.phase == TouchPhase.Began)
                    {
                        touchesBegan.Add(uiTouch);
                        hasTouchesBegan = true;
                    }
                    else if (touch.phase == TouchPhase.Moved)
                    {
                        touchesMoved.Add(uiTouch);
                        hasTouchesMoved = true;
                    }
                    else if (touch.phase == TouchPhase.Ended)
                    {
                        touchesEnded.Add(uiTouch);
                        hasTouchesEnded = true;
                    }
                    else if (touch.phase == TouchPhase.Canceled)
                    {
                        touchesCancelled.Add(uiTouch);
                        hasTouchesCancelled = true;
                    }
                }
            }
            else
            {
                                #if UNITY_EDITOR
                                #if UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_WP8_1
                if (Input.GetMouseButtonDown(0))
                {
                    UITouch uiTouch = new UITouch();
                    uiTouch.fingerId = UITouch.SINGLE_TOUCH_ID;
                    uiTouch.phase    = TouchPhase.Began;
                    Vector3 p = Input.mousePosition;
                    p.z = -Camera.main.transform.position.z;
                    uiTouch.location  = Camera.main.ScreenToWorldPoint(p) * PIXEL_PER_UNIT;
                    uiTouch.tapCount  = 1;
                    uiTouch.timestamp = DateTime.Now;

                    touchesBegan.Add(uiTouch);
                    hasTouchesBegan = true;
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    UITouch uiTouch = new UITouch();
                    uiTouch.fingerId = UITouch.SINGLE_TOUCH_ID;
                    uiTouch.phase    = TouchPhase.Ended;
                    Vector3 p = Input.mousePosition;
                    p.z = -Camera.main.transform.position.z;
                    uiTouch.location  = Camera.main.ScreenToWorldPoint(p) * PIXEL_PER_UNIT;
                    uiTouch.tapCount  = 1;
                    uiTouch.timestamp = DateTime.Now;

                    touchesEnded.Add(uiTouch);
                    hasTouchesEnded = true;
                }
                else if (Input.GetMouseButton(0))
                {
                    UITouch uiTouch = new UITouch();
                    uiTouch.fingerId = UITouch.SINGLE_TOUCH_ID;
                    uiTouch.phase    = TouchPhase.Moved;
                    Vector3 p = Input.mousePosition;
                    p.z = -Camera.main.transform.position.z;
                    uiTouch.location  = Camera.main.ScreenToWorldPoint(p) * PIXEL_PER_UNIT;
                    uiTouch.tapCount  = 1;
                    uiTouch.timestamp = DateTime.Now;

                    touchesMoved.Add(uiTouch);
                    hasTouchesMoved = true;
                }
                                #endif
                                #endif
            }
            if (hasTouchesBegan)
            {
                _rootViewController.view.touchesBegan(touchesBegan);
            }
            if (hasTouchesMoved)
            {
                _rootViewController.view.touchesMoved(touchesMoved);
            }
            if (hasTouchesEnded)
            {
                _rootViewController.view.touchesEnded(touchesEnded);
            }
            if (hasTouchesCancelled)
            {
                _rootViewController.view.touchesCancelled(touchesCancelled);
            }
            touchesBegan.Clear();
            touchesMoved.Clear();
            touchesEnded.Clear();
            touchesCancelled.Clear();

                        #if UNITY_STANDALONE || UNITY_WEBGL
            if (Input.GetMouseButtonDown(0))
            {
                NSEvent nsevent = getMouseEvent();
                _rootViewController.view.mouseDown(nsevent);
            }
            else if (Input.GetMouseButtonUp(0))
            {
                NSEvent nsevent = getMouseEvent();
                _rootViewController.view.mouseUp(nsevent);
            }
            else if (Input.GetMouseButton(0))
            {
                NSEvent nsevent = getMouseEvent();
                _rootViewController.view.mouseDragged(nsevent);
            }
            else if (Input.GetMouseButtonDown(1))
            {
                NSEvent nsevent = getMouseEvent();
                _rootViewController.view.rightMouseDown(nsevent);
            }
            else if (Input.GetMouseButtonUp(1))
            {
                NSEvent nsevent = getMouseEvent();
                _rootViewController.view.rightMouseUp(nsevent);
            }
            else if (Input.GetMouseButton(1))
            {
                NSEvent nsevent = getMouseEvent();
                _rootViewController.view.rightMouseDragged(nsevent);
            }
            else if (Input.GetMouseButtonDown(2))
            {
                NSEvent nsevent = getMouseEvent();
                _rootViewController.view.otherMouseDown(nsevent);
            }
            else if (Input.GetMouseButtonUp(2))
            {
                NSEvent nsevent = getMouseEvent();
                _rootViewController.view.otherMouseUp(nsevent);
            }
            else if (Input.GetMouseButton(2))
            {
                NSEvent nsevent = getMouseEvent();
                _rootViewController.view.otherMouseDragged(nsevent);
            }
            else
            {
                float d = Input.GetAxis("Mouse ScrollWheel");
                if (!FloatUtils.EQ(d, 0))
                {
                    NSEvent wheelEvt = getMouseEvent();
                    wheelEvt.mouseWheelDelta = d;
                    _rootViewController.view.scrollWheel(wheelEvt);
                }
                float dx = Input.GetAxis("Mouse X");
                float dy = Input.GetAxis("Mouse Y");
                if (!FloatUtils.EQ(dx, 0) || !FloatUtils.EQ(dy, 0))
                {
                    NSEvent nsevent = getMouseEvent();
                    nsevent.mouseDelta = new Vector2(dx, dy) * PIXEL_PER_UNIT;
                    _rootViewController.view.mouseMoved(nsevent);
                }
            }
            //Keybaord Events
            keyboardEvent();
                        #endif
        }
Exemplo n.º 24
0
        public override void update(float t)
        {
            int   found = 0;
            float new_t = 0;

            CCAction action0 = _actions [0];
            CCAction action1 = _actions [1];

            if (FloatUtils.Small(t, _split))
            {
                // action[0]
                found = 0;
                if (!FloatUtils.EQ(_split, 0))
                {
                    new_t = t / _split;
                }
                else
                {
                    new_t = 1;
                }
            }
            else
            {
                // action[1]
                found = 1;
                if (FloatUtils.EQ(_split, 1))
                {
                    new_t = 1;
                }
                else
                {
                    new_t = (t - _split) / (1 - _split);
                }
            }

            if (found == 1)
            {
                if (_last == -1)
                {
                    // action[0] was skipped, execute it.
                    action0.startWithTarget(_target);
                    action0.update(1.0f);
                    action0.stop();
                }
                else if (_last == 0)
                {
                    // switching to action 1. stop action 0.
                    action0.update(1.0f);
                    action0.stop();
                }
            }
            else if (found == 0 && _last == 1)
            {
                // Reverse mode ?
                // XXX: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode"
                // since it will require a hack to know if an action is on reverse mode or not.
                // "step" should be overriden, and the "reverseMode" value propagated to inner Sequences.
                action1.update(0);
                action1.stop();
            }

            // Last action found and it is done.
            if (found == _last && _actions[found].isDone())
            {
                return;
            }

            // New action. Start it.
            if (found != _last)
            {
                _actions[found].startWithTarget(_target);
            }

            _actions[found].update(new_t);
            _last = found;
        }