protected override async void Init() { var cache = Application.ResourceCache; var node = Node; var model = node.CreateComponent<StaticModel>(); model.Model = cache.GetModel(Assets.Models.Player); var material = cache.GetMaterial(Assets.Materials.Player).Clone(""); model.SetMaterial(material); node.SetScale(0.45f); node.Position = new Vector3(0f, -6f, 0f); node.Rotation = new Quaternion(-40, 0, 0); //TODO: rotor should be defined in the model + animation rotor = node.CreateChild(); var rotorModel = rotor.CreateComponent<StaticModel>(); rotorModel.Model = cache.GetModel(Assets.Models.Box); rotorModel.SetMaterial(cache.GetMaterial(Assets.Materials.Black)); rotor.Scale = new Vector3(0.1f, 1.4f, 0.1f); rotor.Rotation = new Quaternion(0, 0, 0); rotor.Position = new Vector3(0, -0.15f, 1.2f); rotor.RunActionsAsync(new RepeatForever(new RotateBy(1f, 0, 0, 360f * 4))); //RPM // Load weapons node.AddComponent(new MachineGun()); node.AddComponent(new Missile()); await node.RunActionsAsync(new EaseOut(new MoveBy(0.5f, new Vector3(0, 3, 0)), 2)); MoveRandomly(); }
public ScaleByState (ScaleTo action, Node target) : base (action, target) { DeltaX = StartScaleX * EndScaleX - StartScaleX; DeltaY = StartScaleY * EndScaleY - StartScaleY; DeltaZ = StartScaleZ * EndScaleZ - StartScaleZ; }
public ActionState GetActionState(int tag, Node target) { Debug.Assert(tag != (int)ActionTag.Invalid); // Early out if we do not have any targets to search if (targets.Count == 0) return null; HashElement element; if (targets.TryGetValue(target, out element)) { if (element.ActionStates != null) { int limit = element.ActionStates.Count; for (int i = 0; i < limit; i++) { var actionState = element.ActionStates[i]; if (actionState.Action.Tag == tag) { return actionState; } } } } return null; }
protected override void Start() { // base.Start() creates a basic scene base.Start(); // Create a node for the Earth earthNode = Scene.CreateChild(); earthNode.Position = new Vector3(0, 0, 1); // One meter away earthNode.SetScale(0.2f); // 20cm // Create a static model component - Sphere: var earth = earthNode.CreateComponent<Sphere>(); // Materials are usually more complicated than just textures, but for such // simple cases we can use quick FromImage method to create a material from an image. earth.SetMaterial(Material.FromImage("Textures/Earth.jpg")); // Same steps for the Moon var moonNode = earthNode.CreateChild(); moonNode.SetScale(0.27f); // Relative size of the Moon is 1738.1km/6378.1km moonNode.Position = new Vector3(1.2f, 0, 0); var moon = moonNode.CreateComponent<Sphere>(); moon.SetMaterial(Material.FromImage("Textures/Moon.jpg")); // Run a an action to spin the Earth (5 degrees per second) earthNode.RunActions(new RepeatForever(new RotateBy(duration: 1f, deltaAngleX: 0, deltaAngleY: -5, deltaAngleZ: 0))); }
public TintByState (TintBy action, Node target) : base (action, target) { DeltaB = action.DeltaB; DeltaG = action.DeltaG; DeltaR = action.DeltaR; staticSprite = Target.GetComponent<StaticSprite2D>(); if (staticSprite != null) { var color = staticSprite.Color; FromR = color.R; FromG = color.G; FromB = color.B; return; } shape = Target.GetComponent<Shape>(); if (shape != null) { FromR = shape.Color.R; FromG = shape.Color.G; FromB = shape.Color.B; return; } throw new NotSupportedException("The node should have StaticSprite2D or Shape component"); }
protected override async void Start() { ResourceCache.AutoReloadResources = true; base.Start(); EnableGestureTapped = true; busyIndicatorNode = Scene.CreateChild(); busyIndicatorNode.SetScale(0.06f); busyIndicatorNode.CreateComponent<BusyIndicator>(); mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); await mediaCapture.AddVideoEffectAsync(new MrcVideoEffectDefinition(), MediaStreamType.Photo); await RegisterCortanaCommands(new Dictionary<string, Action> { {"Describe", () => CaptureAndShowResult(false)}, {"Read this text", () => CaptureAndShowResult(true)}, {"Enable preview", () => EnablePreview(true) }, {"Disable preview", () => EnablePreview(false) }, {"Help", Help } }); ShowBusyIndicator(true); await TextToSpeech("Welcome to the Microsoft Cognitive Services sample for HoloLens and UrhoSharp."); ShowBusyIndicator(false); inited = true; }
public virtual void OnHit(Aircraft target, bool killed, Node bulletNode) { var body = bulletNode.GetComponent<RigidBody>(); if (body != null) body.Enabled = false; bulletNode.SetScale(0); }
protected override async void Start() { base.Start(); EnableGestureManipulation = true; EnableGestureTapped = true; Log.LogLevel = LogLevel.Warning; Log.LogMessage += l => { Debug.WriteLine(l.Level + ": " + l.Message); }; // Create a node for the Earth earthNode = Scene.CreateChild(); earthNode.Position = new Vector3(0, 0, 1.5f); earthNode.SetScale(0.3f); DirectionalLight.Brightness = 1f; DirectionalLight.Node.SetDirection(new Vector3(-1, 0, 0.5f)); var earth = earthNode.CreateComponent<Sphere>(); earthMaterial = ResourceCache.GetMaterial("Materials/Earth.xml"); earth.SetMaterial(earthMaterial); var moonNode = earthNode.CreateChild(); moonNode.SetScale(0.27f); moonNode.Position = new Vector3(1.2f, 0, 0); var moon = moonNode.CreateComponent<Sphere>(); moon.SetMaterial(ResourceCache.GetMaterial("Materials/Moon.xml")); // Run a few actions to spin the Earth, the Moon and the clouds. earthNode.RunActions(new RepeatForever(new RotateBy(duration: 1f, deltaAngleX: 0, deltaAngleY: -4, deltaAngleZ: 0))); }
protected override async void Start() { base.Start(); clientConnection = new ClientConnection(); clientConnection.Disconnected += ClientConnection_Disconnected; clientConnection.RegisterForRealtimeUpdate(GetCurrentPositionDto); clientConnection.RegisterFor<PointerPositionChangedDto>(OnClientPointerChanged); Zone.AmbientColor = new Color(0.3f, 0.3f, 0.3f); DirectionalLight.Brightness = 0.5f; environmentNode = Scene.CreateChild(); EnableGestureTapped = true; cubeNode = environmentNode.CreateChild(); cubeNode.SetScale(0.2f); cubeNode.Position = new Vector3(1000, 1000, 1000); var box = cubeNode.CreateComponent<Box>(); box.Color = Color.White; var moveAction = new MoveBy(0.5f, new Vector3(0, 0.005f, 0)); cubeNode.RunActions(new RepeatForever(new RotateBy(1f, 0, 120, 0))); cubeNode.RunActions(new RepeatForever(moveAction, moveAction.Reverse())); //material = Material.FromColor(Color.Gray); //-- debug mode material = Material.FromColor(Color.Transparent, true); await RegisterCortanaCommands(new Dictionary<string, Action> { { "stop spatial mapping", StopSpatialMapping} }); while (!await ConnectAsync()) { } }
protected override void OnExplode(Node explodeNode) { rotor.RemoveAllActions(); rotor.Remove(); var particleEmitter = explodeNode.CreateComponent<ParticleEmitter2D>(); explodeNode.SetScale(1.5f); particleEmitter.Effect = Application.ResourceCache.GetParticleEffect2D(Assets.Particles.PlayerExplosion); }
public override void OnHit(Aircraft target, bool killed, Node bulletNode) { var soundSource = Node.CreateComponent<SoundSource>(); soundSource.Gain = 0.1f; soundSource.Play(Application.ResourceCache.GetSound(Assets.Sounds.Powerup)); base.OnHit(target, killed, bulletNode); ((SamplyGame)Application).OnCoinCollected(); }
public TargetedActionState (TargetedAction action, Node target) : base (action, target) { ForcedTarget = action.ForcedTarget; TargetedAction = action.Action; ActionState = (FiniteTimeActionState)TargetedAction.StartAction (ForcedTarget); }
public RotateByState (RotateBy action, Node target) : base (action, target) { AngleX = action.AngleX; AngleY = action.AngleY; AngleZ = action.AngleZ; StartAngles = target.Rotation; }
public JumpByState (JumpBy action, Node target) : base (action, target) { Delta = action.Position; Height = action.Height; Jumps = action.Jumps; P = StartPosition = target.Position; }
public SequenceState (Sequence action, Node target) : base (action, target) { actionSequences = action.Actions; hasInfiniteAction = (actionSequences [0] is RepeatForever) || (actionSequences [1] is RepeatForever); split = actionSequences [0].Duration / Duration; last = -1; }
async void Launch(Node bulletNode) { await bulletNode.RunActionsAsync( new MoveTo(3f, new Vector3(RandomHelper.NextRandom(-6f, 6f), -6, 0)), new CallFunc(() => bulletNode.SetScale(0f))); //remove the bullet from the scene. bulletNode.Remove(); }
public void Start() { // Background consists of two huge tiles (each BackgroundScale x BackgroundScale) frontTile = CreateTile(0); rearTile = CreateTile(1); // Move them and swap (rotate) to be looked like the background is infinite RotateBackground(); }
public BezierToState (BezierBy action, Node target) : base (action, target) { var config = BezierConfig; config.ControlPoint1 -= StartPosition; config.ControlPoint2 -= StartPosition; config.EndPosition -= StartPosition; BezierConfig = config; }
public ParallelState (Parallel action, Node target) : base (action, target) { Actions = action.Actions; ActionStates = new FiniteTimeActionState[Actions.Length]; for (int i = 0; i < Actions.Length; i++) { ActionStates [i] = (FiniteTimeActionState)Actions [i].StartAction (target); } }
public RepeatState (Repeat action, Node target) : base (action, target) { InnerAction = action.InnerAction; Times = action.Times; Total = action.Total; ActionInstant = action.ActionInstant; NextDt = InnerAction.Duration / Duration; InnerActionState = (FiniteTimeActionState)InnerAction.StartAction (target); }
public FadeOutState (FadeOut action, Node target) : base (action, target) { staticSprite = Target.GetComponent<StaticSprite2D>(); if (staticSprite != null) return; shape = Target.GetComponent<Shape>(); if (shape != null) return; throw new NotSupportedException("The node should have StaticSprite2D or Shape component"); }
public async Task ShowStartMenu(bool gameOver) { var cache = Application.ResourceCache; bigAircraft = Node.CreateChild(); var model = bigAircraft.CreateComponent<StaticModel>(); if (gameOver) { model.Model = cache.GetModel(Assets.Models.Enemy1); model.SetMaterial(cache.GetMaterial(Assets.Materials.Enemy1).Clone("")); bigAircraft.SetScale(0.3f); bigAircraft.Rotate(new Quaternion(180, 90, 20), TransformSpace.Local); } else { model.Model = cache.GetModel(Assets.Models.Player); model.SetMaterial(cache.GetMaterial(Assets.Materials.Player).Clone("")); bigAircraft.SetScale(1f); bigAircraft.Rotate(new Quaternion(0, 40, -50), TransformSpace.Local); } bigAircraft.Position = new Vector3(10, 2, 10); bigAircraft.RunActions(new RepeatForever(new Sequence(new RotateBy(1f, 0f, 0f, 5f), new RotateBy(1f, 0f, 0f, -5f)))); //TODO: rotor should be defined in the model + animation rotor = bigAircraft.CreateChild(); var rotorModel = rotor.CreateComponent<Box>(); rotorModel.Color = Color.White; rotor.Scale = new Vector3(0.1f, 1.5f, 0.1f); rotor.Position = new Vector3(0, 0, -1.3f); var rotorAction = new RepeatForever(new RotateBy(1f, 0, 0, 360f*6)); //RPM rotor.RunActions(rotorAction); menuLight = bigAircraft.CreateChild(); menuLight.Position = new Vector3(-3, 6, 2); menuLight.AddComponent(new Light { LightType = LightType.Point, Brightness = 0.3f }); await bigAircraft.RunActionsAsync(new EaseIn(new MoveBy(1f, new Vector3(-10, -2, -10)), 2)); textBlock = new Text(); textBlock.HorizontalAlignment = HorizontalAlignment.Center; textBlock.VerticalAlignment = VerticalAlignment.Bottom; textBlock.Value = gameOver ? "GAME OVER" : "TAP TO START"; textBlock.SetFont(cache.GetFont(Assets.Fonts.Font), Application.Graphics.Width / 15); Application.UI.Root.AddChild(textBlock); menuTaskSource = new TaskCompletionSource<bool>(); finished = false; await menuTaskSource.Task; }
static void AddCollisionDebugBox(Node rootNode, bool add) { var nodes = rootNode.GetChildrenWithComponent<CollisionShape>(true); foreach (var node in nodes) { node.GetChild("CollisionDebugBox", false)?.Remove(); if (!add) continue; var subNode = node.CreateChild("CollisionDebugBox"); var box = subNode.CreateComponent<Box>(); subNode.Scale = node.GetComponent<CollisionShape>().WorldBoundingBox.Size; box.Color = new Color(Color.Red, 0.4f); } }
public ScaleToState (ScaleTo action, Node target) : base (action, target) { var scale = target.Scale; StartScaleX = scale.X; StartScaleY = scale.Y; StartScaleZ = scale.Z; EndScaleX = action.EndScaleX; EndScaleY = action.EndScaleY; EndScaleZ = action.EndScaleZ; DeltaX = EndScaleX - StartScaleX; DeltaY = EndScaleY - StartScaleY; DeltaZ = EndScaleZ - StartScaleZ; }
public override void OnAttachedToNode(Node node) { barNode = node.CreateChild(); barNode.Scale = new Vector3(1, 0, 1); var box = barNode.CreateComponent<Box>(); box.Color = color; textNode = node.CreateChild(); textNode.Position = new Vector3(0, 3, 0); var text3D = textNode.CreateComponent<Text3D>(); text3D.SetFont(CoreAssets.Fonts.AnonymousPro, 60); text3D.TextEffect = TextEffect.Stroke; text3D.Text = name; base.OnAttachedToNode(node); }
public override async void OnHit(Aircraft target, bool killed, Node bulletNode) { // show a small explosion when the cube reaches an aircraft. base.OnHit(target, killed, bulletNode); var cache = Application.ResourceCache; var explosionNode = Scene.CreateChild(); SoundSource soundSource = explosionNode.CreateComponent<SoundSource>(); soundSource.Play(Application.ResourceCache.GetSound(Assets.Sounds.SmallExplosion)); soundSource.Gain = 0.3f; explosionNode.Position = target.Node.WorldPosition; explosionNode.SetScale(1.6f); var particleEmitter = explosionNode.CreateComponent<ParticleEmitter2D>(); particleEmitter.Effect = cache.GetParticleEffect2D(Assets.Particles.Explosion); ScaleBy scaleBy = new ScaleBy(0.3f, 0.1f); await explosionNode.RunActionsAsync(scaleBy, new DelayTime(1f)); explosionNode.Remove(); }
protected override void Start() { debugHud = new MonoDebugHud(this) { FpsOnly = true }; debugHud.Show(); scene = new Scene(); scene.CreateComponent<Octree>(); var zone = scene.CreateComponent<Zone>(); zone.AmbientColor = new Color(0.5f, 0.5f, 0.5f); cameraNode = scene.CreateChild(); var camera = cameraNode.CreateComponent<Camera>(); var viewport = new Viewport(scene, camera, null); // viewport.SetClearColor(Color.White); Renderer.SetViewport(0, viewport); lightNode = scene.CreateChild(); lightNode.Position = new Vector3(0, 3, 0); var light = lightNode.CreateComponent<Light>(); light.LightType = LightType.Directional; light.Brightness = 0.6f; light.Range = 200; environmentNode = scene.CreateChild(); environmentNode.SetScale(0.1f); humanNode = environmentNode.CreateChild(); humanNode.Position = new Vector3(0, -1f, 0); humanNode.SetScale(1f); var model = humanNode.CreateComponent<StaticModel>(); model.Model = ResourceCache.GetModel("Jack.mdl"); material = Material.FromColor(new Color(72/255f, 99/255f, 142/255f)); yaw = -65; pitch = 55; cameraNode.Position = new Vector3(0.6f, 1.3f, -0.4f); cameraNode.Rotation = new Quaternion(pitch, yaw, 0); lightNode.SetDirection(new Vector3(-1, -1f, 0)); InitTouchInput(); var pointer = scene.CreateComponent<CubePointer>(); pointer.PositionChanged += Pointer_PositionChanged; }
async void CreateScene () { Input.SubscribeToTouchEnd(OnTouched); var cache = ResourceCache; scene = new Scene (); octree = scene.CreateComponent<Octree> (); plotNode = scene.CreateChild(); var baseNode = plotNode.CreateChild().CreateChild(); var plane = baseNode.CreateComponent<StaticModel>(); plane.Model = ResourceCache.GetModel("Models/Plane.mdl"); var cameraNode = scene.CreateChild ("camera"); camera = cameraNode.CreateComponent<Camera>(); cameraNode.Position = new Vector3(10, 15, 10) / 1.75f; cameraNode.Rotation = new Quaternion(-0.121f, 0.878f, -0.305f, -0.35f); Node lightNode = cameraNode.CreateChild(name: "light"); var light = lightNode.CreateComponent<Light>(); light.LightType = LightType.Point; light.Range = 100; light.Brightness = 1.3f; int size = 3; baseNode.Scale = new Vector3(size * 1.5f, 1, size * 1.5f); bars = new List<Bar>(size * size); for (var i = 0f; i < size * 1.5f; i += 1.5f) { for (var j = 0f; j < size * 1.5f; j += 1.5f) { var boxNode = plotNode.CreateChild(); boxNode.Position = new Vector3(size / 2f - i, 0, size / 2f - j); var box = new Bar(new Color(RandomHelper.NextRandom(), RandomHelper.NextRandom(), RandomHelper.NextRandom(), 0.9f)); boxNode.AddComponent(box); box.SetValueWithAnimation((Math.Abs(i) + Math.Abs(j) + 1) / 2f); bars.Add(box); } } SelectedBar = bars.First(); SelectedBar.Select(); await plotNode.RunActionsAsync(new EaseBackOut(new RotateBy(2f, 0, 360, 0))); movementsEnabled = true; }
protected override async void Start() { base.Start(); //change the default brigtness Zone.AmbientColor = new Color(0.2f, 0.2f, 0.2f); DirectionalLight.Brightness = 0.5f; environmentNode = Scene.CreateChild(); EnableGestureTapped = true; await RegisterCortanaCommands(new Dictionary<string, Action> { { "show results", ShowResults }, { "stop spatial mapping", StopSpatialMapping } }); // requires 'spatialMapping' capabilaty await StartSpatialMapping(new Vector3(50, 50, 50)); }
public override void OnAttachedToNode(Node node) { base.OnAttachedToNode(node); Application.Input.TouchEnd += Input_TouchEnd; Application.Input.TouchBegin += Input_TouchBegin; cubeNode = node.CreateChild(); cubeNode.Position = new Vector3(1000, 1000, 1000); cubeNode.SetScale(0.02f); var box = cubeNode.CreateComponent<Box>(); box.Color = Color.White; var moveAction = new MoveBy(0.5f, new Vector3(0, 0.005f, 0)); cubeNode.RunActionsAsync(new RepeatForever(new RotateBy(1f, 0, 120, 0))); cubeNode.RunActionsAsync(new RepeatForever(moveAction, moveAction.Reverse())); camera = Scene.GetChildrenWithComponent<Camera>(true).First().GetComponent<Camera>(); octree = Scene.GetComponent<Octree>(true); }