//if mouse over on any sub collider
    void OnComponentMouseOverHandle(CollisionNodeInfo collisionInfo)
    {
        SpriteTransform tmpSprTransform = spriteRenderer.GetSpriteTransform( collisionInfo.hitNode.componentPath);

        //save the last hover component
        if ( tmpSprTransform != null )
        {
            lastHoverSprite = tmpSprTransform;
        }
    }
예제 #2
0
        public override int Draw(IDrawContext drawContext, Transform transform)
        {
            if (this.Sprite != null && this.IsVisible)
            {
                var newTransform = new SpriteTransform(transform, this.Position, this.Rotation, this.Scale, this.Color);

                return this.Sprite.Draw(drawContext, newTransform);
            }

            return 0;
        }
        internal SpriteAnimationKeyFrame EvaluateBlending(float time, SpriteTransform transform, float[] transformProperty)
        {
            int idx = (int)curves[0].curve.Evaluate(time);
            SpriteAnimationKeyFrame kf = keyFrames[idx];

            if (!transform.isSpriteValid && kf.isSpriteValid )
            {
                transform._sprite = kf.sprite;
                transform.isSpriteValid = true;
            }

            float v = 0f;
            foreach (SpriteAnimationCurve curve in curves)
            {
                transformProperty[(int)curve.type] = curve.length == 0 ? curve.defaultValue : curve.curve.Evaluate(time);
            }
            return kf;
        }
        internal SpriteAnimationKeyFrame EvaluateAddtive(float time, SpriteTransform transform, float[] transformProperty)
        {
            int idx = (int)curves[0].curve.Evaluate(time);
            SpriteAnimationKeyFrame kf = keyFrames[idx];

            SpriteAnimationCurve curve = null;
            for (int i = 1, e = curves.Length; i < e; i++)
            {
                curve = curves[i];
                transformProperty[(int)curve.type] = curve.length == 0 ? 0f : (curve.curve.Evaluate(time) - curve.defaultValue);
            }
            return kf;
        }
        void RemoveSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash)
        {
            int searchHash = component._fullPathHash + parentHash;
            SpriteTransform sprTransfrom = spriteRenderer.GetSpriteTransformByFullPathHash(searchHash);


            for (int i = 0, e = component.children.Length; i < e; i++)
                RemoveSprite(state, state.clip.subComponents[component.children[i]], sprTransfrom, parentHash);


            if (sprTransfrom != null)
            {
                //if (sprTransfrom.lastRefClip != null)
                //{
                //    string name = state.name + "_" + sprTransfrom.lastRefClip.name;
                //    SpriteAnimationState _state = this[name];


                //    if (_state != null)
                //    {
                //        if (_state.parentState != null)
                //            _state.parentState.subClipState.Remove(_state);

                //        Stop(_state);
                //    }

                //    sprTransfrom.lastRefClip = null;
                //}


                sprTransfrom.DetachState(state, component);


                if (sprTransfrom.attachStateComponent.Count <= 0)
                {

                    if (sprTransfrom.prve != null)
                        sprTransfrom.prve.next = sprTransfrom.next;

                    if (sprTransfrom.next != null)
                        sprTransfrom.next.prve = sprTransfrom.prve;

                    if (sprTransfrom.parent != null && sprTransfrom.parent.firstChild == sprTransfrom)
                        sprTransfrom.parent.firstChild = sprTransfrom.next;

                    for (SpriteTransform child = sprTransfrom.firstChild; child != null; child = child.next)
                        child.parent = null;

                    {
                        sprTransfrom.parent = null;
                        sprTransfrom.next = null;
                        sprTransfrom.prve = null;
                        sprTransfrom.firstChild = null;
                        sprTransfrom.lastChild = null;
                    }

                    if (stateRoot.Contains(sprTransfrom))
                        stateRoot.Remove(sprTransfrom);


                    spriteRenderer.DetachSprite(sprTransfrom.id);
                }
            }
        }
