Beispiel #1
0
        private static GameObject CreatePhysicsBullet(PhysicsBulletProperties properties)
        {
            // Initialize gameobjects.
            GameObject     bullet          = new GameObject(properties.GetModel());
            GameObject     bulletModel     = GameObject.Instantiate(properties.GetBullet(), Vector3.zero, Quaternion.identity, bullet.transform);
            ParticleSystem explosionEffect = null;

            if (properties.GetBulletType() == PhysicsBullet.BulletType.Rocket || properties.GetExplosionEffect() != null)
            {
                explosionEffect = GameObject.Instantiate(properties.GetExplosionEffect(), Vector3.zero, Quaternion.identity, bullet.transform);
            }

            // Initialize components
            BoxCollider   boxCollider            = UEditorInternal.AddComponent <BoxCollider>(bullet);
            PhysicsBullet physicsBulletComponent = UEditorInternal.AddComponent <PhysicsBullet>(bullet);
            Rigidbody     rigidbody   = UEditorInternal.AddComponent <Rigidbody>(bullet);
            AudioSource   audioSource = UEditorInternal.AddComponent <AudioSource>(bullet);

            // Setup PhysicsBullet component.
            physicsBulletComponent.SetBulletType(properties.GetBulletType());
            physicsBulletComponent.SetBullet(properties.GetBullet());
            physicsBulletComponent.SetModel(properties.GetModel());
            physicsBulletComponent.SetDamage(properties.GetDamage());
            physicsBulletComponent.SetVariance(properties.GetVariance());
            physicsBulletComponent.SetNumberBullet(properties.GetNumberBullet());
            physicsBulletComponent.SetExplosionRadius(properties.GetExplosionRadius());
            physicsBulletComponent.SetExplosionPower(properties.GetExplosionPower());
            if (properties.GetBulletType() == PhysicsBullet.BulletType.Rocket || explosionEffect != null)
            {
                physicsBulletComponent.SetExplosionEffect(explosionEffect);
            }
            physicsBulletProperties.SetExplosionSound(properties.GetExplosionSound());
            physicsBulletComponent.SetDecalProperties(properties.GetDecalProperties());

            // Setup BoxCollider component.
            Renderer renderer = bulletModel.GetComponent <Renderer>();

            if (renderer != null)
            {
                boxCollider.center = renderer.bounds.center;
                boxCollider.size   = renderer.bounds.size;
            }

            // Apply components position.
            UEditorInternal.MoveComponentBottom <PhysicsBullet>(bullet.transform);
            UEditorInternal.MoveComponentBottom <Rigidbody>(bullet.transform);
            UEditorInternal.MoveComponentBottom <BoxCollider>(bullet.transform);
            UEditorInternal.MoveComponentBottom <AudioSource>(bullet.transform);

            return(bullet);
        }