/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 / /   U T A G E :   U n i t y   T e x t   A d v e n t u r e   G a m e   E n g i n e 
 / /   C o p y r i g h t   2 0 1 4   R y o h e i   T o k i m u r a 
 / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 u s i n g   S y s t e m . C o l l e c t i o n s ; 
 u s i n g   S y s t e m . C o l l e c t i o n s . G e n e r i c ; 
 u s i n g   S y s t e m . I O ; 
 u s i n g   S y s t e m ; 
 u s i n g   U n i t y E n g i n e ; 
 
 n a m e s p a c e   U t a g e 
 { 
 	 p u b l i c   c l a s s   A d x 2 P l a y e r   :   M o n o B e h a v i o u r 
 	 { 
 	 	 A d x 2 L e F o r U t a g e   A d x 2 L e F o r U t a g e   {   g e t ;   s e t ;   } 
 	 	 i n t e r n a l   v o i d   I n i t ( A d x 2 L e F o r U t a g e   A d x 2 L e F o r U t a g e ) 
 	 	 { 
 	 	 	 t h i s . A d x 2 L e F o r U t a g e   =   A d x 2 L e F o r U t a g e ; 
 	 	 } 
 
 
 	 	 C r i A t o m S o u r c e   S o u r c e   {   g e t   {   r e t u r n   s o u r c e   ? ?   ( s o u r c e   =   t h i s . g a m e O b j e c t . A d d C o m p o n e n t < C r i A t o m S o u r c e > ( ) ) ;   }   } 
 	 	 C r i A t o m S o u r c e   s o u r c e ; 
 
 	 	 C r i A t o m S o u r c e . S t a t u s   S t a t u s   {   g e t   {   r e t u r n   s t a t u s ; }   } 
 	 	 [ S e r i a l i z e F i e l d ,   N o t E d i t a b l e ] 
 	 	 C r i A t o m S o u r c e . S t a t u s   s t a t u s ; 
 
 	 	 b o o l   i s F a d e O u t i n g   =   f a l s e ; 
 
 	 	 c l a s s   F a d e I n f o 
 	 	 { 
 	 	 	 p u b l i c   b o o l   E n a b l e   {   g e t ;   p r i v a t e   s e t ;   } 
 	 	 	 p u b l i c   f l o a t   F r o m   {   g e t ;   s e t ;   } 
 	 	 	 p u b l i c   f l o a t   T o   {   g e t ;   p r i v a t e   s e t ;   } 
 	 	 	 p u b l i c   f l o a t   T i m e   {   g e t ;   p r i v a t e   s e t ;   } 
 	 	 	 p u b l i c   f l o a t   D u r a t i o n   {   g e t ;   p r i v a t e   s e t ;   } 
 	 	 	 p u b l i c   f l o a t   V a l u e   {   g e t ;   p r i v a t e   s e t ;   } 
 
 	 	 	 p u b l i c   v o i d   S t a r t ( f l o a t   f r o m ,   f l o a t   t o ,   f l o a t   d u r a t i o n ) 
 	 	 	 { 
 	 	 	 	 E n a b l e   =   t r u e ; 
 	 	 	 	 V a l u e   =   F r o m   =   f r o m ; 
 	 	 	 	 T o   =   t o ; 
 	 	 	 	 D u r a t i o n   =   d u r a t i o n ; 
 	 	 	 	 T i m e   =   0 ; 
 	 	 	 } 
 	 	 	 p u b l i c   b o o l   U p d a t e ( ) 
 	 	 	 { 
 	 	 	 	 i f   ( ! E n a b l e )   r e t u r n   f a l s e ; 
 
 	 	 	 	 T i m e   + =   U n i t y E n g i n e . T i m e . d e l t a T i m e ; 
 	 	 	 	 i f   ( T i m e   > =   D u r a t i o n ) 
 	 	 	 	 { 
 	 	 	 	 	 V a l u e   =   T o ; 
 	 	 	 	 	 E n a b l e   =   f a l s e ; 
 	 	 	 	 } 
 	 	 	 	 e l s e 
 	 	 	 	 { 
 	 	 	 	 	 V a l u e   =   M a t h f . L e r p ( F r o m , T o , T i m e / D u r a t i o n ) ; 
 	 	 	 	 } 
 	 	 	 	 r e t u r n   t r u e ; 
 	 	 	 } 
 	 	 } 
 	 	 F a d e I n f o   f a d e I n f o   =   n e w   F a d e I n f o ( ) ; 
 
 	 	 v o i d   U p d a t e ( ) 
 	 	 { 
 	 	 	 s t a t u s   =   S o u r c e . s t a t u s ; 
 	 	 	 i f   ( f a d e I n f o . U p d a t e ( ) ) 
 	 	 	 { 
 	 	 	 	 S o u r c e . v o l u m e   =   f a d e I n f o . V a l u e ; 
 	 	 	 	 i f   ( i s F a d e O u t i n g ) 
 	 	 	 	 { 
 	 	 	 	 	 i f (   A d x 2 L e F o r U t a g e . D e b u g L o g   )   D e b u g . L o g ( s t r i n g . F o r m a t ( " S t o p   { 0 } " ,   S o u r c e . c u e N a m e ) ) ; 
 	 	 	 	 	 S o u r c e . S t o p ( ) ; 
 	 	 	 	 } 
 	 	 	 } 
 	 	 } 
 
 	 	 p u b l i c   b o o l   I s P l a y i n g ( ) 
 	 	 { 
 	 	 	 i f   ( i s F a d e O u t i n g )   r e t u r n   f a l s e ; 
 	 	 	 i f   ( S o u r c e . s t a t u s   = =   C r i A t o m S o u r c e . S t a t u s . P l a y i n g )   r e t u r n   t r u e ; 
 	 	 	 r e t u r n   f a l s e ; 
 	 	 } 
 
 	 	 p u b l i c   b o o l   I s P l a y i n g L o o p ( ) 
 	 	 { 
 	 	 	 r e t u r n   I s P l a y i n g ( )   & &   S o u r c e . l o o p ; 
 	 	 } 
 
 	 	 i n t e r n a l   b o o l   I s P l a y i n g ( s t r i n g   c u e N a m e ) 
 	 	 { 
 	 	 	 r e t u r n   ( S o u r c e . c u e N a m e   = =   c u e N a m e   & &   I s P l a y i n g ( ) ) ; 
 	 	 } 
 
 	 	 p u b l i c   f l o a t   t i m e S a m p l e s 
 	 	 { 
 	 	 	 g e t 
 	 	 	 { 
 	 	 	 	 r e t u r n   S o u r c e . t i m e   /   1 0 0 0 . 0 f   *   4 4 1 0 0 f ; 
 	 	 	 } 
 	 	 } 
 	 	 p u b l i c   f l o a t   p i t c h 
 	 	 { 
 	 	 	 g e t 
 	 	 	 { 
 	 	 	 	 r e t u r n   M a t h f . P o w ( 2 ,   S o u r c e . p i t c h   /   1 2 0 0 . 0 f ) ; 
 	 	 	 } 
 	 	 	 s e t 
 	 	 	 { 
 	 	 	 	 S o u r c e . p i t c h   =   1 2 0 0 . 0 f   *   M a t h f . L o g ( v a l u e )   /   M a t h f . L o g ( 2 . 0 f ) ; 
 	 	 	 } 
 	 	 } 
 
 	 	 i n t e r n a l   v o i d   P l a y (   s t r i n g   c u e S h e e t ,   s t r i n g   c u e N a m e ,   f l o a t   f a d e I n T i m e ,   f l o a t   f a d e O u t T i m e ,   f l o a t   v o l u m e ,   b o o l   i s L o o p ,   b o o l   i s S t r e a m i n g ,   F u n c < f l o a t >   c a l l b a c k M a s t e r V o l u m e ) 
 	 	 { 
 	 	 	 i f   ( A d x 2 L e F o r U t a g e . D e b u g L o g )   D e b u g . L o g ( s t r i n g . F o r m a t ( " P l a y C o m m a n d   { 0 }   F a d e I n : { 1 }   F a d e O u t { 2 } " ,   c u e N a m e ,   f a d e I n T i m e ,   f a d e O u t T i m e ) ) ; 
 	 	 	 f l o a t   d e l a y   =   0 ; 
 	 	 	 i f   ( I s P l a y i n g ( ) ) 
 	 	 	 { 
 	 	 	 	 S t o p ( f a d e O u t T i m e ) ; 
 	 	 	 	 d e l a y   =   f a d e O u t T i m e ; 
 	 	 	 } 
 	 	 	 i f   ( i s F a d e O u t i n g ) 
 	 	 	 { 
 	 	 	 	 S t o p A l l C o r o u t i n e s ( ) ; 
 	 	 	 } 
 	 	 	 S t a r t C o r o u t i n e ( C o P l a y A f t e r S t o p ( d e l a y ,   c u e S h e e t ,   c u e N a m e ,   f a d e I n T i m e ,   v o l u m e ,   i s L o o p ) ) ; 
 	 	 } 
 
 	 	 I E n u m e r a t o r   C o P l a y A f t e r S t o p ( f l o a t   d e l a y ,   s t r i n g   c u e S h e e t ,   s t r i n g   c u e N a m e ,   f l o a t   f a d e I n T i m e ,   f l o a t   v o l u m e ,   b o o l   i s L o o p ) 
 	 	 { 
 	 	 	 w h i l e   ( S o u r c e . s t a t u s   = =   C r i A t o m S o u r c e . S t a t u s . P l a y i n g ) 
 	 	 	 { 
 	 	 	 	 y i e l d   r e t u r n   0 ; 
 	 	 	 } 
 
 	 	 	 i f   ( A d x 2 L e F o r U t a g e . E n a b l e F a d e O n D a t a ) 
 	 	 	 { 
 	 	 	 	 i s F a d e O u t i n g   =   f a l s e ; 
 	 	 	 	 i f   ( A d x 2 L e F o r U t a g e . D e b u g L o g )   D e b u g . L o g ( s t r i n g . F o r m a t ( " P l a y   { 0 }   " ,   c u e N a m e ) ) ; 
 	 	 	 	 S o u r c e . l o o p   =   i s L o o p ; 
 	 	 	 	 S o u r c e . v o l u m e   =   v o l u m e ; 
 	 	 	 	 S o u r c e . c u e S h e e t   =   c u e S h e e t ; 
 	 	 	 	 S o u r c e . c u e N a m e   =   c u e N a m e ; 
 	 	 	 	 S o u r c e . P l a y ( ) ; 
 	 	 	 } 
 	 	 	 e l s e 
 	 	 	 { 
 	 	 	 	 P l a y F a d i n ( c u e S h e e t ,   c u e N a m e ,   f a d e I n T i m e ,   v o l u m e ,   i s L o o p ) ; 
 	 	 	 } 
 	 	 } 
 
 	 	 v o i d   P l a y F a d i n ( s t r i n g   c u e S h e e t ,   s t r i n g   c u e N a m e ,   f l o a t   f a d e T i m e ,   f l o a t   v o l u m e ,   b o o l   i s L o o p ) 
 	 	 { 
 	 	 	 i f   ( A d x 2 L e F o r U t a g e . D e b u g L o g )   D e b u g . L o g ( s t r i n g . F o r m a t ( " P l a y   { 0 }   F a d e I n { 1 } " ,   S o u r c e . c u e N a m e ,   f a d e T i m e ) ) ; 
 	 	 	 i f   ( ! A d x 2 L e F o r U t a g e . E n a b l e F a d e O n D a t a   & &   f a d e T i m e   >   0 ) 
 	 	 	 { 
 	 	 	 	 f a d e I n f o . S t a r t ( 0 ,   v o l u m e ,   f a d e T i m e ) ; 
 	 	 	 	 v o l u m e   =   0 ; 
 	 	 	 } 
 	 	 	 S o u r c e . l o o p   =   i s L o o p ; 
 	 	 	 S o u r c e . v o l u m e   =   v o l u m e ; 
 	 	 	 S o u r c e . c u e S h e e t   =   c u e S h e e t ; 
 	 	 	 S o u r c e . c u e N a m e   =   c u e N a m e ; 
 	 	 	 S o u r c e . P l a y ( ) ; 
 	 	 } 
 
 	 	 i n t e r n a l   v o i d   S t o p ( f l o a t   f a d e T i m e   =   0 ) 
 	 	 { 
 	 	 	 i f   ( A d x 2 L e F o r U t a g e . D e b u g L o g )   D e b u g . L o g ( s t r i n g . F o r m a t ( " S t o p   { 0 }   F a d e O u t { 1 } " ,   S o u r c e . c u e N a m e ,   f a d e T i m e ) ) ; 
 	 	 	 i f   ( ! I s P l a y i n g ( ) )   r e t u r n ; 
 
 	 	 	 i s F a d e O u t i n g   =   t r u e ; 
 	 	 	 i f   ( ! A d x 2 L e F o r U t a g e . E n a b l e F a d e O n D a t a   & &   f a d e T i m e   >   0 ) 
 	 	 	 { 
 	 	 	 	 f a d e I n f o . S t a r t ( S o u r c e . v o l u m e ,   0 ,   f a d e T i m e ) ; 
 	 	 	 } 
 	 	 	 e l s e 
 	 	 	 { 
 	 	 	 	 S o u r c e . S t o p ( ) ; 
 	 	 	 } 
 	 	 } 
 	 } 
 } 
 