示例#1
0
        public AudioSampler(string name, SCNNode node, SFXCoordinator sfxCoordinator)
        {
            this.node        = node;
            this.AudioNode   = new AUSamplerNode();
            this.AudioPlayer = new SCNAudioPlayer(this.AudioNode);

            this.presetUrl = NSBundle.MainBundle.GetUrlForResource($"Sounds/{name}", "aupreset");
            if (this.presetUrl == null)
            {
                throw new System.IO.FileNotFoundException("Failed to load preset.");
            }

            AudioSampler.LoadingQueue.DispatchAsync(() =>
            {
                this.loaded.LockWhenCondition(0);

                this.AudioNode.LoadAudioUnitPreset(this.presetUrl, out NSError error);

                sfxCoordinator.AttachSampler(this, this.node);

                // now this sampler is ready to play.
                this.loaded.UnlockWithCondition(1);
            });
        }
示例#2
0
        public void DoHighlight(bool show, SFXCoordinator sfxCoordinator)
        {
            if (this.HighlightObject != null)
            {
                this.IsHighlighted          = show;
                this.HighlightObject.Hidden = !show;

                if (show)
                {
                    var seconds   = (DateTime.UtcNow - Time1970).TotalSeconds;
                    var intensity = (float)(Math.Sin(seconds.TruncatingRemainder(1) * 3.1415 * 2.0) * 0.2);
                    if (this.HighlightObject.Geometry?.FirstMaterial != null)
                    {
                        var color = new CIColor(this.highlightColor);
                        this.HighlightObject.Geometry.FirstMaterial.Diffuse.Contents = UIColor.FromRGBA((Single)DigitExtensions.Clamp(color.Red + intensity, 0, 1),
                                                                                                        (Single)DigitExtensions.Clamp(color.Green + intensity, 0, 1),
                                                                                                        (Single)DigitExtensions.Clamp(color.Blue + intensity, 0, 1),
                                                                                                        (Single)1);
                    }
                }

                sfxCoordinator?.CatapultDidChangeHighlight(this, show);
            }
        }
示例#3
0
        public Catapult(SCNNode node, SFXCoordinator sfxCoordinator, int identifier, Dictionary <string, object> gamedefs) : base(node, null, gamedefs, true, false)
        {
            this.Base             = node;
            this.audioEnvironment = sfxCoordinator.AudioEnvironment;

            // Base teamID and name off looking up teamA or teamB folder in the level parents
            // This won't work on the old levels.
            this.Team     = this.Base.GetTeam();
            this.TeamName = this.Team.GetDescription();

            // have team id established
            this.Base.SetPaintColors();

            // correct for the pivot point to place catapult flat on ground
            this.Base.Position = new SCNVector3(this.Base.Position.X, this.Base.Position.Y - 0.13f, this.Base.Position.Z);

            // highlight setup
            this.HighlightObject = node.FindChildNode("Highlight", true);
            if (this.HighlightObject != null)
            {
                this.HighlightObject = this.HighlightObject.FindNodeWithGeometry();
            }

            // hide the highlights on load
            if (this.HighlightObject != null)
            {
                this.HighlightObject.Hidden = true;
            }

            if (this.HighlightObject?.Geometry?.FirstMaterial?.Diffuse?.Contents is UIColor color)
            {
                this.highlightColor = color;
            }

            // they should only have y orientation, nothing in x or z
            // current scene files have the catapults with correct orientation, but the
            // eulerAngles are different - x and z are both π, y is within epsilon of 0
            // That's from bad decomposition of the matrix.  Need to restore the eulerAngles from the source.
            // Especially if we have animations tied to the euler angles.
            if (Math.Abs(node.EulerAngles.X) > 0.001f || Math.Abs(node.EulerAngles.Z) > 0.001f)
            {
                //Console.WriteLine("Catapult can only have y rotation applied");
            }

            // where to place the ball so it sits on the strap
            this.catapultStrap = this.Base.FindChildNode("catapultStrap", true);
            if (this.catapultStrap == null)
            {
                throw new Exception("No node with name catapultStrap");
            }

            // this only rotates, and represents the center of the catapult through which to fire
            this.pullOrigin = this.Base.FindChildNode("pullOrigin", true);
            if (this.pullOrigin == null)
            {
                throw new Exception("No node with name pullOrigin");
            }

            // This is a rope simulation meant for a fixed catapult, the catapult rotates.
            this.rope = new CatapultRope(node);

            // attach ball to the inactive strap, search for ballOriginInactiveBelow
            this.ballOriginInactiveBelow = this.Base.FindChildNode("ballOriginInactiveBelow", true);
            if (this.ballOriginInactiveBelow == null)
            {
                throw new Exception("No node with name ballOriginInactiveBelow");
            }

            this.ballOriginInactiveAbove = this.Base.FindChildNode("ballOriginInactiveAbove", true);
            if (this.ballOriginInactiveAbove == null)
            {
                throw new Exception("No node with name ballOriginInactiveAbove");
            }

            // ball will be made visible and drop once projectile is set and cooldown exceeded
            this.StrapVisible = StrapVisible.Visible;

            this.CatapultId = identifier;

            this.Base.SetValueForKey(NSObject.FromObject(this.CatapultId), new NSString(Catapult.CollisionKey));

            this.AudioPlayer = new CatapultAudioSampler(this.Base, sfxCoordinator);

            // use the teamID to set the collision category mask
            if (this.PhysicsNode?.PhysicsBody != null)
            {
                if (this.Team == Team.TeamA)
                {
                    this.PhysicsNode.PhysicsBody.CategoryBitMask = (int)CollisionMask.CatapultTeamA;
                    var collisionBitMask = (CollisionMask)(int)this.PhysicsNode.PhysicsBody.CollisionBitMask;
                    this.PhysicsNode.PhysicsBody.CollisionBitMask = (nuint)(int)(collisionBitMask | CollisionMask.CatapultTeamB);
                }
                else if (this.Team == Team.TeamB)
                {
                    this.PhysicsNode.PhysicsBody.CategoryBitMask = (int)CollisionMask.CatapultTeamB;
                    var collisionBitMask = (CollisionMask)(int)this.PhysicsNode.PhysicsBody.CollisionBitMask;
                    this.PhysicsNode.PhysicsBody.CollisionBitMask = (nuint)(int)(collisionBitMask | CollisionMask.CatapultTeamA);
                }
            }
        }
示例#4
0
 private void UpdateEffectsVolume()
 {
     this.effectsGain = SFXCoordinator.EffectsGain();
     this.AudioEnvironment.OutputVolume = effectsGain;
 }
示例#5
0
 public CollisionAudioSampler(SCNNode node, Config config, SFXCoordinator sfxCoordinator) : base(config.PresetName, node, sfxCoordinator)
 {
     this.configuration = config;
 }
示例#6
0
 public void Play()
 {
     this.Player.Volume = this.volume * SFXCoordinator.EffectsGain();
     this.Player.Play();
 }
示例#7
0
 public CatapultAudioSampler(SCNNode node, SFXCoordinator sfxCoordinator) : base("catapult", node, sfxCoordinator)
 {
 }