1
2
3
4
5
6
|
myObject = FindMyObjectInScene ( ) ;
if ( myObjet = = null )
{
myObject = SpawnMyObject ( ) ;
}
|
1
2
3
4
|
public void Invoke ( Task task , float time )
{
Invoke ( task.Method.Name , time ) ;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
/ / Defined in the common base class for all mono behaviours
public I GetInterfaceComponent < I > ( ) where I : class
{
return GetComponent ( typeof ( I ) ) as I;
}
public static List < I > FindObjectsOfInterface < I > ( ) where I : class
{
MonoBehaviour[] monoBehaviours = FindObjectsOfType < MonoBehaviour > ( ) ;
List < I > list = new List < I > ( ) ;
foreach ( MonoBehaviour behaviour in monoBehaviours )
{
I component = behaviour.GetComponent ( typeof ( I ) ) as I;
if ( component ! = null )
{
list .Add ( component ) ;
}
}
return list ;
}
|
01
02
03
04
05
06
07
08
09
10
11
|
public static class CSTransform
{
public static void SetX ( this Transform transform , float x )
{
Vector 3 newPosition =
new Vector 3 ( x , transform. position .y , transform. position .z ) ;
transform. position = newPosition;
}
...
}
|
01
02
03
04
05
06
07
08
09
10
11
12
|
public static T GetSafeComponent < T > ( this GameObject obj ) where T : MonoBehaviour
{
T component = obj.GetComponent < T > ( ) ;
if ( component = = null )
{
Debug.LogError ( "Expected to find component of type "
+ typeof ( T ) + " but found none" , obj ) ;
}
return component;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
public class Singleton < T > : MonoBehaviour where T : MonoBehaviour
{
protected static T instance;
/ * *
Returns the instance of this singleton.
* /
public static T Instance
{
get
{
if ( instance = = null )
{
instance = ( T ) FindObjectOfType ( typeof ( T ) ) ;
if ( instance = = null )
{
Debug.LogError ( "An instance of " + typeof ( T ) +
" is needed in the scene, but there is none." ) ;
}
}
return instance;
}
}
}
|
1
|
public float __aVariable;
|
01
02
03
04
05
06
07
08
09
10
11
12
13
|
[Serializable]
PlayerSaveData
{
public float health; / / public for serialisation , not exposed in inspector
}
Player
{
/ / ... bookkeeping variables
/ / Don’t expose state in inspector. State is not tweakable.
private PlayerSaveData playerSaveData;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
|
public class BaseTemplate
{
...
}
public class ActorTemplate : BaseTemplate
{
...
}
public class Entity < EntityTemplateType > where EntityTemplateType : BaseTemplate
{
EntityTemplateType template;
...
}
public class Actor : Entity < ActorTemplate >
{
...
}
|
01
02
03
04
05
06
07
08
09
10
11
|
public void SelectWeapon ( int index )
{
currentWeaponIndex = index ;
Player.SwitchWeapon ( weapons[currentWeapon] ) ;
}
public void Shoot ( )
{
Fire ( bullets[currentWeapon] ) ;
FireParticles ( particles[currentWeapon] ) ;
}
|
1
2
3
4
5
6
|
public class Weapon
{
public GameObject prefab;
public ParticleSystem particles;
public Bullet bullet;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
public void FireAttack ( )
{
/ / / behaviour
Fire ( bullets[ 0 ] ) ;
}
public void IceAttack ( )
{
/ / / behaviour
Fire ( bullets[ 1 ] ) ;
}
public void WindAttack ( )
{
/ / / behaviour
Fire ( bullets[ 2 ] ) ;
}
|
1
2
3
4
5
|
public void WindAttack ( )
{
/ / / behaviour
Fire ( bullets[WeaponType.Wind] ) ;
}
|
1
2
3
4
5
6
|
public class Bullets
{
public Bullet FireBullet;
public Bullet IceBullet;
public Bullet WindBullet;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
public class MovementProperties / / Not a MonoBehaviour!
{
public float movementSpeed;
public float turnSpeed = 1 ; / / default provided
}
public class HealthProperties / / Not a MonoBehaviour!
{
public float maxHealth;
public float regenerationRate;
}
public class Player : MonoBehaviour
{
public MovementProperties movementProeprties;
public HealthPorperties healthProeprties;
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
Materials
GUI
Effects
Meshes
Actors
DarkVampire
LightVampire
...
Structures
Buildings
...
Props
Plants
...
...
Plugins
Prefabs
Actors
Items
...
Resources
Actors
Items
...
Scenes
GUI
Levels
TestScenes
Scripts
Textures
GUI
Effects
...
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
Cameras
Dynamic Objects
Gameplay
Actors
Items
...
GUI
HUD
PauseMenu
...
Management
Lights
World
Ground
Props
Structure
...
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
|
ThirdParty
...
MyGenericScripts
Debug
Extensions
Framework
Graphics
IO
Math
...
MyGameScripts
Debug
Gameplay
Actors
Items
...
Framework
Graphics
GUI
...
|