/// <summary> /// Builds the character. /// </summary> private void BuildCharacter() { if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(m_Character))) { var name = m_Character.name; m_Character = GameObject.Instantiate(m_Character) as GameObject; m_Character.name = name; } // Call a runtime component to build the character so the character can be built at runtime. var isNetworked = m_IsNetworked; var baseDirectory = Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this))).Replace("Editor/Builders", ""); var maxFrictionMaterial = AssetDatabase.LoadAssetAtPath(baseDirectory + "Demos/Shared/Physic Materials/MaxFriction.physicMaterial", typeof(PhysicMaterial)) as PhysicMaterial; var frictionlessMaterial = AssetDatabase.LoadAssetAtPath(baseDirectory + "Demos/Shared/Physic Materials/Frictionless.physicMaterial", typeof(PhysicMaterial)) as PhysicMaterial; if (m_ModelType == ModelType.Humanoid) { ThirdPersonController.CharacterBuilder.BuildHumanoidCharacter(m_Character, m_AIAgent, isNetworked, m_MovementType, m_AnimatorController, maxFrictionMaterial, frictionlessMaterial); } else { ThirdPersonController.CharacterBuilder.BuildCharacter(m_Character, m_AIAgent, isNetworked, m_MovementType, m_AnimatorController, maxFrictionMaterial, frictionlessMaterial, m_ItemTransforms, m_FootTransforms); } if (isNetworked) { #if !ENABLE_MULTIPLAYER // The character is networked so enable the multiplayer symbol. RigidbodyCharacterControllerInspector.ToggleMultiplayerSymbol(); #endif } else { #if ENABLE_MULTIPLAYER // The character isn't networked so disable the multiplayer symbol. RigidbodyCharacterControllerInspector.ToggleMultiplayerSymbol(); #endif } Selection.activeGameObject = m_Character; if (m_ModelType == ModelType.Humanoid) { // Add the Fall and Jump abilities. if (m_AddStandardAbilities) { var controller = m_Character.GetComponent <RigidbodyCharacterController>(); AddAbility(controller, typeof(Opsive.ThirdPersonController.Wrappers.Abilities.Fall), "", Abilities.Ability.AbilityStartType.Automatic, Abilities.Ability.AbilityStopType.Manual); AddAbility(controller, typeof(Opsive.ThirdPersonController.Wrappers.Abilities.Jump), "Jump", Abilities.Ability.AbilityStartType.ButtonDown, Abilities.Ability.AbilityStopType.Automatic); AddAbility(controller, typeof(Opsive.ThirdPersonController.Wrappers.Abilities.SpeedChange), "Change Speeds", Abilities.Ability.AbilityStartType.ButtonDown, Abilities.Ability.AbilityStopType.ButtonUp); } // Open up the ragdoll builder. This class is internal to the Unity editor so reflection must be used to access it. if (m_AddRagdoll) { AddRagdoll(); } } #if DEATHMATCH_AI_KIT_PRESENT // Open the Agent Builder. if (m_AIAgent && m_DeathmatchAgent) { DeathmatchAIKit.Editor.AgentBuilder.ShowWindow(); var windows = Resources.FindObjectsOfTypeAll(typeof(DeathmatchAIKit.Editor.AgentBuilder)); if (windows != null && windows.Length > 0) { var agentBuilder = windows[0] as DeathmatchAIKit.Editor.AgentBuilder; agentBuilder.Agent = m_Character; } } #endif InspectorUtility.SetObjectDirty(m_Character); Close(); }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { var shootableWeapon = target as ShootableWeaponExtension; if (shootableWeapon == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); if ((m_FireFoldout = EditorGUILayout.Foldout(m_FireFoldout, "Fire Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DebugDrawFireRay")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CanUseInAir")); var firePoint = PropertyFromName(serializedObject, "m_FirePoint"); EditorGUILayout.PropertyField(firePoint); if (firePoint.objectReferenceValue == null) { EditorGUILayout.HelpBox("This field is required. The fire point specifies where the bullet should leave the weapon.", MessageType.Error); } var fireMode = PropertyFromName(serializedObject, "m_FireMode"); EditorGUILayout.PropertyField(fireMode); if (fireMode.intValue == (int)ShootableWeapon.FireMode.Burst) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_BurstRate")); EditorGUI.indentLevel--; } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireRate")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_Spread")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireCount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireOnUsedEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_WaitForEndUseEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RecoilAmount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireParticles")); EditorGUI.indentLevel--; } GameObject projectile = null; if ((m_ProjectileFoldout = EditorGUILayout.Foldout(m_ProjectileFoldout, "Projectile Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var projectileField = PropertyFromName(serializedObject, "m_Projectile"); EditorGUILayout.PropertyField(projectileField); projectile = projectileField.objectReferenceValue as GameObject; EditorGUI.indentLevel--; } if (projectile == null) { if ((m_HitscanFoldout = EditorGUILayout.Foldout(m_HitscanFoldout, "Hitscan Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; InspectorUtility.DrawFloatInfinityField(PropertyFromName(serializedObject, "m_HitscanFireRange")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HitscanImpactLayers")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HitscanDamageEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HitscanDamageAmount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HitscanImpactForce")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultHitscanDecal")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultHitscanDust")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultHitscanSpark")); var tracer = PropertyFromName(serializedObject, "m_Tracer"); EditorGUILayout.PropertyField(tracer); if (tracer.objectReferenceValue != null) { var tracerLocation = PropertyFromName(serializedObject, "m_TracerLocation"); EditorGUILayout.PropertyField(tracerLocation); if (tracerLocation == null) { EditorGUILayout.HelpBox("This field is required. The tracer location specifies where the tracer should spawn from weapon.", MessageType.Error); } } EditorGUI.indentLevel--; } } if ((m_AudioFoldout = EditorGUILayout.Foldout(m_AudioFoldout, "Audio Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireSound"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireSoundDelay")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_EmptyFireSound"), true); if (projectile == null) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultHitscanImpactSound")); } EditorGUI.indentLevel--; } if ((m_ShellFoldout = EditorGUILayout.Foldout(m_ShellFoldout, "Shell Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var shell = PropertyFromName(serializedObject, "m_Shell"); EditorGUILayout.PropertyField(shell); if (shell.objectReferenceValue != null) { var shellLocation = PropertyFromName(serializedObject, "m_ShellLocation"); EditorGUILayout.PropertyField(shellLocation); if (shellLocation == null) { EditorGUILayout.HelpBox("This field is required. The shell location specifies where the shell should leave the weapon.", MessageType.Error); } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ShellForce")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ShellTorque")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ShellDelay")); } EditorGUI.indentLevel--; } if ((m_MuzzleFlashFoldout = EditorGUILayout.Foldout(m_MuzzleFlashFoldout, "Muzzle Flash Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var muzzleFlash = PropertyFromName(serializedObject, "m_MuzzleFlash"); EditorGUILayout.PropertyField(muzzleFlash); if (muzzleFlash.objectReferenceValue != null) { var muzzleFlashLocation = PropertyFromName(serializedObject, "m_MuzzleFlashLocation"); EditorGUILayout.PropertyField(muzzleFlashLocation); if (muzzleFlashLocation == null) { EditorGUILayout.HelpBox("This field is required. The muzzle flash location specifies where the muzzle flash should appear from weapon.", MessageType.Error); } } EditorGUI.indentLevel--; } if ((m_SmokeFoldout = EditorGUILayout.Foldout(m_SmokeFoldout, "Smoke Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var smoke = PropertyFromName(serializedObject, "m_Smoke"); EditorGUILayout.PropertyField(smoke); if (smoke.objectReferenceValue != null) { var smokeLocation = PropertyFromName(serializedObject, "m_SmokeLocation"); EditorGUILayout.PropertyField(smokeLocation); if (smokeLocation == null) { EditorGUILayout.HelpBox("This field is required. The smoke location specifies where the smoke should appear from the weapon.", MessageType.Error); } } EditorGUI.indentLevel--; } if ((m_RegenerativeFoldout = EditorGUILayout.Foldout(m_RegenerativeFoldout, "Regeneration Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RegenerateRate")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RegenerateAmount")); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(shootableWeapon, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(shootableWeapon); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { var item = target as Item; if (item == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); // Allow the user to assign the item if it isn't already assigned if (item.transform.parent == null) { m_AssignTo = EditorGUILayout.ObjectField("Assign To", m_AssignTo, typeof(GameObject), true) as GameObject; var enableGUI = m_AssignTo != null && m_AssignTo.GetComponent <Animator>() != null; if (enableGUI) { if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(m_AssignTo))) { EditorGUILayout.HelpBox("The character must be located within the scene.", MessageType.Error); enableGUI = false; } else { if (m_AssignTo.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftHand) == null) { // The ItemPlacement component must be specified for generic models. m_ItemPlacement = EditorGUILayout.ObjectField("Item Placement", m_ItemPlacement, typeof(ItemPlacement), true) as ItemPlacement; if (m_ItemPlacement == null) { EditorGUILayout.HelpBox("The ItemPlacement GameObject must be specified for Generic models.", MessageType.Error); enableGUI = false; } } else { m_HandAssignment = (HandAssignment)EditorGUILayout.EnumPopup("Hand", m_HandAssignment); } } } GUI.enabled = enableGUI; if (GUILayout.Button("Assign")) { Transform itemPlacement = null; if (m_AssignTo.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftHand) == null) { itemPlacement = m_ItemPlacement.transform; } else { var handTransform = m_AssignTo.GetComponent <Animator>().GetBoneTransform(m_HandAssignment == HandAssignment.Left ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand); itemPlacement = handTransform.GetComponentInChildren <ItemPlacement>().transform; } AssignItem(item.gameObject, itemPlacement); } GUI.enabled = true; } var itemTypeProperty = PropertyFromName(serializedObject, "m_ItemType"); EditorGUILayout.PropertyField(itemTypeProperty); if (itemTypeProperty.objectReferenceValue == null) { EditorGUILayout.HelpBox("This field is required. The Inventory uses the Item Type to determine the type of item.", MessageType.Error); } var itemName = PropertyFromName(serializedObject, "m_ItemName"); EditorGUILayout.PropertyField(itemName); if (string.IsNullOrEmpty(itemName.stringValue)) { EditorGUILayout.HelpBox("The Item Name specifies the name of the Animator substate machine. It should not be empty unless you only have one item type.", MessageType.Warning); } if ((m_CharacterAnimatorFoldout = EditorGUILayout.Foldout(m_CharacterAnimatorFoldout, "Character Animator Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var canAim = PropertyFromName(serializedObject, "m_CanAim"); EditorGUILayout.PropertyField(canAim); if (canAim.boolValue) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RequireAim")); } DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_DefaultStates")); if (canAim.boolValue) { DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_AimStates")); } if (target is IUseableItem) { DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_UseStates")); } if (target is IReloadableItem) { DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_ReloadStates")); } if (target is MeleeWeapon || target is Shield) { DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_RecoilStates")); } DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_EquipStates")); DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_UnequipStates")); EditorGUI.indentLevel--; } if ((m_UIFoldout = EditorGUILayout.Foldout(m_UIFoldout, "UI Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemSprite"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RightItemSprite"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CrosshairsSprite"), true); EditorGUI.indentLevel--; } if ((m_InputFoldout = EditorGUILayout.Foldout(m_InputFoldout, "Input Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; if (item is IUseableItem) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_UseInputName")); if (serializedObject.FindProperty("m_DualWieldUseInputName") != null) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DualWieldUseInputName")); } } if (item is IReloadableItem) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ReloadInputName")); } if (item is IFlashlightUseable) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ToggleFlashlightInputName")); } if (item is ILaserSightUseable) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ToggleLaserSightInputName")); } EditorGUI.indentLevel--; } if ((m_GeneralFoldout = EditorGUILayout.Foldout(m_GeneralFoldout, "General Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_TwoHandedItem"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_NonDominantHandPosition"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HolsterTarget"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemPickup"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AimCameraState")); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(item, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(item); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { m_Controller = target as RigidbodyCharacterController; if (m_Controller == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); // Ensure the correct multiplayer symbol is defined. #if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0) var hasNetworkIdentity = (target as MonoBehaviour).GetComponent <UnityEngine.Networking.NetworkIdentity>() != null; var showNetworkToggle = false; var removeSymbol = false; #if ENABLE_MULTIPLAYER if (!hasNetworkIdentity) { EditorGUILayout.HelpBox("ENABLE_MULTIPLAYER is defined but no NetworkIdentity can be found. This symbol needs to be removed.", MessageType.Error); showNetworkToggle = true; removeSymbol = true; } #else if (hasNetworkIdentity) { EditorGUILayout.HelpBox("A NetworkIdentity was found but ENABLE_MULTIPLAYER is not defined. This symbol needs to be defined.", MessageType.Error); showNetworkToggle = true; } #endif if (!EditorApplication.isCompiling && showNetworkToggle && GUILayout.Button((removeSymbol ? "Remove" : "Add") + " Multiplayer Symbol")) { ToggleMultiplayerSymbol(); } #endif EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MovementType")); if ((m_MovementFoldout = EditorGUILayout.Foldout(m_MovementFoldout, "Movement Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var useRootMotion = PropertyFromName(serializedObject, "m_UseRootMotion"); EditorGUILayout.PropertyField(useRootMotion); if (!useRootMotion.boolValue) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundSpeed")); } else { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RootMotionSpeedMultiplier")); } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundDampening")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AirSpeed")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AirDampening")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RotationSpeed")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AimRotationSpeed")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_TorsoLookThreshold")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_LocalCoopCharacter")); if (m_Controller.Movement == RigidbodyCharacterController.MovementType.Pseudo3D || m_Controller.Movement == RigidbodyCharacterController.MovementType.TopDown) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_LookInMoveDirection")); } var alignToGround = PropertyFromName(serializedObject, "m_AlignToGround"); EditorGUILayout.PropertyField(alignToGround); if (alignToGround.boolValue) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AlignToGroundRotationSpeed")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AlignToGroundDepthOffset")); } EditorGUI.indentLevel--; } if ((m_CollisionFoldout = EditorGUILayout.Foldout(m_CollisionFoldout, "Collision Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MaxStepHeight")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_StepOffset")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_StepSpeed")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_SlopeLimit")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_StopMovementThreshold")); EditorGUI.indentLevel--; } if ((m_PhysicsFoldout = EditorGUILayout.Foldout(m_PhysicsFoldout, "Physics Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_SkinWidth")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MovingPlatformSkinWidth")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundStickiness")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CollisionPointLayerIgnore")); if (m_Controller.GetComponent <CapsuleCollider>() == null) { var capsuleCollider = PropertyFromName(serializedObject, "m_CapsuleCollider"); EditorGUILayout.PropertyField(capsuleCollider); if (capsuleCollider.objectReferenceValue == null) { EditorGUILayout.HelpBox("This field is required if no CapsuleColliders exist on the base character object.", MessageType.Error); } } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_LinkedColliders"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundedIdleFrictionMaterial")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundedMovingFrictionMaterial")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_StepFrictionMaterial")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_SlopeFrictionMaterial")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AirFrictionMaterial")); EditorGUI.indentLevel--; } if ((m_RestrictionsFoldout = EditorGUILayout.Foldout(m_RestrictionsFoldout, "Constraint Options", InspectorUtility.BoldFoldout))) { var movementRestriction = PropertyFromName(serializedObject, "m_MovementConstraint"); EditorGUILayout.PropertyField(movementRestriction); if ((RigidbodyCharacterController.MovementConstraint)movementRestriction.enumValueIndex == RigidbodyCharacterController.MovementConstraint.RestrictX || (RigidbodyCharacterController.MovementConstraint)movementRestriction.enumValueIndex == RigidbodyCharacterController.MovementConstraint.RestrictXZ) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MinXPosition")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MaxXPosition")); } if ((RigidbodyCharacterController.MovementConstraint)movementRestriction.enumValueIndex == RigidbodyCharacterController.MovementConstraint.RestrictZ || (RigidbodyCharacterController.MovementConstraint)movementRestriction.enumValueIndex == RigidbodyCharacterController.MovementConstraint.RestrictXZ) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MinZPosition")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MaxZPosition")); } } if ((m_ItemFoldout = EditorGUILayout.Foldout(m_ItemFoldout, "Item Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; // Explicitly update always aim so the property updates the Animator Monitor. var alwaysAim = EditorGUILayout.Toggle("Always Aim", m_Controller.AlwaysAim); if (m_Controller.AlwaysAim != alwaysAim) { m_Controller.AlwaysAim = alwaysAim; } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CombatMovementOnAim")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemUseRotationThreshold")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemForciblyUseDuration")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DualWieldItemForciblyUseDuration")); EditorGUI.indentLevel--; } if ((m_AbilityFoldout = EditorGUILayout.Foldout(m_AbilityFoldout, "Abilities", InspectorUtility.BoldFoldout))) { if (m_ReorderableAbilityList == null) { m_Abilities = PropertyFromName(serializedObject, "m_Abilities"); m_ReorderableAbilityList = new ReorderableList(serializedObject, m_Abilities, true, true, true, true); m_ReorderableAbilityList.drawElementCallback = OnAbilityListDraw; m_ReorderableAbilityList.drawHeaderCallback = OnAbilityListDrawHeader; m_ReorderableAbilityList.onReorderCallback = OnAbilityListReorder; m_ReorderableAbilityList.onAddCallback = OnAbilityListAdd; m_ReorderableAbilityList.onRemoveCallback = OnAbilityListRemove; m_ReorderableAbilityList.onSelectCallback = OnAbilityListSelect; if (m_Controller.SelectedAbility != -1) { m_ReorderableAbilityList.index = m_Controller.SelectedAbility; } } m_ReorderableAbilityList.DoLayoutList(); if (m_ReorderableAbilityList.index != -1) { if (m_ReorderableAbilityList.index < m_Abilities.arraySize) { DrawSelectedAbility(m_Abilities.GetArrayElementAtIndex(m_ReorderableAbilityList.index).objectReferenceValue as Ability); } else { m_ReorderableAbilityList.index = m_Controller.SelectedAbility = -1; } } } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_Controller, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(m_Controller); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { var itemExtension = target as ItemExtension; if (itemExtension == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); // An item must exist to be able to extend it. if (itemExtension.GetComponent <Item>() == null) { EditorGUILayout.HelpBox("An Item component is required. Please run the Item Builder and create your item.", MessageType.Error); return; } var itemTypeProperty = PropertyFromName(serializedObject, "m_ConsumableItemType"); EditorGUILayout.PropertyField(itemTypeProperty); if (itemTypeProperty.objectReferenceValue == null) { EditorGUILayout.HelpBox("This field is required. The Inventory uses the Consumable Item Type to determine the type of item.", MessageType.Error); } if ((m_CharacterAnimatorFoldout = EditorGUILayout.Foldout(m_CharacterAnimatorFoldout, "Character Animator Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; ItemInspector.DrawAnimatorStateSet(itemExtension, m_ReorderableListMap, m_ReordableLists, OnListSelect, OnListAdd, OnListRemove, PropertyFromName(serializedObject, "m_UseStates")); if (itemExtension is IReloadableItem) { ItemInspector.DrawAnimatorStateSet(itemExtension, m_ReorderableListMap, m_ReordableLists, OnListSelect, OnListAdd, OnListRemove, PropertyFromName(serializedObject, "m_ReloadStates")); } if (target is MeleeWeaponExtension) { ItemInspector.DrawAnimatorStateSet(itemExtension, m_ReorderableListMap, m_ReordableLists, OnListSelect, OnListAdd, OnListRemove, PropertyFromName(serializedObject, "m_RecoilStates")); } EditorGUI.indentLevel--; } if ((m_InputFoldout = EditorGUILayout.Foldout(m_InputFoldout, "Input Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; if (itemExtension is IUseableItem) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_UseInputName")); } EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(itemExtension, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(itemExtension); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { var shootableWeapon = target as ShootableWeapon; if (shootableWeapon == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); GameObject projectile = null; if ((m_FireFoldout = EditorGUILayout.Foldout(m_FireFoldout, "Fire Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DebugDrawFireRay")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CanUseInAir")); var firePoint = PropertyFromName(serializedObject, "m_FirePoint"); EditorGUILayout.PropertyField(firePoint); if (firePoint.objectReferenceValue == null) { EditorGUILayout.HelpBox("This field is required. The fire point specifies where the bullet should leave the weapon.", MessageType.Error); } var fireMode = PropertyFromName(serializedObject, "m_FireMode"); EditorGUILayout.PropertyField(fireMode); if (fireMode.intValue == (int)ShootableWeapon.FireMode.Burst) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_BurstRate")); EditorGUI.indentLevel--; } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireRate")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_Spread")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireCount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireType")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireOnUsedEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_WaitForEndUseEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_UseScope")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RecoilAmount")); var particles = PropertyFromName(serializedObject, "m_Particles"); EditorGUILayout.PropertyField(particles); if (particles.objectReferenceValue != null) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_StopParticlesOnEndUse")); } EditorGUI.indentLevel--; } if ((m_ProjectileFoldout = EditorGUILayout.Foldout(m_ProjectileFoldout, "Projectile Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var projectileField = PropertyFromName(serializedObject, "m_Projectile"); EditorGUILayout.PropertyField(projectileField); projectile = projectileField.objectReferenceValue as GameObject; EditorGUILayout.HelpBox("If a projectile GameObject is specified then this projectile will be fired from the weapon. If no projectile is specified then a hitscan will be used.", MessageType.Info); if (projectile != null) { var alwaysVisible = PropertyFromName(serializedObject, "m_ProjectileAlwaysVisible"); EditorGUILayout.PropertyField(alwaysVisible); if (alwaysVisible.boolValue) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ProjectileRestLocation")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ProjectileRestParent")); } } EditorGUI.indentLevel--; } if (projectile == null) { if ((m_HitscanFoldout = EditorGUILayout.Foldout(m_HitscanFoldout, "Hitscan Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; InspectorUtility.DrawFloatInfinityField(PropertyFromName(serializedObject, "m_HitscanFireRange")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HitscanImpactLayers")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HitscanDamageEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HitscanDamageAmount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HitscanImpactForce")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultHitscanDecal")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultHitscanDust")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultHitscanSpark")); var tracer = PropertyFromName(serializedObject, "m_Tracer"); EditorGUILayout.PropertyField(tracer); if (tracer.objectReferenceValue != null) { var tracerLocation = PropertyFromName(serializedObject, "m_TracerLocation"); EditorGUILayout.PropertyField(tracerLocation); if (tracerLocation == null) { EditorGUILayout.HelpBox("This field is required. The tracer location specifies where the tracer should spawn from weapon.", MessageType.Error); } } EditorGUI.indentLevel--; } } if ((m_ClipFoldout = EditorGUILayout.Foldout(m_ClipFoldout, "Clip Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; InspectorUtility.DrawIntInfinityField(PropertyFromName(serializedObject, "m_ClipSize")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AutoReload")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RegenerateRate")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RegenerateAmount")); EditorGUI.indentLevel--; } if ((m_OverheatFoldout = EditorGUILayout.Foldout(m_OverheatFoldout, "Overheat Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var overheat = PropertyFromName(serializedObject, "m_Overheat"); EditorGUILayout.PropertyField(overheat); if (overheat.boolValue) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_OverheatShotCount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CooldownDuration")); } EditorGUI.indentLevel--; } if ((m_AudioFoldout = EditorGUILayout.Foldout(m_AudioFoldout, "Audio Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireSound"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireSoundDelay")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_EmptyFireSound"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ReloadSound"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ReloadSoundDelay"), true); if (projectile == null) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultHitscanImpactSound")); } EditorGUI.indentLevel--; } if ((m_AnimatorFoldout = EditorGUILayout.Foldout(m_AnimatorFoldout, "Animator Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_IdleAnimationStateName")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireAnimationStateName")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ReloadAnimationStateName")); EditorGUI.indentLevel--; } if ((m_ShellFoldout = EditorGUILayout.Foldout(m_ShellFoldout, "Shell Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var shell = PropertyFromName(serializedObject, "m_Shell"); EditorGUILayout.PropertyField(shell); if (shell.objectReferenceValue != null) { var shellLocation = PropertyFromName(serializedObject, "m_ShellLocation"); EditorGUILayout.PropertyField(shellLocation); if (shellLocation == null) { EditorGUILayout.HelpBox("This field is required. The shell location specifies where the shell should leave the weapon.", MessageType.Error); } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ShellForce")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ShellTorque")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ShellDelay")); } EditorGUI.indentLevel--; } if ((m_MuzzleFlashFoldout = EditorGUILayout.Foldout(m_MuzzleFlashFoldout, "Muzzle Flash Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var muzzleFlash = PropertyFromName(serializedObject, "m_MuzzleFlash"); EditorGUILayout.PropertyField(muzzleFlash); if (muzzleFlash.objectReferenceValue != null) { var muzzleFlashLocation = PropertyFromName(serializedObject, "m_MuzzleFlashLocation"); EditorGUILayout.PropertyField(muzzleFlashLocation); if (muzzleFlashLocation == null) { EditorGUILayout.HelpBox("This field is required. The muzzle flash location specifies where the muzzle flash should appear from weapon.", MessageType.Error); } } EditorGUI.indentLevel--; } if ((m_SmokeFoldout = EditorGUILayout.Foldout(m_SmokeFoldout, "Smoke Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var smoke = PropertyFromName(serializedObject, "m_Smoke"); EditorGUILayout.PropertyField(smoke); if (smoke.objectReferenceValue != null) { var smokeLocation = PropertyFromName(serializedObject, "m_SmokeLocation"); EditorGUILayout.PropertyField(smokeLocation); if (smokeLocation == null) { EditorGUILayout.HelpBox("This field is required. The smoke location specifies where the smoke should appear from the weapon.", MessageType.Error); } } EditorGUI.indentLevel--; } if ((m_AttachmentsFoldout = EditorGUILayout.Foldout(m_AttachmentsFoldout, "Attachment Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var flashlight = PropertyFromName(serializedObject, "m_Flashlight"); EditorGUILayout.PropertyField(flashlight); if (flashlight.objectReferenceValue != null) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ActivateFlashlightOnAim")); } var laserSight = PropertyFromName(serializedObject, "m_LaserSight"); EditorGUILayout.PropertyField(laserSight); if (laserSight.objectReferenceValue != null) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ActivateLaserSightOnAim")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DisableCrosshairsWhenLaserSightActive")); } EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(shootableWeapon, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(shootableWeapon); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { var magicItem = target as MagicItem; if (magicItem == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); if ((m_MagicFoldout = EditorGUILayout.Foldout(m_MagicFoldout, "Magic Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CanUseInAir")); var useMode = PropertyFromName(serializedObject, "m_CastMode"); EditorGUILayout.PropertyField(useMode); if ((MagicItem.CastMode)useMode.enumValueIndex == MagicItem.CastMode.Continuous) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ContinuousMinUseDuration")); } var useShape = PropertyFromName(serializedObject, "m_CastShape"); EditorGUILayout.PropertyField(useShape); if ((MagicItem.CastShape)useShape.enumValueIndex == MagicItem.CastShape.Linear) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CastDistance")); } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CastRate")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CastPoint")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CastAmount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CastRadius")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_TargetLayer")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_WaitForEndUseEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CanStopBeforeUse")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CastParticles")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CastSound"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CastSoundDelay")); EditorGUI.indentLevel--; } if ((m_ImpactFoldout = EditorGUILayout.Foldout(m_ImpactFoldout, "Impact Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DamageEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DamageAmount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_NormalizeDamage")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ImpactForce")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultImpactSound")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultSpark")); EditorGUI.indentLevel--; } if ((m_RegenerativeFoldout = EditorGUILayout.Foldout(m_RegenerativeFoldout, "Regenerative Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RegenerateRate")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RegenerateAmount")); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(magicItem, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(magicItem); } }
/// <summary> /// Draws the ItemAmount ReordableList element. /// </summary> public static void OnItemAmountElementDraw(ReorderableList reordableList, Rect rect, int index, bool isActive, bool isFocused) { EditorGUI.BeginChangeCheck(); var loadout = reordableList.serializedProperty.GetArrayElementAtIndex(index); var itemType = loadout.FindPropertyRelative("m_ItemType"); var amount = loadout.FindPropertyRelative("m_Amount"); var objFieldWidth = rect.width - 190; itemType.objectReferenceValue = EditorGUI.ObjectField(new Rect(rect.x, rect.y + 1, objFieldWidth, EditorGUIUtility.singleLineHeight), itemType.objectReferenceValue, typeof(ItemType), true) as ItemType; if (GUI.changed && itemType.objectReferenceValue is PrimaryItemType) { loadout.FindPropertyRelative("m_Equip").boolValue = true; } // DualWieldItemTypes cannot be directly picked up. if (itemType.objectReferenceValue is DualWieldItemType) { itemType.objectReferenceValue = null; } GUI.enabled = itemType.objectReferenceValue is PrimaryItemType; var equip = loadout.FindPropertyRelative("m_Equip"); equip.boolValue = EditorGUI.Toggle(new Rect(rect.x + objFieldWidth, rect.y, 50, EditorGUIUtility.singleLineHeight), equip.boolValue); var prevInfinity = (amount.intValue == int.MaxValue); GUI.enabled = !prevInfinity; if (itemType.objectReferenceValue is PrimaryItemType) { amount.intValue = Mathf.Min(EditorGUI.IntField(new Rect(rect.x + objFieldWidth + 50, rect.y, 70, EditorGUIUtility.singleLineHeight), Mathf.Max(amount.intValue, 1)), 2); } else { amount.intValue = EditorGUI.IntField(new Rect(rect.x + objFieldWidth + 50, rect.y, 70, EditorGUIUtility.singleLineHeight), amount.intValue); } GUI.enabled = !(itemType.objectReferenceValue is PrimaryItemType); var infinity = EditorGUI.Toggle(new Rect(rect.x + objFieldWidth + 120, rect.y, 70, EditorGUIUtility.singleLineHeight), prevInfinity); if (prevInfinity != infinity) { if (infinity) { amount.intValue = int.MaxValue; } else { amount.intValue = 1; } } GUI.enabled = true; if (EditorGUI.EndChangeCheck()) { var serializedObject = reordableList.serializedProperty.serializedObject; Undo.RecordObject(serializedObject.targetObject, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(serializedObject.targetObject); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { var inventory = target as Inventory; if (inventory == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_UnlimitedAmmo")); var unequippedItemType = PropertyFromName(serializedObject, "m_UnequippedItemType"); EditorGUILayout.PropertyField(unequippedItemType); if (unequippedItemType.objectReferenceValue != null) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CanSwitchToUnequippedItemType")); EditorGUI.indentLevel--; } var dropItemsOnDeath = PropertyFromName(serializedObject, "m_DropItems"); EditorGUILayout.PropertyField(dropItemsOnDeath); if (dropItemsOnDeath.boolValue) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DroppedItemsParent")); EditorGUI.indentLevel--; } if ((m_DefaultLoadoutFoldout = EditorGUILayout.Foldout(m_DefaultLoadoutFoldout, "Default Loadout", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; if (m_ReordableDefaultLoadout == null) { var defaultLoadoutProperty = PropertyFromName(serializedObject, "m_DefaultLoadout"); m_ReordableDefaultLoadout = new ReorderableList(serializedObject, defaultLoadoutProperty, true, true, true, true); m_ReordableDefaultLoadout.drawHeaderCallback = OnItemAmountHeaderDraw; m_ReordableDefaultLoadout.drawElementCallback = OnItemAmountElementDraw; } m_ReordableDefaultLoadout.DoLayoutList(); EditorGUI.indentLevel--; } if ((m_ItemOrderFoldout = EditorGUILayout.Foldout(m_ItemOrderFoldout, "Item Order", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; if (m_ReordableItemOrder == null) { var itemOrderProperty = PropertyFromName(serializedObject, "m_ItemOrder"); m_ReordableItemOrder = new ReorderableList(serializedObject, itemOrderProperty, true, false, true, true); m_ReordableItemOrder.drawElementCallback = OnItemOrderDraw; } m_ReordableItemOrder.DoLayoutList(); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(inventory, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(inventory); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { m_CameraController = target as CameraController; if (m_CameraController == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); if (m_ReorderableCameraStateList == null) { m_CameraStates = PropertyFromName(serializedObject, "m_CameraStates"); m_ReorderableCameraStateList = new ReorderableList(serializedObject, m_CameraStates, true, true, true, true); m_ReorderableCameraStateList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Camera States"); }; m_ReorderableCameraStateList.drawElementCallback = OnCameraStateListDraw; m_ReorderableCameraStateList.onAddCallback = OnCameraStateListAdd; m_ReorderableCameraStateList.onRemoveCallback = OnCameraStateListRemove; m_ReorderableCameraStateList.onSelectCallback = (ReorderableList list) => { m_CameraController.SelectedCameraState = list.index; }; if (m_CameraController.SelectedCameraState != -1) { m_ReorderableCameraStateList.index = m_CameraController.SelectedCameraState; } } m_ReorderableCameraStateList.DoLayoutList(); if ((!Application.isPlaying || AssetDatabase.GetAssetPath(m_CameraController).Length == 0) && m_ReorderableCameraStateList.index != -1) { if (m_ReorderableCameraStateList.index < m_CameraStates.arraySize) { var cameraStateProperty = m_CameraStates.GetArrayElementAtIndex(m_ReorderableCameraStateList.index); if (cameraStateProperty.objectReferenceValue != null) { var cameraState = cameraStateProperty.objectReferenceValue as CameraState; var cameraStateSerializedObject = new SerializedObject(cameraState); if (CameraStateInspector.DrawCameraState(cameraState, cameraStateSerializedObject, false)) { Undo.RecordObject(cameraState, "Inspector"); cameraStateSerializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(cameraState); } } } else { m_ReorderableCameraStateList.index = m_CameraController.SelectedCameraState = -1; } } else if (Application.isPlaying && AssetDatabase.GetAssetPath(m_CameraController).Length == 0) { EditorGUILayout.LabelField("Active State", EditorStyles.boldLabel); EditorGUI.indentLevel++; // If the game is playing draw the active state. var cameraStateSerializedObject = new SerializedObject(m_CameraController.ActiveState); if (CameraStateInspector.DrawCameraState(m_CameraController.ActiveState, cameraStateSerializedObject, true)) { Undo.RecordObject(m_CameraController.ActiveState, "Inspector"); cameraStateSerializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(m_CameraController.ActiveState); } EditorGUI.indentLevel--; } if ((m_CharacterFoldout = EditorGUILayout.Foldout(m_CharacterFoldout, "Character Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var initCharacterOnStartProperty = PropertyFromName(serializedObject, "m_InitCharacterOnStart"); EditorGUILayout.PropertyField(initCharacterOnStartProperty); var characterProperty = PropertyFromName(serializedObject, "m_Character"); if (initCharacterOnStartProperty.boolValue) { characterProperty.objectReferenceValue = EditorGUILayout.ObjectField("Character", characterProperty.objectReferenceValue, typeof(GameObject), true, GUILayout.MinWidth(80)) as GameObject; if (characterProperty.objectReferenceValue == null) { EditorGUILayout.HelpBox("This field is required. The character specifies the GameObject that the CameraController should interact with.", MessageType.Error); } else { if ((characterProperty.objectReferenceValue as GameObject).GetComponent <Opsive.ThirdPersonController.Input.PlayerInput>() == null) { EditorGUILayout.HelpBox("The Camera Controller component cannot reference an AI Agent. Ensure the Camera Controller is referencing a player controlled character.", MessageType.Error); } } } else if (characterProperty.objectReferenceValue != null) { characterProperty.objectReferenceValue = null; } var autoAnchorProperty = PropertyFromName(serializedObject, "m_AutoAnchor"); EditorGUILayout.PropertyField(autoAnchorProperty); if (autoAnchorProperty.boolValue) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AutoAnchorBone")); } else { var anchorProperty = PropertyFromName(serializedObject, "m_Anchor"); anchorProperty.objectReferenceValue = EditorGUILayout.ObjectField("Anchor", anchorProperty.objectReferenceValue, typeof(Transform), true, GUILayout.MinWidth(80)) as Transform; if (anchorProperty.objectReferenceValue == null) { EditorGUILayout.HelpBox("The anchor specifies the Transform that the camera should follow. If null it will use the Character's Transform.", MessageType.Info); } } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FadeTransform")); EditorGUI.indentLevel--; } // The following properties are only applicable to the third person view. if ((m_DeathOrbitFoldout = EditorGUILayout.Foldout(m_DeathOrbitFoldout, "Death Orbit Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DeathAnchor")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_UseDeathOrbit")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DeathRotationSpeed")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DeathOrbitMoveSpeed")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DeathOrbitDistance")); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_CameraController, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(m_CameraController); } }
/// <summary> /// Adds a new camera state element to the list. /// </summary> private void AddCameraStateElement() { m_CameraStates.InsertArrayElementAtIndex(m_CameraStates.arraySize); m_CameraStates.serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(m_CameraController); }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { var meleeWeapon = target as MeleeWeapon; if (meleeWeapon == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); // A collider must exist. var collider = meleeWeapon.GetComponent <Collider>(); if (collider == null) { EditorGUILayout.HelpBox("A collider must exist on the weapon.", MessageType.Error); } // As does a Rigidbody. var rigidbody = meleeWeapon.GetComponent <Rigidbody>(); if (rigidbody == null) { EditorGUILayout.HelpBox("A Rigidbody must exist on the weapon.", MessageType.Error); } if ((m_AttackFoldout = EditorGUILayout.Foldout(m_AttackFoldout, "Attack Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CanUseInAir")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AttackRate")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AttackLayer")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AttackHitboxes"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CanInterruptAttack")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_SingleHitAttack")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_WaitForEndUseEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AttackSound"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AttackSoundDelay")); EditorGUI.indentLevel--; } if ((m_ImpactFoldout = EditorGUILayout.Foldout(m_ImpactFoldout, "Impact Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DamageEvent")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DamageAmount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ImpactForce")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultDust")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DefaultImpactSound")); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(meleeWeapon, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(meleeWeapon); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { var turret = target as SimpleTurret; if (turret == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); var turretHeadProperty = PropertyFromName(serializedObject, "m_TurretHead"); turretHeadProperty.objectReferenceValue = EditorGUILayout.ObjectField("Turret Head", turretHeadProperty.objectReferenceValue, typeof(GameObject), true, GUILayout.MinWidth(80)) as GameObject; if (turretHeadProperty.objectReferenceValue == null) { EditorGUILayout.HelpBox("This field is required. The turret head specifies the GameObject that can rotate to aim at the target.", MessageType.Error); } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RotationSpeed")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_TargetLayers")); if ((m_FireFoldout = EditorGUILayout.Foldout(m_FireFoldout, "Fire Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var projectile = PropertyFromName(serializedObject, "m_Projectile"); EditorGUILayout.PropertyField(projectile); if (projectile.objectReferenceValue == null) { EditorGUILayout.HelpBox("This field is required. The projectile specifies the GameObject that will damage the target.", MessageType.Error); } var firePoint = PropertyFromName(serializedObject, "m_FirePoint"); EditorGUILayout.PropertyField(firePoint); if (firePoint.objectReferenceValue == null) { EditorGUILayout.HelpBox("This field is required. The fire point specifies where the bullet should leave the weapon.", MessageType.Error); } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireRange")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireRate")); EditorGUI.indentLevel--; } if ((m_AudioFoldout = EditorGUILayout.Foldout(m_AudioFoldout, "Audio Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireSound")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_FireSoundDelay")); EditorGUI.indentLevel--; } if ((m_MuzzleFlashFoldout = EditorGUILayout.Foldout(m_MuzzleFlashFoldout, "Muzzle Flash Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var muzzleFlash = PropertyFromName(serializedObject, "m_MuzzleFlash"); EditorGUILayout.PropertyField(muzzleFlash); if (muzzleFlash.objectReferenceValue != null) { var muzzleFlashLocation = PropertyFromName(serializedObject, "m_MuzzleFlashLocation"); EditorGUILayout.PropertyField(muzzleFlashLocation); if (muzzleFlashLocation == null) { EditorGUILayout.HelpBox("This field is required. The muzzle flash location specifies where the muzzle flash should appear from weapon.", MessageType.Error); } } EditorGUI.indentLevel--; } if ((m_SmokeFoldout = EditorGUILayout.Foldout(m_SmokeFoldout, "Smoke Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; var smoke = PropertyFromName(serializedObject, "m_Smoke"); EditorGUILayout.PropertyField(smoke); if (smoke.objectReferenceValue != null) { var smokeLocation = PropertyFromName(serializedObject, "m_SmokeLocation"); EditorGUILayout.PropertyField(smokeLocation); if (smokeLocation == null) { EditorGUILayout.HelpBox("This field is required. The smoke location specifies where the smoke should appear from the weapon.", MessageType.Error); } } EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(turret, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(turret); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { var health = target as Health; if (health == null || serializedObject == null) { return; // How'd this happen? } base.OnInspectorGUI(); // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); if (Application.isPlaying) { GUI.enabled = false; EditorGUILayout.FloatField("Current Health", health.CurrentHealth); EditorGUILayout.FloatField("Current Shield", health.CurrentShield); GUI.enabled = true; } EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_Invincible")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MaxHealth")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_TimeInvincibleAfterSpawn")); if ((m_ShieldFoldout = EditorGUILayout.Foldout(m_ShieldFoldout, "Shield Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MaxShield")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ShieldRegenerativeInitialWait")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ShieldRegenerativeAmount")); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ShieldRegenerativeWait")); EditorGUI.indentLevel--; } if ((m_DamageMultiplierFoldout = EditorGUILayout.Foldout(m_DamageMultiplierFoldout, "Damage Multiplier Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; if (m_DamageMultiplierList == null) { var damageMultiplierProperty = PropertyFromName(serializedObject, "m_DamageMultipliers"); m_DamageMultiplierList = new ReorderableList(serializedObject, damageMultiplierProperty, true, true, true, true); m_DamageMultiplierList.drawHeaderCallback = OnDamageMultiplierHeaderDraw; m_DamageMultiplierList.drawElementCallback = OnDamageMultiplierElementDraw; } // Indent the list so it lines up with the rest of the content. var rect = GUILayoutUtility.GetRect(0, m_DamageMultiplierList.GetHeight()); rect.x += EditorGUI.indentLevel * 15; rect.xMax -= EditorGUI.indentLevel * 15; m_DamageMultiplierList.DoList(rect); EditorGUI.indentLevel--; } if ((m_DeathFoldout = EditorGUILayout.Foldout(m_DeathFoldout, "Death Options", InspectorUtility.BoldFoldout))) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_SpawnedObjectsOnDeath"), true); EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DestroyedObjectsOnDeath"), true); var deactivateOnDeath = PropertyFromName(serializedObject, "m_DeactivateOnDeath"); EditorGUILayout.PropertyField(deactivateOnDeath); if (deactivateOnDeath.boolValue) { EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DeactivateOnDeathDelay")); } var deathLayerProperty = PropertyFromName(serializedObject, "m_DeathLayer"); deathLayerProperty.intValue = EditorGUILayout.LayerField("Death Layer", deathLayerProperty.intValue); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(health, "Inspector"); serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(health); } }