Difference between revisions of "API:Layers"

From Kerbal Space Program Wiki
Jump to: navigation, search
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Layers are used to allow cameras and lights to act only on certain parts of the scene, or to have collisions or ray casts ignore certain objects. Layers 0 to 7 are reserved by Unity. See the Unity [http://docs.unity3d.com/Manual/Layers.html Layers] page for more details.
+
{{Orphan}}
 +
Layers are used to allow cameras and lights to act only on certain parts of the scene, or to have collisions or ray casts ignore certain objects. See the Unity [http://docs.unity3d.com/Manual/Layers.html Layers] page for more details.
  
 
==Layers in KSP==
 
==Layers in KSP==
  
There are 32 layers available:
+
There are 32 layers available. This is a hard limit in Unity. Layers 0 to 7 are reserved by Unity.
 
* 0: Default (Unity built-in)
 
* 0: Default (Unity built-in)
 
* 1: TransparentFX (Unity built-in)
 
* 1: TransparentFX (Unity built-in)
Line 15: Line 16:
 
* 9: Atmosphere
 
* 9: Atmosphere
 
* 10: Scaled Scenery
 
* 10: Scaled Scenery
* 11: UI_Culled
+
* 11: UIDialog
* 12: UI_Main
+
* 12: UIVectors
 
* 13: UI_Mask
 
* 13: UI_Mask
 
* 14: Screens
 
* 14: Screens
 
* 15: Local Scenery
 
* 15: Local Scenery
 
* 16: kerbals
 
* 16: kerbals
* 17: Editor_UI
+
* 17: EVA
 
* 18: SkySphere
 
* 18: SkySphere
* 19: Disconnected Parts
+
* 19: PhysicalObjects
 
* 20: Internal Space
 
* 20: Internal Space
 
* 21: Part Triggers
 
* 21: Part Triggers
 
* 22: KerbalInstructors
 
* 22: KerbalInstructors
* 23: ScaledSpaceSun
+
* 23: AeroFXIgnore
 
* 24: MapFX
 
* 24: MapFX
* 25: EzGUI_UI
+
* 25: UIAdditional
 
* 26: WheelCollidersIgnore
 
* 26: WheelCollidersIgnore
 
* 27: WheelColliders
 
* 27: WheelColliders
 
* 28: TerrainColliders
 
* 28: TerrainColliders
* 29:  
+
* 29: DragRender
* 30:  
+
* 30: SurfaceFX
 
* 31: Vectors
 
* 31: Vectors
 +
 +
==Collisions==
 +
The layer system can be used to have collisions between objects on different layers be ignored.
 +
Combinations marked with an X have collisions enabled between them. Combinations marked with a _ ignore collisions between them.
 +
<code>
 +
    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
 +
    1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
 +
  0 _ _ _ _ X X _ _ X _ _ _ X _ X _ X _ _ _ _ _ _ _ X X _ X X X X X
 +
  1 _ _ _ _ X X _ _ X _ _ _ _ _ X _ X _ _ _ _ _ _ _ X X _ X X X X
 +
  2 _ _ _ _ X X _ _ X _ _ _ _ _ X _ X _ _ _ _ _ _ _ X X _ X X X
 +
  3 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
 +
  4 _ _ _ _ X X _ _ X _ _ _ _ _ X _ X _ _ _ _ _ _ _ X X _ X
 +
  5 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ X X _
 +
  6 X X X X X X X X X X X X X X X X X X X X X X X X X X
 +
  7 X X X X X X X X X X X X X X X X X X X X X X X X X
 +
  8 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 +
  9 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 +
10 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 +
11 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 +
12 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 +
13 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 +
14 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 +
15 _ _ _ X X X _ _ X _ _ _ X _ X _ X
 +
16 _ _ _ _ _ _ _ _ _ _ _ X _ _ _ _
 +
17 _ _ _ _ _ _ _ _ X _ _ _ X _ X
 +
18 _ _ _ _ _ _ _ _ _ _ _ _ _ _
 +
19 _ _ _ _ X X _ _ X _ _ _ X
 +
20 _ _ _ _ _ _ _ _ _ _ _ X
 +
21 _ _ _ _ _ _ _ _ _ _ X
 +
22 _ _ _ _ _ _ _ _ _ _
 +
23 _ _ _ _ X X _ _ X
 +
24 _ _ _ _ _ _ _ _
 +
25 _ _ _ _ _ _ _
 +
26 _ _ _ _ _ X
 +
27 _ _ _ _ _
 +
28 _ _ _ X
 +
29 _ _ _
 +
30 _ _
 +
31 _
 +
</code>
 +
 +
==Cameras==
 +
 +
 +
==Common Camera Configurations==
 +
===External views===
 +
Used for EVA or flight, without any GUI elements (layers 0, 4, 9, 10, 15 18 and 23 enabled, all others disabled).
 +
 +
<code>myExternalCamera.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 18) | (1 << 23);</code>
 +
 +
This sets the culling mask to 100001001000011000010001, or 8,685,073 in decimal.
 +
The culling mask can also be set in decimal:
 +
 +
<code>myExternalCamera.cullingMask = 8685073;</code>
 +
 +
 +
===IVA===
 +
Used for IVA views which can also see outside.
 +
 +
<code>myInternalCamera.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 18) | (1 << 20) | (1 << 23);</code>
 +
 +
 +