예제 #6
0
        static public void DrawProjection(DayLightCollider2D id, Vector2 offset)
        {
            if (id.mainShape.shadowType != DayLightCollider2D.ShadowType.SpriteProjection)
            {
                return;
            }

            if (id.InAnyCamera() == false)
            {
                return;
            }

            Material material = Lighting2D.materials.GetSpriteShadow();

            material.color = Color.black;

            foreach (DayLightColliderShape shape in id.shapes)
            {
                SpriteRenderer spriteRenderer = shape.spriteShape.GetSpriteRenderer();
                if (spriteRenderer == null)
                {
                    continue;
                }

                virtualSpriteRenderer.sprite = spriteRenderer.sprite;
                virtualSpriteRenderer.flipX  = spriteRenderer.flipX;
                virtualSpriteRenderer.flipY  = spriteRenderer.flipY;

                Sprite sprite = virtualSpriteRenderer.sprite;

                if (virtualSpriteRenderer.sprite == null)
                {
                    continue;
                }

                float sunHeight = Lighting2D.DayLightingSettings.height;
                float rot       = Lighting2D.DayLightingSettings.direction * Mathf.Deg2Rad;

                Vector2 pos   = new Vector2(id.transform.position.x + offset.x, id.transform.position.y + offset.y);
                Vector2 scale = new Vector2(id.transform.lossyScale.x, id.transform.lossyScale.y);

                SpriteTransform spriteTransform = new SpriteTransform(virtualSpriteRenderer, pos, scale, id.transform.rotation.eulerAngles.z);

                Rect uv = spriteTransform.uv;

                float pivotY = (float)sprite.pivot.y / sprite.texture.height;
                pivotY = uv.y + pivotY;

                float pivotX = (float)sprite.pivot.x / sprite.texture.width;


                Pair2 pair = Pair2.Zero();
                pair.A = pos + pair.A.Push(-rot + Mathf.PI / 2, id.shadowThickness);
                pair.B = pos + pair.B.Push(-rot - Mathf.PI / 2, id.shadowThickness);

                if (Lighting2D.DayLightingSettings.direction < 180)
                {
                    float uvx = uv.x;
                    uv.x     = uv.width;
                    uv.width = uvx;
                }

                Vector2 v1 = pair.A;
                Vector2 v2 = pair.A;
                Vector2 v3 = pair.B;
                Vector2 v4 = pair.B;

                v2 = v2.Push(-rot, id.shadowDistance * sunHeight);
                v3 = v3.Push(-rot, id.shadowDistance * sunHeight);

                material.mainTexture = virtualSpriteRenderer.sprite.texture;

                material.SetPass(0);

                GL.Begin(GL.QUADS);

                GL.Color(GLExtended.color);

                GL.TexCoord3(uv.x, pivotY, 0);
                GL.Vertex3(v1.x, v1.y, 0);

                GL.TexCoord3(uv.x, uv.height, 0);
                GL.Vertex3(v2.x, v2.y, 0);

                GL.TexCoord3(uv.width, uv.height, 0);
                GL.Vertex3(v3.x, v3.y, 0);

                GL.TexCoord3(uv.width, pivotY, 0);
                GL.Vertex3(v4.x, v4.y, 0);

                GL.End();
            }

            material.color = Color.white;
        }
