Beispiel #1
0
        /// <summary>
        /// Notifies that this collider has changed.
        /// </summary>
        protected void NotifyColliderChanged(ISpaceObject newSpaceObject)
        {
            Collidable    = newSpaceObject as Collidable;
            materialOwner = newSpaceObject as IMaterialOwner;
            if (materialOwner != null)
            {
                materialOwner.Material.Bounciness      = restitution;
                materialOwner.Material.StaticFriction  = friction.Min;
                materialOwner.Material.KineticFriction = friction.Max;
            }

            var entity = newSpaceObject as Entity;

            if (body != null && entity == null)
            {
                throw new InvalidOperationException();
            }

            if (entity != null)
            {
                this.entity     = entity;
                this.Collidable = entity.CollisionInformation;
            }

            if (spaceObject != null && removed != null)
            {
                removed(spaceObject);
            }
            spaceObject = newSpaceObject;
            if (spaceObject != null && added != null)
            {
                added(spaceObject);
            }
        }
Beispiel #2
0
        public void AddMaterialListener(IMaterialOwner owner, string name)
        {
            if (!materialOwners.ContainsKey(name))
            {
                materialOwners.Add(name, new List <IMaterialOwner>());
            }

            if (!materialOwners[name].Contains(owner))
            {
                materialOwners[name].Add(owner);
            }
        }
Beispiel #3
0
        public void RemoveMaterialListener(IMaterialOwner owner, string name)
        {
            if (!materialOwners.ContainsKey(name))
            {
                return;
            }

            if (materialOwners[name].Contains(owner))
            {
                materialOwners[name].Remove(owner);
            }
            if (materialOwners[name].Count == 0)
            {
                materialOwners.Remove(name);
            }
        }