Пример #1
0
        public override void Initialize(ActorBaseComponent actorBaseComponent)
        {
            base.Initialize(actorBaseComponent);

            ActorComponent actorComponent = actorBaseComponent as ActorComponent;

            m_SortingOrderOffset = actorComponent.SortingOrder;

            ActorImage imageNode = m_ActorNode as ActorImage;

            // Attach the skinned bone nodes to the bones of the skinned renderer.
            if (imageNode.IsSkinned)
            {
                SkinnedMeshRenderer skinnedRenderer = gameObject.GetComponent <SkinnedMeshRenderer>();

                Transform[] transforms = new Transform[imageNode.ConnectedBoneCount + 1];
                transforms[0] = actorComponent.DefaultBone.transform;
                int idx = 1;
                foreach (ActorImage.BoneConnection bc in imageNode.BoneConnections)
                {
                    ActorNodeComponent boneComponent = actorComponent.Nodes[bc.m_BoneIdx];
                    transforms[idx] = boneComponent.gameObject.transform;
                    idx++;
                }
                skinnedRenderer.bones = transforms;
            }
        }
Пример #2
0
        public override void ApplyInterpolation(ActorComponent component, float time, KeyFrame toFrame, float mix)
        {
            ActorImage imageNode = component as ActorImage;

            float[] wr = imageNode.AnimationDeformedVertices;
            float[] to = (toFrame as KeyFrameVertexDeform).m_Vertices;
            int     l  = m_Vertices.Length;

            float f  = (time - m_Time) / (toFrame.Time - m_Time);
            float fi = 1.0f - f;

            if (mix == 1.0f)
            {
                for (int i = 0; i < l; i++)
                {
                    wr[i] = m_Vertices[i] * fi + to[i] * f;
                }
            }
            else
            {
                float mixi = 1.0f - mix;
                for (int i = 0; i < l; i++)
                {
                    float v = m_Vertices[i] * fi + to[i] * f;

                    wr[i] = wr[i] * mixi + v * mix;
                }
            }

            imageNode.IsVertexDeformDirty = true;
        }
Пример #3
0
 void Start()
 {
     if (m_ActorNode == null)
     {
         return;
     }
     m_ActorImage           = m_ActorNode as ActorImage;
     m_VertexPositionBuffer = m_ActorImage.MakeVertexPositionBuffer();
 }
