a Mike Ton 10 éve
327
Még több ilyen
IEnumerator
TriggerAnimation(){ ... }
yield return null;
//Why return null??? As opposed to doing nothing???
targetScale.y = 1.0f;
targetScale.x = 1.0f;
targetScale = transform.localScale;
yield return new WaitForSeconds(0.3f);
transform.localScale = targetScale;
targetScale.y = 1.2f;
targetScale.x = 1.2f;
Vector3 targetScale = transform.localScale;
//wth is IEnumerator
You don't use IEnumerable "over" foreach. Implementing IEnumerable makes using foreach possible.
When you write code like:
foreach (Foo bar in baz)
{
...
}
it's functionally equivalent to writing:
IEnumerator bat = baz.GetEnumerator();
while (bat.MoveNext())
{
bar = (Foo)bat.Current
...
}
By "functionally equivalent," I mean that's actually what the compiler turns the code into. You can't use foreach on baz in this example unless baz implements IEnumerable.
IEnumerable means that baz implements the method
IEnumerator GetEnumerator()
The IEnumerator object that this method returns must implement the methods
bool MoveNext()
and
Object Current()
The first method advances to the next object in the IEnumerable object that created the enumerator, returning false if it's done, and the second returns the current object.
Anything in .Net that you can iterate over implements IEnumerable. If you're building your own class, and it doesn't already inherit from a class that implements IEnumerable, you can make your class usable in foreach statements by implementing IEnumerable (and by creating an enumerator class that its new GetEnumerator method will return).
HandleSequencerAdvancedStep(int inStep){ ... }
if ((inStep == step) && Selected) { ... }
StartCoroutine("TriggerAnimation");
StopCoroutine("TriggerAnimation");
HandleMouseUpAsButton(bool selected){ ... }
stepSequencer.RemovePitchAtStep(pitch, step);
stepSequencer.AddPitchAtStep(pitch, step);
Awake(){ ... }
stepSequencer.advancedStepDelegate += HandleSequencerAdvancedStep;
MouseUpAsButton += HandleMouseUpAsButton;
OnMouseUpAsButton(){ ... }
if (MouseUpAsButton != null) { ... }
MouseUpAsButton(Selected);
Selected = !Selected;
selected = false;
bool
Selected{ ... }
set{ ... }
spriteRenderer.sprite = (Selected) ? selectedSprite : deselectedSprite;
SpriteRenderer spriteRenderer = (SpriteRenderer)GetComponent
selected = value;
//wth is value defined???
//special in the language
get{ ... }
return selected;
//wth is this???
ButtonHandler
MouseUpAsButton;
ButtonHandler(bool selected);
Sprite
deselectedSprite
selectedSprite
HandlePowerButtonPressed( bool selected ){ ... }
else { ... }
stepIndicator.GetComponent
stepSequencer.StopSequencer();
if (selected) { ... }
stepSequencer.StartSequencer();
HandleSequencerStepAdvance( int step ){ ... }
stepIndicator.transform.position = position;
position.x = (step*2.0f) - 7.0f;
Vector3 position = stepIndicator.transform.position;
if (stepIndicator.GetComponent
stepIndicator.GetComponent
Start(){ ... }
playButton.MouseUpAsButton += HandlePowerButtonPressed;
stepSequencer.advancedStepDelegate += HandleSequencerStepAdvance;
GameObject
stepIndicator
Button
playButton
stepSequencer
ClearAllPitches()
StopSequencer()
StartSequencer()
advancedStepDelegate
Add callbacks to the advancedStepDelegateto be notified when the sequencer advances to a new step. The demo sequencer uses this to update the position of the StepIndicator game object.
(call)
private void Updat(){ ... }
if ((currentStep >= 0) && (advancedStepDelegate != null)) { ... }
advancedStepDelegate(currentStep);
(passes int currentStep)
(path/config)
(define)
public
SteppCallback
advancedStepDelegate;
delegate
void
SteppCallback(int step);
private
(step)
currentStep;
//The current step that the sequencer is on.
lastStep;
//The last step that the sequencer was on. Used to determine when step boundaries are crossed.
double
stepDuration;
The duration of a single step at the current temp;
class
{ ... }
(func)
(constructor)
Voice (AudioSource inAudioSource, int inPitch, int inStep){ ... }
(init)
step = inStep;
pitch = inPitch;
audioSource = inAudioSource;
(var)
public
int
step
pitch
readonly
AudioSource
audioSource;
Voice[]
voices;
//can be run while sequencer is active
RemovePitchAtStep(pitch,step)
AddPitchAtStep(pitch, step)
Voice
Pitch
Pitches
Audio Files
Step