Browse Source

Features examples updates

Josh Engebretson 9 years ago
parent
commit
50afadf61f

+ 1 - 1
FeatureExamples/Resources/Components/Vehicle.cs

@@ -71,7 +71,7 @@ namespace FeatureExamples
         float steering;
 
 
-        public void FixedUpdate(float timeStep)
+        public void PhysicsPreStep(float timeStep)
         {
             float newSteering = 0.0f;
             float accelerator = 0.0f;

+ 1 - 1
FeatureExamples/Resources/Scripts/01_HelloWorld.cs

@@ -41,7 +41,7 @@ namespace FeatureExamples
             graphics.WindowTitle = "Atomic Game Engine Feature Example";
 
             // Subscribe to Esc key:
-            SubscribeToEvent<KeyDownEvent>(e => { if (e.Key == Constants.KEY_ESCAPE) Exit(); });
+            SubscribeToEvent<KeyDownEvent>(e => { if (e.Key == Constants.KEY_ESCAPE) BackToSelector(); });
 
             // Say Hello
 

+ 1 - 1
FeatureExamples/Resources/Scripts/02_HelloGUI.cs

@@ -93,7 +93,7 @@ namespace FeatureExamples
 
             SubscribeToEvent<WidgetDeletedEvent>(window, e =>
             {
-                Exit();
+                BackToSelector();
             });
 
         }

+ 2 - 1
FeatureExamples/Resources/Scripts/09_MultipleViewports.cs

@@ -63,7 +63,8 @@ namespace FeatureExamples
 			SimpleMoveCamera3D(timeStep);
 
             var input = GetSubsystem<Input>();
-			var effectRenderPath = GetSubsystem<Renderer>().GetViewport(0).GetRenderPath();
+            var viewport = GetSubsystem<Renderer>().GetViewport(0);
+            var effectRenderPath = viewport.GetRenderPath();
 
 			if (input.GetKeyPress(Constants.KEY_B))
 				effectRenderPath.ToggleEnabled("Bloom");

+ 1 - 2
FeatureExamples/Resources/Scripts/19_VehicleDemo.cs

@@ -89,8 +89,7 @@ namespace FeatureExamples
                 CameraNode.Position = cameraTargetPos;
                 CameraNode.Rotation = dir;
             });
-
-            scene.GetComponent<PhysicsWorld>().SubscribeToEvent<PhysicsPreStepEvent>(e => vehicle?.FixedUpdate(e.TimeStep));
+            
         }
 
         protected override void Update(float timeStep)

+ 2 - 5
FeatureExamples/Resources/Scripts/AtomicMain.cs

@@ -8,11 +8,8 @@ public class AtomicMain : AppDelegate
 {
     public override void Start()
     {
-        sample = new RagdollSample();
-        sample.Start();
-        
+        SampleSelector.UIView = new UIView();
+        new SampleSelector();        
     }
 
-    Sample sample;
-
 }

+ 18 - 6
FeatureExamples/Resources/Scripts/Sample.cs

@@ -40,7 +40,7 @@ namespace FeatureExamples
 
         protected Sample()
         {
-            UIView = new UIView();
+            UIView = SampleSelector.UIView;
         }
 
         protected void Exit() { GetSubsystem<Engine>().Exit(); }
@@ -62,8 +62,6 @@ namespace FeatureExamples
 
             SubscribeToEvent<KeyDownEvent>(HandleKeyDown);
 
-
-
         }
 
         protected virtual void Update(float timeStep)
@@ -197,12 +195,28 @@ namespace FeatureExamples
         {
         }
 
+        protected void BackToSelector()
+        {
+            UnsubscribeFromAllEvents();
+            var renderer = GetSubsystem<Renderer>();
+            for (uint i = 0; i <  renderer.NumViewports; i++)
+            {
+                renderer.SetViewport(i, null);
+            }
+            SampleSelector.sampleRef = null;
+            SampleSelector.UIView.DeleteAllChildren();
+            new SampleSelector();
+        }
+
+
         void HandleKeyDown(KeyDownEvent e)
         {
+            var renderer = GetSubsystem<Renderer>();
+
             switch (e.Key)
             {
                 case Constants.KEY_ESCAPE:
-                    GetSubsystem<Engine>().Exit();
+                    BackToSelector();
                     return;
                 case Constants.KEY_F1:
                     GetSubsystem<UI>().ToggleConsole();
@@ -212,8 +226,6 @@ namespace FeatureExamples
                     return;
             }
 
-            var renderer = GetSubsystem<Renderer>();
-
             switch (e.Key)
             {
                 case Constants.KEY_1:

+ 68 - 0
FeatureExamples/Resources/Scripts/SampleSelector.cs

@@ -0,0 +1,68 @@
+
+using System;
+using System.Linq;
+using AtomicEngine;
+
+
+namespace FeatureExamples
+{
+
+    class SampleSelector : NETScriptObject
+    {
+        public static UIView UIView;
+
+        public static Sample sampleRef = null;
+
+        public SampleSelector()
+        {
+            sampleRef = null;            
+
+            var rootLayout = new UILayout();
+            rootLayout.Axis = UI_AXIS.UI_AXIS_Y;
+            rootLayout.Rect = UIView.Rect;
+            UIView.AddChild(rootLayout);
+
+            SubscribeToEvent<KeyDownEvent>(e =>
+            {
+                if (e.Key == Constants.KEY_ESCAPE)
+                    GetSubsystem<Engine>().Exit();
+            });
+
+#if ATOMIC_DESKTOP || ATOMIC_MOBILE
+            var sampleTypes = typeof(Sample).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(Sample)) && t != typeof(Sample) ).ToArray();
+            foreach (var sample in sampleTypes)
+            {
+                var button = new UIButton();
+                button.Text = sample.Name;
+
+                button.SubscribeToEvent<WidgetEvent>( button,  e => 
+                {
+                    // We're only interested in clicks
+                    if (e.Type != UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
+                        return;
+
+                    // set the event as handled, as the UI is about to go away
+                    e.Handled = true;
+               
+                    // Goodbye UI
+                    UIView.RemoveChild(rootLayout);
+                    
+                    sampleRef = (Sample) Activator.CreateInstance(sample);
+                    sampleRef.Start();
+
+                    UnsubscribeFromEvent<KeyDownEvent>();
+
+
+                });
+
+
+                rootLayout.AddChild(button);
+                   
+            }
+#endif
+
+        }
+
+    }
+
+}

+ 5 - 0
FeatureExamples/Resources/Scripts/SampleSelector.cs.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "6742918b3f3a081c708d6f4749d565b4",
+	"CSharpImporter": null
+}