Пример #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);
        }
Пример #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);
        }
Пример #5
0
        private static GameObject CreateAI(AIProperties properties)
        {
            // Instantiate AI object
            GameObject ai = GameObject.Instantiate(properties.GetModel(), Vector3.zero, Quaternion.identity);

            // Set tag and layer
            ai.name = properties.GetName();
            ai.tag  = TNC.AI;
            switch (properties.GetAIType())
            {
            case AIProperties.AIType.AgainstAll:
                ai.layer = LayerMask.NameToLayer(LNC.AI);
                break;

            case AIProperties.AIType.Friendly:
                ai.layer = LayerMask.NameToLayer(LNC.AI_FRIENDLY);
                break;

            case AIProperties.AIType.Enemy:
                ai.layer = LayerMask.NameToLayer(LNC.AI_ENEMY);
                break;
            }

            // Set components
            Animator animator = ai.GetComponent <Animator>();

            if (animator == null)
            {
                animator = ai.AddComponent <Animator>();
            }
            if (properties.GetController() != null)
            {
                animator.runtimeAnimatorController = properties.GetController();
            }

            AIController controller = ai.GetComponent <AIController>();

            if (controller == null)
            {
                controller = ai.AddComponent <AIController>();
            }

            AIHealth health = ai.GetComponent <AIHealth>();

            if (health == null)
            {
                health = ai.AddComponent <AIHealth>();
            }

            AIFieldOfView fieldOfView = ai.GetComponent <AIFieldOfView>();

            if (fieldOfView == null)
            {
                fieldOfView = ai.AddComponent <AIFieldOfView>();
            }

            AIAttackSystem attackSystem = ai.GetComponent <AIAttackSystem>();

            if (attackSystem == null)
            {
                attackSystem = ai.AddComponent <AIAttackSystem>();
            }

            AIReloadSystem reloadSystem = ai.GetComponent <AIReloadSystem>();

            if (reloadSystem == null)
            {
                reloadSystem = ai.AddComponent <AIReloadSystem>();
            }

            AIAnimatorHandler animatorHandler = ai.GetComponent <AIAnimatorHandler>();

            if (animatorHandler == null)
            {
                animatorHandler = ai.AddComponent <AIAnimatorHandler>();
            }

            CharacterRagdollSystem ragdollSystem = ai.GetComponent <CharacterRagdollSystem>();

            if (ragdollSystem == null)
            {
                ragdollSystem = ai.AddComponent <CharacterRagdollSystem>();
            }

            NavMeshAgent navMeshAgent = ai.GetComponent <NavMeshAgent>();

            if (navMeshAgent == null)
            {
                navMeshAgent = ai.AddComponent <NavMeshAgent>();
            }

            CapsuleCollider capsuleCollider = ai.GetComponent <CapsuleCollider>();

            if (capsuleCollider == null)
            {
                capsuleCollider = ai.AddComponent <CapsuleCollider>();
            }

            AudioSource audioSource = ai.GetComponent <AudioSource>();

            if (audioSource == null)
            {
                audioSource = ai.AddComponent <AudioSource>();
            }

            // Set component positions
            UEditorInternal.MoveComponentBottom <Animator>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIController>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIHealth>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIFieldOfView>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIAttackSystem>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIReloadSystem>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIAnimatorHandler>(ai.transform);
            UEditorInternal.MoveComponentBottom <CharacterRagdollSystem>(ai.transform);
            UEditorInternal.MoveComponentBottom <NavMeshAgent>(ai.transform);
            UEditorInternal.MoveComponentBottom <CapsuleCollider>(ai.transform);
            UEditorInternal.MoveComponentBottom <AudioSource>(ai.transform);

            // Set properties settings
            fieldOfView.SetTargetMask(properties.GetTargets());
            fieldOfView.SetObstacleMask(properties.GetObstacles());

            return(ai);
        }