private static void GrenadeGUI() { GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Space(5); GUILayout.Label(ContentProperties.BaseOptions, UEditorStyles.SectionHeaderLabel); GUILayout.Space(7); grenadeProperties.SetGrenadeObject((GameObject)EditorGUILayout.ObjectField(new GUIContent("Grenade", "Grenade gameobject."), grenadeProperties.GetGrenadeObject(), typeof(GameObject), true)); if (grenadeProperties.GetGrenadeObject() == null) { UEditorHelpBoxMessages.Error("Grenade object cannot be empty!", "Add grenade gameobject."); } grenadeProperties.SetModel(EditorGUILayout.TextField(ContentProperties.Model, grenadeProperties.GetModel())); grenadeProperties.SetRadius(EditorGUILayout.FloatField(ContentProperties.G_ExplosionRadius, grenadeProperties.GetRadius())); grenadeProperties.SetDelay(EditorGUILayout.FloatField(ContentProperties.Delay, grenadeProperties.GetDelay())); grenadeProperties.SetExplosionEffect((ParticleSystem)EditorGUILayout.ObjectField(ContentProperties.G_ExplosionEffect, grenadeProperties.GetExplosionEffect(), typeof(ParticleSystem), true)); grenadeProperties.SetExplosionSound((AudioClip)EditorGUILayout.ObjectField(ContentProperties.ExplosionSound, grenadeProperties.GetExplosionSound(), typeof(AudioClip), true)); grenadeProperties.SetExplosionProperties((ExplosionProperties)EditorGUILayout.ObjectField(ContentProperties.ExplosionProperties, grenadeProperties.GetExplosionProperties(), typeof(ExplosionProperties), true)); grenadeProperties.SetDecalProperties((DecalProperties)EditorGUILayout.ObjectField(ContentProperties.DecalProperties, grenadeProperties.GetDecalProperties(), typeof(DecalProperties), true)); GUILayout.Space(5); UEditor.HorizontalLine(); GUILayout.Space(5); EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(grenadeProperties.GetModel()) || grenadeProperties.GetGrenadeObject() == null); if (UEditor.Button("Create", "Right", GUILayout.Width(70))) { createdObject = CreateGreanade(grenadeProperties); } EditorGUI.EndDisabledGroup(); if (createdObject != null && editorDelay.WaitForSeconds()) { if (UDisplayDialogs.Message("Create Successful", "Greanade was created on scene!\nSetup grenade components before start play.", "Select", "Ok")) { Selection.activeGameObject = createdObject; } createdObject = null; } GUILayout.Space(5); GUILayout.EndVertical(); }
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); }