{"id":328,"date":"2015-03-29T09:34:58","date_gmt":"2015-03-29T01:34:58","guid":{"rendered":"http:\/\/qxu1606620110.my3w.com\/?p=328"},"modified":"2016-10-11T09:35:15","modified_gmt":"2016-10-11T01:35:15","slug":"%e5%9c%a8unity%e4%b8%ad%e5%ae%9e%e7%8e%b0animation%e5%8a%a8%e7%94%bb%e7%9a%84%e6%ad%a3%e5%8f%8d%e6%92%ad%e6%94%be","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=328","title":{"rendered":"\u5728Unity\u4e2d\u5b9e\u73b0Animation\u52a8\u753b\u7684\u6b63\u53cd\u64ad\u653e"},"content":{"rendered":"\n<pre class=\"lang:c# decode:true \" >using UnityEngine;\r\nusing System.Collections;\r\n \r\npublic class AnimationAntiSowing : MonoBehaviour {\r\n \r\n \r\n    public static AnimationAntiSowing _initialise;\r\n \r\n    void Awake()\r\n    {\r\n        _initialise = this;\r\n    }\r\n \r\n    \/\/\/ &lt;summary&gt;\r\n    \/\/\/ \u52a8\u753b\u8fdb\u884c\u6b63\u53cd\u64ad\u653e\r\n    \/\/\/ &lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"gameObject\"&gt;\u9700\u8981\u64ad\u653e\u52a8\u753b\u7684\u7269\u4f53&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"isZhengOrFan\"&gt;\u52a8\u753b\u7684\u64ad\u653e\u72b6\u6001&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"animation\"&gt;\u52a8\u753b\u72b6\u6001&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n    public bool isPositiveAndNegativePlay(GameObject gameObject,bool isZhengOrFan,AnimationState animation)\r\n    {\r\n        \/\/\u5224\u65ad\u4f20\u5165\u7684\u52a8\u753b\u7684\u64ad\u653e\u72b6\u6001\r\n        \/\/----\u4f20\u5165\u7684\u72b6\u6001\u4e3atrue\u65f6\uff0c\u8868\u793a\u6b63\u5e38\u64ad\u653e\r\n        \/\/----\u4f20\u5165\u7684\u72b6\u6001\u4e3afalse\u65f6\uff0c\u8868\u793a\u52a8\u753b\u64ad\u653e\u5b8c\uff0c\u53ef\u4ee5\u8fdb\u884c\u53cd\u5411\u64ad\u653e\r\n        if(!isZhengOrFan)\r\n        {\r\n            \/\/\u5f53\u6ca1\u6709\u64ad\u653e\u52a8\u753b\u7684\u65f6\u5019\uff0c\u64ad\u653e\u52a8\u753b\r\n            if(!gameObject.animation.isPlaying)\r\n            {\r\n                gameObject.animation.Play();\r\n                \/\/-----\u6539\u53d8\u52a8\u753b\u7684\u64ad\u653e\u72b6\u6001-----\r\n                \/\/\u52a8\u753b\u7684\u5f53\u524d\u65f6\u95f4\u7f6e\u4e3a\u521d\u59cb\r\n                animation.time = 0f;\r\n                \/\/\u52a8\u753b\u7684\u64ad\u653e\u901f\u5ea6\u4e3a\u6b63\u5e38\u901f\u5ea6\r\n                animation.speed = 1.0f;\r\n                \/\/\u6539\u53d8\u4f20\u5165\u7684bool\u53d8\u91cf\u7684\u503c\r\n                isZhengOrFan = true;\r\n            }\r\n        }\r\n        else\r\n        {\r\n            \/\/\u5f53\u6ca1\u6709\u64ad\u653e\u52a8\u753b\u7684\u65f6\u5019\uff0c\u64ad\u653e\u52a8\u753b\r\n            if (!gameObject.animation.isPlaying)\r\n            {\r\n                gameObject.animation.Play();\r\n                \/\/-----\u6539\u53d8\u52a8\u753b\u7684\u64ad\u653e\u72b6\u6001-----\r\n                \/\/\u52a8\u753b\u7684\u5f53\u524d\u65f6\u95f4\u7f6e\u4e3a\u52a8\u753b\u7684\u65f6\u957f\r\n                animation.time = animation.length;\r\n                \/\/\u5411\u540e\u8d70\uff0c\u5373\u52a8\u753b\u8fdb\u884c\u53cd\u5411\u64ad\u653e\uff0c\u4ece\u7ec8\u70b9\u5411\u8d77\u70b9\u64ad\u653e\r\n                animation.speed = -1.0f;\r\n                \/\/\u6539\u53d8\u4f20\u5165\u7684bool\u53d8\u91cf\u7684\u503c\r\n                isZhengOrFan = false;\r\n            }\r\n        }\r\n \r\n        return isZhengOrFan;\r\n    }\r\n}<\/pre>\n<p style=\"text-align: center;\"><span style=\"color: #ff0000;\">\u8f6c\u81ea\uff1ahttp:\/\/www.oschina.net\/code\/snippet_2272150_45358<\/span><\/p>\n<p style=\"text-align: left;\">\n","protected":false},"excerpt":{"rendered":"<p>using UnityEngine; using System.Collecti &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=328\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[84,83],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/328"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=328"}],"version-history":[{"count":3,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/328\/revisions"}],"predecessor-version":[{"id":762,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/328\/revisions\/762"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=328"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}