Пример #4
0
        public IActionResult Delete(ActorImage carImage)
        {
            IResult result = _actorImageService.Delete(carImage);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Пример #5
0
        public override void Apply(ActorComponent component, float mix)
        {
            Actor actor = component.Actor;

            foreach (DrawOrderIndex doi in m_OrderedNodes)
            {
                ActorImage actorImage = actor[doi.nodeIdx] as ActorImage;
                if (actorImage != null)
                {
                    actorImage.DrawOrder = doi.order;
                }
            }
        }
Пример #6
0
        public IActionResult Update([FromForm] ActorImage carImage, [FromForm] IFormFile file)
        {
            if (file == null)
            {
                return(BadRequest("Boş resim gönderemezsin"));
            }
            IResult result = _actorImageService.Update(carImage, file);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Пример #7
0
        public new void LateUpdate()
        {
            base.LateUpdate();
            if (m_Mesh == null)
            {
                return;
            }
            m_Mesh.Clear();
            m_Mesh.subMeshCount = m_ImageComponents.Count;
            int vertexOffset = 0;

            Vector3[]  vertices  = m_UsingA ? m_VerticesB : m_VerticesA;
            Color32[]  colors    = m_UsingA ? m_ColorsB : m_ColorsA;
            Material[] materials = m_UsingA ? m_MaterialsB : m_MaterialsA;

            m_UsingA = !m_UsingA;

            // Set vertices, colors, and uv first
            foreach (ActorSingleMeshImageComponent component in m_ImageComponents)
            {
                if (component == null || component.Node == null)
                {
                    continue;
                }
                ActorImage ai          = component.Node as ActorImage;
                int        vertexCount = ai.VertexCount;
                component.UpdateMesh(vertices, colors, vertexOffset);
                vertexOffset += vertexCount;
            }

            m_Mesh.vertices = vertices;
            m_Mesh.colors32 = colors;
            m_Mesh.uv       = m_UVs;

            // Then updated triangles (same as before)...
            foreach (ActorSingleMeshImageComponent component in m_ImageComponents)
            {
                if (component == null || component.Node == null)
                {
                    continue;
                }
                ActorImage ai = component.Node as ActorImage;
                m_Mesh.SetTriangles(/*ai.DoesAnimationVertexDeform ? new int[0] : */ component.m_Triangles, ai.DrawIndex);
                materials[ai.DrawIndex] = component.m_Material;
            }

            m_MeshRenderer.sharedMaterials = materials;
        }
Пример #8
0
        public IResult Add(ActorImage carImage, IFormFile file)
        {
            IResult result = BusinessRules.Run(
                CheckIfImageLimitExpired(carImage.ActorId)
                );

            if (result != null)
            {
                return(result);
            }

            carImage.ImagePath = ActorImagesFileHelper.Add(file);
            carImage.Date      = DateTime.Now;
            _actorImageDal.Add(carImage);
            return(new SuccessResult());
        }
Пример #9
0
        public IResult Delete(ActorImage carImage)
        {
            IResult result = BusinessRules.Run(
                CheckIfImageExists(carImage.Id)
                );

            if (result != null)
            {
                return(result);
            }
            string path = GetById(carImage.Id).Data.ImagePath;

            ActorImagesFileHelper.Delete(path);
            _actorImageDal.Delete(carImage);
            return(new SuccessResult());
        }
Пример #10
0
        void Start()
        {
            ActorImage imageNode = m_ActorNode as ActorImage;

            if (imageNode == null)
            {
                return;
            }
            if (imageNode.IsSkinned)
            {
                m_Mesh = GetComponent <SkinnedMeshRenderer>().sharedMesh;
            }
            else
            {
                m_Mesh = GetComponent <MeshFilter>().sharedMesh;
            }
        }
Пример #11
0
        public override void UpdateTransform()
        {
            if (m_ActorNode == null || m_Mesh == null)
            {
                return;
            }

            ActorImage imageNode = m_ActorNode as ActorImage;

            if (imageNode.IsVertexDeformDirty)
            {
                float[]   v     = imageNode.AnimationDeformedVertices;
                int       l     = imageNode.VertexCount;
                int       vi    = 0;
                Vector3[] verts = m_Mesh.vertices;
                for (int i = 0; i < l; i++)
                {
                    float x = v[vi++];
                    float y = v[vi++];
                    verts[i] = new Vector3(x, y, 0.0f);
                }
                m_Mesh.vertices = verts;
                imageNode.IsVertexDeformDirty = false;
            }
            if (!imageNode.IsSkinned)
            {
                base.UpdateTransform();
            }

            Renderer renderer = gameObject.GetComponent <Renderer>();


            if (m_Mesh.colors[0].a != m_ActorNode.RenderOpacity)
            {
                Color32[] colors = new Color32[m_Mesh.colors32.Length];
                for (int i = 0; i < m_Mesh.colors32.Length; i++)
                {
                    colors[i] = new Color32(255, 255, 255, (byte)(255.0f * m_ActorNode.RenderOpacity));
                }
                m_Mesh.colors32 = colors;
                //renderer.sharedMaterial.color = new Color(1.0f,1.0f,1.0f,m_ActorNode.RenderOpacity);
            }
            renderer.sortingOrder = m_SortingOrderOffset + imageNode.DrawOrder;
            //renderer.sharedMaterial.renderQueue = m_RenderQueueOffset+imageNode.DrawOrder;
        }
Пример #12
0
        public static KeyFrame Read(BinaryReader reader, ActorComponent component)
        {
            KeyFrameVertexDeform frame = new KeyFrameVertexDeform();

            if (!KeyFrameWithInterpolation.Read(reader, frame))
            {
                return(null);
            }

            ActorImage imageNode = component as ActorImage;

            frame.m_Vertices = new float[imageNode.VertexCount * 2];
            Actor.ReadFloat32Array(reader, frame.m_Vertices);

            imageNode.DoesAnimationVertexDeform = true;

            return(frame);
        }
Пример #13
0
        public IResult Update(ActorImage carImage, IFormFile file)
        {
            IResult result = BusinessRules.Run(
                CheckIfImageLimitExpired(carImage.ActorId),
                CheckIfImageExists(carImage.Id)
                );

            if (result != null)
            {
                return(result);
            }

            carImage.Date = DateTime.Now;
            string OldPath = GetById(carImage.Id).Data.ImagePath;

            ActorImagesFileHelper.Update(file, OldPath);
            _actorImageDal.Update(carImage);
            return(new SuccessResult());
        }
        void ReleaseDesignerOutlets()
        {
            if (ActionText != null)
            {
                ActionText.Dispose();
                ActionText = null;
            }

            if (ActorImage != null)
            {
                ActorImage.Dispose();
                ActorImage = null;
            }

            if (btnConfirm != null)
            {
                btnConfirm.Dispose();
                btnConfirm = null;
            }

            if (btnDelete != null)
            {
                btnDelete.Dispose();
                btnDelete = null;
            }

            if (CreationDate != null)
            {
                CreationDate.Dispose();
                CreationDate = null;
            }

            if (separatorView != null)
            {
                separatorView.Dispose();
                separatorView = null;
            }
        }
Пример #15
0
        public override void Apply(ActorComponent component, float mix)
        {
            ActorImage imageNode = component as ActorImage;
            int        l         = m_Vertices.Length;

            float[] wr = imageNode.AnimationDeformedVertices;
            if (mix == 1.0f)
            {
                for (int i = 0; i < l; i++)
                {
                    wr[i] = m_Vertices[i];
                }
            }
            else
            {
                float mixi = 1.0f - mix;
                for (int i = 0; i < l; i++)
                {
                    wr[i] = wr[i] * mixi + m_Vertices[i] * mix;
                }
            }

            imageNode.IsVertexDeformDirty = true;
        }
Пример #16
0
        void ReleaseDesignerOutlets()
        {
            if (Actor_Name != null)
            {
                Actor_Name.Dispose();
                Actor_Name = null;
            }

            if (Actor_NameHeight != null)
            {
                Actor_NameHeight.Dispose();
                Actor_NameHeight = null;
            }

            if (ActorImage != null)
            {
                ActorImage.Dispose();
                ActorImage = null;
            }

            if (BackgroundContentFriendJoined != null)
            {
                BackgroundContentFriendJoined.Dispose();
                BackgroundContentFriendJoined = null;
            }

            if (BackgroundProductSold != null)
            {
                BackgroundProductSold.Dispose();
                BackgroundProductSold = null;
            }

            if (btn_OtherUsers != null)
            {
                btn_OtherUsers.Dispose();
                btn_OtherUsers = null;
            }

            if (btnDotsTop != null)
            {
                btnDotsTop.Dispose();
                btnDotsTop = null;
            }

            if (btnOpenInvitedProfile != null)
            {
                btnOpenInvitedProfile.Dispose();
                btnOpenInvitedProfile = null;
            }

            if (ButtonFacebook != null)
            {
                ButtonFacebook.Dispose();
                ButtonFacebook = null;
            }

            if (ButtonInviteFriends != null)
            {
                ButtonInviteFriends.Dispose();
                ButtonInviteFriends = null;
            }

            if (ButtonProductSold != null)
            {
                ButtonProductSold.Dispose();
                ButtonProductSold = null;
            }

            if (ButtonRewardClaimed != null)
            {
                ButtonRewardClaimed.Dispose();
                ButtonRewardClaimed = null;
            }

            if (ButtonTwitter != null)
            {
                ButtonTwitter.Dispose();
                ButtonTwitter = null;
            }

            if (CollectionUserView != null)
            {
                CollectionUserView.Dispose();
                CollectionUserView = null;
            }

            if (CommentButton != null)
            {
                CommentButton.Dispose();
                CommentButton = null;
            }

            if (CommentsText != null)
            {
                CommentsText.Dispose();
                CommentsText = null;
            }

            if (ContectRewardClaimed != null)
            {
                ContectRewardClaimed.Dispose();
                ContectRewardClaimed = null;
            }

            if (ContectRewardClaimedAspectRatio != null)
            {
                ContectRewardClaimedAspectRatio.Dispose();
                ContectRewardClaimedAspectRatio = null;
            }

            if (ContectRewardClaimedRightBackground != null)
            {
                ContectRewardClaimedRightBackground.Dispose();
                ContectRewardClaimedRightBackground = null;
            }

            if (ContectRewardClaimedTitle != null)
            {
                ContectRewardClaimedTitle.Dispose();
                ContectRewardClaimedTitle = null;
            }

            if (ContentCollectionAvatarView != null)
            {
                ContentCollectionAvatarView.Dispose();
                ContentCollectionAvatarView = null;
            }

            if (ContentCollectionAvatarViewAspectRatio != null)
            {
                ContentCollectionAvatarViewAspectRatio.Dispose();
                ContentCollectionAvatarViewAspectRatio = null;
            }

            if (ContentCollectionCheckInView != null)
            {
                ContentCollectionCheckInView.Dispose();
                ContentCollectionCheckInView = null;
            }

            if (ContentCollectionCheckInViewAspectRatio != null)
            {
                ContentCollectionCheckInViewAspectRatio.Dispose();
                ContentCollectionCheckInViewAspectRatio = null;
            }

            if (ContentFriendJoined != null)
            {
                ContentFriendJoined.Dispose();
                ContentFriendJoined = null;
            }

            if (ContentFriendJoinedAspectRatio != null)
            {
                ContentFriendJoinedAspectRatio.Dispose();
                ContentFriendJoinedAspectRatio = null;
            }

            if (ContentFriendJoinedBackground != null)
            {
                ContentFriendJoinedBackground.Dispose();
                ContentFriendJoinedBackground = null;
            }

            if (ContentFriendJoinedPhoto != null)
            {
                ContentFriendJoinedPhoto.Dispose();
                ContentFriendJoinedPhoto = null;
            }

            if (ContentFriendJoinedUserName != null)
            {
                ContentFriendJoinedUserName.Dispose();
                ContentFriendJoinedUserName = null;
            }

            if (ContentHeaderView != null)
            {
                ContentHeaderView.Dispose();
                ContentHeaderView = null;
            }

            if (ContentImage != null)
            {
                ContentImage.Dispose();
                ContentImage = null;
            }

            if (ContentImageAspectRatio != null)
            {
                ContentImageAspectRatio.Dispose();
                ContentImageAspectRatio = null;
            }

            if (ContentImageTextCaption != null)
            {
                ContentImageTextCaption.Dispose();
                ContentImageTextCaption = null;
            }

            if (ContentMap != null)
            {
                ContentMap.Dispose();
                ContentMap = null;
            }

            if (ContentMapAspectRatio != null)
            {
                ContentMapAspectRatio.Dispose();
                ContentMapAspectRatio = null;
            }

            if (ContentMapView != null)
            {
                ContentMapView.Dispose();
                ContentMapView = null;
            }

            if (ContentProductSold != null)
            {
                ContentProductSold.Dispose();
                ContentProductSold = null;
            }

            if (ContentProductSoldAspectRatio != null)
            {
                ContentProductSoldAspectRatio.Dispose();
                ContentProductSoldAspectRatio = null;
            }

            if (ContentProductSoldTextView != null)
            {
                ContentProductSoldTextView.Dispose();
                ContentProductSoldTextView = null;
            }

            if (ContentShare != null)
            {
                ContentShare.Dispose();
                ContentShare = null;
            }

            if (ContentShareAspectRatio != null)
            {
                ContentShareAspectRatio.Dispose();
                ContentShareAspectRatio = null;
            }

            if (ContentText != null)
            {
                ContentText.Dispose();
                ContentText = null;
            }

            if (ContentTextHeight != null)
            {
                ContentTextHeight.Dispose();
                ContentTextHeight = null;
            }

            if (ContentVideo != null)
            {
                ContentVideo.Dispose();
                ContentVideo = null;
            }

            if (ContentVideoAspectRatio != null)
            {
                ContentVideoAspectRatio.Dispose();
                ContentVideoAspectRatio = null;
            }

            if (ContentVideoButtonPlay != null)
            {
                ContentVideoButtonPlay.Dispose();
                ContentVideoButtonPlay = null;
            }

            if (ContentWebView != null)
            {
                ContentWebView.Dispose();
                ContentWebView = null;
            }

            if (ContentWebViewAspectRatio != null)
            {
                ContentWebViewAspectRatio.Dispose();
                ContentWebViewAspectRatio = null;
            }

            if (Creation_Date != null)
            {
                Creation_Date.Dispose();
                Creation_Date = null;
            }

            if (Creation_DateHeight != null)
            {
                Creation_DateHeight.Dispose();
                Creation_DateHeight = null;
            }

            if (GradientImageView != null)
            {
                GradientImageView.Dispose();
                GradientImageView = null;
            }

            if (GradientImageViewAspect != null)
            {
                GradientImageViewAspect.Dispose();
                GradientImageViewAspect = null;
            }

            if (IconContentFriendJoined != null)
            {
                IconContentFriendJoined.Dispose();
                IconContentFriendJoined = null;
            }

            if (IconProductSold != null)
            {
                IconProductSold.Dispose();
                IconProductSold = null;
            }

            if (Label_ContectReward_Claimed != null)
            {
                Label_ContectReward_Claimed.Dispose();
                Label_ContectReward_Claimed = null;
            }

            if (LabelFriendsWelcome != null)
            {
                LabelFriendsWelcome.Dispose();
                LabelFriendsWelcome = null;
            }

            if (LikeButton != null)
            {
                LikeButton.Dispose();
                LikeButton = null;
            }

            if (LikesText != null)
            {
                LikesText.Dispose();
                LikesText = null;
            }

            if (LikesView != null)
            {
                LikesView.Dispose();
                LikesView = null;
            }

            if (LikesViewHeightAspecnRatio != null)
            {
                LikesViewHeightAspecnRatio.Dispose();
                LikesViewHeightAspecnRatio = null;
            }

            if (LineSeparator != null)
            {
                LineSeparator.Dispose();
                LineSeparator = null;
            }

            if (MainBackgroundView != null)
            {
                MainBackgroundView.Dispose();
                MainBackgroundView = null;
            }

            if (MainView != null)
            {
                MainView.Dispose();
                MainView = null;
            }

            if (PointsIconWidthConstraint != null)
            {
                PointsIconWidthConstraint.Dispose();
                PointsIconWidthConstraint = null;
            }

            if (ProductSoldCount != null)
            {
                ProductSoldCount.Dispose();
                ProductSoldCount = null;
            }

            if (ProductSoldMainBackground != null)
            {
                ProductSoldMainBackground.Dispose();
                ProductSoldMainBackground = null;
            }

            if (ProductSoldTitle != null)
            {
                ProductSoldTitle.Dispose();
                ProductSoldTitle = null;
            }

            if (ProductSoldUpBackground != null)
            {
                ProductSoldUpBackground.Dispose();
                ProductSoldUpBackground = null;
            }

            if (PtsText != null)
            {
                PtsText.Dispose();
                PtsText = null;
            }

            if (ReadCommentButtonHeight != null)
            {
                ReadCommentButtonHeight.Dispose();
                ReadCommentButtonHeight = null;
            }

            if (ReadCommentsButton != null)
            {
                ReadCommentsButton.Dispose();
                ReadCommentsButton = null;
            }

            if (RewardClaimedCount != null)
            {
                RewardClaimedCount.Dispose();
                RewardClaimedCount = null;
            }

            if (SmileButton != null)
            {
                SmileButton.Dispose();
                SmileButton = null;
            }

            if (TextContentFriendJoined != null)
            {
                TextContentFriendJoined.Dispose();
                TextContentFriendJoined = null;
            }

            if (TextProductSold != null)
            {
                TextProductSold.Dispose();
                TextProductSold = null;
            }

            if (TextQuoteLineSeparatorHeight != null)
            {
                TextQuoteLineSeparatorHeight.Dispose();
                TextQuoteLineSeparatorHeight = null;
            }

            if (TopActionText != null)
            {
                TopActionText.Dispose();
                TopActionText = null;
            }

            if (TopActionTextHeight != null)
            {
                TopActionTextHeight.Dispose();
                TopActionTextHeight = null;
            }

            if (TopPaddingView != null)
            {
                TopPaddingView.Dispose();
                TopPaddingView = null;
            }

            if (TopPaddingViewAspect != null)
            {
                TopPaddingViewAspect.Dispose();
                TopPaddingViewAspect = null;
            }

            if (TopView != null)
            {
                TopView.Dispose();
                TopView = null;
            }

            if (TopViewHeight != null)
            {
                TopViewHeight.Dispose();
                TopViewHeight = null;
            }

            if (uiProfileButton != null)
            {
                uiProfileButton.Dispose();
                uiProfileButton = null;
            }

            if (vDotsTop != null)
            {
                vDotsTop.Dispose();
                vDotsTop = null;
            }

            if (vDotsTopHeight != null)
            {
                vDotsTopHeight.Dispose();
                vDotsTopHeight = null;
            }
        }
Пример #17
0
        public void InitializeFromAsset(ActorAsset actorAsset)
        {
            HideFlags hideFlags = HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild | HideFlags.DontUnloadUnusedAsset | HideFlags.HideInHierarchy | HideFlags.HideInInspector;

            m_ActorAsset = actorAsset;

            if (!actorAsset.Loaded && !actorAsset.Load())
            {
#if UNITY_EDITOR
                Debug.Log("Bad actorAsset referenced by Actor2D.");
#endif
                return;
            }

            RemoveNodes();

            m_ActorInstance = new Actor();
            m_ActorInstance.Copy(m_ActorAsset.Actor);
            OnActorInstanced();

            // Instance actor bones first as our image nodes need to know about them if they are skinned.
            {
                //ActorNode[] allNodes = m_ActorInstance.AllNodes;
                IList <Nima.ActorComponent> actorComponents = m_ActorInstance.Components;
                m_Nodes = new ActorNodeComponent[actorComponents.Count];

                int imgNodeIdx = 0;
                for (int i = 0; i < actorComponents.Count; i++)
                {
                    Nima.ActorComponent ac = actorComponents[i];
                    ActorNode           an = ac as ActorNode;
                    if (an == null)
                    {
                        continue;
                    }
                    GameObject go = null;
                    ActorImage ai = an as ActorImage;
                    if (ai != null)
                    {
                        ActorNodeComponent nodeComponent = MakeImageNodeComponent(imgNodeIdx, ai);
                        nodeComponent.Node = ai;
                        go         = nodeComponent.gameObject;
                        m_Nodes[i] = nodeComponent;
                        imgNodeIdx++;
                    }
                    else
                    {
                        ActorCollider actorCollider = an as ActorCollider;
                        if (actorCollider != null && InstanceColliders)
                        {
                            go = new GameObject(an.Name, typeof(ActorColliderComponent));
                            ActorColliderComponent colliderComponent = go.GetComponent <ActorColliderComponent>();
                            colliderComponent.Node = actorCollider;
                            m_Nodes[i]             = colliderComponent;
                        }
                        // else
                        // {
                        //  go = new GameObject(an.Name, typeof(ActorNodeComponent));

                        //  ActorNodeComponent nodeComponent = go.GetComponent<ActorNodeComponent>();
                        //  nodeComponent.Node = an;
                        //  m_Nodes[i] = nodeComponent;
                        // }
                    }

                    if (go != null)
                    {
                        go.hideFlags = hideFlags;
                    }
                }
                // After they are all created, initialize them.
                for (int i = 0; i < m_Nodes.Length; i++)
                {
                    ActorNodeComponent nodeComponent = m_Nodes[i];
                    if (nodeComponent != null)
                    {
                        nodeComponent.Initialize(this);
                    }
                }
            }

            OnActorInitialized();

#if UNITY_EDITOR
            LateUpdate();
            UpdateEditorBounds();
#endif
        }
Пример #18
0
 protected abstract ActorNodeComponent MakeImageNodeComponent(int imageNodeIndex, ActorImage actorImage);
Пример #19
0
        protected override ActorNodeComponent MakeImageNodeComponent(int imageNodeIndex, ActorImage actorImage)
        {
            if (actorImage.VertexCount == 0)
            {
                GameObject         go            = new GameObject(actorImage.Name, typeof(ActorNodeComponent));
                ActorNodeComponent nodeComponent = go.GetComponent <ActorNodeComponent>();
                return(nodeComponent);
            }
            else
            {
                Mesh mesh     = m_ActorAsset.GetMesh(imageNodeIndex);
                bool hasBones = actorImage.ConnectedBoneCount > 0;

                GameObject go = hasBones ?
                                new GameObject(actorImage.Name, typeof(SkinnedMeshRenderer), typeof(ActorImageComponent)) :
                                new GameObject(actorImage.Name, typeof(MeshFilter), typeof(MeshRenderer), typeof(ActorImageComponent));


                ActorImageComponent actorImageComponent = go.GetComponent <ActorImageComponent>();
                // Clone the vertex array alway right now so we can update opacity
                // In future we could check if this node animates opacity as we did for vertex deform
                //if(actorImage.DoesAnimationVertexDeform)
                {
                    // Clone the vertex array if we deform.
                    Mesh clonedMesh = new Mesh();
                    clonedMesh.vertices    = (Vector3[])mesh.vertices.Clone();
                    clonedMesh.uv          = mesh.uv;
                    clonedMesh.boneWeights = mesh.boneWeights;
                    clonedMesh.bindposes   = mesh.bindposes;
                    clonedMesh.triangles   = mesh.triangles;
                    clonedMesh.colors32    = (UnityEngine.Color32[])mesh.colors32.Clone();
                    clonedMesh.RecalculateNormals();
                    clonedMesh.MarkDynamic();
                    mesh = clonedMesh;
                }
                if (hasBones)
                {
                    Mesh skinnedMesh = new Mesh();
                    skinnedMesh.vertices    = mesh.vertices;
                    skinnedMesh.uv          = mesh.uv;
                    skinnedMesh.boneWeights = mesh.boneWeights;
                    skinnedMesh.triangles   = mesh.triangles;
                    skinnedMesh.colors32    = (UnityEngine.Color32[])mesh.colors32.Clone();
                    skinnedMesh.bindposes   = mesh.bindposes;

                    go.GetComponent <SkinnedMeshRenderer>().sharedMesh = skinnedMesh;
                }
                else
                {
                    MeshFilter meshFilter = go.GetComponent <MeshFilter>();
                    meshFilter.sharedMesh = mesh;
                }

                Renderer renderer = go.GetComponent <Renderer>();

                Material material = m_ActorAsset.GetMaterial(actorImage.TextureIndex);
                renderer.sortingLayerID = m_SortingLayerID;

                switch (actorImage.BlendMode)
                {
                case BlendModes.Screen:
                {
                    Material overrideMaterial = new Material(Shader.Find("Nima/Screen"));
                    overrideMaterial.mainTexture = material.mainTexture;
                    material = overrideMaterial;
                    break;
                }

                case BlendModes.Additive:
                {
                    Material overrideMaterial = new Material(Shader.Find("Nima/Additive"));
                    overrideMaterial.mainTexture = material.mainTexture;
                    material = overrideMaterial;
                    break;
                }

                case BlendModes.Multiply:
                {
                    Material overrideMaterial = new Material(Shader.Find("Nima/Multiply"));
                    overrideMaterial.mainTexture = material.mainTexture;
                    material = overrideMaterial;
                    break;
                }

                default:
                {
                    /*Material overrideMaterial = new Material(Shader.Find("Nima/Normal"));
                     * overrideMaterial.mainTexture = material.mainTexture;
                     * material = overrideMaterial;*/
                    break;
                }
                }

                renderer.sharedMaterial = material;
                return(actorImageComponent);
            }
        }
Пример #20
0
        protected override ActorNodeComponent MakeImageNodeComponent(int imageNodeIndex, ActorImage actorImage)
        {
            bool hasBones = actorImage.ConnectedBoneCount > 0;

            GameObject go = new GameObject(actorImage.Name, typeof(ActorSingleMeshImageComponent));

            ActorSingleMeshImageComponent actorImageComponent = go.GetComponent <ActorSingleMeshImageComponent>();

            actorImageComponent.Node = actorImage;
            m_ImageComponents.Add(actorImageComponent);

            Material material = m_ActorAsset.GetMaterial(actorImage.TextureIndex);

            if (material != null)
            {
                switch (actorImage.BlendMode)
                {
                case BlendModes.Screen:
                {
                    Material overrideMaterial = new Material(Shader.Find("Nima/Screen"));
                    overrideMaterial.mainTexture = material.mainTexture;
                    material = overrideMaterial;
                    break;
                }

                case BlendModes.Additive:
                {
                    Material overrideMaterial = new Material(Shader.Find("Nima/Additive"));
                    overrideMaterial.mainTexture = material.mainTexture;
                    material = overrideMaterial;
                    break;
                }

                case BlendModes.Multiply:
                {
                    Material overrideMaterial = new Material(Shader.Find("Nima/Multiply"));
                    overrideMaterial.mainTexture = material.mainTexture;
                    material = overrideMaterial;
                    break;
                }

                default:
                {
                    /*	Material overrideMaterial = new Material(Shader.Find("Nima/Normal"));
                     *      //Material overrideMaterial = new Material(Shader.Find("Transparent/Diffuse"));
                     *      overrideMaterial.color = Color.white;
                     *      overrideMaterial.mainTexture = material.mainTexture;
                     *      material = overrideMaterial;*/
                    break;
                }
                }
            }
            //	actorImageComponent.m_Mesh = mesh;
            actorImageComponent.m_Material = material;
            if (material != null)
            {
                material.hideFlags = HideFlags.HideInInspector;
            }

            return(actorImageComponent);
        }
Пример #21
0
        protected override void OnActorInitialized()
        {
            m_MeshRenderer = gameObject.GetComponent <MeshRenderer>();
            m_MeshRenderer.sortingOrder   = m_SortingOrder;
            m_MeshRenderer.sortingLayerID = m_SortingLayerID;

            m_Mesh = new Mesh();
            m_Mesh.MarkDynamic();
            m_Mesh.subMeshCount = m_ImageComponents.Count;

            // Count vertex size.
            int totalVertexCount = 0;

            foreach (ActorSingleMeshImageComponent component in m_ImageComponents)
            {
                if (component == null || component.Node == null)
                {
                    continue;
                }
                ActorImage imageNode = component.Node as ActorImage;

                totalVertexCount += imageNode.VertexCount;
            }


            int vertexOffset = 0;

            m_VerticesA  = new Vector3[totalVertexCount];
            m_VerticesB  = new Vector3[totalVertexCount];
            m_ColorsA    = new Color32[totalVertexCount];
            m_ColorsB    = new Color32[totalVertexCount];
            m_MaterialsA = new Material[m_Mesh.subMeshCount];
            m_MaterialsB = new Material[m_Mesh.subMeshCount];

            m_UsingA = true;
            Vector3[]  vertices  = m_VerticesA;
            Color32[]  colors    = m_ColorsA;
            Material[] materials = m_MaterialsA;

            m_UVs = new Vector2[totalVertexCount];
            m_MeshRenderer.sharedMaterials = materials;

            // Update vertices and colors first so that triangles are set after the buffers are valid.
            foreach (ActorSingleMeshImageComponent component in m_ImageComponents)
            {
                if (component == null || component.Node == null)
                {
                    continue;
                }
                ActorImage ai          = component.Node as ActorImage;
                int        vertexCount = ai.VertexCount;
                component.UpdateMesh(vertices, colors, vertexOffset);

                int     writeIdx       = vertexOffset;
                float[] vertexBuffer   = ai.Vertices;
                int     aiUVOffset     = ai.VertexUVOffset;
                int     aiVertexStride = ai.VertexStride;
                int     idx            = 0;
                for (int i = 0; i < vertexCount; i++)
                {
                    m_UVs[writeIdx++] = new Vector2(vertexBuffer[idx + aiUVOffset], 1.0f - vertexBuffer[idx + aiUVOffset + 1]);
                    idx += aiVertexStride;
                }
                vertexOffset += vertexCount;
            }

            m_Mesh.vertices = vertices;
            m_Mesh.colors32 = colors;
            m_Mesh.uv       = m_UVs;

            // Unity requires setting the triangles after the mesh is valid (we also do this to ensure bounds are calculated correctly)
            vertexOffset = 0;
            foreach (ActorSingleMeshImageComponent component in m_ImageComponents)
            {
                if (component == null || component.Node == null)
                {
                    continue;
                }
                ActorImage ai          = component.Node as ActorImage;
                int        vertexCount = ai.VertexCount;
                component.UpdateMesh(vertices, colors, vertexOffset);

                int      triangleCount  = ai.TriangleCount;
                ushort[] triangleBuffer = ai.Triangles;
                int[]    triangles      = new int[triangleCount * 3];
                int      triIdx         = 0;
                for (int i = 0; i < triangleCount; i++)
                {
                    triangles[triIdx]     = (int)triangleBuffer[triIdx + 2] + vertexOffset;
                    triangles[triIdx + 1] = (int)triangleBuffer[triIdx + 1] + vertexOffset;
                    triangles[triIdx + 2] = (int)triangleBuffer[triIdx] + vertexOffset;
                    triIdx += 3;
                }

                component.m_Triangles = triangles;
                m_Mesh.SetTriangles(/*ai.DoesAnimationVertexDeform ? new int[0] : */ triangles, ai.DrawIndex);
                materials[ai.DrawIndex] = component.m_Material;

                vertexOffset += vertexCount;
            }


            // set to show they updated

            MeshFilter filter = GetComponent <MeshFilter>();

            filter.sharedMesh        = m_Mesh;
            m_MeshRenderer.hideFlags = HideFlags.HideInInspector;
            filter.hideFlags         = HideFlags.HideInInspector;

            m_MeshRenderer.sharedMaterials = materials;
            m_Mesh.RecalculateBounds();
            m_Mesh.RecalculateNormals();
        }
Пример #22
0
        private void InitializeActor()
        {
            IEnumerable <ActorNode> nodes = m_Actor.Nodes;
            //m_Actor.Root.ScaleX = NimaToUnityScale;
            //m_Actor.Root.ScaleY = NimaToUnityScale;

            int imgNodeCount = 0;

            foreach (ActorNode node in nodes)
            {
                ActorImage ai = node as ActorImage;
                if (ai != null)
                {
                    imgNodeCount++;
                }
            }
            m_ImageNodes = new ActorImage[imgNodeCount];
            m_Meshes     = new Mesh[imgNodeCount];

            int imgIdx = 0;

            foreach (ActorNode node in nodes)
            {
                ActorImage ai = node as ActorImage;
                if (ai != null)
                {
                    m_ImageNodes[imgIdx] = ai;
                    Mesh mesh = new Mesh();
                    if (ai.DoesAnimationVertexDeform)
                    {
                        mesh.MarkDynamic();
                    }
                    m_Meshes[imgIdx] = mesh;
                    imgIdx++;

                    int     aiVertexCount    = ai.VertexCount;
                    int     aiVertexStride   = ai.VertexStride;
                    int     aiPositionOffset = ai.VertexPositionOffset;
                    int     aiUVOffset       = ai.VertexUVOffset;
                    float[] vertexBuffer     = ai.Vertices;

                    Vector3[] vertices = new Vector3[aiVertexCount];
                    Vector2[] uvs      = new Vector2[aiVertexCount];
                    Color32[] colors   = new Color32[aiVertexCount];

                    if (aiVertexStride == 12)
                    {
                        // We have bone weights.
                        int aiVertexBoneIndexOffset  = ai.VertexBoneIndexOffset;
                        int aiVertexBoneWeightOffset = ai.VertexBoneWeightOffset;
                        int idx = 0;

                        Mat2D newWorldOverride = new Mat2D();
                        // Change the override to scale by our UnityScale
                        Mat2D.Multiply(newWorldOverride, m_Actor.Root.Transform, ai.WorldTransformOverride);
                        ai.WorldTransformOverride = newWorldOverride;

                        // We don't use the bind transforms in the regular render path as we let Unity do the deform
                        // But in the Canvas render path we need to manually deform the vertices so we need to have our
                        // bind matrices in the correct world transform.
                        ai.TransformBind(m_Actor.Root.Transform);

                        if (ai.DoesAnimationVertexDeform)
                        {
                            // Update the vertex deforms too.
                            ai.TransformDeformVertices(ai.WorldTransform);
                        }

                        // Unity expects skinned mesh vertices to be in bone world space (character world).
                        // So we transform them to our world transform.
                        BoneWeight[] weights = new BoneWeight[aiVertexCount];

                        Mat2D wt = ai.WorldTransform;

                        for (int j = 0; j < aiVertexCount; j++)
                        {
                            float x = vertexBuffer[idx + aiPositionOffset];
                            float y = vertexBuffer[idx + aiPositionOffset + 1];
                            vertices[j] = new Vector3(wt[0] * x + wt[2] * y + wt[4], wt[1] * x + wt[3] * y + wt[5], 0.0f);

                            uvs[j]    = new Vector2(vertexBuffer[idx + aiUVOffset], 1.0f - vertexBuffer[idx + aiUVOffset + 1]);
                            colors[j] = new Color32(255, 255, 255, (byte)Math.Round(255 * ai.RenderOpacity));

                            BoneWeight weight = new BoneWeight();
                            weight.boneIndex0 = (int)vertexBuffer[idx + aiVertexBoneIndexOffset];
                            weight.boneIndex1 = (int)vertexBuffer[idx + aiVertexBoneIndexOffset + 1];
                            weight.boneIndex2 = (int)vertexBuffer[idx + aiVertexBoneIndexOffset + 2];
                            weight.boneIndex3 = (int)vertexBuffer[idx + aiVertexBoneIndexOffset + 3];
                            weight.weight0    = vertexBuffer[idx + aiVertexBoneWeightOffset];
                            weight.weight1    = vertexBuffer[idx + aiVertexBoneWeightOffset + 1];
                            weight.weight2    = vertexBuffer[idx + aiVertexBoneWeightOffset + 2];
                            weight.weight3    = vertexBuffer[idx + aiVertexBoneWeightOffset + 3];
                            weights[j]        = weight;

                            idx += aiVertexStride;
                        }
                        mesh.vertices    = vertices;
                        mesh.uv          = uvs;
                        mesh.boneWeights = weights;

                        // Set up bind poses.
                        int bindBoneCount = ai.ConnectedBoneCount + 1;                         // Always an extra bone for the root transform (identity).

                        Matrix4x4[] bindPoses = new Matrix4x4[bindBoneCount];
                        for (int i = 0; i < bindBoneCount; i++)
                        {
                            Matrix4x4 mat = new Matrix4x4();
                            mat          = Matrix4x4.identity;
                            bindPoses[i] = mat;
                        }

                        int bidx = 1;

                        foreach (ActorImage.BoneConnection bc in ai.BoneConnections)
                        {
                            Matrix4x4 mat   = bindPoses[bidx];
                            Mat2D     ibind = bc.InverseBind;

                            mat[0, 0]       = ibind[0];
                            mat[1, 0]       = ibind[1];
                            mat[0, 1]       = ibind[2];
                            mat[1, 1]       = ibind[3];
                            mat[0, 3]       = ibind[4];
                            mat[1, 3]       = ibind[5];
                            bindPoses[bidx] = mat;
                            bidx++;
                        }
                        mesh.bindposes = bindPoses;
                    }
                    else
                    {
                        int idx = 0;
                        for (int j = 0; j < aiVertexCount; j++)
                        {
                            vertices[j] = new Vector3(vertexBuffer[idx + aiPositionOffset], vertexBuffer[idx + aiPositionOffset + 1], 0);
                            uvs[j]      = new Vector2(vertexBuffer[idx + aiUVOffset], 1.0f - vertexBuffer[idx + aiUVOffset + 1]);
                            colors[j]   = new Color32(255, 255, 255, (byte)Math.Round(255 * ai.RenderOpacity));

                            idx += aiVertexStride;
                        }
                        mesh.vertices = vertices;
                        mesh.uv       = uvs;
                    }


                    int      triangleCount  = ai.TriangleCount;
                    ushort[] triangleBuffer = ai.Triangles;

                    int[] tris   = new int[triangleCount * 3];
                    int   triIdx = 0;
                    for (int j = 0; j < triangleCount; j++)
                    {
                        tris[triIdx]     = (int)triangleBuffer[triIdx + 2];
                        tris[triIdx + 1] = (int)triangleBuffer[triIdx + 1];
                        tris[triIdx + 2] = (int)triangleBuffer[triIdx];
                        triIdx          += 3;
                    }

                    mesh.triangles = tris;
                    mesh.colors32  = colors;
                    mesh.RecalculateBounds();
                    mesh.RecalculateNormals();

                    // We don't need to hold the geometry data in the node now that it's in our buffers.
                    // ai.DisposeGeometry(); // We now do need to hold onto it as we manually deform.
                }
            }

            // Find any vertex deform animation keyframes and update them to scale the vertices as is necessary for the skinned path.
            foreach (Nima.Animation.ActorAnimation animation in m_Actor.Animations)
            {
                if (animation == null || animation.AnimatedComponents == null)
                {
                    continue;
                }
                foreach (Nima.Animation.ComponentAnimation componentAnimation in animation.AnimatedComponents)
                {
                    ActorNode node = m_Actor[componentAnimation.ComponentIndex] as ActorNode;
                    if (node == null)
                    {
                        continue;
                    }
                    ActorImage actorImage = node as ActorImage;
                    if (actorImage != null && actorImage.ConnectedBoneCount == 0)
                    {
                        // This image is in the hierarchy, no need to transform the vertices.
                        continue;
                    }
                    foreach (Nima.Animation.PropertyAnimation propertyAnimation in componentAnimation.Properties)
                    {
                        if (propertyAnimation != null && propertyAnimation.PropertyType == Nima.Animation.PropertyTypes.VertexDeform)
                        {
                            foreach (Nima.Animation.KeyFrame keyFrame in propertyAnimation.KeyFrames)
                            {
                                (keyFrame as Nima.Animation.KeyFrameVertexDeform).TransformVertices(node.WorldTransform);
                            }
                        }
                    }
                }
            }
        }
Пример #23
0
        protected override ActorNodeComponent MakeImageNodeComponent(int imageNodeIndex, ActorImage actorImage)
        {
            GameObject         gameObject    = new GameObject(actorImage.Name, typeof(ActorNodeComponent));
            ActorNodeComponent nodeComponent = gameObject.GetComponent <ActorNodeComponent>();

            Mesh mesh     = m_ActorAsset.GetMesh(imageNodeIndex);
            bool hasBones = actorImage.ConnectedBoneCount > 0;

            GameObject go = new GameObject(actorImage.Name, typeof(RectTransform), typeof(CanvasRenderer), typeof(ActorCanvasImageComponent));

            ActorCanvasImageComponent actorImageComponent = go.GetComponent <ActorCanvasImageComponent>();

            actorImageComponent.Node = actorImage;
            go.transform.SetParent(m_DrawOrderRoot.transform, false);
            m_ImageComponents.Add(actorImageComponent);

            // Clone the vertex array alway right now so we can update opacity
            Mesh clonedMesh = new Mesh();

            clonedMesh.vertices  = (Vector3[])mesh.vertices.Clone();
            clonedMesh.uv        = mesh.uv;
            clonedMesh.triangles = mesh.triangles;
            clonedMesh.colors32  = (UnityEngine.Color32[])mesh.colors32.Clone();
            clonedMesh.RecalculateNormals();
            clonedMesh.MarkDynamic();
            mesh = clonedMesh;

            Material material = m_ActorAsset.GetMaterial(actorImage.TextureIndex);

            switch (actorImage.BlendMode)
            {
            case BlendModes.Screen:
            {
                Material overrideMaterial = new Material(Shader.Find("Nima/Screen"));
                overrideMaterial.mainTexture = material.mainTexture;
                material = overrideMaterial;
                break;
            }

            case BlendModes.Additive:
            {
                Material overrideMaterial = new Material(Shader.Find("Nima/Additive"));
                overrideMaterial.mainTexture = material.mainTexture;
                material = overrideMaterial;
                break;
            }

            case BlendModes.Multiply:
            {
                Material overrideMaterial = new Material(Shader.Find("Nima/Multiply"));
                overrideMaterial.mainTexture = material.mainTexture;
                material = overrideMaterial;
                break;
            }

            default:
            {
                /*	Material overrideMaterial = new Material(Shader.Find("Nima/Normal"));
                 *      //Material overrideMaterial = new Material(Shader.Find("Transparent/Diffuse"));
                 *      overrideMaterial.color = Color.white;
                 *      overrideMaterial.mainTexture = material.mainTexture;
                 *      material = overrideMaterial;*/
                break;
            }
            }

            actorImageComponent.m_Mesh     = mesh;
            actorImageComponent.m_Material = material;

            return(nodeComponent);
        }