碧血红天的HomePage

U3d杂谈 — 修改RectTransform.anchors

今天想实现一个进度条,但是分为3段那种。目前Unity中提供得Silder不能满足,看了下它Slider的实现原理。控制进度就是控制Anchors.Max这个变量来改变填充区域的大小,但是自己尝试使用代码修改的时候,发现使用fill2.anchorMax方法修改这个值,导致上面的位置方式也出现修改,不能达到想要的效果。最后尝试了其中的一个函数,达到了效果,但是不是非常明白这其中的原理,因此在这记录一笔。

首先,我们要的RectTransform设置如下:

现在我们要保证Left,Right,Top,Bottom都是一个固定值(0)。然后动态的修改Anchors的值:

rectTransfrom.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 0);       rectTransfrom.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, 0);
rectTransfrom.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 0);        rectTransfrom.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, 0);
rectTransfrom.anchorMin = Vector2.zero;
//fill2AnchorMax 是Vector2
fill2AnchorMax.x = 0.3f;
fill2AnchorMax.y = 1;
rectTransfrom.anchorMax = fill2AnchorMax;

首先使用SetInsetAndSizeFromParentEdge方法设置一遍,再设置anchors的值,这个时候上面的Left,Right,Top,Bottom才没有发生改变。

希望能够帮到大家。

6364 评论

  1. google services instagram buy hacklink.

  2. I have been exploring for a bit for any high quality articles or blog posts on this sort of space . Exploring in Yahoo I at last stumbled upon this website. Reading this info So i?¦m glad to exhibit that I’ve a very good uncanny feeling I discovered exactly what I needed. I such a lot undoubtedly will make certain to do not forget this site and give it a glance on a continuing basis.

  3. Keywords Cytochrome P 450 expression; herb drug interaction; raloxifene; red clover; tamoxifen buy cialis online us

  4. The only side effect was ovarian cyst formation in one patient in group 1 buy clomiphene citrate

  5. can a woman take half a viagra Like succinylcholine, non depolarizing relaxants are potentiated with certain antibiotics, magnesium, and calcium channel blockers

  6. Great amazing issues here. I am very glad to look your article. Thank you so much and i am taking a look forward to contact you. Will you please drop me a mail?

  7. 12 It can be used to further evaluate ovarian reserve, but isn t necessarily more helpful than day 3 FSH and estradiol alone can i buy priligy over the counter LASIK is the premier surgery for vision correction

  8. nolvadex pct for sarms Cardiovascular events and deaths were adjudicated as Major Adverse Cardiovascular Events cardiovascular death, non fatal myocardial infarction, and non fatal stroke in the Phase 3 randomized controlled studies of ZURAMPIC

  9. Hello.This post was extremely fascinating, especially since I was searching for thoughts on this issue last couple of days.

  10. I like this site very much, Its a real nice office to read and obtain information.

  11. Tesisathane ile petek temizleme hizmeti, yangın alarm sistemi kurulumu, güvenlik kamerası sistemleri ve daha onlarca hizmet ile profesyonel hizmetin tadını çıkartabilirsiniz!

  12. Just wish to say your article is as astounding. The clearness in your post is simply spectacular and i could assume you are an expert on this subject. Fine with your permission allow me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please continue the rewarding work.