Hides
How do I use Hides
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
127 | HideSprites(root, hiddenSprites, mainlineKey.Time); | 1 |
182 |
private void HideSprites(GameObject root, IEnumerable |
2 |
File name: AnimationBuilder.cs
Copy
112 private void MakeAnimationCurves(GameObject root, AnimationClip animClip, Animation animation)
113 {
114 acb = new AnimationCurveBuilder();
115
116 //Get a list of all sprites on this GO
117 var allSprites = root.GetComponentsInChildren
118
119 //Add a key for all objects on the first frame
120 SetGameObjectForKey(root, animClip, animation.MainlineKeys.First(), 0);
121
122 foreach (var mainlineKey in animation.MainlineKeys)
123 {
124
125 var visibleSprites = SetGameObjectForKey(root, animClip, mainlineKey);
126 var hiddenSprites = allSprites.Except(visibleSprites);
127 HideSprites(root, hiddenSprites, mainlineKey.Time);
128 }
129
130 switch (animation.LoopType)
131 {
132 case LoopType.True:
133 //Cycle back to first frame
134 SetGameObjectForKey(root, animClip, animation.MainlineKeys.First(), animation.Length);
135 break;
136 case LoopType.False:
137 //Duplicate the last key at the end time of the animation
138 SetGameObjectForKey(root, animClip, animation.MainlineKeys.Last(), animation.Length);
139 break;
140 default:
141 Debug.LogWarning("Unsupported loop type: " + animation.LoopType.ToString());
142 break;
143 }
144
145 //Add the curves to our animation clip
146 //NOTE: This MUST be done before modifying the settings, thus the double switch statement
147 acb.AddCurves(animClip);
148
149 foreach (var sprite in spriteChangeKeys)
150 {
151 if (sprite.Value.Count > 0)
152 {
153 BuildSpriteChangeCurve(ref animClip, sprite);
154 }
155 }
156
157 //Set the loop/wrap settings for the animation clip
158 var animSettings = AnimationUtility.GetAnimationClipSettings(animClip);
159 switch(animation.LoopType)
160 {
161 case LoopType.True:
162 animClip.wrapMode = WrapMode.Loop;
163 animSettings.loopTime = true;
164 break;
165 case LoopType.False:
166 animClip.wrapMode = WrapMode.ClampForever;
167 break;
168 case LoopType.PingPong:
169 animClip.wrapMode = WrapMode.PingPong;
170 animSettings.loopTime = true;
171 break;
172 default:
173 Debug.LogWarning("Unsupported loop type: " + animation.LoopType.ToString());
174 break;
175 }
176
177 animClip.SetAnimationSettings(animSettings);
178
179 //Debug.Log(string.Format("Setting animation {0} to {1} loop mode (WrapMode:{2} LoopTime:{3}) ", animClip.name, animation.LoopType, animClip.wrapMode, animSettings.loopTime));
180 }
File name: AnimationBuilder.cs
Copy
182 private void HideSprites(GameObject root, IEnumerable183 {
184 foreach(var relativePath in relativePaths)
185 {
186 //Find the gameObject based on relative path
187 var transform = root.transform.Find(relativePath);
188 if (transform == null)
189 {
190 Debug.LogError("ERROR: Unable to find GameObject at relative path " + relativePath);
191 return;
192 }
193
194 var gameObject = transform.gameObject;
195 gameObject.SetActive(false);
196
197 acb.SetCurveActiveOnly(root.transform, transform, time);
198 }
199 }
Hides 110 lượt xem
Gõ tìm kiếm nhanh...