Game Development Reference
In-Depth Information
62 FirstCreated = this;
63
64 //Should we update last created
65 if(Wizard.LastCreated != null)
66 {
67 Wizard.LastCreated.NextWizard = this;
68 PrevWizard = Wizard.LastCreated;
69 }
70
71 Wizard.LastCreated = this;
72 }
73 //----------------------------------------------------
74 //Called on object destruction
75 void OnDestroy()
76 {
77 //Repair links if object in chain is destroyed
78 if(PrevWizard!=null)
79 PrevWizard.NextWizard = NextWizard;
80
81 if(NextWizard!=null)
82 NextWizard.PrevWizard = PrevWizard;
83 }
84 //----------------------------------------------------
85 //Get this class as enumerator
86 public IEnumerator GetEnumerator()
87 {
88 return new WizardEnumerator();
89 }
90 //----------------------------------------------------
91 }
92 //----------------------------------------------------------------
---
The following are the comments for code sample 6-8:
Lines 07 and 39 : Two classes are created here: the first is WizardEnumerator ,
which implements IEnumerator , and the second is Wizard , which
implements IEnumerable . The WizardEnumerator class is instantiated
simply to iterate over a collection of wizards that keeps track of the current
wizard in the iteration process. To loop through or iterate over all wizards in
the scene, it relies on member variables for the Wizard class, as we'll see in
the upcoming sections.
 
Search WWH ::




Custom Search