void SetPageSoft(GComponent obj, bool front) { obj.touchable = false; obj.displayObject.cacheAsBitmap = false; DisplayObject mask = front ? _mask1.displayObject : _mask2.displayObject; obj.mask = mask; PolygonMesh mesh = mask.graphics.GetMeshFactory <PolygonMesh>(); mesh.usePercentPositions = false; mesh.points.Clear(); mesh.texcoords.Clear(); mask.graphics.SetMeshDirty(); if (front) { mesh.Add(new Vector2(0, _pageHeight)); mesh.Add(Vector2.zero); mesh.Add(new Vector2(_pageWidth, 0)); mesh.Add(new Vector2(_pageWidth, _pageHeight)); } else if (_softShadow != null) { obj.AddChild(_softShadow); } }
void PlayCoverEffect() { float amount = Mathf.Clamp01(_turningAmount); float ratio; bool isLeft; GComponent turningObj = (_coverTurningOp == CoverTurningOp.ShowFront || _coverTurningOp == CoverTurningOp.HideFront) ? _frontCover : _backCover; PolygonMesh mesh = GetHardMesh(turningObj); if (amount < 0.5f) { ratio = 1 - amount * 2; isLeft = _coverTurningOp == CoverTurningOp.ShowFront || _coverTurningOp == CoverTurningOp.HideBack; } else { ratio = (amount - 0.5f) * 2; isLeft = _coverTurningOp == CoverTurningOp.HideFront || _coverTurningOp == CoverTurningOp.ShowBack; } if (turningObj == _frontCover) { SetCoverStatus(turningObj, CoverType.Front, !isLeft); } else { SetCoverStatus(turningObj, CoverType.Back, isLeft); } mesh.points.Clear(); mesh.texcoords.Clear(); if (isLeft) { float topOffset = 1f / 8 * (1 - ratio); float xOffset = 1 - ratio; mesh.Add(new Vector2(xOffset, 1 + topOffset)); mesh.Add(new Vector2(xOffset, -topOffset)); mesh.Add(new Vector2(1, 0)); mesh.Add(new Vector2(1, 1)); } else { float topOffset = 1f / 8 * (1 - ratio); mesh.Add(new Vector2(0, 1)); mesh.Add(new Vector2(0, 0)); mesh.Add(new Vector2(ratio, -topOffset)); mesh.Add(new Vector2(ratio, 1 + topOffset)); } mesh.texcoords.AddRange(VertexBuffer.NormalizedUV); }
void PlaySoftEffect() { GComponent turningObj1 = _objects[2]; GComponent turningObj2 = _objects[3]; PolygonMesh mesh1 = GetSoftMesh(turningObj1); PolygonMesh mesh2 = GetSoftMesh(turningObj2); /** * a * / \ * f(0,0)------/ b--g(w,0) * | / / | * | / / | * | c / | * | \ / | * | \ / | * e(0,h)-----d--------h(w,h) */ Vector2 pa, pb, pc, pd, pe, pf, pg, ph; float k, angle; bool threePoints = false; pc = _dragPoint; pe = new Vector2(0, _pageHeight); pf = Vector2.zero; pg = new Vector2(_pageWidth, 0); ph = new Vector2(_pageWidth, _pageHeight); FlipPoint(ref pc, _pageWidth * 2, _pageHeight); pc.x -= _pageWidth; if (pc.x >= _pageWidth) { return; } k = (ph.y - pc.y) / (ph.x - pc.x); float k2 = 1 + Mathf.Pow(k, 2); float min; min = ph.x - _pageWidth * 2 / k2; if (pc.x < min) { pc.x = min; if (pc.x >= _pageWidth) { return; } pc.y = ph.y - k * (ph.x - pc.x); } min = ph.x - (_pageWidth + _pageHeight * k) * 2 / k2; if (pc.x < min) { pc.x = min; if (pc.x >= _pageWidth) { return; } pc.y = ph.y - k * (ph.x - pc.x); } angle = Mathf.Atan(k) * Mathf.Rad2Deg; pd = new Vector2(_pageWidth - k2 * (ph.x - pc.x) / 2, _pageHeight); pb = new Vector2(pd.x + _pageHeight * k, 0); pa = new Vector2(); if (pb.x > _pageWidth) { pb.x = _pageWidth; pa = new Vector2(_pageWidth, _pageHeight - (_pageWidth - pd.x) / k); threePoints = true; } FlipPoint(ref pa, _pageWidth, _pageHeight); FlipPoint(ref pb, _pageWidth, _pageHeight); FlipPoint(ref pd, _pageWidth, _pageHeight); FlipPoint(ref pc, _pageWidth, _pageHeight); if (_draggingCorner == Corner.BL || _draggingCorner == Corner.TL) { angle = -angle; } switch (_draggingCorner) { case Corner.BR: { turningObj1.SetPivot(0, 0, true); turningObj1.position = new Vector2(_pageWidth, 0); turningObj2.SetPivot(0, 1, true); turningObj2.position = new Vector2(_pageWidth + pc.x, pc.y); turningObj2.rotation = 2 * angle; if (_softShadow != null) { _softShadow.SetPivot(1, (_softShadow.height - 30) / _softShadow.height, true); _softShadow.position = new Vector2(Vector2.Distance(pc, pd), _pageHeight); _softShadow.rotation = -angle; if (_softShadow.x > _pageWidth - 20) { _softShadow.alpha = (_pageWidth - _softShadow.x) / 20; } else { _softShadow.alpha = 1; } } mesh1.points.Clear(); mesh1.Add(pe); mesh1.Add(pf); mesh1.Add(pb); if (threePoints) { mesh1.Add(pa); } mesh1.Add(pd); mesh2.points.Clear(); mesh2.Add(new Vector2(Vector2.Distance(pc, pd), _pageHeight)); mesh2.Add(new Vector2(0, _pageHeight)); if (threePoints) { mesh2.Add(new Vector2(0, _pageHeight - Vector2.Distance(pc, pa))); } else { mesh2.Add(new Vector2(0, 0)); mesh2.Add(new Vector2(Vector2.Distance(pg, pb), 0)); } break; } case Corner.TR: { turningObj1.SetPivot(0, 0, true); turningObj1.position = new Vector2(_pageWidth, 0); turningObj2.SetPivot(0, 0, true); turningObj2.position = new Vector2(_pageWidth + pc.x, pc.y); turningObj2.rotation = -2 * angle; if (_softShadow != null) { _softShadow.SetPivot(1, 30 / _softShadow.height, true); _softShadow.position = new Vector2(Vector2.Distance(pc, pd), 0); _softShadow.rotation = angle; if (_softShadow.x > _pageWidth - 20) { _softShadow.alpha = (_pageWidth - _softShadow.x) / 20; } else { _softShadow.alpha = 1; } } mesh1.points.Clear(); mesh1.Add(pe); mesh1.Add(pf); mesh1.Add(pd); if (threePoints) { mesh1.Add(pa); } mesh1.Add(pb); mesh2.points.Clear(); if (threePoints) { mesh2.Add(new Vector2(0, Vector2.Distance(pc, pa))); } else { mesh2.Add(new Vector2(Vector2.Distance(pb, ph), _pageHeight)); mesh2.Add(new Vector2(0, _pageHeight)); } mesh2.Add(new Vector2(0, 0)); mesh2.Add(new Vector2(Vector2.Distance(pc, pd), 0)); break; } case Corner.BL: { turningObj1.SetPivot(0, 0, true); turningObj1.position = Vector2.zero; turningObj2.SetPivot(1, 1, true); turningObj2.position = pc; turningObj2.rotation = 2 * angle; if (_softShadow != null) { _softShadow.SetPivot(1, 30 / _softShadow.height, true); _softShadow.position = new Vector2(_pageWidth - Vector2.Distance(pc, pd), _pageHeight); _softShadow.rotation = 180 - angle; if (_softShadow.x < 20) { _softShadow.alpha = (_softShadow.x - 20) / 20; } else { _softShadow.alpha = 1; } } mesh1.points.Clear(); mesh1.Add(pb); mesh1.Add(pg); mesh1.Add(ph); mesh1.Add(pd); if (threePoints) { mesh1.Add(pa); } mesh2.points.Clear(); if (!threePoints) { mesh2.Add(new Vector2(_pageWidth - Vector2.Distance(pf, pb), 0)); mesh2.Add(new Vector2(_pageWidth, 0)); } else { mesh2.Add(new Vector2(_pageWidth, _pageHeight - Vector2.Distance(pc, pa))); } mesh2.Add(new Vector2(_pageWidth, _pageHeight)); mesh2.Add(new Vector2(_pageWidth - Vector2.Distance(pc, pd), _pageHeight)); break; } case Corner.TL: { turningObj1.SetPivot(0, 0, true); turningObj1.position = Vector2.zero; turningObj2.SetPivot(1, 0, true); turningObj2.position = pc; turningObj2.rotation = -2 * angle; if (_softShadow != null) { _softShadow.SetPivot(1, (_softShadow.height - 30) / _softShadow.height, true); _softShadow.position = new Vector2(_pageWidth - Vector2.Distance(pc, pd), 0); _softShadow.rotation = 180 + angle; if (_softShadow.x < 20) { _softShadow.alpha = (_softShadow.x - 20) / 20; } else { _softShadow.alpha = 1; } } mesh1.points.Clear(); mesh1.Add(pd); mesh1.Add(pg); mesh1.Add(ph); mesh1.Add(pb); if (threePoints) { mesh1.Add(pa); } mesh2.points.Clear(); mesh2.Add(new Vector2(_pageWidth - Vector2.Distance(pc, pd), 0)); mesh2.Add(new Vector2(_pageWidth, 0)); if (threePoints) { mesh2.Add(new Vector2(_pageWidth, Vector2.Distance(pc, pa))); } else { mesh2.Add(new Vector2(_pageWidth, _pageHeight)); mesh2.Add(new Vector2(_pageWidth - Vector2.Distance(pe, pb), _pageHeight)); } break; } } }