本文整理汇总了C#中SceneObject.AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# SceneObject.AddComponent方法的具体用法?C# SceneObject.AddComponent怎么用?C# SceneObject.AddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SceneObject
的用法示例。
在下文中一共展示了SceneObject.AddComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SceneAxesGUI
/// <summary>
/// Creates a new scene axes GUI.
/// </summary>
/// <param name="window">Window in which the GUI is located in.</param>
/// <param name="panel">Panel onto which to place the GUI element.</param>
/// <param name="width">Width of the GUI element.</param>
/// <param name="height">Height of the GUI element.</param>
/// <param name="projType">Projection type to display on the GUI.</param>
public SceneAxesGUI(SceneWindow window, GUIPanel panel, int width, int height, ProjectionType projType)
{
renderTexture = new RenderTexture2D(PixelFormat.R8G8B8A8, width, height);
renderTexture.Priority = 1;
SceneObject cameraSO = new SceneObject("SceneAxesCamera", true);
camera = cameraSO.AddComponent<Camera>();
camera.Target = renderTexture;
camera.ViewportRect = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);
cameraSO.Position = new Vector3(0, 0, 5);
cameraSO.LookAt(new Vector3(0, 0, 0));
camera.Priority = 2;
camera.NearClipPlane = 0.05f;
camera.FarClipPlane = 1000.0f;
camera.ClearColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
camera.ProjectionType = ProjectionType.Orthographic;
camera.Layers = SceneAxesHandle.LAYER;
camera.AspectRatio = 1.0f;
camera.OrthoHeight = 2.0f;
camera.HDR = false;
renderTextureGUI = new GUIRenderTexture(renderTexture, true);
GUILayoutY layout = panel.AddLayoutY();
GUILayoutX textureLayout = layout.AddLayoutX();
textureLayout.AddElement(renderTextureGUI);
textureLayout.AddFlexibleSpace();
Rect2I bounds = new Rect2I(0, 0, width, height);
sceneHandles = new SceneHandles(window, camera);
renderTextureGUI.Bounds = bounds;
labelGUI = new GUILabel(projType.ToString(), EditorStyles.LabelCentered);
layout.AddElement(labelGUI);
layout.AddFlexibleSpace();
this.panel = panel;
this.bounds = bounds;
}
示例2: UpdateRenderTexture
/// <summary>
/// Creates the scene camera and updates the render texture. Should be called at least once before using the
/// scene view. Should be called whenever the window is resized.
/// </summary>
/// <param name="width">Width of the scene render target, in pixels.</param>
/// <param name="height">Height of the scene render target, in pixels.</param>
private void UpdateRenderTexture(int width, int height)
{
width = MathEx.Max(20, width);
height = MathEx.Max(20, height);
// Note: Depth buffer and readable flags are required because ScenePicking uses it
Texture2D colorTex = new Texture2D(width, height, PixelFormat.R8G8B8A8, TextureUsage.Render | TextureUsage.CPUReadable);
Texture2D depthTex = new Texture2D(width, height, PixelFormat.D32_S8X24, TextureUsage.DepthStencil | TextureUsage.CPUReadable);
renderTexture = new RenderTexture2D(colorTex, depthTex);
renderTexture.Priority = 1;
if (camera == null)
{
SceneObject sceneCameraSO = new SceneObject("SceneCamera", true);
camera = sceneCameraSO.AddComponent<Camera>();
camera.Target = renderTexture;
camera.ViewportRect = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);
sceneCameraSO.Position = new Vector3(0, 0.5f, 1);
sceneCameraSO.LookAt(new Vector3(0, 0.5f, 0));
camera.Priority = 2;
camera.NearClipPlane = 0.05f;
camera.FarClipPlane = 2500.0f;
camera.ClearColor = ClearColor;
camera.Layers = UInt64.MaxValue & ~SceneAxesHandle.LAYER; // Don't draw scene axes in this camera
cameraController = sceneCameraSO.AddComponent<SceneCamera>();
renderTextureGUI = new GUIRenderTexture(renderTexture);
rtPanel.AddElement(renderTextureGUI);
sceneGrid = new SceneGrid(camera);
sceneSelection = new SceneSelection(camera);
sceneGizmos = new SceneGizmos(camera);
sceneHandles = new SceneHandles(this, camera);
}
else
{
camera.Target = renderTexture;
renderTextureGUI.RenderTexture = renderTexture;
}
Rect2I rtBounds = new Rect2I(0, 0, width, height);
renderTextureGUI.Bounds = rtBounds;
focusCatcher.Bounds = GUIUtility.CalculateBounds(rtPanel, GUI);
sceneAxesGUI.SetPosition(width - HandleAxesGUISize - HandleAxesGUIPaddingX, HandleAxesGUIPaddingY);
// TODO - Consider only doing the resize once user stops resizing the widget in order to reduce constant
// render target destroy/create cycle for every single pixel.
camera.AspectRatio = width / (float)height;
if (profilerCamera != null)
profilerCamera.Target = renderTexture;
}
示例3: UpdateProfilerOverlay
/// <summary>
/// Activates or deactivates the profiler overlay according to current editor settings.
/// </summary>
private void UpdateProfilerOverlay()
{
if (EditorSettings.GetBool(ProfilerOverlayActiveKey))
{
if (activeProfilerOverlay == null)
{
SceneObject profilerSO = new SceneObject("EditorProfilerOverlay");
profilerCamera = profilerSO.AddComponent<Camera>();
profilerCamera.Target = renderTexture;
profilerCamera.ClearFlags = ClearFlags.None;
profilerCamera.Priority = 1;
profilerCamera.Layers = 0;
profilerCamera.HDR = false;
activeProfilerOverlay = profilerSO.AddComponent<ProfilerOverlay>();
}
}
else
{
if (activeProfilerOverlay != null)
{
activeProfilerOverlay.SceneObject.Destroy();
activeProfilerOverlay = null;
profilerCamera = null;
}
}
}
示例4: OnEditorUpdate
private void OnEditorUpdate()
{
if (HasFocus)
{
if (!Input.IsPointerButtonHeld(PointerButton.Right))
{
if (VirtualInput.IsButtonDown(EditorApplication.DuplicateKey))
DuplicateSelection();
else if (VirtualInput.IsButtonDown(EditorApplication.DeleteKey))
DeleteSelection();
else if (VirtualInput.IsButtonDown(toggleProfilerOverlayKey))
EditorSettings.SetBool(ProfilerOverlayActiveKey, !EditorSettings.GetBool(ProfilerOverlayActiveKey));
else if(VirtualInput.IsButtonDown(viewToolKey))
EditorApplication.ActiveSceneTool = SceneViewTool.View;
else if(VirtualInput.IsButtonDown(moveToolKey))
EditorApplication.ActiveSceneTool = SceneViewTool.Move;
else if(VirtualInput.IsButtonDown(rotateToolKey))
EditorApplication.ActiveSceneTool = SceneViewTool.Rotate;
else if(VirtualInput.IsButtonDown(scaleToolKey))
EditorApplication.ActiveSceneTool = SceneViewTool.Scale;
}
}
// Refresh GUI buttons if needed (in case someones changes the values from script)
if (editorSettingsHash != EditorSettings.Hash)
{
UpdateButtonStates();
UpdateProfilerOverlay();
editorSettingsHash = EditorSettings.Hash;
}
// Update scene view handles and selection
sceneGizmos.Draw();
sceneGrid.Draw();
bool handleActive = sceneHandles.IsActive() || sceneAxesGUI.IsActive();
Vector2I scenePos;
bool inBounds = ScreenToScenePos(Input.PointerPosition, out scenePos);
bool dragResult = false;
if (Input.IsPointerButtonUp(PointerButton.Left))
{
dragResult = EndDragSelection();
if (sceneHandles.IsActive())
sceneHandles.ClearSelection();
if (sceneAxesGUI.IsActive())
sceneAxesGUI.ClearSelection();
}
else if (Input.IsPointerButtonDown(PointerButton.Left))
{
mouseDownPosition = scenePos;
}
bool draggedOver = DragDrop.DragInProgress || DragDrop.DropInProgress;
draggedOver &= IsPointerHovering && inBounds && DragDrop.Type == DragDropType.Resource;
if (draggedOver)
{
if (DragDrop.DropInProgress)
{
dragActive = false;
if (draggedSO != null)
{
Selection.SceneObject = draggedSO;
EditorApplication.SetSceneDirty();
}
draggedSO = null;
}
else
{
if (!dragActive)
{
dragActive = true;
ResourceDragDropData dragData = (ResourceDragDropData)DragDrop.Data;
string[] draggedPaths = dragData.Paths;
for (int i = 0; i < draggedPaths.Length; i++)
{
ResourceMeta meta = ProjectLibrary.GetMeta(draggedPaths[i]);
if (meta != null)
{
if (meta.ResType == ResourceType.Mesh)
{
if (!string.IsNullOrEmpty(draggedPaths[i]))
{
string meshName = Path.GetFileNameWithoutExtension(draggedPaths[i]);
draggedSO = UndoRedo.CreateSO(meshName, "Created a new Renderable \"" + meshName + "\"");
Mesh mesh = ProjectLibrary.Load<Mesh>(draggedPaths[i]);
Renderable renderable = draggedSO.AddComponent<Renderable>();
renderable.Mesh = mesh;
if (mesh != null)
draggedSOOffset = mesh.Bounds.Box.Center;
else
draggedSOOffset = Vector3.Zero;
}
//.........这里部分代码省略.........
示例5: UnitTest1_ManagedSerialization
/// <summary>
/// Tests managed object serialization and deserialization.
/// </summary>
static void UnitTest1_ManagedSerialization()
{
SceneObject otherSO = new SceneObject("OtherSO");
UT1_Component2 dbgComponent2 = otherSO.AddComponent<UT1_Component2>();
dbgComponent2.a2 = 33;
SceneObject so = new SceneObject("TestSO");
UT1_Component1 dbgComponent = so.AddComponent<UT1_Component1>();
dbgComponent.a = 5;
dbgComponent.b = "SomeTestVal";
dbgComponent.complex.someValue = 19;
dbgComponent.complex.anotherValue = "AnotherValue";
dbgComponent.complex2.someValue2 = 21;
dbgComponent.complex2.anotherValue2 = "AnotherValue2";
dbgComponent.arrA = new int[5];
dbgComponent.arrA[4] = 5;
dbgComponent.arrB = new string[5];
dbgComponent.arrB[4] = "ArrAnotherValue";
dbgComponent.arrComplex = new UT1_SerzObj[5];
dbgComponent.arrComplex[4].someValue = 99;
dbgComponent.arrComplex[4].anotherValue = "ArrComplexAnotherValue";
dbgComponent.arrComplex2 = new UT1_SerzCls[5];
dbgComponent.arrComplex2[4] = new UT1_SerzCls();
dbgComponent.arrComplex2[4].someValue2 = 101;
dbgComponent.arrComplex2[4].anotherValue2 = "ArrComplex2AnotherValue";
dbgComponent.listA = new List<int>();
dbgComponent.listA.Add(5);
dbgComponent.listB = new List<string>();
dbgComponent.listB.Add("ListAnotherValue");
dbgComponent.listB.Add(null);
dbgComponent.listComplex = new List<UT1_SerzObj>();
dbgComponent.listComplex.Add(new UT1_SerzObj());
dbgComponent.listComplex.Add(new UT1_SerzObj(99, "ListComplexAnotherValue"));
dbgComponent.listComplex2 = new List<UT1_SerzCls>();
dbgComponent.listComplex2.Add(new UT1_SerzCls());
dbgComponent.listComplex2[0].someValue2 = 101;
dbgComponent.listComplex2[0].anotherValue2 = "ListComplexAnotherValue";
dbgComponent.listComplex2.Add(null);
dbgComponent.dictA = new Dictionary<int, string>();
dbgComponent.dictA[5] = "value";
dbgComponent.dictA[10] = "anotherValue";
dbgComponent.dictB = new Dictionary<string, UT1_SerzObj>();
dbgComponent.dictB["key1"] = new UT1_SerzObj(99, "DictComplexValue");
dbgComponent.otherComponent = dbgComponent2;
dbgComponent.otherSO = otherSO;
Internal_UT1_GameObjectClone(so);
System.Diagnostics.Debug.Assert(so.GetNumChildren() == 1);
for (int i = 0; i < so.GetNumChildren(); i++)
{
SceneObject childSO = so.GetChild(i);
UT1_Component1 otherComponent = childSO.GetComponent<UT1_Component1>();
DebugUnit.Assert(otherComponent.a == 5);
DebugUnit.Assert(otherComponent.b == "SomeTestVal");
DebugUnit.Assert(otherComponent.complex.someValue == 19);
DebugUnit.Assert(otherComponent.complex2.anotherValue2 == "AnotherValue2");
DebugUnit.Assert(otherComponent.arrA[4] == 5);
DebugUnit.Assert(otherComponent.arrB[4] == "ArrAnotherValue");
DebugUnit.Assert(otherComponent.arrComplex[4].someValue == 99);
DebugUnit.Assert(otherComponent.arrComplex2[4].anotherValue2 == "ArrComplex2AnotherValue");
DebugUnit.Assert(otherComponent.listA[0] == 5);
DebugUnit.Assert(otherComponent.listB[0] == "ListAnotherValue");
DebugUnit.Assert(otherComponent.listComplex[1].someValue == 99);
DebugUnit.Assert(otherComponent.listComplex2[0].anotherValue2 == "ListComplexAnotherValue");
}
so.Destroy();
otherSO.Destroy();
}