Example #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);
        }
        /// <summary>
        /// Create new weapon by properties.
        /// </summary>
        private static GameObject CreatePickableWeapon(WeaponProperties properties)
        {
            // Initialize gameobjects.
            GameObject weponObject = new GameObject(properties.GetName());
            GameObject weapon      = GameObject.Instantiate(properties.GetClearWeapon(), Vector3.zero, Quaternion.identity, weponObject.transform);

            // Initialize weapon components.
            PickableItem   pickupItem       = UEditorInternal.AddComponent <PickableItem>(weponObject);
            Rigidbody      physicsRigidbody = UEditorInternal.AddComponent <Rigidbody>(weponObject);
            AudioSource    audioSource      = UEditorInternal.AddComponent <AudioSource>(weponObject);
            SphereCollider triggerCollider  = UEditorInternal.AddComponent <SphereCollider>(weponObject);
            BoxCollider    physicsCollider  = UEditorInternal.AddComponent <BoxCollider>(weponObject);

            // Setup PickableItem component.
            pickupItem.SetProcessingType(properties.GetProcessingType());
            pickupItem.SetObjectType(properties.GetObjectType());
            pickupItem.SetPickUpKey(properties.GetPickUpKey());
            pickupItem.SetItem(weapon.transform);
            pickupItem.SetWeapon(properties.GetWeaponID());
            pickupItem.SetValue(properties.GetValue());
            pickupItem.SetReusableDelay(properties.GetReusableDelay());
            pickupItem.IsReusable(properties.IsReusable());
            pickupItem.DestroyAfterUse(properties.DestroyAfterUse());
            pickupItem.SetPickUpMessage(properties.GetPickUpMessage());
            pickupItem.SetSoundEffect(properties.GetSoundEffect());

            // Setup SphereCollider component.
            triggerCollider.isTrigger = true;
            triggerCollider.radius    = 1.25f;

            // Setup BoxCollider component.
            Renderer renderer = weapon.GetComponentInChildren <Renderer>();

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

            // Apply components position.
            UEditorInternal.MoveComponentBottom <PickableItem>(weponObject.transform);
            UEditorInternal.MoveComponentBottom <Rigidbody>(weponObject.transform);
            UEditorInternal.MoveComponentBottom <SphereCollider>(weponObject.transform);
            UEditorInternal.MoveComponentBottom <BoxCollider>(weponObject.transform);
            UEditorInternal.MoveComponentBottom <AudioSource>(weponObject.transform);

            return(weponObject);
        }
