Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
PreviewWorld.c
Go to the documentation of this file.
1 class PreviewWorldExampleClass: GenericEntityClass
2 {
3 };
4 
6 {
7  static ref array<ResourceName> s_Models = {"{9A85D4C454E19ED7}entities/Props/Crates/Crate_02.et", "{A0190761A41888C6}entities/Props/Military/AmmoBoxes/AmmoBox_03.et", "{728DD36004461456}entities/Props/Furniture/Cupboard_01_B.et"};
8  ref SharedItemRef m_World;
9  RenderTargetWidget m_RenderWidget;
10  IEntity m_Model;
11  vector m_Angle;
12  int m_ModelIndex;
13 
14  void PreviewWorldExample(IEntitySource src, IEntity parent)
15  {
16  SetEventMask(EntityEvent.INIT | EntityEvent.FRAME);
17  }
18 
19  void ~PreviewWorldExample()
20  {
21  delete m_RenderWidget;
22  }
23 
24  override void EOnInit(IEntity owner)
25  {
26  m_World = BaseWorld.CreateWorld("Preview", "Preview");
27  BaseWorld world = m_World.GetRef();
28  m_RenderWidget = RenderTargetWidget.Cast(GetGame().GetWorkspace().CreateWidget(WidgetType.RenderTargetWidgetTypeID, WidgetFlags.VISIBLE, new Color(), 100));
29  FrameSlot.SetOffsets(m_RenderWidget, 0, 0, 0, 0);
30  FrameSlot.SetAnchorMin(m_RenderWidget, 0.1, 0.1);
31  FrameSlot.SetAnchorMax(m_RenderWidget, 0.5, 0.5);
32  m_RenderWidget.Update();
33  m_RenderWidget.SetWorld(world, 0);
34 
35  // create generic world
36  Resource rsc = Resource.Load("{43DA8BEC8468C7F5}worlds/TestMaps/PreviewWorld/PreviewWorld.et");
37  if (rsc.IsValid())
38  GetGame().SpawnEntityPrefab(rsc, world);
39 
40  // setup cam
41  world.SetCamera(0, "0 0.5 -3", "0 0 0");
42  world.SetCameraType(0, CameraType.PERSPECTIVE);
43  world.SetCameraNearPlane(0, 0.1);
44  world.SetCameraFarPlane(0, 4000);
45  world.SetCameraVerticalFOV(0, 60);
46 
47  // load model
48  LoadModel();
49  }
50 
51  void LoadModel()
52  {
53  if (m_Model)
54  delete m_Model;
55 
56  Resource rsc = Resource.Load(s_Models[m_ModelIndex]);
57  if (rsc.IsValid())
58  {
59  BaseWorld world = m_World.GetRef();
60  m_Model = GetGame().SpawnEntityPrefab(rsc, world);
61  m_Model.SetOrigin("0 0 0");
62  }
63 
64  m_ModelIndex++;
65  if (m_ModelIndex >= s_Models.Count())
66  m_ModelIndex = 0;
67  }
68 
69  override void EOnFrame(IEntity owner, float timeSlice)
70  {
71  m_Angle[0] = m_Angle[0] + timeSlice * 30;
72  while (m_Angle[0] > 180.0)
73  {
74  LoadModel();
75  m_Angle[0] = m_Angle[0] - 180.0;
76  }
77 
78  m_Model.SetYawPitchRoll(m_Angle);
79  }
80 };
81 
82 
83 
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
PreviewWorldExampleClass
Definition: PreviewWorld.c:1
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
PreviewWorldExample
Definition: PreviewWorld.c:5
m_World
protected BaseWorld m_World
Definition: SCR_PreviewEntityEditorUIComponent.c:46