blob: d6053a3c47a393bd5eca61f848641a8cc11006b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
C++RAW
#include "UnityPrefix.h"
#include "Configuration/UnityConfigure.h"
#include "Runtime/Camera/LODGroup.h"
#include "Runtime/Scripting/ScriptingUtility.h"
#include "Runtime/Mono/MonoBehaviour.h"
#include "Runtime/Utilities/LODUtility.h"
#include "Runtime/Camera/LODGroupManager.h"
CSRAW
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections;
namespace UnityEngine
{
// Structure for building a LOD for passing to the SetLODs function
CONDITIONAL !UNITY_FLASH
STRUCT LOD
// Construct a LOD
CSRAW public LOD (float screenRelativeTransitionHeight, Renderer[] renderers)
{
this.screenRelativeTransitionHeight = screenRelativeTransitionHeight;
this.renderers = renderers;
}
// The screen relative height to use for the transition [0-1]
CSRAW public float screenRelativeTransitionHeight;
// List of renderers for this LOD level
CSRAW public Renderer[] renderers;
END
// LODGroup lets you group multiple Renderers into LOD levels.
CLASS LODGroup : Component
// The local reference point against which the LOD distance is calculated.
AUTO_PROP Vector3 localReferencePoint GetLocalReferencePoint SetLocalReferencePoint
// The size of LOD object in local space
AUTO_PROP float size GetSize SetSize
// The number of LOD levels
CUSTOM_PROP int lodCount { return self->GetLODCount(); }
// Enable / Disable the LODGroup - Disabling will turn off all renderers.
CUSTOM_PROP bool enabled { return self->GetEnabled (); } { self->SetEnabled (value); }
// Recalculate the bounding region for the LODGroup (Relatively slow, do not call often)
CUSTOM void RecalculateBounds ()
{
CalculateLODGroupBoundingBox (*self);
}
// Set the LODs for the LOD group. This will remove any existing LODs configured on the LODGroup
CONDITIONAL !UNITY_FLASH
CUSTOM void SetLODS (LOD[] scriptingLODs)
{
//Number of LOD's
int size = GetScriptingArraySize (scriptingLODs);
if (size > kMaximumLODLevels)
{
WarningString(Format("SetLODs: Attempting to set more then the maximum number of LODS (%i) clamping", kMaximumLODLevels));
size = kMaximumLODLevels;
}
LODGroup::LODArray lods;
lods.resize(size);
for (int i = 0; i < size; i++)
{
#if UNITY_WINRT
// LOD is a structure with managed type inside that's why we need to perform slow Marshalling here.
MonoLOD monoLOD;
MarshallManagedStructIntoNative(Scripting::GetScriptingArrayElementNoRef<ScriptingObjectPtr>(scriptingLODs, i), &monoLOD);
#else
MonoLOD& monoLOD = Scripting::GetScriptingArrayElement<MonoLOD> (scriptingLODs, i);
#endif
lods[i].screenRelativeHeight = monoLOD.screenRelativeTransitionHeight;
// clamp to 0 - 1
lods[i].screenRelativeHeight = clamp01 (lods[i].screenRelativeHeight);
// if our values are broken...
if (i > 0 && (lods[i].screenRelativeHeight >= lods[i-1].screenRelativeHeight))
{
ErrorString("SetLODs: Attempting to set LOD where the screen relative size is greater then or equal to a higher detail LOD level.");
return;
}
int renderersSize = GetScriptingArraySize (monoLOD.renderers);
lods[i].renderers.resize_initialized(renderersSize);
for (int r = 0; r < renderersSize; r++)
{
ScriptingObjectPtr o = Scripting::GetScriptingArrayElementNoRef<ScriptingObjectPtr>(monoLOD.renderers,r);
lods[i].renderers[r].renderer = ScriptingObjectToObject<Renderer> (o);;
}
}
self->SetLODArray (lods);
CalculateLODGroupBoundingBox (*self);
}
// Force a LOD level on this LOD group
//
// @param index The LOD level to use. Passing index < 0 will return to standard LOD processing
CUSTOM void ForceLOD (int index)
{
ForceLODLevel (*self, index);
}
END
CSRAW
}
|