Example #3
0
        private static GameObject CreateGreanade(GrenadeProperties properties)
        {
            // Initialize gameobjects.
            GameObject grenade      = new GameObject(properties.GetModel());
            GameObject grenadeModel = GameObject.Instantiate(properties.GetGrenadeObject(), Vector3.zero, Quaternion.identity, grenade.transform);

            // Initialize components
            Grenade        grenadeComponent = UEditorInternal.AddComponent <Grenade>(grenade);
            Rigidbody      rigidbody        = UEditorInternal.AddComponent <Rigidbody>(grenade);
            SphereCollider sphereCollider   = UEditorInternal.AddComponent <SphereCollider>(grenade);
            AudioSource    audioSource      = UEditorInternal.AddComponent <AudioSource>(grenade);

            // Setup Grenade component.
            grenadeComponent.SetGrenadeObject(properties.GetGrenadeObject());
            grenadeComponent.SetRadius(properties.GetRadius());
            grenadeComponent.SetExplosionEffect(properties.GetExplosionEffect());
            grenadeComponent.SetExplosionSound(properties.GetExplosionSound());
            grenadeComponent.SetExplosionProperties(properties.GetExplosionProperties());
            grenadeComponent.SetDecalProperties(properties.GetDecalProperties());
            grenadeComponent.SetDelay(properties.GetDelay());

            // Setup SphereCollider component.
            Renderer renderer = grenadeModel.GetComponent <Renderer>();

            if (renderer != null)
            {
                sphereCollider.center = renderer.bounds.center;
                sphereCollider.radius = renderer.bounds.size.x;
            }

            // Apply components position.
            UEditorInternal.MoveComponentBottom <Grenade>(grenade.transform);
            UEditorInternal.MoveComponentBottom <Rigidbody>(grenade.transform);
            UEditorInternal.MoveComponentBottom <SphereCollider>(grenade.transform);
            UEditorInternal.MoveComponentBottom <AudioSource>(grenade.transform);

            return(grenade);
        }
        /// <summary>
        /// Create new weapon by properties.
        /// </summary>
        private static GameObject CreateFPWeapon(WeaponProperties properties)
        {
            // Initialize gameobjects.
            GameObject weapon = GameObject.Instantiate <GameObject>(properties.GetWeapon(), Vector3.zero, Quaternion.identity);

            weapon.name  = properties.GetName();
            weapon.tag   = TNC.WEAPON;
            weapon.layer = LayerMask.NameToLayer(LNC.WEAPON);
            for (int i = 0, length = weapon.transform.childCount; i < length; i++)
            {
                weapon.transform.GetChild(i).gameObject.layer = LayerMask.NameToLayer(LNC.WEAPON);
            }

            // Initialize weapon components.
            Animator              animator              = UEditorInternal.AddComponent <Animator>(weapon);
            WeaponIdentifier      weaponIdentifier      = UEditorInternal.AddComponent <WeaponIdentifier>(weapon);
            WeaponAnimationSystem weaponAnimationSystem = UEditorInternal.AddComponent <WeaponAnimationSystem>(weapon);

            switch (properties.GetWeaponType())
            {
            case WeaponProperties.Type.Gun:
            {
                WeaponShootingSystem weaponShootingSystem = UEditorInternal.AddComponent <WeaponShootingSystem>(weapon);
                WeaponReloadSystem   weaponReloadSystem   = UEditorInternal.AddComponent <WeaponReloadSystem>(weapon);
                break;
            }

            case WeaponProperties.Type.Melee:
            {
                WeaponMeleeSystem weaponMeleeSystem = UEditorInternal.AddComponent <WeaponMeleeSystem>(weapon);
                break;
            }

            case WeaponProperties.Type.Throw:
            {
                ThrowingWeaponSystem throwingWeaponSystem = UEditorInternal.AddComponent <ThrowingWeaponSystem>(weapon);
                WeaponReloadSystem   weaponReloadSystem   = UEditorInternal.AddComponent <WeaponReloadSystem>(weapon);
                break;
            }
            }
            AudioSource audioSource = UEditorInternal.AddComponent <AudioSource>(weapon);

            // Setup Animator component.
            if (properties.GetController() != null)
            {
                animator.runtimeAnimatorController = properties.GetController();
            }

            // Setup WeaponID component.
            if (properties.GetWeaponID() != null)
            {
                weaponIdentifier.SetWeapon(properties.GetWeaponID());
            }

            // Apply components position.
            UEditorInternal.MoveComponentBottom <Animator>(weapon.transform);
            UEditorInternal.MoveComponentBottom <WeaponIdentifier>(weapon.transform);
            UEditorInternal.MoveComponentBottom <WeaponAnimationSystem>(weapon.transform);
            switch (properties.GetWeaponType())
            {
            case WeaponProperties.Type.Gun:
            {
                UEditorInternal.MoveComponentBottom <WeaponShootingSystem>(weapon.transform);
                UEditorInternal.MoveComponentBottom <WeaponReloadSystem>(weapon.transform);
                break;
            }

            case WeaponProperties.Type.Melee:
            {
                UEditorInternal.MoveComponentBottom <WeaponMeleeSystem>(weapon.transform);
                break;
            }

            case WeaponProperties.Type.Throw:
            {
                UEditorInternal.MoveComponentBottom <ThrowingWeaponSystem>(weapon.transform);
                UEditorInternal.MoveComponentBottom <WeaponReloadSystem>(weapon.transform);
                break;
            }
            }
            for (int i = 0, length = additionalComponents.Count; i < length; i++)
            {
                AdditionalComponents component = additionalComponents[i];
                if (component.isActive)
                {
                    weapon.AddComponent(component.component);
                }
            }
            UEditorInternal.MoveComponentBottom <AudioSource>(weapon.transform);

            return(weapon);
        }