private CCBKeyframe ReadKeyframe(CCBPropertyType type) { var keyframe = new CCBKeyframe(); keyframe.Time = ReadFloat(); var easingType = (CCBEasingType) ReadInt(false); float easingOpt = 0; object value = null; if (easingType == CCBEasingType.CubicIn || easingType == CCBEasingType.CubicOut || easingType == CCBEasingType.CubicInOut || easingType == CCBEasingType.ElasticIn || easingType == CCBEasingType.ElasticOut || easingType == CCBEasingType.ElasticInOut) { easingOpt = ReadFloat(); } keyframe.EasingType = easingType; keyframe.EasingOpt = easingOpt; if (type == CCBPropertyType.Check) { value = new CCBValue(ReadBool()); } else if (type == CCBPropertyType.Byte) { value = new CCBValue(ReadByte()); } else if (type == CCBPropertyType.Color3) { byte r = ReadByte(); byte g = ReadByte(); byte b = ReadByte(); var c = new CCColor3B(r, g, b); value = new CCColor3BWapper(c); } else if (type == CCBPropertyType.Degrees) { value = new CCBValue(ReadFloat()); } else if (type == CCBPropertyType.ScaleLock || type == CCBPropertyType.Position || type == CCBPropertyType.FloatXY) { float a = ReadFloat(); float b = ReadFloat(); value = new List<CCBValue> { new CCBValue(a), new CCBValue(b) }; } else if (type == CCBPropertyType.SpriteFrame) { string spriteSheet = ReadCachedString(); string spriteFile = ReadCachedString(); CCSpriteFrame spriteFrame; if (String.IsNullOrEmpty(spriteSheet)) { spriteFile = _CCBRootPath + spriteFile; CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile)); var bounds = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height); spriteFrame = new CCSpriteFrame(texture, bounds); } else { spriteSheet = _CCBRootPath + spriteSheet; CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; // Load the sprite sheet only if it is not loaded if (!_loadedSpriteSheets.Contains(spriteSheet)) { frameCache.AddSpriteFramesWithFile(spriteSheet); _loadedSpriteSheets.Add(spriteSheet); } spriteFrame = frameCache.SpriteFrameByName(spriteFile); } value = spriteFrame; } keyframe.Value = value; return keyframe; }
private CCBKeyframe ReadKeyframe(CCBPropertyType type) { var keyframe = new CCBKeyframe(); keyframe.Time = ReadFloat(); var easingType = (CCBEasingType)ReadInt(false); float easingOpt = 0; object value = null; if (easingType == CCBEasingType.CubicIn || easingType == CCBEasingType.CubicOut || easingType == CCBEasingType.CubicInOut || easingType == CCBEasingType.ElasticIn || easingType == CCBEasingType.ElasticOut || easingType == CCBEasingType.ElasticInOut) { easingOpt = ReadFloat(); } keyframe.EasingType = easingType; keyframe.EasingOpt = easingOpt; if (type == CCBPropertyType.Check) { value = new CCBValue(ReadBool()); } else if (type == CCBPropertyType.Byte) { value = new CCBValue(ReadByte()); } else if (type == CCBPropertyType.Color3) { byte r = ReadByte(); byte g = ReadByte(); byte b = ReadByte(); var c = new CCColor3B(r, g, b); value = new CCColor3BWapper(c); } else if (type == CCBPropertyType.Degrees) { value = new CCBValue(ReadFloat()); } else if (type == CCBPropertyType.ScaleLock || type == CCBPropertyType.Position || type == CCBPropertyType.FloatXY) { float a = ReadFloat(); float b = ReadFloat(); value = new List <CCBValue> { new CCBValue(a), new CCBValue(b) }; } else if (type == CCBPropertyType.SpriteFrame) { string spriteSheet = ReadCachedString(); string spriteFile = ReadCachedString(); CCSpriteFrame spriteFrame; if (String.IsNullOrEmpty(spriteSheet)) { spriteFile = _CCBRootPath + spriteFile; CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile)); var bounds = new CCRect(0, 0, texture.ContentSizeInPixels.Width, texture.ContentSizeInPixels.Height); spriteFrame = new CCSpriteFrame(texture, bounds); } else { spriteSheet = _CCBRootPath + spriteSheet; CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; // Load the sprite sheet only if it is not loaded if (!_loadedSpriteSheets.Contains(spriteSheet)) { frameCache.AddSpriteFrames(spriteSheet); _loadedSpriteSheets.Add(spriteSheet); } spriteFrame = frameCache[spriteFile]; } value = spriteFrame; } keyframe.Value = value; return(keyframe); }