===Game Objects===
 +
Game Objects can only have one layer. This layer is referred to numerically rather than in mask form.
 +
For example, to set an object to use the Local Scenery layer:
 +
 +
<code>myGameObject.layer = 15;</code>
 +
 +
Objects are visible in game when on layers 0 (Default), 15 (Local Scenery) and 19 (Disconnected Parts), and can also be visible on the camera plane on layers 12 (UI_Main) and 13 (UI_Mask). Only layer 0 displays mach and re-entry effects, so placing an object on layer 15 will disable these effects for that object.
  
 
[[Category:Community API Documentation]]
 
[[Category:Community API Documentation]]

Latest revision as of 21:43, 15 March 2021

This page is an orphan, as no other articles link to it.


Layers are used to allow cameras and lights to act only on certain parts of the scene, or to have collisions or ray casts ignore certain objects. See the Unity Layers page for more details.

Layers in KSP

There are 32 layers available. This is a hard limit in Unity. Layers 0 to 7 are reserved by Unity.

  • 0: Default (Unity built-in)
  • 1: TransparentFX (Unity built-in)
  • 2: Ignore Raycast (Unity built-in)
  • 3:
  • 4: Water (Unity built-in)
  • 5: UI (Unity built-in)
  • 6:
  • 7:
  • 8: PartsList_Icons
  • 9: Atmosphere
  • 10: Scaled Scenery
  • 11: UIDialog
  • 12: UIVectors
  • 13: UI_Mask
  • 14: Screens
  • 15: Local Scenery
  • 16: kerbals
  • 17: EVA
  • 18: SkySphere
  • 19: PhysicalObjects
  • 20: Internal Space
  • 21: Part Triggers
  • 22: KerbalInstructors
  • 23: AeroFXIgnore
  • 24: MapFX
  • 25: UIAdditional
  • 26: WheelCollidersIgnore
  • 27: WheelColliders
  • 28: TerrainColliders
  • 29: DragRender
  • 30: SurfaceFX
  • 31: Vectors

Collisions

The layer system can be used to have collisions between objects on different layers be ignored. Combinations marked with an X have collisions enabled between them. Combinations marked with a _ ignore collisions between them.

   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
 0 _ _ _ _ X X _ _ X _ _ _ X _ X _ X _ _ _ _ _ _ _ X X _ X X X X X
 1 _ _ _ _ X X _ _ X _ _ _ _ _ X _ X _ _ _ _ _ _ _ X X _ X X X X
 2 _ _ _ _ X X _ _ X _ _ _ _ _ X _ X _ _ _ _ _ _ _ X X _ X X X
 3 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
 4 _ _ _ _ X X _ _ X _ _ _ _ _ X _ X _ _ _ _ _ _ _ X X _ X
 5 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ X X _
 6 X X X X X X X X X X X X X X X X X X X X X X X X X X
 7 X X X X X X X X X X X X X X X X X X X X X X X X X
 8 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 9 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
10 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
11 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
12 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
13 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
14 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
15 _ _ _ X X X _ _ X _ _ _ X _ X _ X
16 _ _ _ _ _ _ _ _ _ _ _ X _ _ _ _
17 _ _ _ _ _ _ _ _ X _ _ _ X _ X
18 _ _ _ _ _ _ _ _ _ _ _ _ _ _
19 _ _ _ _ X X _ _ X _ _ _ X
20 _ _ _ _ _ _ _ _ _ _ _ X
21 _ _ _ _ _ _ _ _ _ _ X
22 _ _ _ _ _ _ _ _ _ _
23 _ _ _ _ X X _ _ X
24 _ _ _ _ _ _ _ _
25 _ _ _ _ _ _ _
26 _ _ _ _ _ X
27 _ _ _ _ _
28 _ _ _ X
29 _ _ _
30 _ _
31 _

Cameras

Common Camera Configurations

External views

Used for EVA or flight, without any GUI elements (layers 0, 4, 9, 10, 15 18 and 23 enabled, all others disabled).

myExternalCamera.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 18) | (1 << 23);

This sets the culling mask to 100001001000011000010001, or 8,685,073 in decimal. The culling mask can also be set in decimal:

myExternalCamera.cullingMask = 8685073;


IVA

Used for IVA views which can also see outside.

myInternalCamera.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 18) | (1 << 20) | (1 << 23);


Game Objects

Game Objects can only have one layer. This layer is referred to numerically rather than in mask form. For example, to set an object to use the Local Scenery layer:

myGameObject.layer = 15;

Objects are visible in game when on layers 0 (Default), 15 (Local Scenery) and 19 (Disconnected Parts), and can also be visible on the camera plane on layers 12 (UI_Main) and 13 (UI_Mask). Only layer 0 displays mach and re-entry effects, so placing an object on layer 15 will disable these effects for that object.