예제 #7
0
		public override List<Polygon2> GetPolygonsWorld() {
			if (WorldPolygons == null) {

				Vector2 v1, v2, v3, v4;

				if (WorldCache == null) {

					WorldPolygons = new List<Polygon2>();

					if (spriteRenderer == null) {
						Debug.LogWarning("Light Collider 2D: Cannot access sprite renderer (Sprite Shape)", transform.gameObject);
						return(null);
					}

					if ( spriteRenderer.drawMode == SpriteDrawMode.Tiled && spriteRenderer.tileMode == SpriteTileMode.Continuous) {

						float rot = transform.eulerAngles.z;
						Vector2 size = transform.lossyScale * spriteRenderer.size * 0.5f;
						Vector2 pos = transform.position;

						rot = rot * Mathf.Deg2Rad + Mathf.PI;

						float rectAngle = Mathf.Atan2(size.y, size.x);
						float dist = Mathf.Sqrt(size.x * size.x + size.y * size.y);

						v1 = new Vector2(pos.x + Mathf.Cos(rectAngle + rot) * dist, pos.y + Mathf.Sin(rectAngle + rot) * dist);
						v2 = new Vector2(pos.x + Mathf.Cos(-rectAngle + rot) * dist, pos.y + Mathf.Sin(-rectAngle + rot) * dist);
						v3 = new Vector2(pos.x + Mathf.Cos(rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(rectAngle + Mathf.PI + rot) * dist);
						v4 = new Vector2(pos.x + Mathf.Cos(-rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(-rectAngle + Mathf.PI + rot) * dist);

					} else {

						virtualSpriteRenderer.Set(spriteRenderer);

						Vector2 position = transform.position;
						Vector2 scale = transform.lossyScale;
						float rotation = transform.eulerAngles.z;
			
						SpriteTransform spriteTransform = new SpriteTransform(virtualSpriteRenderer, position, scale, rotation);

						float rot = spriteTransform.rotation;
						Vector2 size = spriteTransform.scale;
						Vector2 pos = spriteTransform.position;

						rot = rot * Mathf.Deg2Rad + Mathf.PI;

						float rectAngle = Mathf.Atan2(size.y, size.x);
						float dist = Mathf.Sqrt(size.x * size.x + size.y * size.y);

						v1 = new Vector2(pos.x + Mathf.Cos(rectAngle + rot) * dist, pos.y + Mathf.Sin(rectAngle + rot) * dist);
						v2 = new Vector2(pos.x + Mathf.Cos(-rectAngle + rot) * dist, pos.y + Mathf.Sin(-rectAngle + rot) * dist);
						v3 = new Vector2(pos.x + Mathf.Cos(rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(rectAngle + Mathf.PI + rot) * dist);
						v4 = new Vector2(pos.x + Mathf.Cos(-rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(-rectAngle + Mathf.PI + rot) * dist);
					
						WorldCache = WorldPolygons;
					}

					Polygon2 polygon = new Polygon2(4);

					polygon.points[0] = v1;
					polygon.points[1] = v2;
					polygon.points[2] = v3;
					polygon.points[3] = v4;

					WorldPolygons.Add(polygon);

				} else {
					
					WorldPolygons = WorldCache;

					if (spriteRenderer.drawMode == SpriteDrawMode.Tiled && spriteRenderer.tileMode == SpriteTileMode.Continuous) {

						float rot = transform.eulerAngles.z;
						Vector2 size = transform.lossyScale * spriteRenderer.size * 0.5f;
						Vector2 pos = transform.position;

						rot = rot * Mathf.Deg2Rad + Mathf.PI;

						float rectAngle = Mathf.Atan2(size.y, size.x);
						float dist = Mathf.Sqrt(size.x * size.x + size.y * size.y);

						v1 = new Vector2(pos.x + Mathf.Cos(rectAngle + rot) * dist, pos.y + Mathf.Sin(rectAngle + rot) * dist);
						v2 = new Vector2(pos.x + Mathf.Cos(-rectAngle + rot) * dist, pos.y + Mathf.Sin(-rectAngle + rot) * dist);
						v3 = new Vector2(pos.x + Mathf.Cos(rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(rectAngle + Mathf.PI + rot) * dist);
						v4 = new Vector2(pos.x + Mathf.Cos(-rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(-rectAngle + Mathf.PI + rot) * dist);

					} else {
						
						virtualSpriteRenderer.Set(spriteRenderer);

						Vector2 position = transform.position;
						Vector2 scale = transform.lossyScale;
						float rotation = transform.eulerAngles.z;
			
						SpriteTransform spriteTransform = new SpriteTransform(virtualSpriteRenderer, position, scale, rotation);

						float rot = spriteTransform.rotation;
						Vector2 size = spriteTransform.scale;
						Vector2 pos = spriteTransform.position;

						rot = rot * Mathf.Deg2Rad + Mathf.PI;

						float rectAngle = Mathf.Atan2(size.y, size.x);
						float dist = Mathf.Sqrt(size.x * size.x + size.y * size.y);

						v1 = new Vector2(pos.x + Mathf.Cos(rectAngle + rot) * dist, pos.y + Mathf.Sin(rectAngle + rot) * dist);
						v2 = new Vector2(pos.x + Mathf.Cos(-rectAngle + rot) * dist, pos.y + Mathf.Sin(-rectAngle + rot) * dist);
						v3 = new Vector2(pos.x + Mathf.Cos(rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(rectAngle + Mathf.PI + rot) * dist);
						v4 = new Vector2(pos.x + Mathf.Cos(-rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(-rectAngle + Mathf.PI + rot) * dist);
					}

					Polygon2 polygon = WorldPolygons[0];
						
					polygon.points[0] = v1;
					polygon.points[1] = v2;
					polygon.points[2] = v3;
					polygon.points[3] = v4;

				}
				
			}

			return(WorldPolygons);
		}
        bool SetupSpritePrimitiveXZ(SpritePrimitive pri, SpriteTransform sTransform, Vector2 parentPosition, float parentRotation, Vector2 parentScale, int layer,  bool isFirst)
        {
            sTransform.primitive = pri;

            if ( !sTransform.visible || (!sTransform.isSpriteValid && !sTransform.isOverride) )
            {
                pri.visible = false;
                return isFirst;
            }

            Sprite spr = sTransform.isOverride ? sTransform._override : sTransform._sprite;


            layer = (layer - 0xf <= 0 ? 0 : layer) & 0xf;

            float z = (layer << 3) | sTransform.layer;
            pri.compareKey = calcSortKey((ulong)spr.texID, pri, gameObjectLayer, (uint)depth, (uint)sTransform.layer, renderMode, applyLayerToZ);

            //TRS
            {
                float ry = -pri.z;

                float r = Mathf.Deg2Rad * (sTransform.rotation);
                float sin = Mathf.Sin(r);
                float cos = Mathf.Cos(r);

                float pr = Mathf.Deg2Rad * (parentRotation);
                float psin = Mathf.Sin(pr);
                float pcos = Mathf.Cos(pr);


                float sx = 0;
                float sy = 0;
                float tx = 0;
                float ty = 0;
                float psx = 0;
                float psy = 0;
                float px = 0;
                float py = 0;


                for (int i = 0, e = spr.vertices.Length; i < e; i++)
                {
                    sx = (spr.vertices[i].x + (spr.vertices[i].y * -sTransform.shear.y)) * sTransform.scale.x;
                    sy = (spr.vertices[i].y + (spr.vertices[i].x * -sTransform.shear.x)) * sTransform.scale.y;

                    tx = (sx * cos - sy * sin);
                    ty = (sx * sin + sy * cos);

                    psx = (sTransform.position.x + tx) * parentScale.x;
                    psy = (sTransform.position.y + ty) * parentScale.y;

                    tx = parentPosition.x + (psx * pcos - psy * psin);
                    ty = parentPosition.y + (psx * psin + psy * pcos);

                    pri.position[i].x = tx;
                    pri.position[i].z = ty;
                    pri.position[i].y = ry;

                    //Vector2 
                    if (isFirst)
                    {
                        boundingAABB.position_minx = tx;
                        boundingAABB.position_miny = ty;
                        boundingAABB.position_maxx = tx;
                        boundingAABB.position_maxy = ty;
                        isFirst = false;
                    }
                    else
                    {
                        boundingAABB.position_minx = tx < boundingAABB.position_minx ? tx : boundingAABB.position_minx;
                        boundingAABB.position_miny = ty < boundingAABB.position_miny ? ty : boundingAABB.position_miny;
                        boundingAABB.position_maxx = tx > boundingAABB.position_maxx ? tx : boundingAABB.position_maxx;
                        boundingAABB.position_maxy = ty > boundingAABB.position_maxy ? ty : boundingAABB.position_maxy;
                    }
                }
            }

            {
                float tmpColorR = color.r * sTransform.color.r;
                float tmpColorG = color.g * sTransform.color.g;
                float tmpColorB = color.b * sTransform.color.b;
                float tmpColorA = color.a * sTransform.color.a;

                pri.color[3].a = tmpColorA * __colorLB.a;
                pri.color[3].r = tmpColorR * __colorLB.r;
                pri.color[3].g = tmpColorG * __colorLB.g;
                pri.color[3].b = tmpColorB * __colorLB.b;

                pri.color[2].a = tmpColorA * __colorRB.a;
                pri.color[2].r = tmpColorR * __colorRB.r;
                pri.color[2].g = tmpColorG * __colorRB.g;
                pri.color[2].b = tmpColorB * __colorRB.b;

                pri.color[1].a = tmpColorA * __colorRT.a;
                pri.color[1].r = tmpColorR * __colorRT.r;
                pri.color[1].g = tmpColorG * __colorRT.g;
                pri.color[1].b = tmpColorB * __colorRT.b;

                pri.color[0].a = tmpColorA * __colorLT.a;
                pri.color[0].r = tmpColorR * __colorLT.r;
                pri.color[0].g = tmpColorG * __colorLT.g;
                pri.color[0].b = tmpColorB * __colorLT.b;
            }

            pri.renderMode = _renderMode;

            //if (pri.texId != spr.texID)
            {
                pri.uv[0] = spr.uvs[0];
                pri.uv[1] = spr.uvs[1];
                pri.uv[2] = spr.uvs[2];
                pri.uv[3] = spr.uvs[3];

                pri.texture = spr.image;
                pri.texId = spr.texID;
            }

            pri.visible = _visible;

            return isFirst;
        }
        void RemoveSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash)
        {
            SpriteTransform sprTransfrom = spriteRenderer.GetSpriteTransformByFullPathHash(component._fullPathHash + parentHash );


            if (sprTransfrom != null)
            {
                sprTransfrom.DetachState(state, component);

                if (sprTransfrom.attachStateComponent.Count <= 0)
                {
                    if (sprTransfrom.prve != null)
                        sprTransfrom.prve.next = sprTransfrom.next;

                    if (sprTransfrom.next != null)
                        sprTransfrom.next.prve = sprTransfrom.prve;

                    if (sprTransfrom.parent != null && sprTransfrom.parent.firstChild == sprTransfrom)
                        sprTransfrom.parent.firstChild = sprTransfrom.next;

                    for (SpriteTransform child = sprTransfrom.firstChild; child != null; child = child.next)
                        child.parent = null;
                    {
                        sprTransfrom.parent = null;
                        sprTransfrom.next = null;
                        sprTransfrom.prve = null;
                        sprTransfrom.firstChild = null;
                        sprTransfrom.lastChild = null;
                    }

                    if (stateRoot.Contains(sprTransfrom))
                        stateRoot.Remove(sprTransfrom);

                    spriteRenderer.DetachSprite(sprTransfrom.id);
                }
            }

            for (int i = 0, e = component.children.Length; i < e; i++)
                RemoveSprite(state, state.clip.subComponents[component.children[i]], sprTransfrom, 0);
        }
        private void TransformComponent()
        {
            SpriteTransform parentTransform = new SpriteTransform();

            foreach (SpriteTransform rootTransform in stateRoot)
            {
                parentTransform.ResetTransform();
                TransformNode(rootTransform, parentTransform);
            }

            if (postTransformUpdate != null)
                postTransformUpdate(this);
        }
예제 #11
0
        public static void Draw(List <Polygon2> polygons, float shadowDistance, float translucency)
        {
            if (polygons == null)
            {
                return;
            }

            Vector2[] uv       = new Vector2[4];
            Vector2[] vertices = new Vector2[4];

            Material mat = Lighting2D.materials.GetSpriteProjectionMaterial();

            if (ShadowEngine.spriteProjection == null)
            {
                return;
            }

            mat.mainTexture = ShadowEngine.spriteProjection.texture;
            mat.SetPass(0);

            GL.Begin(GL.QUADS);

            GL.Color(new Color(translucency, 0, 0, 0));


            UVRect fill = ShadowEngine.FillBlack.uvRect;

            Light2D light     = ShadowEngine.light;
            Vector2 offset    = ShadowEngine.lightOffset + ShadowEngine.objectOffset;
            float   lightSize = ShadowEngine.lightSize;

            float pivotY = (float)ShadowEngine.spriteProjection.pivot.y / ShadowEngine.spriteProjection.texture.height;

            VirtualSpriteRenderer virtualSpriteRenderer = new VirtualSpriteRenderer();

            virtualSpriteRenderer.sprite = ShadowEngine.spriteProjection;
            // virtualSpriteRenderer.flipX = spriteRenderer.flipX;
            // virtualSpriteRenderer.flipY = spriteRenderer.flipY;

            SpriteTransform spriteTransform = new SpriteTransform(virtualSpriteRenderer, Vector2.zero, Vector2.one, 0);

            Rect uvRect = spriteTransform.uv;

            pivotY = uvRect.y + pivotY;


            if (shadowDistance == 0)
            {
                shadowDistance = lightSize;
            }

            float outerAngle = light.outerAngle;


            Vector2 vA, vB, vC, vD;
            float   angleA, angleB, rotA, rotB;

            int PolygonCount = polygons.Count;

            for (int i = 0; i < PolygonCount; i++)
            {
                Vector2[] pointsList  = polygons[i].points;
                int       pointsCount = pointsList.Length;

                SoftShadowSorter.Set(polygons[i], light);


                pair.A.x = SoftShadowSorter.minPoint.x;
                pair.A.y = SoftShadowSorter.minPoint.y;

                pair.B.x = SoftShadowSorter.maxPoint.x;
                pair.B.y = SoftShadowSorter.maxPoint.y;

                float edgeALocalX = pair.A.x;
                float edgeALocalY = pair.A.y;

                float edgeBLocalX = pair.B.x;
                float edgeBLocalY = pair.B.y;

                float edgeAWorldX = edgeALocalX + offset.x;
                float edgeAWorldY = edgeALocalY + offset.y;

                float edgeBWorldX = edgeBLocalX + offset.x;
                float edgeBWorldY = edgeBLocalY + offset.y;


                float lightDirection = Mathf.Atan2((edgeAWorldY + edgeBWorldY) / 2, (edgeAWorldX + edgeBWorldX) / 2) * Mathf.Rad2Deg;
                float EdgeDirection  = (Mathf.Atan2(edgeALocalY - edgeBLocalY, edgeALocalX - edgeBLocalX) * Mathf.Rad2Deg - 180 + 720) % 360;

                lightDirection -= EdgeDirection;
                lightDirection  = (lightDirection + 720) % 360;

                if (lightDirection > 180)
                {
                    // continue;
                }

                for (float s = 0; s <= 1; s += 0.1f)
                {
                    float step0 = s;
                    float step1 = s + 0.1f;

                    float dir      = SoftShadowSorter.minPoint.Atan2(SoftShadowSorter.maxPoint) - Mathf.PI;
                    float distance = Vector2.Distance(SoftShadowSorter.minPoint, SoftShadowSorter.maxPoint);

                    pair.A.x = SoftShadowSorter.minPoint.x + Mathf.Cos(dir) * distance * step0;
                    pair.A.y = SoftShadowSorter.minPoint.y + Mathf.Sin(dir) * distance * step0;

                    pair.B.x = SoftShadowSorter.minPoint.x + Mathf.Cos(dir) * distance * step1;
                    pair.B.y = SoftShadowSorter.minPoint.y + Mathf.Sin(dir) * distance * step1;

                    edgeALocalX = pair.A.x;
                    edgeALocalY = pair.A.y;

                    edgeBLocalX = pair.B.x;
                    edgeBLocalY = pair.B.y;

                    edgeAWorldX = edgeALocalX + offset.x;
                    edgeAWorldY = edgeALocalY + offset.y;

                    edgeBWorldX = edgeBLocalX + offset.x;
                    edgeBWorldY = edgeBLocalY + offset.y;

                    angleA = (float)System.Math.Atan2(edgeAWorldY, edgeAWorldX);
                    angleB = (float)System.Math.Atan2(edgeBWorldY, edgeBWorldX);

                    rotA = angleA - Mathf.Deg2Rad * light.outerAngle;
                    rotB = angleB + Mathf.Deg2Rad * light.outerAngle;

                    // Right Collision
                    vC.x = edgeAWorldX;
                    vC.y = edgeAWorldY;

                    // Left Collision
                    vD.x = edgeBWorldX;
                    vD.y = edgeBWorldY;

                    // Right Inner
                    vA.x  = edgeAWorldX;
                    vA.y  = edgeAWorldY;
                    vA.x += Mathf.Cos(angleA) * shadowDistance;
                    vA.y += Mathf.Sin(angleA) * shadowDistance;

                    // Left Inner
                    vB.x  = edgeBWorldX;
                    vB.y  = edgeBWorldY;
                    vB.x += Mathf.Cos(angleB) * shadowDistance;
                    vB.y += Mathf.Sin(angleB) * shadowDistance;

                    vertices[0] = new Vector2(vD.x, vD.y);
                    vertices[1] = new Vector2(vC.x, vC.y);
                    vertices[2] = new Vector2(vA.x, vA.y);
                    vertices[3] = new Vector2(vB.x, vB.y);

                    float x0;
                    float x1;

                    if (edgeAWorldY < 0)
                    {
                        x0 = Mathf.Lerp(uvRect.width, uvRect.x, step0);
                        x1 = Mathf.Lerp(uvRect.width, uvRect.x, step1);
                    }
                    else
                    {
                        x0 = Mathf.Lerp(uvRect.x, uvRect.width, step0);
                        x1 = Mathf.Lerp(uvRect.x, uvRect.width, step1);
                    }


                    float y0 = Mathf.Lerp(uvRect.y, uvRect.height, pivotY);
                    float y1 = Mathf.Lerp(uvRect.y, uvRect.height, 1);



                    uv[0] = new Vector2(x1, y0);
                    uv[1] = new Vector2(x0, y0);
                    uv[2] = new Vector2(x0, y1);
                    uv[3] = new Vector2(x1, y1);

                    // Right Fin
                    GL.MultiTexCoord3(0, uv[2].x, uv[2].y, 0);
                    GL.Vertex3(vertices[2].x, vertices[2].y, 0);

                    GL.MultiTexCoord3(0, uv[3].x, uv[3].y, 0);
                    GL.Vertex3(vertices[3].x, vertices[3].y, 0);

                    GL.MultiTexCoord3(0, uv[0].x, uv[0].y, 0);
                    GL.Vertex3(vertices[0].x, vertices[0].y, 0);

                    GL.MultiTexCoord3(0, uv[1].x, uv[1].y, 0);
                    GL.Vertex3(vertices[1].x, vertices[1].y, 0);
                }
            }

            GL.End();
        }
예제 #12
0
                static public void Draw(SpriteMeshObject spriteMeshObject, Material material, VirtualSpriteRenderer spriteRenderer, Vector2 position, Vector2 scale, float rotation)
                {
                    SpriteTransform spriteTransform = new SpriteTransform(spriteRenderer, position, scale, rotation);

                    Texture.Draw(material, spriteTransform.position, spriteTransform.scale, spriteTransform.uv, rotation, 0);
                }
 //if mouse exit on any sub collider
 void OnComponentMouseExit(CollisionNodeInfo collisionInfo)
 {
     //clear the last hover component
     lastHoverSprite = null;
 }
        internal void EvaluateTransform(SpriteTransform sprTransform)
        {
            sprTransform.ZeroTransform();


            for (int idx = 0; idx < sprTransform.attachStateComponent.Count; idx++)
            {
                SpriteTransform.StateComponentPair pair = sprTransform.attachStateComponent[idx];

                SpriteAnimationKeyFrame kf = null;


                if (pair.state.blendMode == AnimationBlendMode.Additive)
                {
                    //reset buffer
                    transformPropertys[1] = transformPropertys[2] = transformPropertys[3] = 0f;
                    transformPropertys[4] = transformPropertys[5] = transformPropertys[6] = transformPropertys[7] = transformPropertys[8] = transformPropertys[9] = 0f;
                    transformPropertys[10] = transformPropertys[11] = 0f;

                    kf = pair.component.EvaluateAddtive(pair.state.lastEvaluateTime, sprTransform, transformPropertys);
                }
                else
                {
                    //reset buffer
                    transformPropertys[1] = transformPropertys[2] = transformPropertys[3] = 0f;
                    transformPropertys[4] = transformPropertys[5] = transformPropertys[6] = transformPropertys[7] = transformPropertys[8] = transformPropertys[9] = 1f;
                    transformPropertys[10] = transformPropertys[11] = 0f;

                    kf = pair.component.EvaluateBlending(pair.state.lastEvaluateTime, sprTransform, transformPropertys);
                }


                if (pair.lastRefClip != kf.refClip)
                {
                    if (pair.lastRefClip != null)
                    {
                        string name = pair.state.name + "_" + pair.component.fullPath + "_" + pair.lastRefClip.name;
                        SpriteAnimationState state = this[name];

                        if (state != null)
                        {
                            Stop(state);
                        }

                        pair.lastRefClip = null;
                    }


                    if (kf.refClip != null)
                    {
                        string name = pair.state.name + "_" + pair.component.fullPath + "_" + kf.refClip.name;

                        if (!animationStates.ContainsKey(name))
                        {
                            AddClip(kf.refClip, name);
                            SpriteAnimationState state = this[name];

                            state.parentState = pair.state;
                            state.parentTransform = pair.applyTo;
                            state.parentComponentLayer = (int)pair.component.layer;
                            state.removeAfterStop = true;

                            state.layer = pair.state.layer;
                            state.weight = pair.state.weight;

                            state.lastTime = 0f;
                            state.lastFrameIndex = -1;
                            state.lastEvaluateTime = 0;


                            pair.lastRefClip = kf.refClip;
                            state.parentState.subClipState.Add(state);

                            state.enabled = true;
                        }

                    }

                }


                float weight = pair.weight;


                {
                    sprTransform.position.x += transformPropertys[1] * weight;
                    sprTransform.position.y += transformPropertys[2] * weight;
                    sprTransform.rotation += transformPropertys[3] * weight;
                    sprTransform.scale.x += transformPropertys[4] * weight;
                    sprTransform.scale.y += transformPropertys[5] * weight;
                    sprTransform.color.r += transformPropertys[6] * weight;
                    sprTransform.color.g += transformPropertys[7] * weight;
                    sprTransform.color.b += transformPropertys[8] * weight;
                    sprTransform.color.a += transformPropertys[9] * weight;
                    sprTransform.shear.x += transformPropertys[10] * weight;
                    sprTransform.shear.y += transformPropertys[11] * weight;
                }
            }
        }
예제 #15
0
    //register a delegate
    //it will use a animation component's movement information to move the CharacterController
    void RegisterMoveHandler()
    {
        //get transform of a compoent named "Lee"
        warriorRoot = spriteRenderer.GetSpriteTransform("Lee");

        //save the position of x
        lastRootX = warriorRoot.position.x;

        if ( !isRegisterMoveHandler  )
        {
            isRegisterMoveHandler = true;

            //set a delegate function that will callback before a component will transform
            spriteAnimation.AddComponentUpdateHandler( SpriteAnimationComponentUpdateType.PreUpdateComponent, moveHandler);
        }
    }
        void AddSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash )
        {
  
            SpriteTransform sprTransfrom = spriteRenderer.GetSpriteTransformByFullPathHash(component._fullPathHash + parentHash);

            if (sprTransfrom == null)
            {
                {
                    sprTransfrom = spriteRenderer.AttachSpriteComponent(component);

                    sprTransfrom.parent = parentTransform;

                    sprTransfrom.layer = (int)component.layer + state.parentComponentLayer;
                    sprTransfrom.visible = component.visible;
                }


                sprTransfrom.overrideHash = parentHash != 0 ? component._fullPathHash + parentHash : 0;


                if (parentTransform != null)
                {
                    if (parentTransform.firstChild == null)
                    {
                        parentTransform.firstChild = sprTransfrom;
                        parentTransform.lastChild = sprTransfrom;

                        sprTransfrom.prve = null;
                        sprTransfrom.next = null;
                    }
                    else
                    {
                        sprTransfrom.next = parentTransform.lastChild.next;
                        sprTransfrom.prve = parentTransform.lastChild;

                        parentTransform.lastChild.next = sprTransfrom;
                    }
                }
            }

            sprTransfrom.AttachState(state, component);

            for (int i = 0, e = component.children.Length; i < e; i++)
                AddSprite( state, state.clip.subComponents[ component.children[i] ], sprTransfrom, 0);
        }
예제 #17
0
 private void Awake()
 {
     spriteTransform = GetComponent <SpriteTransform>();
 }
예제 #18
0
    //register a delegate
    //it will use a animation component's movement information to move the CharacterController
    void RegisterMoveHandler()
    {
        //get transform of a compoent named "hip"
        mummyHip = spriteRenderer.GetSpriteTransform("hip");

        //save the position of x
        lastHipX = mummyHip.position.x;

        //set a delegate function that will callback before a component will transform
        spriteAnimation.AddComponentUpdateHandler( SpriteAnimationComponentUpdateType.PreUpdateComponent, moveHandler);
    }
        private void TransformNode(SpriteTransform sTransform, SpriteTransform parentTransform)
        {
            float r = 0;
            float sin = 0;
            float cos = 0;

            float sx = 0;
            float sy = 0;

            {
                //TRS
                r = Mathf.Deg2Rad * (parentTransform.rotation);
                sin = Mathf.Sin(r);
                cos = Mathf.Cos(r);

                sx = sTransform.position.x;
                sy = sTransform.position.y;

                sTransform.position.x = parentTransform.position.x + (sx * cos - sy * sin) * parentTransform.scale.x;
                sTransform.position.y = parentTransform.position.y + (sx * sin + sy * cos) * parentTransform.scale.y;


                sTransform.scale.x *= parentTransform.scale.x;
                sTransform.scale.y *= parentTransform.scale.y;

                sTransform.rotation += parentTransform.rotation;
            }

            for (SpriteTransform iter = sTransform.firstChild; iter != null; iter = iter.next)
            {
                TransformNode(iter, sTransform);
            }
        }
        /// <summary>
        /// Set the max <see cref="Sprite">Sprite</see>'s count can be attach to renderer.
        /// </summary>
        /// <param name="maxSprites">How many sprite the renderer can be attach.</param>
        public void Resize( int maxSprites )
        {
            int layer = gameObject.layer;
            int oldLen = primitives.Length;


            if (oldLen < maxSprites)
            {
                //System.Array.Resize<SpritePrimitive>(ref primitives, maxSprites * 2);
                //System.Array.Resize<SpriteTransform>(ref spriteTransforms, maxSprites * 2);

                SpritePrimitive[] oldPriv = primitives;
                primitives = new SpritePrimitive[maxSprites * 2];
                for (int i = 0; i < oldLen; i++)
                    primitives[i] = oldPriv[i];


                SpriteTransform[] oldSprTran = spriteTransforms;
                spriteTransforms = new SpriteTransform[maxSprites * 2];
                for (int i = 0; i < oldLen; i++)
                    spriteTransforms[i] = oldSprTran[i];


                int ownerID = instanceID;
                for (int i = oldLen; i < primitives.Length; i++)
                {
                    SpritePrimitive pri = new SpritePrimitive(1);
                    pri.ownerID = ownerID;
                    primitives[i] = pri;

                    spriteTransforms[i] = new SpriteTransform();
                    spriteTransforms[i].ResetTransform();
                }
            }

            primitiveCount = primitives.Length;

            primitiveGroup.primitives = primitives;
        }
        void AddSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash )
        {
            int searchHash = component._fullPathHash + parentHash;
  
            SpriteTransform sprTransform = spriteRenderer.GetSpriteTransformByFullPathHash(searchHash);

            if (sprTransform == null)
            {
                {
                    sprTransform = spriteRenderer.AttachSpriteComponent(component);

                    sprTransform.parent = parentTransform;

                    sprTransform.layer = (int)component.layer + state.parentComponentLayer;
                    sprTransform.visible = component.visible;

                    sprTransform.searchHash = searchHash;

                    //sprTransform.name = state.parentTransform != null ? state.parentTransform.component._fullPath + component._fullPath : component._fullPath;
                }


                if (parentTransform != null)
                {

                    if (parentTransform.firstChild == null)
                    {
                        parentTransform.firstChild = sprTransform;
                        parentTransform.lastChild = sprTransform;

                        sprTransform.prve = null;
                        sprTransform.next = null;
                    }
                    else
                    {
                        sprTransform.next = parentTransform.lastChild.next;
                        sprTransform.prve = parentTransform.lastChild;

                        parentTransform.lastChild.next = sprTransform;
                    }
                }
            }

            sprTransform.AttachState(state, component);

            for (int i = 0, e = component.children.Length; i < e; i++)
                AddSprite(state, state.clip.subComponents[component.children[i]], sprTransform, parentHash);
        }
예제 #22
0
    public Polygon2D GetSpriteWorldPolygon()
    {
        if (worldPolygon != null)
        {
            return(worldPolygon);
        }

        if (transform == null)
        {
            return(null);
        }

        Vector2 position = transform.position;

        position += lightSpriteTransform.position;

        Vector2 scale = transform.localScale;

        scale *= lightSpriteTransform.scale;

        float rotation = 0;

        if (lightSpriteTransform.applyRotation)
        {
            rotation += transform.eulerAngles.z + lightSpriteTransform.rotation;
        }

        SpriteTransform spriteTransform = new SpriteTransform(spriteRenderer, position, scale, rotation);

        float   rot  = spriteTransform.rotation;
        Vector2 size = spriteTransform.scale;
        Vector2 pos  = spriteTransform.position;

        rot = rot * Mathf.Deg2Rad + Mathf.PI;

        float rectAngle = Mathf.Atan2(size.y, size.x);
        float dist      = Mathf.Sqrt(size.x * size.x + size.y * size.y);

        Vector2 v1 = new Vector2(pos.x + Mathf.Cos(rectAngle + rot) * dist, pos.y + Mathf.Sin(rectAngle + rot) * dist);
        Vector2 v2 = new Vector2(pos.x + Mathf.Cos(-rectAngle + rot) * dist, pos.y + Mathf.Sin(-rectAngle + rot) * dist);
        Vector2 v3 = new Vector2(pos.x + Mathf.Cos(rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(rectAngle + Mathf.PI + rot) * dist);
        Vector2 v4 = new Vector2(pos.x + Mathf.Cos(-rectAngle + Mathf.PI + rot) * dist, pos.y + Mathf.Sin(-rectAngle + Mathf.PI + rot) * dist);

        worldPolygon = GetPolygon();

        worldPolygon.pointsList[0].x = v1.x;
        worldPolygon.pointsList[0].y = v1.y;

        worldPolygon.pointsList[1].x = v2.x;
        worldPolygon.pointsList[1].y = v2.y;

        worldPolygon.pointsList[2].x = v3.x;
        worldPolygon.pointsList[2].y = v3.y;

        worldPolygon.pointsList[3].x = v4.x;
        worldPolygon.pointsList[3].y = v4.y;

        worldrect = worldPolygon.GetRect();

        return(worldPolygon);
    }
        internal SpriteAnimationKeyFrame EvaluateBlending(float time, SpriteTransform transform, float[] transformProperty)
        {
            int idx = (int)curves[0].curve.Evaluate(time);
            SpriteAnimationKeyFrame kf = keyFrames[idx];

            if ( !transform.isSpriteValid )
                transform.sprite = kf.sprite;

            float v = 0f;
            SpriteAnimationCurve curve = null;
            for (int i = 1, e = curves.Length; i < e; i++)
            {
                curve = curves[i];
                transformProperty[(int)curve.type] = curve.length == 0 ? curve.defaultValue : curve.curve.Evaluate(time);
            }
            return kf;
        }