/// <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); }