/// <summary> /// Finds and create an instance of the inspectors for all of the installed integrations. /// </summary> private void BuildInstalledIntegrations() { var integrationInspectors = new List <Type>(); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); var integrationIndexes = new List <int>(); for (int i = 0; i < assemblies.Length; ++i) { var assemblyTypes = assemblies[i].GetTypes(); for (int j = 0; j < assemblyTypes.Length; ++j) { // Must implement IntegrationInspector. if (!typeof(IntegrationInspector).IsAssignableFrom(assemblyTypes[j])) { continue; } // Ignore abstract classes. if (assemblyTypes[j].IsAbstract) { continue; } // A valid inspector class. integrationInspectors.Add(assemblyTypes[j]); var index = integrationIndexes.Count; if (assemblyTypes[j].GetCustomAttributes(typeof(OrderedEditorItem), true).Length > 0) { var item = assemblyTypes[j].GetCustomAttributes(typeof(OrderedEditorItem), true)[0] as OrderedEditorItem; index = item.Index; } integrationIndexes.Add(index); } } // Do not reinitialize the inspectors if they are already initialized and there aren't any changes. if (m_IntegrationInspectors != null && m_IntegrationInspectors.Length == integrationInspectors.Count) { return; } // All of the manager types have been found. Sort by the index. var inspectorTypes = integrationInspectors.ToArray(); Array.Sort(integrationIndexes.ToArray(), inspectorTypes); m_IntegrationInspectors = new IntegrationInspector[integrationInspectors.Count]; m_IntegrationNames = new string[integrationInspectors.Count]; // The inspector types have been found and sorted. Add them to the list. for (int i = 0; i < inspectorTypes.Length; ++i) { m_IntegrationInspectors[i] = Activator.CreateInstance(inspectorTypes[i]) as IntegrationInspector; m_IntegrationInspectors[i].MainManagerWindow = m_MainManagerWindow; var name = InspectorUtility.SplitCamelCase(inspectorTypes[i].Name); if (integrationInspectors[i].GetCustomAttributes(typeof(OrderedEditorItem), true).Length > 0) { var item = inspectorTypes[i].GetCustomAttributes(typeof(OrderedEditorItem), true)[0] as OrderedEditorItem; name = item.Name; } m_IntegrationNames[i] = name; } }
/// <summary> /// Draws the preset values within the inspector. /// </summary> public override void OnInspectorGUI() { // Show all of the fields. serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); var preset = target as PersistablePreset; var fullName = preset.Data.ObjectType; var splitName = fullName.Split('.'); GUILayout.Label(splitName[splitName.Length - 1] + " Preset", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); // Show the property values within a table. var objType = UnityEngineUtility.GetType(preset.Data.ObjectType); if (objType != null) { // Populate the position map so ObjectInspector.DrawProperties to know which properties to draw. var valuePositionMap = new Dictionary <int, int>(preset.Data.ValueHashes.Length); for (int i = 0; i < preset.Data.ValueHashes.Length; ++i) { valuePositionMap.Add(preset.Data.ValueHashes[i], i); } // Draw all of the serialized properties. Implement the start and end callbacks so the delete button can be drawn next to a foldout in the case of a list, class, or struct. ObjectInspector.DrawProperties(objType, null, 0, valuePositionMap, preset.Data, m_Visiblity, () => { GUILayout.BeginHorizontal(); }, (int index, List <int> unityObjectIndexes) => { InspectorUtility.RecordUndoDirtyObject(preset, "Change Value"); var removed = false; if (GUILayout.Button(InspectorStyles.DeleteIcon, InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(16))) { RemoveElement(index, unityObjectIndexes); removed = true; } serializedObject.ApplyModifiedProperties(); GUILayout.EndHorizontal(); return(removed); }); } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.enabled = m_AvailableProperies.Count > 0 && !Application.isPlaying; // Only allow the popup if properties can be selected. var selectedPropertyIndex = EditorGUILayout.Popup(0, m_AvailablePropertyNames, GUILayout.MaxWidth(150)); GUI.enabled = true; GUILayout.EndHorizontal(); // If the selected property index isn't 0 then a property should be added. if (selectedPropertyIndex != 0) { var property = m_AvailableProperies[selectedPropertyIndex - 1]; if (property != null) { // Add the new property to the serialization. object value = null; if (!typeof(UnityEngine.Object).IsAssignableFrom(property.PropertyType)) { // Lists require special handling. if (typeof(IList).IsAssignableFrom(property.PropertyType)) { if (property.PropertyType.IsArray) { var elementType = property.PropertyType.GetElementType(); value = Array.CreateInstance(elementType, 0); } else { var baseType = property.PropertyType; while (!baseType.IsGenericType) { baseType = baseType.BaseType; } var elementType = baseType.GetGenericArguments()[0]; if (property.PropertyType.IsGenericType) { value = Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType)) as IList; } else { value = Activator.CreateInstance(property.PropertyType) as IList; } } } else { var getMethod = property.GetGetMethod(); if (getMethod != null) { // A new GameObject must be created so the component can be added to it. MonoBehaviours cannot use Activator.CreateInstance. GameObject gameObject = null; object obj; var objectType = UnityEngineUtility.GetType(preset.Data.ObjectType); if (typeof(MonoBehaviour).IsAssignableFrom(objectType)) { gameObject = new GameObject(); obj = gameObject.AddComponent(objectType); } else { obj = Activator.CreateInstance(objectType); } value = getMethod.Invoke(obj, null); if (value == null) { if (getMethod.ReturnType == typeof(string)) { value = string.Empty; } else { value = Activator.CreateInstance(getMethod.ReturnType); } } if (gameObject != null) { DestroyImmediate(gameObject); } } } } Serialization.AddProperty(property, value, null, preset.Data, m_Visiblity); InitializeAvailablePropertyArray(); } } if (EditorGUI.EndChangeCheck()) { InspectorUtility.RecordUndoDirtyObject(preset, "Change Value"); serializedObject.ApplyModifiedProperties(); } }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUI.BeginChangeCheck(); if (m_ObjectSurfacesList == null) { var objectSurfacesProperty = PropertyFromName("m_ObjectSurfaces"); m_ObjectSurfacesList = new ReorderableList(serializedObject, objectSurfacesProperty, true, false, true, true); m_ObjectSurfacesList.drawHeaderCallback = OnObjectSurfaceListDrawHeader; m_ObjectSurfacesList.drawElementCallback = OnObjectSurfaceElementDraw; m_ObjectSurfacesList.onSelectCallback = OnObjectSurfaceSelect; if (EditorPrefs.GetInt(SelectedObjectSurfaceIndexKey, -1) != -1) { m_ObjectSurfacesList.index = EditorPrefs.GetInt(SelectedObjectSurfaceIndexKey, -1); } } m_ObjectSurfacesList.DoLayoutList(); if (m_SurfaceManager.ObjectSurfaces != null && m_ObjectSurfacesList.index != -1 && m_ObjectSurfacesList.index < m_SurfaceManager.ObjectSurfaces.Length) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(InspectorUtility.IndentWidth); EditorGUILayout.BeginVertical(); var objectSurface = m_SurfaceManager.ObjectSurfaces[m_ObjectSurfacesList.index]; objectSurface.SurfaceType = EditorGUILayout.ObjectField("Surface Type", objectSurface.SurfaceType, typeof(SurfaceType), true) as SurfaceType; if (objectSurface.UVTextures == null) { objectSurface.UVTextures = new UVTexture[0]; } if (objectSurface.UVTextures.Length > 0) { var columnCount = Mathf.Max(1, Mathf.RoundToInt(EditorGUIUtility.currentViewWidth / 160f) - 1); var columnIndex = 0; for (int i = 0; i < objectSurface.UVTextures.Length; ++i) { if (columnIndex % columnCount == 0) { GUILayout.Space(10); GUILayout.BeginHorizontal(); } // Draw the UVTexture. EditorGUILayout.BeginHorizontal(); objectSurface.UVTextures[i].Texture = EditorGUILayout.ObjectField(objectSurface.UVTextures[i].Texture, typeof(Texture), false, GUILayout.Width(75), GUILayout.Height(75)) as Texture; EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("UV"); objectSurface.UVTextures[i].UV = EditorGUILayout.RectField(objectSurface.UVTextures[i].UV, GUILayout.Width(95)); GUILayout.Space(3); if (GUILayout.Button("Remove", GUILayout.Width(95))) { var uvTextureList = new List <UVTexture>(objectSurface.UVTextures); uvTextureList.RemoveAt(i); objectSurface.UVTextures = uvTextureList.ToArray(); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); // Allow multiple textures to be drawn per row. var guiRect = GUILayoutUtility.GetLastRect(); GUILayout.Space(-guiRect.width - Screen.width); columnIndex = (columnIndex + 1) % columnCount; if (columnIndex % columnCount == 0) { GUILayout.EndHorizontal(); } } if (columnIndex != 0) { GUILayout.EndHorizontal(); } } else { GUILayout.Space(10); GUILayout.Label("(No Textures Added)"); GUILayout.Space(-5); } GUILayout.Space(15); if (GUILayout.Button("Add Texture", GUILayout.Width(140))) { var uvTextures = objectSurface.UVTextures; System.Array.Resize(ref uvTextures, uvTextures.Length + 1); var uvTexture = uvTextures[uvTextures.Length - 1]; uvTexture.UV = new Rect(0, 0, 1, 1); uvTextures[uvTextures.Length - 1] = uvTexture; objectSurface.UVTextures = uvTextures; } GUILayout.Space(5); // ObjectSurface is a struct so it's passed by value and needs to be reassigned. m_SurfaceManager.ObjectSurfaces[m_ObjectSurfacesList.index] = objectSurface; EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } if (Foldout("Fallbacks")) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName("m_FallbackSurfaceImpact"), true); EditorGUILayout.PropertyField(PropertyFromName("m_FallbackSurfaceType"), true); EditorGUILayout.PropertyField(PropertyFromName("m_FallbackAllowDecals"), true); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { InspectorUtility.RecordUndoDirtyObject(target, "Change Value"); serializedObject.ApplyModifiedProperties(); } }
/// <summary> /// Draws the Ability fields related to input. /// </summary> /// <param name="target">The object that is being drawn.</param> /// <param name="parent">The Unity Object that the object belongs to.</param> protected void DrawInputFieldsFields(object target, Object parent) { var startTypeValue = (Ability.AbilityStartType)EditorGUILayout.EnumPopup(new GUIContent("Start Type", InspectorUtility.GetFieldTooltip(target, "m_StartType")), InspectorUtility.GetFieldValue <Ability.AbilityStartType>(target, "m_StartType")); InspectorUtility.SetFieldValue(target, "m_StartType", startTypeValue); if (startTypeValue == Ability.AbilityStartType.Custom) { PopulateAbilityStarterTypes(); if (s_AbilityStarterTypeCache != null) { EditorGUI.indentLevel++; var selected = 0; var forceUpdate = true; var ability = target as Ability; if (ability.StarterData != null && !string.IsNullOrEmpty(ability.StarterData.ObjectType)) { for (int i = 0; i < s_AbilityStarterTypeCache.Count; ++i) { if (s_AbilityStarterTypeCache[i].FullName == ability.StarterData.ObjectType) { selected = i; forceUpdate = false; break; } } } var newSelected = EditorGUILayout.Popup("Starter", selected, s_AbilityStarterTypeName.ToArray()); if (newSelected != selected || forceUpdate) { // Use the Sequence selector as the default (or recoil in the case of a melee weapon). if (forceUpdate) { for (int i = 0; i < s_AbilityStarterTypeCache.Count; ++i) { if (s_AbilityStarterTypeCache[i].FullName == "Opsive.UltimateCharacterController.Character.Abilities.Starters.ComboTimeout") { newSelected = i; break; } } GUI.changed = true; } var starter = System.Activator.CreateInstance(s_AbilityStarterTypeCache[newSelected]) as AbilityStarter; ability.StarterData = Serialization.Serialize(starter); } if (ability.Starter != null) { EditorGUI.indentLevel++; InspectorUtility.DrawObject(ability.Starter, false, true, parent, false, () => { ability.StarterData = Serialization.Serialize <AbilityStarter>(ability.Starter); }); EditorGUI.indentLevel--; } EditorGUI.indentLevel--; } } else if ((target as Ability).Starter != null) { (target as Ability).StarterData = null; } var stopTypeValue = (Ability.AbilityStopType)EditorGUILayout.EnumPopup(new GUIContent("Stop Type", InspectorUtility.GetFieldTooltip(target, "m_StopType")), InspectorUtility.GetFieldValue <Ability.AbilityStopType>(target, "m_StopType")); InspectorUtility.SetFieldValue(target, "m_StopType", stopTypeValue); EditorGUI.indentLevel++; // The input name field only needs to be shown if the start/stop type is set to a value which requires the button press. if ((startTypeValue != Ability.AbilityStartType.Automatic && startTypeValue != Ability.AbilityStartType.Manual && startTypeValue != Ability.AbilityStartType.Custom) || (stopTypeValue != Ability.AbilityStopType.Automatic && stopTypeValue != Ability.AbilityStopType.Manual)) { EditorGUI.BeginChangeCheck(); // Draw a custom array inspector for the input names. var inputNames = InspectorUtility.GetFieldValue <string[]>(target, "m_InputNames"); if (inputNames == null || inputNames.Length == 0) { inputNames = new string[1]; } for (int i = 0; i < inputNames.Length; ++i) { EditorGUILayout.BeginHorizontal(); var fieldName = " "; if (i == 0) { fieldName = "Input Name"; } inputNames[i] = EditorGUILayout.TextField(new GUIContent(fieldName, InspectorUtility.GetFieldTooltip(target, "m_InputName")), inputNames[i]); if (i == inputNames.Length - 1) { if (i > 0 && GUILayout.Button(InspectorStyles.RemoveIcon, InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(18))) { System.Array.Resize(ref inputNames, inputNames.Length - 1); } if (GUILayout.Button(InspectorStyles.AddIcon, InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(18))) { System.Array.Resize(ref inputNames, inputNames.Length + 1); inputNames[inputNames.Length - 1] = inputNames[inputNames.Length - 2]; } } EditorGUILayout.EndHorizontal(); } if (EditorGUI.EndChangeCheck()) { InspectorUtility.SetFieldValue(target, "m_InputNames", inputNames); GUI.changed = true; } // Only show the duration and wait for release options with a LongPress start/stop type. if (startTypeValue == Ability.AbilityStartType.LongPress || stopTypeValue == Ability.AbilityStopType.LongPress) { var duration = EditorGUILayout.FloatField(new GUIContent("Long Press Duration", InspectorUtility.GetFieldTooltip(target, "m_LongPressDuration")), InspectorUtility.GetFieldValue <float>(target, "m_LongPressDuration")); InspectorUtility.SetFieldValue(target, "m_LongPressDuration", duration); var waitForRelease = EditorGUILayout.Toggle(new GUIContent("Wait For Long Press Release", InspectorUtility.GetFieldTooltip(target, "m_WaitForLongPressRelease")), InspectorUtility.GetFieldValue <bool>(target, "m_WaitForLongPressRelease")); InspectorUtility.SetFieldValue(target, "m_WaitForLongPressRelease", waitForRelease); } } EditorGUI.indentLevel--; }
/// <summary> /// Sets up the camera if it hasn't already been setup. /// </summary> private void SetupCamera() { // Setup the camera. GameObject cameraGameObject; var addedCameraController = false; var camera = UnityEngine.Camera.main; if (camera == null) { // If the main camera can't be found then use the first available camera. var cameras = UnityEngine.Camera.allCameras; if (cameras != null && cameras.Length > 0) { camera = cameras[0]; } // A new camera should be created if there isn't a valid camera. if (camera == null) { cameraGameObject = new GameObject("Camera"); cameraGameObject.tag = "MainCamera"; camera = cameraGameObject.AddComponent <UnityEngine.Camera>(); cameraGameObject.AddComponent <AudioListener>(); } } // The near clip plane should adjusted for viewing close objects. camera.nearClipPlane = 0.01f; // Add the CameraController if it isn't already added. cameraGameObject = camera.gameObject; if (cameraGameObject.GetComponent <CameraController>() == null) { var cameraController = cameraGameObject.AddComponent <CameraController>(); if (m_Perspective == Perspective.Both) { ViewTypeBuilder.AddViewType(cameraController, typeof(Camera.ViewTypes.Transition)); } if (m_StartFirstPersonPerspective) { if (!string.IsNullOrEmpty(m_ThirdPersonViewType)) { ViewTypeBuilder.AddViewType(cameraController, UnityEngineUtility.GetType(m_ThirdPersonViewType)); } if (!string.IsNullOrEmpty(m_FirstPersonViewType)) { ViewTypeBuilder.AddViewType(cameraController, UnityEngineUtility.GetType(m_FirstPersonViewType)); } } else { if (!string.IsNullOrEmpty(m_FirstPersonViewType)) { ViewTypeBuilder.AddViewType(cameraController, UnityEngineUtility.GetType(m_FirstPersonViewType)); } if (!string.IsNullOrEmpty(m_ThirdPersonViewType)) { ViewTypeBuilder.AddViewType(cameraController, UnityEngineUtility.GetType(m_ThirdPersonViewType)); } } // Detect if a character exists in the scene. Automatically add the character if it does. var characters = GameObject.FindObjectsOfType <UltimateCharacterController.Character.CharacterLocomotion>(); if (characters != null && characters.Length == 1) { cameraController.InitCharacterOnAwake = true; cameraController.Character = characters[0].gameObject; } // Setup the components which help the Camera Controller. InspectorUtility.AddComponent <CameraControllerHandler>(cameraGameObject); #if THIRD_PERSON_CONTROLLER if (m_Perspective != Perspective.First) { InspectorUtility.AddComponent <ThirdPersonController.Camera.ObjectFader>(cameraGameObject); } #endif addedCameraController = true; if (m_StateConfiguration != null) { if (m_ProfileIndex > 0) { m_StateConfiguration.AddStatesToGameObject(m_ProfileName, cameraGameObject); InspectorUtility.SetDirty(cameraGameObject); } } } if (addedCameraController) { Debug.Log("The Camera Controller has been added."); } else { Debug.LogWarning("Warning: No action was performed, the Camera Controller component has already been added."); } }
public override void OnInspectorGUI() { // Ordinary properties BeginInspector(); DrawHeaderInInspector(); DrawPropertyInInspector(FindProperty(x => x.m_Priority)); DrawTargetsInInspector(FindProperty(x => x.m_Follow), FindProperty(x => x.m_LookAt)); DrawPropertyInInspector(FindProperty(x => x.m_StandbyUpdate)); DrawLensSettingsInInspector(FindProperty(x => x.m_Lens)); DrawRemainingPropertiesInInspector(); // Orbits EditorGUILayout.Space(); EditorGUILayout.LabelField("Orbits", EditorStyles.boldLabel); SerializedProperty orbits = FindProperty(x => x.m_Orbits); EditorGUI.BeginChangeCheck(); for (int i = 0; i < 3; ++i) { var o = orbits.GetArrayElementAtIndex(i); Rect rect = EditorGUILayout.GetControlRect(true); InspectorUtility.MultiPropertyOnLine( rect, mOrbitNames[i], new [] { o.FindPropertyRelative(() => Target.m_Orbits[i].m_Height), o.FindPropertyRelative(() => Target.m_Orbits[i].m_Radius) }, null); } EditorGUILayout.PropertyField(FindProperty(x => x.m_SplineCurvature)); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } // Pipeline Stages EditorGUILayout.Space(); EditorGUILayout.LabelField("Main Rig", EditorStyles.boldLabel); var components = Target.ComponentCache; for (int i = 0; i < mPipelineSet.m_subeditors.Length; ++i) { var ed = mPipelineSet.m_subeditors[i]; if (ed == null) { continue; } if (!ed.HasImplementation) { continue; } if ((CinemachineCore.Stage)i == CinemachineCore.Stage.Body) { ed.TypeIsLocked = true; } ed.OnInspectorGUI(components[i]); // may destroy component } // Rigs EditorGUILayout.Space(); SerializedProperty rigs = FindProperty(x => x.m_Rigs); for (int i = 0; i < 2; ++i) { EditorGUILayout.Separator(); DrawRigEditor(i, rigs.GetArrayElementAtIndex(i)); } // Extensions DrawExtensionsWidgetInInspector(); }
/// <summary> /// Returns the actions to draw before the State list is drawn. /// </summary> /// <returns>The actions to draw before the State list is drawn.</returns> protected override Action GetDrawCallback() { var baseCallback = base.GetDrawCallback(); baseCallback += () => { // The value need to be changed through the property so at runtime any cached values will be updated. var minLimit = PropertyFromName("m_MinPitchLimit").floatValue; var maxLimit = PropertyFromName("m_MaxPitchLimit").floatValue; var minValue = Mathf.Round(minLimit * 100f) / 100f; var maxValue = Mathf.Round(maxLimit * 100f) / 100f; InspectorUtility.MinMaxSlider(ref minValue, ref maxValue, -90, 90, new GUIContent("Pitch Limit", "The min and max limit of the pitch angle (in degrees).")); if (minValue != minLimit) { (target as FirstPersonObjects).MinPitchLimit = minValue; } if (maxValue != maxLimit) { (target as FirstPersonObjects).MaxPitchLimit = maxValue; } var property = PropertyFromName("m_LockPitch"); var value = property.boolValue; EditorGUILayout.PropertyField(property); if (value != property.boolValue) { (target as FirstPersonObjects).LockPitch = property.boolValue; } minLimit = PropertyFromName("m_MinYawLimit").floatValue; maxLimit = PropertyFromName("m_MaxYawLimit").floatValue; minValue = Mathf.Round(minLimit * 100f) / 100f; maxValue = Mathf.Round(maxLimit * 100f) / 100f; InspectorUtility.MinMaxSlider(ref minValue, ref maxValue, -180, 180, new GUIContent("Yaw Limit", "The min and max limit of the yaw angle (in degrees).")); if (minValue != minLimit) { (target as FirstPersonObjects).MinYawLimit = minValue; } if (maxValue != maxLimit) { (target as FirstPersonObjects).MaxYawLimit = maxValue; } property = PropertyFromName("m_LockYaw"); value = property.boolValue; EditorGUILayout.PropertyField(property); if (value != property.boolValue) { (target as FirstPersonObjects).LockYaw = property.boolValue; } property = PropertyFromName("m_RotateWithCrosshairs"); value = property.boolValue; EditorGUILayout.PropertyField(property); if (value != property.boolValue) { (target as FirstPersonObjects).RotateWithCrosshairs = property.boolValue; } EditorGUILayout.PropertyField(PropertyFromName("m_RotationSpeed")); property = PropertyFromName("m_IgnorePositionalLookOffset"); value = property.boolValue; EditorGUILayout.PropertyField(property); if (value != property.boolValue) { (target as FirstPersonObjects).IgnorePositionalLookOffset = property.boolValue; } EditorGUILayout.PropertyField(PropertyFromName("m_PositionOffset")); EditorGUILayout.PropertyField(PropertyFromName("m_MoveSpeed")); }; return(baseCallback); }
public override void OnInspectorGUI(object target, Object parent) { InspectorUtility.DrawAttributeModifier(null, (target as ModifyAttribute).AttributeModifier, "Attribute Modifier"); }
/// <summary> /// Called when the object should be drawn to the inspector. /// </summary> /// <param name="target">The object that is being drawn.</param> /// <param name="parent">The Unity Object that the object belongs to.</param> public override void OnInspectorGUI(object target, Object parent) { // Draw the fields related to rendering. if (InspectorUtility.Foldout(target, "Rendering")) { EditorGUI.indentLevel++; InspectorUtility.DrawField(target, "m_LookDirectionDistance"); var lookOffsetValue = InspectorUtility.GetFieldValue <Vector3>(target, "m_LookOffset"); var lookOffset = EditorGUILayout.Vector3Field(new GUIContent(InspectorUtility.SplitCamelCase("m_LookOffset"), InspectorUtility.GetFieldTooltip(target, "m_LookOffset")), lookOffsetValue); // Set the property if the game is playing so the camera will update. if (lookOffsetValue != lookOffset) { (target as FirstPerson).LookOffset = lookOffset; InspectorUtility.SetFieldValue(target, "m_LookOffset", lookOffset); } InspectorUtility.DrawField(target, "m_LookDownOffset"); InspectorUtility.DrawField(target, "m_CullingMask"); InspectorUtility.DrawFieldSlider(target, "m_FieldOfView", 1, 179); InspectorUtility.DrawFieldSlider(target, "m_FieldOfViewDamping", 0, 5); #if ULTIMATE_CHARACTER_CONTROLLER_LWRP || ULTIMATE_CHARACTER_CONTROLLER_UNIVERSALRP var prevRenderType = InspectorUtility.GetFieldValue <FirstPerson.ObjectOverlayRenderType>(target, "m_OverlayRenderType"); InspectorUtility.DrawField(target, "m_OverlayRenderType"); var renderType = InspectorUtility.GetFieldValue <FirstPerson.ObjectOverlayRenderType>(target, "m_OverlayRenderType"); // Ensure the render type has been switched for all first person view types. if (prevRenderType != renderType) { if (renderType == FirstPerson.ObjectOverlayRenderType.SecondCamera) { UltimateCharacterController.Utility.Builders.ViewTypeBuilder.AddFirstPersonCamera(parent as CameraController, target as FirstPerson); } else if (prevRenderType == FirstPerson.ObjectOverlayRenderType.SecondCamera) { var firstPersonCamera = InspectorUtility.GetFieldValue <UnityEngine.Camera>(target, "m_FirstPersonCamera"); if (firstPersonCamera != null) { if (PrefabUtility.IsPartOfPrefabInstance(firstPersonCamera.gameObject)) { PrefabUtility.UnpackPrefabInstance(PrefabUtility.GetOutermostPrefabInstanceRoot(firstPersonCamera.gameObject), PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); } GameObject.DestroyImmediate(firstPersonCamera.gameObject, true); (target as FirstPerson).FirstPersonCamera = null; } } // All first person view types need to be switched to the currently active render type. var viewTypes = (parent as CameraController).ViewTypes; for (int i = 0; i < viewTypes.Length; ++i) { var firstPersonViewType = viewTypes[i] as FirstPerson; if (firstPersonViewType == null) { continue; } if (renderType == FirstPerson.ObjectOverlayRenderType.RenderPipeline && firstPersonViewType.OverlayRenderType == FirstPerson.ObjectOverlayRenderType.SecondCamera) { firstPersonViewType.FirstPersonCamera = null; firstPersonViewType.OverlayRenderType = renderType; } else if (renderType == FirstPerson.ObjectOverlayRenderType.SecondCamera && firstPersonViewType.OverlayRenderType == FirstPerson.ObjectOverlayRenderType.RenderPipeline) { firstPersonViewType.FirstPersonCamera = (target as FirstPerson).FirstPersonCamera; firstPersonViewType.OverlayRenderType = renderType; } } UltimateCharacterController.Utility.Builders.ViewTypeBuilder.SerializeViewTypes(parent as CameraController); } var drawFirstPersonCamera = renderType == FirstPerson.ObjectOverlayRenderType.SecondCamera; #else InspectorUtility.DrawField(target, "m_UseFirstPersonCamera"); var drawFirstPersonCamera = InspectorUtility.GetFieldValue <bool>(target, "m_UseFirstPersonCamera"); #endif if (drawFirstPersonCamera && InspectorUtility.Foldout(target, "First Person Camera")) { EditorGUI.indentLevel++; InspectorUtility.DrawField(target, "m_FirstPersonCamera"); InspectorUtility.DrawField(target, "m_FirstPersonCullingMask"); InspectorUtility.DrawField(target, "m_SynchronizeFieldOfView"); var synchronizeFieldOfView = InspectorUtility.GetFieldValue <bool>(target, "m_SynchronizeFieldOfView"); if (!synchronizeFieldOfView) { InspectorUtility.DrawFieldSlider(target, "m_FirstPersonFieldOfView", 1, 179); InspectorUtility.DrawFieldSlider(target, "m_FirstPersonFieldOfViewDamping", 0, 5); } var positionOffsetValue = InspectorUtility.GetFieldValue <Vector3>(target, "m_FirstPersonPositionOffset"); var positionOffset = EditorGUILayout.Vector3Field(new GUIContent(InspectorUtility.SplitCamelCase("m_FirstPersonPositionOffset"), InspectorUtility.GetFieldTooltip(target, "m_FirstPersonPositionOffset")), positionOffsetValue); // Set the property if the game is playing so the camera will update. if (positionOffsetValue != positionOffset) { (target as FirstPerson).FirstPersonPositionOffset = positionOffset; InspectorUtility.SetFieldValue(target, "m_FirstPersonPositionOffset", positionOffset); } var rotationOffsetValue = InspectorUtility.GetFieldValue <Vector3>(target, "m_FirstPersonRotationOffset"); var rotationOffset = EditorGUILayout.Vector3Field(new GUIContent(InspectorUtility.SplitCamelCase("m_FirstPersonRotationOffset"), InspectorUtility.GetFieldTooltip(target, "m_FirstPersonRotationOffset")), rotationOffsetValue); // Set the property so the camera will update. if (rotationOffsetValue != rotationOffset) { (target as FirstPerson).FirstPersonRotationOffset = rotationOffset; InspectorUtility.SetFieldValue(target, "m_FirstPersonRotationOffset", rotationOffset); } EditorGUI.indentLevel--; } #if ULTIMATE_CHARACTER_CONTROLLER_LWRP || ULTIMATE_CHARACTER_CONTROLLER_UNIVERSALRP else if (renderType == FirstPerson.ObjectOverlayRenderType.RenderPipeline) { EditorGUI.indentLevel++; InspectorUtility.DrawField(target, "m_FirstPersonCullingMask"); EditorGUI.indentLevel--; } #endif EditorGUI.indentLevel--; } if (InspectorUtility.Foldout(target, "Primary Spring")) { EditorGUI.indentLevel++; InspectorUtility.DrawSpring(target, "Position Spring", "m_PositionSpring"); var lowerLimit = InspectorUtility.GetFieldValue <float>(target, "m_PositionLowerVerticalLimit"); var lowerLimitValue = EditorGUILayout.Slider(new GUIContent(InspectorUtility.SplitCamelCase("m_PositionLowerVerticalLimit"), InspectorUtility.GetFieldTooltip(target, "m_PositionLowerVerticalLimit")), lowerLimit, 0, 5); // Set the property if the game is playing so the camera will update. if (lowerLimitValue != lowerLimit) { (target as FirstPerson).PositionLowerVerticalLimit = lowerLimit; InspectorUtility.SetFieldValue(target, "m_PositionLowerVerticalLimit", lowerLimitValue); } InspectorUtility.DrawFieldSlider(target, "m_PositionFallImpact", 0, 5); InspectorUtility.DrawFieldIntSlider(target, "m_PositionFallImpactSoftness", 1, 30); InspectorUtility.DrawFieldSlider(target, "m_RotationStrafeRoll", -5, 5); InspectorUtility.DrawSpring(target, "Rotation Spring", "m_RotationSpring"); InspectorUtility.DrawFieldSlider(target, "m_RotationFallImpact", 0, 5); InspectorUtility.DrawFieldIntSlider(target, "m_RotationFallImpactSoftness", 1, 30); EditorGUI.indentLevel--; } if (InspectorUtility.Foldout(target, "Secondary Spring")) { EditorGUI.indentLevel++; InspectorUtility.DrawSpring(target, "Secondary Position Spring", "m_SecondaryPositionSpring"); InspectorUtility.DrawSpring(target, "Secondary Rotation Spring", "m_SecondaryRotationSpring"); EditorGUI.indentLevel--; } if (InspectorUtility.Foldout(target, "Shake")) { EditorGUI.indentLevel++; InspectorUtility.DrawFieldSlider(target, "m_ShakeSpeed", 0, 10); InspectorUtility.DrawField(target, "m_ShakeAmplitude"); EditorGUI.indentLevel--; } if (InspectorUtility.Foldout(target, "Bob")) { EditorGUI.indentLevel++; InspectorUtility.DrawField(target, "m_BobPositionalRate"); InspectorUtility.DrawField(target, "m_BobPositionalAmplitude"); InspectorUtility.DrawField(target, "m_BobRollRate"); InspectorUtility.DrawField(target, "m_BobRollAmplitude"); InspectorUtility.DrawFieldSlider(target, "m_BobInputVelocityScale", 0, 10); InspectorUtility.DrawField(target, "m_BobMaxInputVelocity"); InspectorUtility.DrawField(target, "m_BobMinTroughVerticalOffset"); InspectorUtility.DrawField(target, "m_BobTroughForce"); InspectorUtility.DrawField(target, "m_BobRequireGroundContact"); EditorGUI.indentLevel--; } if (InspectorUtility.Foldout(target, "Limits")) { EditorGUI.indentLevel++; var minPitchLimit = InspectorUtility.GetFieldValue <float>(target, "m_MinPitchLimit"); var maxPitchLimit = InspectorUtility.GetFieldValue <float>(target, "m_MaxPitchLimit"); var minValue = Mathf.Round(minPitchLimit * 100f) / 100f; var maxValue = Mathf.Round(maxPitchLimit * 100f) / 100f; InspectorUtility.MinMaxSlider(ref minValue, ref maxValue, -90, 90, new GUIContent("Pitch Limit", "The min and max limit of the pitch angle (in degrees).")); if (minValue != minPitchLimit) { InspectorUtility.SetFieldValue(target, "m_MinPitchLimit", minValue); } if (minValue != maxPitchLimit) { InspectorUtility.SetFieldValue(target, "m_MaxPitchLimit", maxValue); } if (target is FreeLook) { var minYawLimit = InspectorUtility.GetFieldValue <float>(target, "m_MinYawLimit"); var maxYawLimit = InspectorUtility.GetFieldValue <float>(target, "m_MaxYawLimit"); minValue = Mathf.Round(minYawLimit * 100f) / 100f; maxValue = Mathf.Round(maxYawLimit * 100f) / 100f; InspectorUtility.MinMaxSlider(ref minValue, ref maxValue, -180, 180, new GUIContent("Yaw Limit", "The min and max limit of the yaw angle (in degrees).")); if (minValue != minYawLimit) { InspectorUtility.SetFieldValue(target, "m_MinYawLimit", minValue); } if (minValue != maxYawLimit) { InspectorUtility.SetFieldValue(target, "m_MaxYawLimit", maxValue); } InspectorUtility.DrawField(target, "m_YawLimitLerpSpeed"); } InspectorUtility.DrawField(target, "m_LookDirectionDistance"); EditorGUI.indentLevel--; } if (InspectorUtility.Foldout(target, "Head Tracking")) { EditorGUI.indentLevel++; InspectorUtility.DrawField(target, "m_SmoothHeadOffsetSteps"); InspectorUtility.DrawField(target, "m_CollisionRadius"); InspectorUtility.DrawField(target, "m_RotateWithHead"); EditorGUI.indentLevel--; } }
/// <summary> /// Draws the UI for existing item. /// </summary> private void DrawExistingItem() { EditorGUILayout.BeginHorizontal(); m_Item = EditorGUILayout.ObjectField("Item", m_Item, typeof(Item), true) as Item; GUI.enabled = m_Item != null; if (GUILayout.Button("Remove", GUILayout.Width(80))) { #if FIRST_PERSON_CONTROLLER var firstPersonVisibleItemObject = m_Item.GetComponent <UltimateCharacterController.FirstPersonController.Items.FirstPersonPerspectiveItem>(); if (firstPersonVisibleItemObject != null) { ItemBuilder.RemoveFirstPersonObject(firstPersonVisibleItemObject); } #endif var thirdPersonVisibleItemObject = m_Item.GetComponent <UltimateCharacterController.ThirdPersonController.Items.ThirdPersonPerspectiveItem>(); if (thirdPersonVisibleItemObject != null) { ItemBuilder.RemoveThirdPersonObject(thirdPersonVisibleItemObject); } // The ItemType should also be removed from the Inventory/ItemSetManager. var inventory = m_Item.GetComponentInParent <InventoryBase>(); if (inventory != null) { var defaultLoadout = new System.Collections.Generic.List <ItemTypeCount>(inventory.DefaultLoadout); for (int i = defaultLoadout.Count - 1; i > -1; --i) { if (defaultLoadout[i].ItemType == m_Item.ItemType) { defaultLoadout.RemoveAt(i); break; } } inventory.DefaultLoadout = defaultLoadout.ToArray(); EditorUtility.SetDirty(inventory); var itemSetManager = inventory.GetComponent <ItemSetManager>(); if (itemSetManager != null && m_Item.ItemType.CategoryIndices != null) { for (int i = 0; i < m_Item.ItemType.CategoryIndices.Length; ++i) { var category = itemSetManager.CategoryItemSets[i]; for (int j = category.ItemSetList.Count - 1; j > -1; --j) { if (category.ItemSetList[j].Slots[m_Item.SlotID] == m_Item.ItemType) { category.ItemSetList.RemoveAt(j); } } } EditorUtility.SetDirty(itemSetManager); } } Undo.DestroyObjectImmediate(m_Item.gameObject); m_Item = null; } GUI.enabled = m_Item != null; EditorGUILayout.EndHorizontal(); // Actions can be removed. if (m_Item != null) { var actions = m_Item.GetComponents <ItemAction>(); if (actions.Length > 0) { var actionStrings = new string[actions.Length]; for (int i = 0; i < actions.Length; ++i) { actionStrings[i] = InspectorUtility.DisplayTypeName(actions[i].GetType(), false); if (actions.Length > 1) { actionStrings[i] += " (ID " + actions[i].ID + ")"; } } EditorGUILayout.BeginHorizontal(); m_RemoveActionTypeIndex = EditorGUILayout.Popup("Remove Action", m_RemoveActionTypeIndex, actionStrings); if (GUILayout.Button("Remove", GUILayout.Width(80))) { ItemBuilder.RemoveAction(actions[m_RemoveActionTypeIndex]); m_RemoveActionTypeIndex = 0; } EditorGUILayout.EndHorizontal(); } } // Actions can be added. GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); m_AddActionType = (ItemBuilder.ActionType)EditorGUILayout.EnumPopup("Add Action", m_AddActionType); var canBuild = true; #if !ULTIMATE_CHARACTER_CONTROLLER_SHOOTER if (m_AddActionType == ItemBuilder.ActionType.ShootableWeapon) { EditorGUILayout.HelpBox("The shooter controller is necessary in order to create melee weapons.", MessageType.Error); canBuild = false; } #endif #if !ULTIMATE_CHARACTER_CONTROLLER_MELEE if (m_AddActionType == ItemBuilder.ActionType.MeleeWeapon) { EditorGUILayout.HelpBox("The melee controller is necessary in order to create melee weapons.", MessageType.Error); canBuild = false; } #endif if (canBuild && (m_AddActionType != ItemBuilder.ActionType.Shield)) { EditorGUI.indentLevel++; m_ExistingAddActionItemType = EditorGUILayout.ObjectField("Consumable Item Type", m_ExistingAddActionItemType, typeof(ItemType), false) as ItemType; EditorGUI.indentLevel--; } if (GUILayout.Button("Add", GUILayout.Width(80))) { ItemBuilder.AddAction(m_Item.gameObject, m_AddActionType, m_ExistingAddActionItemType); } EditorGUILayout.EndHorizontal(); GUI.enabled = m_Item != null && canBuild; #if FIRST_PERSON_CONTROLLER GUILayout.Space(5); // The first person objects can be added or removed. EditorGUILayout.LabelField("First Person", InspectorStyles.BoldLabel); EditorGUI.indentLevel++; FirstPersonController.Items.FirstPersonPerspectiveItem firstPersonVisibleItem = null; if (m_Item != null) { firstPersonVisibleItem = m_Item.GetComponent <FirstPersonController.Items.FirstPersonPerspectiveItem>(); GUI.enabled = firstPersonVisibleItem == null; if (firstPersonVisibleItem != null) { m_ExistingFirstPersonObject = firstPersonVisibleItem.Object; m_ExistingFirstPersonVisibleItem = firstPersonVisibleItem.VisibleItem; if (m_ExistingFirstPersonVisibleItem != null) { var firstPersonVisibleItemAnimator = firstPersonVisibleItem.VisibleItem.GetComponent <Animator>(); if (firstPersonVisibleItemAnimator != null) { m_ExistingFirstPersonVisibleItemAnimatorController = firstPersonVisibleItemAnimator.runtimeAnimatorController; } else { m_ExistingFirstPersonVisibleItemAnimatorController = null; } } else { m_ExistingFirstPersonVisibleItemAnimatorController = null; } } var character = m_Item.GetComponentInParent <Character.UltimateCharacterLocomotion>(); DrawFirstPersonObject(character != null ? character.gameObject : null, ref m_ExistingFirstPersonObject, ref m_ExistingFirstPersonObjectAnimatorController, ref m_ExistingFirstPersonVisibleItem, ref m_ExistingFirstPersonParent, ref m_ExistingFirstPersonItemSlot, ref m_ExistingFirstPersonVisibleItemAnimatorController, m_ExistingThirdPersonItemSlot != null ? m_ExistingThirdPersonItemSlot.ID : 0, false, true); GUI.enabled = true; } EditorGUILayout.BeginHorizontal(); GUILayout.Space(InspectorUtility.IndentWidth); GUI.enabled = m_Item != null && firstPersonVisibleItem == null; if (GUILayout.Button("Add")) { var character = m_Item.GetComponentInParent <Character.UltimateCharacterLocomotion>(); ItemBuilder.AddFirstPersonObject(character.gameObject, m_Item.name, m_Item.gameObject, ref m_ExistingFirstPersonObject, m_ExistingFirstPersonObjectAnimatorController, ref m_ExistingFirstPersonVisibleItem, m_ExistingFirstPersonItemSlot, m_ExistingFirstPersonVisibleItemAnimatorController); } GUI.enabled = m_Item != null && firstPersonVisibleItem != null; if (GUILayout.Button("Remove")) { ItemBuilder.RemoveFirstPersonObject(firstPersonVisibleItem); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; #endif // The third person objects can be added or removed. GUI.enabled = m_Item != null; GUILayout.Space(5); EditorGUILayout.LabelField("Third Person", InspectorStyles.BoldLabel); EditorGUI.indentLevel++; ThirdPersonController.Items.ThirdPersonPerspectiveItem thirdPersonVisibleItem = null; if (m_Item != null) { thirdPersonVisibleItem = m_Item.GetComponent <ThirdPersonController.Items.ThirdPersonPerspectiveItem>(); GUI.enabled = thirdPersonVisibleItem == null; if (thirdPersonVisibleItem != null) { m_ExistingThirdPersonObject = thirdPersonVisibleItem.Object; if (m_ExistingThirdPersonObject != null) { var thirdPersonAnimator = thirdPersonVisibleItem.Object.GetComponent <Animator>(); if (thirdPersonAnimator != null) { m_ExistingThirdPersonObjectAnimatorController = thirdPersonAnimator.runtimeAnimatorController; } else { m_ExistingThirdPersonObjectAnimatorController = null; } } else { m_ExistingThirdPersonObjectAnimatorController = null; } } var character = m_Item.GetComponentInParent <Character.UltimateCharacterLocomotion>(); if (character == null || (character != null && character.GetComponent <Animator>() != null)) { DrawThirdPersonObject(character != null ? character.gameObject : null, ref m_ExistingThirdPersonObject, ref m_ExistingThirdHumanoidParentHand, ref m_ExistingThirdPersonParent, ref m_ExistingThirdPersonItemSlot, ref m_ExistingThirdPersonObjectAnimatorController, m_ExistingFirstPersonItemSlot != null ? m_ExistingFirstPersonItemSlot.ID : 0, false, true); } } EditorGUILayout.BeginHorizontal(); GUILayout.Space(InspectorUtility.IndentWidth); GUI.enabled = m_Item != null && thirdPersonVisibleItem == null; if (GUILayout.Button("Add")) { var character = m_Item.GetComponentInParent <Character.UltimateCharacterLocomotion>(); ItemBuilder.AddThirdPersonObject(character.gameObject, m_Item.name, m_Item.gameObject, ref m_ExistingThirdPersonObject, m_ExistingThirdPersonItemSlot, m_ExistingThirdPersonObjectAnimatorController, m_InvisibleShadowCaster, false); } GUI.enabled = m_Item != null && thirdPersonVisibleItem != null; if (GUILayout.Button("Remove")) { ItemBuilder.RemoveThirdPersonObject(thirdPersonVisibleItem); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; GUI.enabled = m_Item != null; // Setup profiles. GUILayout.Space(5); EditorGUILayout.LabelField("State Profile", InspectorStyles.BoldLabel); EditorGUI.indentLevel++; var updatedStateConfiguration = EditorGUILayout.ObjectField("State Configuration", m_ExistingStateConfiguration, typeof(StateConfiguration), false) as StateConfiguration; if (updatedStateConfiguration != m_ExistingStateConfiguration) { if (updatedStateConfiguration != null) { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(updatedStateConfiguration))); } else { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, string.Empty); } m_ExistingStateConfiguration = updatedStateConfiguration; } if (m_ExistingStateConfiguration != null) { var profiles = m_ExistingStateConfiguration.GetProfilesForGameObject(m_Item == null ? null : m_Item.gameObject, StateConfiguration.Profile.ProfileType.Item); EditorGUILayout.BeginHorizontal(); var canSetup = true; if (profiles.Count == 0) { canSetup = false; profiles.Add("(None)"); } m_ExistingProfileIndex = EditorGUILayout.Popup("Profile", m_ExistingProfileIndex, profiles.ToArray()); GUI.enabled = m_Item != null && canSetup; if (GUILayout.Button("Apply")) { m_ExistingStateConfiguration.AddStatesToGameObject(profiles[m_ExistingProfileIndex], m_Item.gameObject); InspectorUtility.SetDirty(m_Item.gameObject); } GUI.enabled = m_Item != null; EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; }
/// <summary> /// Draws the inspector. /// </summary> public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUI.BeginChangeCheck(); // Show the items currently within the inspector. if (Foldout("Current Inventory")) { EditorGUI.indentLevel++; var inventory = target as InventoryBase; var itemIdentifiers = inventory.GetAllItemIdentifiers(); if (itemIdentifiers.Count > 0) { GUI.enabled = false; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Item Identifier"); EditorGUILayout.LabelField("Count"); GUILayout.Space(-150); EditorGUILayout.EndHorizontal(); for (int i = 0; i < itemIdentifiers.Count; ++i) { EditorGUILayout.BeginHorizontal(); var style = EditorStyles.label; var label = itemIdentifiers[i].ToString(); var activeCount = 0; for (int j = 0; j < inventory.SlotCount; ++j) { var item = inventory.GetActiveItem(j); if (item != null && item.ItemIdentifier == itemIdentifiers[i]) { if (activeCount == 0) { label += " (Slot " + j; } else { label += ", " + j; } style = EditorStyles.boldLabel; activeCount++; } } if (activeCount > 0) { label += ")"; } EditorGUILayout.LabelField(label, style); EditorGUILayout.LabelField(inventory.GetItemIdentifierAmount(itemIdentifiers[i]).ToString()); GUILayout.Space(-150); EditorGUILayout.EndHorizontal(); } GUI.enabled = true; } else { EditorGUILayout.LabelField("(Nothing in inventory)"); } EditorGUI.indentLevel--; } DrawInventoryProperties(); EditorGUILayout.PropertyField(PropertyFromName("m_RemoveAllOnDeath")); EditorGUILayout.PropertyField(PropertyFromName("m_LoadDefaultLoadoutOnRespawn")); EditorGUILayout.PropertyField(PropertyFromName("m_UnequippedStateName")); if (Foldout("Events")) { EditorGUI.indentLevel++; InspectorUtility.UnityEventPropertyField(PropertyFromName("m_OnAddItemEvent")); InspectorUtility.UnityEventPropertyField(PropertyFromName("m_OnPickupItemIdentifierEvent")); InspectorUtility.UnityEventPropertyField(PropertyFromName("m_OnPickupItemEvent")); InspectorUtility.UnityEventPropertyField(PropertyFromName("m_OnEquipItemEvent")); InspectorUtility.UnityEventPropertyField(PropertyFromName("m_OnAdjustItemIdentifierAmountEvent")); InspectorUtility.UnityEventPropertyField(PropertyFromName("m_OnUnequipItemEvent")); InspectorUtility.UnityEventPropertyField(PropertyFromName("m_OnRemoveItemEvent")); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { InspectorUtility.RecordUndoDirtyObject(target, "Change Value"); serializedObject.ApplyModifiedProperties(); } }
/// <summary> /// Draws the UI for new item. /// </summary> private void DrawNewItem() { var canBuild = true; m_Name = EditorGUILayout.TextField("Name", m_Name); if (string.IsNullOrEmpty(m_Name)) { canBuild = false; EditorGUILayout.HelpBox("The item must have a name.", MessageType.Error); } m_ItemType = EditorGUILayout.ObjectField("Item Type", m_ItemType, typeof(ItemType), false) as ItemType; if (canBuild && m_ItemType == null) { canBuild = false; EditorGUILayout.HelpBox("The item must specify an ItemType.", MessageType.Error); } var character = EditorGUILayout.ObjectField("Character", m_Character, typeof(GameObject), true) as GameObject; var characterUpdate = false; if (character != m_Character) { m_Character = character; characterUpdate = true; #if FIRST_PERSON_CONTROLLER // Try to assign the first person objects if they exist. if (m_Character != null) { var firstPersonObjects = m_Character.GetComponentInChildren <UltimateCharacterController.FirstPersonController.Character.FirstPersonObjects>(); if (firstPersonObjects != null) { var firstPersonBaseObject = firstPersonObjects.GetComponentInChildren <UltimateCharacterController.FirstPersonController.Character.Identifiers.FirstPersonBaseObject>(); if (firstPersonBaseObject != null) { m_FirstPersonObject = firstPersonBaseObject.gameObject; } } m_AddThirdPersonPerspective = m_Character.GetComponent <Animator>() != null; } #endif } if (m_Character == null) { m_SlotID = EditorGUILayout.IntField("Slot ID", m_SlotID); } else { if (EditorUtility.IsPersistent(m_Character)) { if (canBuild) { EditorGUILayout.HelpBox("The character must be located within the scene.", MessageType.Error); canBuild = false; } } else { // The attach to object must be a character already created. if (m_Character.GetComponentInChildren <ItemPlacement>() == null) { if (canBuild) { EditorGUILayout.HelpBox("The character must be an already created character.", MessageType.Error); canBuild = false; } } else { if (m_ItemType != null & m_Character.GetComponent <InventoryBase>() != null) { // The item can automatically be added to the default loadout if the inventory component exists. EditorGUI.indentLevel++; m_AddToDefaultLoadout = EditorGUILayout.Toggle("Add to Default Loadout", m_AddToDefaultLoadout); EditorGUI.indentLevel--; } else { m_AddToDefaultLoadout = false; } } } } m_AnimatorItemID = EditorGUILayout.IntField("Animator Item ID", m_AnimatorItemID); #if FIRST_PERSON_CONTROLLER GUILayout.Space(5); GUILayout.Label("First Person", InspectorStyles.BoldLabel); GUI.enabled = m_FirstPersonObject == null && m_FirstPersonVisibleItem == null; m_AddFirstPersonPerspective = EditorGUILayout.Toggle("Add First Person Item", m_AddFirstPersonPerspective); GUI.enabled = m_AddFirstPersonPerspective; var firstPersonSuccess = DrawFirstPersonObject(m_Character, ref m_FirstPersonObject, ref m_FirstPersonObjectAnimatorController, ref m_FirstPersonVisibleItem, ref m_FirstPersonParent, ref m_FirstPersonItemSlot, ref m_FirstPersonVisibleItemAnimatorController, m_ThirdPersonItemSlot != null ? m_ThirdPersonItemSlot.ID : 0, characterUpdate, canBuild && m_AddFirstPersonPerspective); GUI.enabled = true; if (m_AddFirstPersonPerspective && !firstPersonSuccess) { canBuild = false; } #endif if (m_Character == null || (m_Character != null && m_Character.GetComponent <Animator>() != null)) { GUILayout.Space(10); GUILayout.Label("Third Person (including AI and multiplayer)", InspectorStyles.BoldLabel); GUI.enabled = m_ThirdPersonObject == null; m_AddThirdPersonPerspective = EditorGUILayout.Toggle("Add Third Person Item", m_AddThirdPersonPerspective); GUI.enabled = m_AddThirdPersonPerspective; var thirdPersonSuccess = DrawThirdPersonObject(m_Character, ref m_ThirdPersonObject, ref m_ThirdHumanoidParentHand, ref m_ThirdPersonParent, ref m_ThirdPersonItemSlot, ref m_ThirdPersonObjectAnimatorController, m_FirstPersonItemSlot != null ? m_FirstPersonItemSlot.ID : 0, characterUpdate, canBuild && m_AddThirdPersonPerspective); GUI.enabled = true; if (m_AddThirdPersonPerspective && !thirdPersonSuccess) { canBuild = false; } } if (!m_AddFirstPersonPerspective && !m_AddThirdPersonPerspective) { if (canBuild) { EditorGUILayout.HelpBox("At least one perspective must be added.", MessageType.Error); canBuild = false; } } GUILayout.Space(15); m_ActionType = (ItemBuilder.ActionType)EditorGUILayout.EnumPopup("Action Type", m_ActionType); #if !ULTIMATE_CHARACTER_CONTROLLER_SHOOTER if (m_ActionType == ItemBuilder.ActionType.ShootableWeapon && canBuild) { EditorGUILayout.HelpBox("The shooter controller is necessary in order to create shootable weapons.", MessageType.Error); canBuild = false; } #endif #if !ULTIMATE_CHARACTER_CONTROLLER_MELEE if (m_ActionType == ItemBuilder.ActionType.MeleeWeapon && canBuild) { EditorGUILayout.HelpBox("The melee controller is necessary in order to create melee weapons.", MessageType.Error); canBuild = false; } #endif #if FIRST_PERSON_CONTROLLER // The slot IDs must match. if (m_FirstPersonItemSlot != null && m_ThirdPersonItemSlot != null && m_FirstPersonItemSlot.ID != m_ThirdPersonItemSlot.ID && canBuild) { canBuild = false; EditorGUILayout.HelpBox("The first and third person ItemSlots must use the same ID.", MessageType.Error); } #endif if (canBuild && (m_ActionType != ItemBuilder.ActionType.Shield)) { EditorGUI.indentLevel++; m_ActionItemType = EditorGUILayout.ObjectField("Consumable Item Type", m_ActionItemType, typeof(ItemType), false) as ItemType; EditorGUI.indentLevel--; } // Setup profiles. GUILayout.Space(5); var updatedStateConfiguration = EditorGUILayout.ObjectField("State Configuration", m_AddStateConfiguration, typeof(StateConfiguration), false) as StateConfiguration; if (updatedStateConfiguration != m_AddStateConfiguration) { if (updatedStateConfiguration != null) { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(updatedStateConfiguration))); } else { EditorPrefs.SetString(ManagerUtility.LastStateConfigurationGUIDString, string.Empty); } m_AddStateConfiguration = updatedStateConfiguration; } if (m_AddStateConfiguration != null) { EditorGUI.indentLevel++; var profiles = m_AddStateConfiguration.GetProfilesForGameObject(null, StateConfiguration.Profile.ProfileType.Item); if (profiles.Count > 0) { // The item can be added without any profiles. profiles.Insert(0, "(None)"); m_AddProfileIndex = EditorGUILayout.Popup("Profile", m_AddProfileIndex, profiles.ToArray()); m_AddProfileName = profiles[m_AddProfileIndex]; } EditorGUI.indentLevel--; } GUILayout.Space(5); GUI.enabled = canBuild; if (GUILayout.Button("Build Item")) { var item = ItemBuilder.BuildItem(m_Name, m_ItemType, m_AnimatorItemID, m_Character, m_SlotID, m_AddToDefaultLoadout, m_AddFirstPersonPerspective, m_FirstPersonObject, m_FirstPersonObjectAnimatorController, m_FirstPersonVisibleItem, m_FirstPersonItemSlot, m_FirstPersonVisibleItemAnimatorController, m_AddThirdPersonPerspective, m_ThirdPersonObject, m_ThirdPersonItemSlot, m_ThirdPersonObjectAnimatorController, m_InvisibleShadowCaster, m_ActionType, m_ActionItemType); // Setup any profiles on the item. if (m_AddStateConfiguration != null) { if (m_AddProfileIndex > 0) { m_AddStateConfiguration.AddStatesToGameObject(m_AddProfileName, item.gameObject); InspectorUtility.SetDirty(item.gameObject); } } // If the character is null then a prefab will be created. if (m_Character == null) { var path = EditorUtility.SaveFilePanel("Save Item", "Assets", m_Name + ".prefab", "prefab"); if (path.Length != 0 && Application.dataPath.Length < path.Length) { var relativePath = path.Replace(Application.dataPath, ""); #if UNITY_2018_3_OR_NEWER PrefabUtility.SaveAsPrefabAsset(item, "Assets" + relativePath); #else PrefabUtility.CreatePrefab("Assets" + relativePath, item); #endif Object.DestroyImmediate(item, true); } } // Remove the original objects if they are in the scene - this will prevent duplicate objects from existing. if (m_FirstPersonVisibleItem != null && !EditorUtility.IsPersistent(m_FirstPersonVisibleItem) && (m_Character == null || !m_FirstPersonVisibleItem.transform.IsChildOf(m_Character.transform))) { Object.DestroyImmediate(m_FirstPersonVisibleItem, true); m_FirstPersonVisibleItem = null; } if (m_FirstPersonObject != null && !EditorUtility.IsPersistent(m_FirstPersonObject) && (m_Character == null || !m_FirstPersonObject.transform.IsChildOf(m_Character.transform))) { Object.DestroyImmediate(m_FirstPersonObject, true); m_FirstPersonObject = null; } if (m_ThirdPersonObject != null && !EditorUtility.IsPersistent(m_ThirdPersonObject) && (m_Character == null || !m_ThirdPersonObject.transform.IsChildOf(m_Character.transform))) { Object.DestroyImmediate(m_ThirdPersonObject, true); m_ThirdPersonObject = null; } // Select the newly added item. Selection.activeGameObject = item.gameObject; } GUI.enabled = true; }
/// <summary> /// Returns the actions to draw before the State list is drawn. /// </summary> /// <returns>The actions to draw before the State list is drawn.</returns> protected override Action GetDrawCallback() { var baseCallback = base.GetDrawCallback(); baseCallback += () => { var itemDefinition = PropertyFromName("m_ItemDefinition"); EditorGUILayout.PropertyField(itemDefinition); if (itemDefinition == null) { EditorGUILayout.HelpBox("An Item Definition is required.", MessageType.Error); } else { // Ensure the Item Definition exists within the collection set by the Item Set Manager. var itemSetManager = (target as Item).GetComponentInParent <ItemSetManager>(); if (itemSetManager != null && itemSetManager.ItemCollection != null) { if (AssetDatabase.GetAssetPath(itemDefinition.objectReferenceValue) != AssetDatabase.GetAssetPath(itemSetManager.ItemCollection)) { EditorGUILayout.HelpBox("The Item Definition must exist within the Item Collection specified on the character's Item Set Manager.", MessageType.Error); } } } if (Application.isPlaying) { EditorGUI.indentLevel++; EditorGUILayout.LabelField("Item Identifier", m_Item.ItemIdentifier == null ? "(none)" : m_Item.ItemIdentifier.ToString()); EditorGUI.indentLevel--; } EditorGUILayout.PropertyField(PropertyFromName("m_SlotID")); EditorGUILayout.PropertyField(PropertyFromName("m_AnimatorItemID")); EditorGUILayout.PropertyField(PropertyFromName("m_AnimatorMovementSetID")); EditorGUILayout.PropertyField(PropertyFromName("m_DominantItem")); EditorGUILayout.PropertyField(PropertyFromName("m_UniqueItemSet")); EditorGUILayout.PropertyField(PropertyFromName("m_AllowCameraZoom")); EditorGUILayout.PropertyField(PropertyFromName("m_DropPrefab")); if (PropertyFromName("m_DropPrefab").objectReferenceValue != null) { EditorGUI.indentLevel++; #if ULTIMATE_CHARACTER_CONTROLLER_VR EditorGUILayout.PropertyField(PropertyFromName("m_DropVelocityMultiplier")); #endif EditorGUI.indentLevel--; } EditorGUILayout.PropertyField(PropertyFromName("m_FullInventoryDrop")); EditorGUILayout.PropertyField(PropertyFromName("m_DropConsumableItems")); if (Foldout("Equip")) { EditorGUI.indentLevel++; InspectorUtility.DrawAnimationEventTrigger(target, "Equip Event", PropertyFromName("m_EquipEvent")); InspectorUtility.DrawAnimationEventTrigger(target, "Equip Complete Event", PropertyFromName("m_EquipCompleteEvent")); if (Foldout("Animator Audio")) { EditorGUI.indentLevel++; AnimatorAudioStateSetInspector.DrawAnimatorAudioStateSet(m_Item, m_Item.EquipAnimatorAudioStateSet, "m_EquipAnimatorAudioStateSet", true, ref m_ReorderableEquipAnimatorAudioStateSetList, OnEquipAnimatorAudioStateListDraw, OnEquipAnimatorAudioStateListSelect, OnEquipAnimatorAudioStateListAdd, OnEquipAnimatorAudioStateListRemove, SelectedEquipAnimatorAudioStateSetIndexKey, ref m_ReorderableEquipAnimatorAudioStateSetAudioList, OnEquipAudioListElementDraw, OnEquipAudioListAdd, OnEquipAudioListRemove, ref m_ReorderableEquipAnimatorAudioStateSetStateList, OnEquipAnimatorAudioStateSetStateListDraw, OnEquipAnimatorAudioStateSetStateListAdd, OnEquipAnimatorAudioStateSetStateListReorder, OnEquipAnimatorAudioStateSetStateListRemove, GetSelectedEquipAnimatorAudioStateSetStateIndexKey(EditorPrefs.GetInt(SelectedEquipAnimatorAudioStateSetIndexKey))); EditorGUI.indentLevel--; } EditorGUI.indentLevel--; } if (Foldout("Unequip")) { EditorGUI.indentLevel++; InspectorUtility.DrawAnimationEventTrigger(target, "Unequip Event", PropertyFromName("m_UnequipEvent")); InspectorUtility.DrawAnimationEventTrigger(target, "Unequip Complete Event", PropertyFromName("m_UnequipCompleteEvent")); if (Foldout("Animator Audio")) { EditorGUI.indentLevel++; AnimatorAudioStateSetInspector.DrawAnimatorAudioStateSet(m_Item, m_Item.UnequipAnimatorAudioStateSet, "m_UnequipAnimatorAudioStateSet", true, ref m_ReorderableUnequipAnimatorAudioStateSetList, OnUnequipAnimatorAudioStateListDraw, OnUnequipAnimatorAudioStateListSelect, OnUnequipAnimatorAudioStateListAdd, OnUnequipAnimatorAudioStateListRemove, SelectedUnequipAnimatorAudioStateSetIndexKey, ref m_ReorderableUnequipAnimatorAudioStateSetAudioList, OnUnequipAudioListElementDraw, OnUnequipAudioListAdd, OnUnequipAudioListRemove, ref m_ReorderableUnequipAnimatorAudioStateSetStateList, OnUnequipAnimatorAudioStateSetStateListDraw, OnUnequipAnimatorAudioStateSetStateListAdd, OnUnequipAnimatorAudioStateSetStateListReorder, OnUnequipAnimatorAudioStateSetStateListRemove, GetSelectedUnequipAnimatorAudioStateSetStateIndexKey(EditorPrefs.GetInt(SelectedUnequipAnimatorAudioStateSetIndexKey))); EditorGUI.indentLevel--; } EditorGUI.indentLevel--; } if (Foldout("UI")) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName("m_UIMonitorID")); EditorGUILayout.PropertyField(PropertyFromName("m_Icon")); EditorGUILayout.PropertyField(PropertyFromName("m_ShowCrosshairsOnAim")); EditorGUILayout.PropertyField(PropertyFromName("m_CenterCrosshairs")); EditorGUILayout.PropertyField(PropertyFromName("m_QuadrantOffset")); EditorGUILayout.PropertyField(PropertyFromName("m_MaxQuadrantSpread")); EditorGUILayout.PropertyField(PropertyFromName("m_QuadrantSpreadDamping")); EditorGUILayout.PropertyField(PropertyFromName("m_LeftCrosshairs")); EditorGUILayout.PropertyField(PropertyFromName("m_TopCrosshairs")); EditorGUILayout.PropertyField(PropertyFromName("m_RightCrosshairs")); EditorGUILayout.PropertyField(PropertyFromName("m_BottomCrosshairs")); EditorGUILayout.PropertyField(PropertyFromName("m_ShowFullScreenUI")); EditorGUILayout.PropertyField(PropertyFromName("m_FullScreenUIID")); EditorGUI.indentLevel--; } if (Foldout("Events")) { EditorGUI.indentLevel++; Shared.Editor.Inspectors.Utility.InspectorUtility.UnityEventPropertyField(PropertyFromName("m_PickupItemEvent")); Shared.Editor.Inspectors.Utility.InspectorUtility.UnityEventPropertyField(PropertyFromName("m_EquipItemEvent")); Shared.Editor.Inspectors.Utility.InspectorUtility.UnityEventPropertyField(PropertyFromName("m_UnequipItemEvent")); Shared.Editor.Inspectors.Utility.InspectorUtility.UnityEventPropertyField(PropertyFromName("m_DropItemEvent")); EditorGUI.indentLevel--; } }; return(baseCallback); }
/// <summary> /// Draws the specified attribute. /// </summary> private void DrawSelectedAttribute(int index) { EditorGUI.BeginChangeCheck(); var attributesProperty = PropertyFromName("m_Attributes"); var attributeProperty = attributesProperty.GetArrayElementAtIndex(index); if (attributeProperty == null) { return; } // The name must be unique. var name = attributeProperty.FindPropertyRelative("m_Name"); var desiredName = EditorGUILayout.TextField(new GUIContent("Name", "The name of the attribute."), name.stringValue); if (name.stringValue != desiredName && IsUniqueName(m_AttributeManager.Attributes, desiredName)) { name.stringValue = desiredName; } var minValue = attributeProperty.FindPropertyRelative("m_MinValue"); var maxValue = attributeProperty.FindPropertyRelative("m_MaxValue"); EditorGUILayout.PropertyField(minValue); if (minValue.floatValue > maxValue.floatValue) { maxValue.floatValue = minValue.floatValue; } EditorGUILayout.PropertyField(maxValue); if (maxValue.floatValue < minValue.floatValue) { minValue.floatValue = maxValue.floatValue; } var value = attributeProperty.FindPropertyRelative("m_Value"); EditorGUILayout.PropertyField(value); if (maxValue.floatValue < value.floatValue) { value.floatValue = maxValue.floatValue; } else if (minValue.floatValue > value.floatValue) { value.floatValue = minValue.floatValue; } if (value.floatValue > maxValue.floatValue) { maxValue.floatValue = value.floatValue; } else if (value.floatValue < minValue.floatValue) { minValue.floatValue = value.floatValue; } var autoUpdateValueType = attributeProperty.FindPropertyRelative("m_AutoUpdateValueType"); EditorGUILayout.PropertyField(autoUpdateValueType); if (autoUpdateValueType.intValue != (int)Attribute.AutoUpdateValue.None) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(attributeProperty.FindPropertyRelative("m_AutoUpdateStartDelay")); EditorGUILayout.PropertyField(attributeProperty.FindPropertyRelative("m_AutoUpdateInterval")); EditorGUILayout.PropertyField(attributeProperty.FindPropertyRelative("m_AutoUpdateAmount")); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); InspectorUtility.RecordUndoDirtyObject(target, "Change Value"); } var attribute = m_AttributeManager.Attributes[index]; if (InspectorUtility.Foldout(attribute, new GUIContent("States"), false)) { // The Attribute class derives from system.object at the base level and reorderable lists can only operate on Unity objects. To get around this restriction // create a dummy array within a Unity object that corresponds to the number of elements within the view type's state list. When the reorderable list is drawn // the view type object will be used so it's like the dummy object never existed. var selectedAttribute = attribute as Attribute; var gameObject = new GameObject(); var stateIndexHelper = gameObject.AddComponent <StateInspectorHelper>(); stateIndexHelper.StateIndexData = new int[selectedAttribute.States.Length]; for (int i = 0; i < stateIndexHelper.StateIndexData.Length; ++i) { stateIndexHelper.StateIndexData[i] = i; } var stateIndexSerializedObject = new SerializedObject(stateIndexHelper); m_ReorderableAttributeStateList = StateInspector.DrawStates(m_ReorderableAttributeStateList, serializedObject, stateIndexSerializedObject.FindProperty("m_StateIndexData"), GetSelectedAttributeStateIndexKey(selectedAttribute), OnAttributeStateListDraw, OnAttributeStateListAdd, OnAttributeStateListReorder, OnAttributeStateListRemove); DestroyImmediate(gameObject); } }
/// <summary> /// Creates a new preset and adds it to a new state in the list. /// </summary> public static UltimateCharacterController.StateSystem.State[] CreatePreset(object target, UltimateCharacterController.StateSystem.State[] states, ReorderableList reorderableList, string selectedIndexKey) { var preset = PersistablePreset.CreatePreset(target); if (preset != null) { var startName = target.GetType().Name + "Preset.asset"; var path = EditorPrefs.GetString(c_EditorPrefsLastPresetPathKey, InspectorUtility.GetSaveFilePath()); path = EditorUtility.SaveFilePanel("Save Preset", path, startName, "asset"); if (path.Length != 0 && Application.dataPath.Length < path.Length) { EditorPrefs.SetString(c_EditorPrefsLastPresetPathKey, System.IO.Path.GetDirectoryName(path)); // The path is relative to the project. path = string.Format("Assets/{0}", path.Substring(Application.dataPath.Length + 1)); // Do not delete/add if an existing preset already exists to prevent the references from being destroyed. var existingPreset = AssetDatabase.LoadAssetAtPath <Preset>(path); if (existingPreset != null) { EditorUtility.DisplayDialog("Unable to Save Preset", "The preset must reference a unique file name.", "Okay"); return(states); } var name = System.IO.Path.GetFileNameWithoutExtension(path); if (!string.IsNullOrEmpty(name.Replace(target.GetType().Name + "Preset", ""))) { name = name.Replace(target.GetType().Name + "Preset", ""); } AssetDatabase.CreateAsset(preset, path); AssetDatabase.ImportAsset(path); EditorGUIUtility.PingObject(preset); if (!Application.isPlaying) { states = InsertStateElement(states, reorderableList, selectedIndexKey, name, preset); } } } return(states); }
/// <summary> /// Draws the custom inspector. /// </summary> public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(PropertyFromName("m_InitializeOnEnable")); if (Foldout("Physics")) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName("m_Mass")); EditorGUILayout.PropertyField(PropertyFromName("m_StartVelocityMultiplier")); EditorGUILayout.PropertyField(PropertyFromName("m_GravityMagnitude")); EditorGUILayout.PropertyField(PropertyFromName("m_Speed")); EditorGUILayout.PropertyField(PropertyFromName("m_RotationSpeed")); EditorGUILayout.PropertyField(PropertyFromName("m_Damping")); EditorGUILayout.PropertyField(PropertyFromName("m_RotationDamping")); EditorGUILayout.PropertyField(PropertyFromName("m_RotateInMoveDirection")); EditorGUILayout.PropertyField(PropertyFromName("m_SettleThreshold")); EditorGUILayout.PropertyField(PropertyFromName("m_SidewaysSettleThreshold")); EditorGUILayout.PropertyField(PropertyFromName("m_StartSidewaysVelocityMagnitude")); EditorGUILayout.PropertyField(PropertyFromName("m_MaxCollisionCount")); EditorGUI.indentLevel--; } if (Foldout("Impact")) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName("m_ImpactLayers")); EditorGUILayout.PropertyField(PropertyFromName("m_SurfaceImpact")); EditorGUILayout.PropertyField(PropertyFromName("m_ForceMultiplier")); EditorGUILayout.PropertyField(PropertyFromName("m_BounceMode")); if (PropertyFromName("m_BounceMode").enumValueIndex != (int)TrajectoryObject.BounceMode.None) { EditorGUILayout.PropertyField(PropertyFromName("m_BounceMultiplier")); } else { if (target is Destructible) { EditorGUILayout.PropertyField(PropertyFromName("m_StickyLayers"), true); } } EditorGUI.indentLevel--; } if (Foldout("Audio")) { EditorGUI.indentLevel++; m_ReorderableActiveAudioClipsList = AudioClipSetInspector.DrawAudioClipSet(m_TrajectoryObject.ActiveAudioClipSet, PropertyFromName("m_ActiveAudioClipSet"), m_ReorderableActiveAudioClipsList, OnActiveAudioClipDraw, OnActiveAudioClipListAdd, OnActiveAudioClipListRemove); EditorGUI.indentLevel--; } DrawObjectFields(); if (Foldout("Curve")) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(PropertyFromName("m_MaxPositionCount")); EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { InspectorUtility.RecordUndoDirtyObject(target, "Value Change"); serializedObject.ApplyModifiedProperties(); } }
static void DrawMovingPlatformGizmo(MovingPlatform movingPlatform, GizmoType gizmoType) { if (movingPlatform.Waypoints == null) { return; } Mesh mesh = null; var meshFilter = movingPlatform.GetComponent <MeshFilter>(); if (meshFilter != null) { mesh = meshFilter.sharedMesh; } for (int i = 0; i < movingPlatform.Waypoints.Length; ++i) { if (movingPlatform.Waypoints[i].Transform == null) { continue; } Gizmos.color = movingPlatform.GizmoColor; // Draw the mesh if it exists. if (mesh != null) { Gizmos.DrawMesh(mesh, movingPlatform.Waypoints[i].Transform.position, movingPlatform.Waypoints[i].Transform.rotation, movingPlatform.transform.localScale); } Gizmos.DrawWireSphere(movingPlatform.Waypoints[i].Transform.position, 0.5f); if (movingPlatform.DrawDebugLabels) { if (s_DebugLabelStyle == null) { s_DebugLabelStyle = new GUIStyle(EditorStyles.label); s_DebugLabelStyle.fontSize = 16; s_DebugLabelStyle.normal.textColor = InspectorUtility.GetContrastColor(movingPlatform.GizmoColor); } // Draw the delay in the center of the platform. Handles.Label(movingPlatform.Waypoints[i].Transform.position, movingPlatform.Waypoints[i].Delay.ToString(), s_DebugLabelStyle); } // Draw a line connecting the platforms. if (i > 0 && movingPlatform.Waypoints[i - 1].Transform != null && movingPlatform.MovementType != MovingPlatform.PathMovementType.Target) { Gizmos.color = InspectorUtility.GetContrastColor(movingPlatform.GizmoColor); Gizmos.DrawLine(movingPlatform.Waypoints[i - 1].Transform.position, movingPlatform.Waypoints[i].Transform.position); if (movingPlatform.DrawDebugLabels) { // Draw a distance in the center of the line. var distance = decimal.Round((decimal)Vector3.Distance(movingPlatform.Waypoints[i - 1].Transform.position, movingPlatform.Waypoints[i].Transform.position), 3); Handles.Label((movingPlatform.Waypoints[i - 1].Transform.position + movingPlatform.Waypoints[i].Transform.position) / 2, distance.ToString(), s_DebugLabelStyle); } } } // Complete the path drawing. if (movingPlatform.MovementType == MovingPlatform.PathMovementType.Loop && movingPlatform.Waypoints.Length > 0 && movingPlatform.Waypoints[0].Transform != null && movingPlatform.Waypoints[movingPlatform.Waypoints.Length - 1].Transform != null) { Gizmos.color = InspectorUtility.GetContrastColor(movingPlatform.GizmoColor); Gizmos.DrawLine(movingPlatform.Waypoints[0].Transform.position, movingPlatform.Waypoints[movingPlatform.Waypoints.Length - 1].Transform.position); if (movingPlatform.DrawDebugLabels) { // Draw a distance in the center of the line. var distance = decimal.Round((decimal)Vector3.Distance(movingPlatform.Waypoints[0].Transform.position, movingPlatform.Waypoints[movingPlatform.Waypoints.Length - 1].Transform.position), 3); Handles.Label((movingPlatform.Waypoints[0].Transform.position + movingPlatform.Waypoints[movingPlatform.Waypoints.Length - 1].Transform.position) / 2, distance.ToString(), s_DebugLabelStyle); } } else if (movingPlatform.MovementType == MovingPlatform.PathMovementType.Target && movingPlatform.TargetWaypoint < movingPlatform.Waypoints.Length && movingPlatform.Waypoints[movingPlatform.TargetWaypoint].Transform != null) { Gizmos.color = InspectorUtility.GetContrastColor(movingPlatform.GizmoColor); Gizmos.DrawLine(movingPlatform.transform.position, movingPlatform.Waypoints[movingPlatform.TargetWaypoint].Transform.position); } // Draw the current waypoint the platform is moving towards. if (Application.isPlaying && movingPlatform.enabled && movingPlatform.Waypoints.Length > 0) { Gizmos.color = Color.green; Gizmos.DrawLine(movingPlatform.transform.position, movingPlatform.Waypoints[movingPlatform.NextWaypoint].Transform.position); } }
public override void OnInspectorGUI() { serializedObject.Update(); // Header InspectorUtility.ScriptPropertyField(serializedObject); //GUI.enabled = false; //EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script")); //GUI.enabled = true; InspectorUtility.LabelField(m_ActionSettingsHeader); InspectorUtility.PropertyField(serializedObject.FindProperty("m_stateName")); InspectorUtility.PropertyField(serializedObject.FindProperty("m_TransitionDuration")); InspectorUtility.PropertyField(serializedObject.FindProperty("m_SpeedMultiplier")); InspectorUtility.PropertyField(serializedObject.FindProperty("m_actionID")); //InspectorUtility.PropertyField(serializedObject.FindProperty("m_startType")); //InspectorUtility.PropertyField(serializedObject.FindProperty("m_stopType")); SerializedProperty inputNames = serializedObject.FindProperty("m_InputNames"); inputNames.isExpanded = true; //if (m_action.StartType == ActionStartType.ButtonDown || // m_action.StartType == ActionStartType.DoublePress || // m_action.StopType == ActionStopType.ButtonToggle || // m_action.StopType == ActionStopType.ButtonUp // ) { // //EditorGUILayout.Space(); // SerializedProperty inputNames = serializedObject.FindProperty("m_InputNames"); // inputNames.isExpanded = true; // //EditorGUI.indentLevel++; // //if(inputNames.isExpanded){ // // if(inputNames.arraySize == 0){ // // inputNames.InsertArrayElementAtIndex(0); // // } // // else{ // // for (int index = 0; index < inputNames.arraySize; index++) // // { // // EditorGUILayout.BeginHorizontal(); // // //inputNames.GetArrayElementAtIndex(index).stringValue = EditorGUILayout.TextField(inputNames.GetArrayElementAtIndex(index).stringValue); // // EditorGUILayout.PropertyField(inputNames.GetArrayElementAtIndex(index), GUIContent.none); // // if (index == inputNames.arraySize - 1){ // // if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(28))){ // // inputNames.InsertArrayElementAtIndex(index); // // } // // } // // if (inputNames.arraySize > 1){ // // if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.Width(28))){ // // inputNames.DeleteArrayElementAtIndex(index); // // } // // } // // EditorGUILayout.EndHorizontal(); // // } // // } // //} // //EditorGUI.indentLevel--; //} // Draw animator motion. InspectorUtility.PropertyField(m_animatorMotion); // Draw on start Audio and PArticle effects DrawExecuteEffects(ref m_action.executeOnStart, new GUIContent("Play On Start", "Execute effects when action start."), new string[2] { "m_StartEffect", "m_StartAudioClips" }); DrawExecuteEffects(ref m_action.executeOnStop, new GUIContent("Play On Stop", "Execute effects when action stops."), new string[2] { "m_EndEffect", "m_StopAudioClips" }); EditorGUILayout.Space(); // Draw properties. DrawPropertiesExcluding(serializedObject, m_DontIncude); // ----- // Debugging // ----- EditorGUILayout.Space(); EditorGUILayout.BeginVertical(EditorStyles.helpBox); { InspectorUtility.PropertyField(enableDebug, true); } EditorGUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); }
static void DrawSpawnPointGizmo(SpawnPoint spawnPoint, GizmoType gizmoType) { var transform = spawnPoint.transform; Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, transform.lossyScale); Gizmos.color = spawnPoint.GizmoColor; var position = Vector3.zero; if (spawnPoint.Shape == SpawnPoint.SpawnShape.Point || spawnPoint.Shape == SpawnPoint.SpawnShape.Sphere) { var size = spawnPoint.Shape == SpawnPoint.SpawnShape.Sphere ? spawnPoint.Size : 0.2f; Gizmos.DrawSphere(position, size); // Draw the outline when the component is selected. if (MathUtility.InLayerMask((int)GizmoType.Selected, (int)gizmoType)) { Gizmos.color = InspectorUtility.GetContrastColor(spawnPoint.GizmoColor); Gizmos.DrawWireSphere(position, size); } } else if (spawnPoint.Shape == SpawnPoint.SpawnShape.Box) { var size = Vector3.zero; size.x = size.z = spawnPoint.Size; size.y = spawnPoint.GroundSnapHeight; position += spawnPoint.transform.up * size.y / 2; Gizmos.DrawCube(position, size); // Draw the outline when the component is selected. if (MathUtility.InLayerMask((int)GizmoType.Selected, (int)gizmoType)) { Gizmos.color = InspectorUtility.GetContrastColor(spawnPoint.GizmoColor); Gizmos.DrawWireCube(position, size); } } if (MathUtility.InLayerMask((int)GizmoType.Selected, (int)gizmoType)) { // The Gizmo class cannot draw a wire disk. Handles.color = InspectorUtility.GetContrastColor(spawnPoint.GizmoColor); Handles.DrawWireDisc(spawnPoint.transform.position, spawnPoint.transform.up, 1); // Draw directional arrows when selected. var rad = spawnPoint.Size > 0 ? spawnPoint.Size : 1; if (spawnPoint.RandomDirection) { // Draw four big arrows, relative to the spawnpoint and perpendicular to each other. Gizmos.DrawLine((Vector3.back * 2) * rad, (Vector3.forward * 2) * rad); Gizmos.DrawLine((Vector3.left * 2) * rad, (Vector3.right * 2) * rad); Gizmos.DrawLine((Vector3.forward * 2) * rad, (Vector3.forward * 1.5f * rad) + (Vector3.left * 0.5f) * rad); Gizmos.DrawLine((Vector3.forward * 2) * rad, (Vector3.forward * 1.5f * rad) + (Vector3.right * 0.5f) * rad); Gizmos.DrawLine((Vector3.back * 2) * rad, (Vector3.back * 1.5f * rad) + (Vector3.left * 0.5f) * rad); Gizmos.DrawLine((Vector3.back * 2) * rad, (Vector3.back * 1.5f * rad) + (Vector3.right * 0.5f) * rad); Gizmos.DrawLine((Vector3.left * 2) * rad, (Vector3.left * 1.5f * rad) + (Vector3.forward * 0.5f) * rad); Gizmos.DrawLine((Vector3.left * 2) * rad, (Vector3.left * 1.5f * rad) + (Vector3.back * 0.5f) * rad); Gizmos.DrawLine((Vector3.right * 2) * rad, (Vector3.right * 1.5f * rad) + (Vector3.forward * 0.5f) * rad); Gizmos.DrawLine((Vector3.right * 2) * rad, (Vector3.right * 1.5f * rad) + (Vector3.back * 0.5f) * rad); } else { // Draw a single big arrow pointing in the spawnpoint's forward direction. Gizmos.DrawLine(Vector3.zero, (Vector3.forward * 2) * rad); Gizmos.DrawLine((Vector3.forward * 2) * rad, (Vector3.forward * 1.5f * rad) + (Vector3.left * 0.5f) * rad); Gizmos.DrawLine((Vector3.forward * 2) * rad, (Vector3.forward * 1.5f * rad) + (Vector3.right * 0.5f) * rad); } } }
/// <summary> /// Draws the control point. /// </summary> /// <param name="index">The index that should be drawn.</param> /// <returns>The position of the control point</returns> private Vector3 DrawControlPoint(int index) { var position = m_Path.ControlPoints[index]; if (index % 3 != 0 && (index < m_SelectedMiddleIndex - 1 || index > m_SelectedMiddleIndex + 1)) { return(position); } if (index == 0) { Handles.color = Color.green; } else if (index == m_Path.ControlPoints.Length - 1) { Handles.color = Color.red; } else { Handles.color = Color.white; } var size = HandleUtility.GetHandleSize(position) * 0.02f * (index % 3 == 0 ? 2 : 1); if (Handles.Button(position, Quaternion.identity, size, size * 4, Handles.DotHandleCap)) { m_SelectedIndex = index; EditorPrefs.SetInt(EditorPrefsSelectedIndexKey, m_SelectedIndex); if (index % 3 == 0) { m_SelectedMiddleIndex = index; EditorPrefs.SetInt(EditorPrefsSelectedMiddleIndexKey, m_SelectedMiddleIndex); } Repaint(); } // If the control point is selected then the handles should be drawn so it can be repositioned. if (index == m_SelectedIndex) { EditorGUI.BeginChangeCheck(); position = Handles.DoPositionHandle(m_Path.ControlPoints[index], Quaternion.identity); if (EditorGUI.EndChangeCheck()) { // Middle control points should also move their tangents. if (index % 3 == 0) { var delta = position - m_Path.ControlPoints[index]; if (index > 0) { m_Path.ControlPoints[index - 1] += delta; } if (index < m_Path.ControlPoints.Length - 1) { m_Path.ControlPoints[index + 1] += delta; } } m_Path.ControlPoints[index] = position; AdjustControlPoint(index); InspectorUtility.SetDirty(m_Path); } } return(m_Path.ControlPoints[index]); }
public override void OnInspectorGUI() { //base.OnInspectorGUI(); serializedObject.Update(); InspectorUtility.PropertyField(serializedObject.FindProperty("m_Script")); // ----- // Character Movement // ----- SetGUIContent(ref motorGUIContent, k_motorHeader, k_motorTooltip); SetGUIContent(ref physicsGUIContent, k_physicsContentHeader, k_physicsTooltip); SetGUIContent(ref collisionsGUIContent, k_collisionsHeader, k_collisionsTooltip); SetGUIContent(ref animationGUIContent, k_animationHeader, k_animationTooltip); SetGUIContent(ref advanceGUIContent, k_advanceHeader, k_advanceTooltip); DrawProperties(m_motorSettings, motorGUIContent); DrawProperties(m_physicsSettings, physicsGUIContent); DrawProperties(m_collisionSettings, collisionsGUIContent); DrawProperties(m_animationSettings, animationGUIContent); DrawProperties(m_advanceSettings, advanceGUIContent); // ----- // Character Actions // ----- EditorGUILayout.BeginVertical(EditorStyles.helpBox); { EditorGUI.indentLevel++; displayActions.boolValue = m_useCustomeHeader ? InspectorUtility.Foldout(displayActions.boolValue, ActionsFoldoutHeader) : EditorGUILayout.Foldout(displayActions.boolValue, ActionsFoldoutHeader); //displayActions.boolValue = EditorGUILayout.Foldout(displayActions.boolValue, ActionsFoldoutHeader); if (displayActions.boolValue) { //GUILayout.BeginVertical("box"); DrawReorderableList(m_ActionsList); //GUILayout.EndVertical(); // Draw Selected Action Inspector. //EditorGUI.indentLevel++; if (m_SelectedAction != null) { GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Space(12); m_ActionEditor = CreateEditor(m_SelectedAction); //m_ActionEditor.DrawDefaultInspector(); m_ActionEditor.OnInspectorGUI(); GUILayout.Space(12); GUILayout.EndVertical(); } //EditorGUI.indentLevel--; //EditorGUI.indentLevel--; } EditorGUI.indentLevel--; } EditorGUILayout.EndVertical(); if (m_spaceBetweenSections) { EditorGUILayout.Space(); } // ----- // Debugging // ----- EditorGUILayout.BeginVertical(EditorStyles.helpBox); { EditorGUI.indentLevel++; if (debugger.isExpanded) { InspectorUtility.PropertyField(debugger, true); } else { EditorGUILayout.BeginVertical(InspectorUtility.HeaderStyleBlue); { InspectorUtility.PropertyField(debugger, true); } EditorGUILayout.EndVertical(); } EditorGUI.indentLevel--; } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Draws the inspector. /// </summary> public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); // Allow for fine grain control of the position. if (m_SelectedIndex != -1 && m_SelectedIndex < m_Path.ControlPoints.Length) { m_Path.ControlPoints[m_SelectedIndex] = EditorGUILayout.Vector3Field("Position", m_Path.ControlPoints[m_SelectedIndex]); AdjustControlPoint(m_SelectedIndex); } EditorGUILayout.BeginHorizontal(); // Adds a new curve to the end of the path. if (GUILayout.Button("Add Curve Segment")) { var controlPoints = m_Path.ControlPoints; int count; var position = Vector3.zero; if (controlPoints == null || controlPoints.Length == 0) { // A Cubic Bezier Curve requires a minimum of four points. count = 4; position = Vector3.up; controlPoints = new Vector3[count]; } else { // The last point from the previous curve will be used as the fourth point for the new curve. count = 3; position = controlPoints[controlPoints.Length - 1]; System.Array.Resize(ref controlPoints, controlPoints.Length + count); } for (int i = 0; i < count; ++i) { controlPoints[controlPoints.Length - i - 1] = position; position.x += 1; } m_Path.ControlPoints = controlPoints; // If a new curve is added then the control point should be adjusted so the tangents are equal distance. if (controlPoints.Length > 4) { AdjustControlPoint(controlPoints.Length - 3); } m_SelectedIndex = m_SelectedMiddleIndex = controlPoints.Length - 1; EditorPrefs.SetInt(EditorPrefsSelectedIndexKey, m_SelectedIndex); EditorPrefs.SetInt(EditorPrefsSelectedMiddleIndexKey, m_SelectedMiddleIndex); Repaint(); } if (GUILayout.Button("Remove Last Curve Segment")) { var controlPoints = m_Path.ControlPoints; var count = m_Path.ControlPoints.Length > 4 ? 3 : 4; System.Array.Resize(ref controlPoints, controlPoints.Length - count); m_Path.ControlPoints = controlPoints; if (m_SelectedIndex >= controlPoints.Length) { m_SelectedIndex = m_SelectedMiddleIndex = -1; EditorPrefs.SetInt(EditorPrefsSelectedIndexKey, m_SelectedIndex); EditorPrefs.SetInt(EditorPrefsSelectedMiddleIndexKey, m_SelectedMiddleIndex); } Repaint(); } EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { InspectorUtility.SetDirty(m_Path); } }
/// <summary> /// Called when the object should be drawn to the inspector. /// </summary> /// <param name="target">The object that is being drawn.</param> /// <param name="parent">The Unity Object that the object belongs to.</param> public override void OnInspectorGUI(object target, Object parent) { m_Ability = (target as Ability); DrawInputFieldsFields(target, parent); InspectorUtility.DrawAttributeModifier(parent, (parent as Component).GetComponent <AttributeManager>(), (target as Ability).AttributeModifier); EditorGUILayout.BeginHorizontal(); InspectorUtility.DrawField(target, "m_State"); GUI.enabled = !string.IsNullOrEmpty(InspectorUtility.GetFieldValue <string>(target, "m_State")); // The InspectorUtility doesn't support a toggle with the text on the right. var field = InspectorUtility.GetField(target, "m_StateAppendItemTypeName"); GUILayout.Space(-5); var value = EditorGUILayout.ToggleLeft(new GUIContent("Append Item", InspectorUtility.GetFieldTooltip(field)), (bool)field.GetValue(target), GUILayout.Width(110)); InspectorUtility.SetFieldValue(target, "m_StateAppendItemTypeName", value); GUI.enabled = true; EditorGUILayout.EndHorizontal(); InspectorUtility.DrawField(target, "m_AbilityIndexParameter"); DrawInspectorDrawerFields(target, parent); if (InspectorUtility.Foldout(target, "Audio")) { EditorGUI.indentLevel++; if (InspectorUtility.Foldout(target, "Start")) { EditorGUI.indentLevel++; AudioClipSetInspector.DrawAudioClipSet(m_Ability.StartAudioClipSet, null, ref m_ReorderableStartAudioClipsList, OnStartAudioClipDraw, OnStartAudioClipListAdd, OnStartAudioClipListRemove); EditorGUI.indentLevel--; } DrawAudioFields(); if (InspectorUtility.Foldout(target, "Stop")) { EditorGUI.indentLevel++; AudioClipSetInspector.DrawAudioClipSet(m_Ability.StopAudioClipSet, null, ref m_ReorderableStopAudioClipsList, OnStopAudioClipDraw, OnStopAudioClipListAdd, OnStopAudioClipListRemove); EditorGUI.indentLevel--; } EditorGUI.indentLevel--; } var startEffectValue = InspectorUtility.GetFieldValue <string>(target, "m_StartEffectName"); var newStartEffectValue = InspectorUtility.DrawTypePopup(typeof(UltimateCharacterController.Character.Effects.Effect), startEffectValue, "Start Effect", true); if (startEffectValue != newStartEffectValue) { InspectorUtility.SetFieldValue(target, "m_StartEffectName", newStartEffectValue); InspectorUtility.SetDirty(parent); } if (!string.IsNullOrEmpty(newStartEffectValue)) { EditorGUI.indentLevel++; InspectorUtility.DrawField(target, "m_StartEffectIndex"); EditorGUI.indentLevel--; } if (InspectorUtility.Foldout(target, "General")) { EditorGUI.indentLevel++; InspectorUtility.DrawField(target, "m_InspectorDescription"); var itemAbilityMoveTowards = (target is MoveTowards) || target is UltimateCharacterController.Character.Abilities.Items.ItemAbility; if (itemAbilityMoveTowards) { GUI.enabled = false; } InspectorUtility.DrawField(target, "m_AllowPositionalInput"); InspectorUtility.DrawField(target, "m_AllowRotationalInput"); GUI.enabled = true; InspectorUtility.DrawField(target, "m_UseGravity"); InspectorUtility.DrawField(target, "m_UseRootMotionPosition"); InspectorUtility.DrawField(target, "m_UseRootMotionRotation"); InspectorUtility.DrawField(target, "m_DetectHorizontalCollisions"); InspectorUtility.DrawField(target, "m_DetectVerticalCollisions"); InspectorUtility.DrawField(target, "m_AnimatorMotion"); if (itemAbilityMoveTowards) { GUI.enabled = false; } var inventory = (parent as Component).GetComponent <UltimateCharacterController.Inventory.InventoryBase>(); if (inventory != null && (parent as Component).GetComponent <UltimateCharacterController.Inventory.ItemSetManager>() != null) { var slotCount = inventory.SlotCount; if (InspectorUtility.Foldout(target, "Allow Equipped Slots")) { EditorGUI.indentLevel++; var mask = InspectorUtility.GetFieldValue <int>(target, "m_AllowEquippedSlotsMask"); var newMask = 0; for (int i = 0; i < slotCount; ++i) { var enabled = (mask & (1 << i)) == (1 << i); if (EditorGUILayout.Toggle("Slot " + i, enabled)) { newMask |= 1 << i; } } // If all of the slots are enabled then use -1. if (newMask == (1 << slotCount) - 1 || itemAbilityMoveTowards) { newMask = -1; } if (mask != newMask) { InspectorUtility.SetFieldValue(target, "m_AllowEquippedSlotsMask", newMask); } InspectorUtility.DrawField(target, "m_ImmediateUnequip"); InspectorUtility.DrawField(target, "m_ReequipSlots"); if (itemAbilityMoveTowards && InspectorUtility.GetFieldValue <bool>(target, "m_ReequipSlots")) { InspectorUtility.SetFieldValue(target, "m_ReequipSlots", false); GUI.changed = true; } EditorGUI.indentLevel--; } } GUI.enabled = true; EditorGUI.indentLevel--; } if (InspectorUtility.Foldout(target, "UI")) { EditorGUI.indentLevel++; InspectorUtility.DrawField(target, "m_AbilityMessageText"); InspectorUtility.DrawField(target, "m_AbilityMessageIcon"); EditorGUI.indentLevel--; } }
/// <summary> /// Draws the fields related to the inspector drawer. /// </summary> /// <param name="target">The object that is being drawn.</param> /// <param name="parent">The Unity Object that the object belongs to.</param> protected override void DrawInspectorDrawerFields(object target, Object parent) { Shared.Editor.Inspectors.Utility.ObjectInspector.DrawFields(target, true); var shakeTarget = (Shake.ShakeTarget)EditorGUILayout.EnumFlagsField(new GUIContent("Shake Target", InspectorUtility.GetFieldTooltip(target, "m_Target")), InspectorUtility.GetFieldValue <Shake.ShakeTarget>(target, "m_Target")); InspectorUtility.SetFieldValue(target, "m_Target", shakeTarget); }
/// <summary> /// Initialize the manager after deserialization. /// </summary> public override void Initialize(MainManagerWindow mainManagerWindow) { base.Initialize(mainManagerWindow); // Set the default perspective based on what asset is installed. if (m_Perspective == Perspective.None) { #if FIRST_PERSON_CONTROLLER m_Perspective = Perspective.First; #elif THIRD_PERSON_CONTROLLER m_Perspective = Perspective.Third; #endif } // Get a list of the available view types. var assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; ++i) { var assemblyTypes = assemblies[i].GetTypes(); for (int j = 0; j < assemblyTypes.Length; ++j) { // Must derive from ViewType. if (!typeof(Camera.ViewTypes.ViewType).IsAssignableFrom(assemblyTypes[j])) { continue; } // Ignore abstract classes. if (assemblyTypes[j].IsAbstract) { continue; } if (assemblyTypes[j].FullName.Contains("FirstPersonController")) { m_FirstPersonViewTypes.Add(assemblyTypes[j]); } else if (assemblyTypes[j].FullName.Contains("ThirdPersonController")) { m_ThirdPersonViewTypes.Add(assemblyTypes[j]); } } } // Create an array of display names for the popup. if (m_FirstPersonViewTypes.Count > 0) { m_FirstPersonViewTypeStrings = new string[m_FirstPersonViewTypes.Count]; for (int i = 0; i < m_FirstPersonViewTypes.Count; ++i) { m_FirstPersonViewTypeStrings[i] = InspectorUtility.DisplayTypeName(m_FirstPersonViewTypes[i], true); } } if (m_ThirdPersonViewTypes.Count > 0) { m_ThirdPersonViewTypeStrings = new string[m_ThirdPersonViewTypes.Count]; for (int i = 0; i < m_ThirdPersonViewTypes.Count; ++i) { m_ThirdPersonViewTypeStrings[i] = InspectorUtility.DisplayTypeName(m_ThirdPersonViewTypes[i], true); } } // Find the state configuration. var stateConfiguration = ManagerUtility.FindStateConfiguration(m_MainManagerWindow); if (stateConfiguration != null) { if (m_StateConfiguration == null) { m_StateConfiguration = stateConfiguration; } } }
/// <summary> /// Removes the objects specified by the object references object. /// </summary> private static void ProcessObjectReferences(ObjectReferences objectReferences, bool fromScene) { if (objectReferences == null) { return; } RemoveObjects(objectReferences.RemoveObjects); objectReferences.RemoveObjects = null; #if !FIRST_PERSON_CONTROLLER RemoveObjects(objectReferences.FirstPersonObjects); objectReferences.FirstPersonObjects = null; #endif #if !THIRD_PERSON_CONTROLLER RemoveObjects(objectReferences.ThirdPersonObjects); objectReferences.ThirdPersonObjects = null; #endif #if !ULTIMATE_CHARACTER_CONTROLLER_SHOOTER RemoveObjects(objectReferences.ShooterObjects); objectReferences.ShooterObjects = null; #endif #if !ULTIMATE_CHARACTER_CONTROLLER_MELEE RemoveObjects(objectReferences.MeleeObjects); objectReferences.MeleeObjects = null; #endif #if !FIRST_PERSON_CONTROLLER || !THIRD_PERSON_CONTROLLER // Remove any view types and states that are no longer valid. Opsive.UltimateCharacterController.Camera.CameraController cameraController; if (fromScene) { cameraController = GameObject.FindObjectOfType <UltimateCharacterController.Camera.CameraController>(); } else { cameraController = objectReferences.GetComponent <UltimateCharacterController.Camera.CameraController>(); } if (cameraController != null) { cameraController.DeserializeViewTypes(); var viewTypes = new List <ViewType>(cameraController.ViewTypes); for (int i = viewTypes.Count - 1; i > -1; --i) { if (viewTypes[i] == null) { viewTypes.RemoveAt(i); continue; } viewTypes[i].States = RemoveUnusedStates(viewTypes[i].States); } cameraController.ViewTypeData = Serialization.Serialize <ViewType>(viewTypes); cameraController.ViewTypes = viewTypes.ToArray(); InspectorUtility.SetDirty(cameraController); } // Remove any movement types and states that are no longer valid. Character.UltimateCharacterLocomotion characterLocomotion; if (fromScene) { characterLocomotion = GameObject.FindObjectOfType <Character.UltimateCharacterLocomotion>(); } else { characterLocomotion = objectReferences.GetComponent <Character.UltimateCharacterLocomotion>(); } if (characterLocomotion != null) { characterLocomotion.DeserializeMovementTypes(); var movementTypes = new List <MovementType>(characterLocomotion.MovementTypes); for (int i = movementTypes.Count - 1; i > -1; --i) { if (movementTypes[i] == null) { movementTypes.RemoveAt(i); continue; } movementTypes[i].States = RemoveUnusedStates(movementTypes[i].States); } characterLocomotion.MovementTypeData = Serialization.Serialize <MovementType>(movementTypes); characterLocomotion.MovementTypes = movementTypes.ToArray(); #if FIRST_PERSON_CONTROLLER characterLocomotion.SetMovementType(UltimateCharacterController.Utility.UnityEngineUtility.GetType(characterLocomotion.FirstPersonMovementTypeFullName)); #else characterLocomotion.SetMovementType(UltimateCharacterController.Utility.UnityEngineUtility.GetType(characterLocomotion.ThirdPersonMovementTypeFullName)); #endif // Ensure the animator is pointing to the correct reference. var animator = characterLocomotion.GetComponent <Animator>(); if (animator != null && animator.runtimeAnimatorController == null) { animator.runtimeAnimatorController = ManagerUtility.FindAnimatorController(null); InspectorUtility.SetDirty(animator); } // Check for unused ability states. var abilities = new List <Ability>(characterLocomotion.GetSerializedAbilities()); for (int i = abilities.Count - 1; i > -1; --i) { if (abilities[i] == null) { abilities.RemoveAt(i); continue; } abilities[i].States = RemoveUnusedStates(abilities[i].States); } characterLocomotion.AbilityData = Serialization.Serialize <Ability>(abilities); characterLocomotion.Abilities = abilities.ToArray(); // Check for unused item ability states. var itemAbilities = new List <ItemAbility>(characterLocomotion.GetSerializedItemAbilities()); for (int i = itemAbilities.Count - 1; i > -1; --i) { if (itemAbilities[i] == null) { itemAbilities.RemoveAt(i); continue; } itemAbilities[i].States = RemoveUnusedStates(itemAbilities[i].States); } characterLocomotion.ItemAbilityData = Serialization.Serialize <ItemAbility>(itemAbilities); characterLocomotion.ItemAbilities = itemAbilities.ToArray(); InspectorUtility.SetDirty(characterLocomotion); // Update the inventory. var inventory = characterLocomotion.GetComponent <Inventory.Inventory>(); if (inventory != null) { var loadout = new List <Inventory.ItemDefinitionAmount>(inventory.DefaultLoadout); for (int i = loadout.Count - 1; i > -1; --i) { if (loadout[i].ItemDefinition == null) { loadout.RemoveAt(i); } } inventory.DefaultLoadout = loadout.ToArray(); InspectorUtility.SetDirty(inventory); } var itemSetManager = characterLocomotion.GetComponent <Inventory.ItemSetManager>(); if (itemSetManager != null) { var categoryItemSets = itemSetManager.CategoryItemSets; for (int i = 0; i < categoryItemSets.Length; ++i) { for (int j = categoryItemSets[i].ItemSetList.Count - 1; j > -1; --j) { var nullItemIdentifier = true; for (int k = 0; k < categoryItemSets[i].ItemSetList[j].Slots.Length; ++k) { if (categoryItemSets[i].ItemSetList[j].Slots[k] != null) { nullItemIdentifier = false; break; } } if (nullItemIdentifier) { categoryItemSets[i].ItemSetList.RemoveAt(j); } } } ; InspectorUtility.SetDirty(itemSetManager); } } #if !THIRD_PERSON_CONTROLLER // Set the shadow caster for the first person only objects. var shadowCaster = ManagerUtility.FindInvisibleShadowCaster(null); if (shadowCaster != null) { for (int i = 0; i < objectReferences.ShadowCasterObjects.Length; ++i) { if (objectReferences.ShadowCasterObjects[i] == null) { continue; } var renderers = objectReferences.ShadowCasterObjects[i].GetComponentsInChildren <Renderer>(); for (int j = 0; j < renderers.Length; ++j) { var materials = renderers[j].sharedMaterials; for (int k = 0; k < materials.Length; ++k) { materials[k] = shadowCaster; } renderers[j].sharedMaterials = materials; InspectorUtility.SetDirty(renderers[j]); } } } #endif var items = objectReferences.GetComponentsInChildren <Items.Item>(); for (int i = 0; i < items.Length; ++i) { CheckItem(items[i].gameObject); } // Ensure all of the states point to a preset StateBehavior[] stateBehaviors; if (fromScene) { stateBehaviors = GameObject.FindObjectsOfType <StateBehavior>(); } else { stateBehaviors = objectReferences.GetComponentsInChildren <StateBehavior>(true); } if (stateBehaviors != null) { for (int i = 0; i < stateBehaviors.Length; ++i) { stateBehaviors[i].States = RemoveUnusedStates(stateBehaviors[i].States); InspectorUtility.SetDirty(stateBehaviors[i]); } } #endif // Some doors should be locked. #if !FIRST_PERSON_CONTROLLER LockDoors(objectReferences.FirstPersonDoors); #endif #if !THIRD_PERSON_CONTROLLER LockDoors(objectReferences.ThirdPersonDoors); #endif for (int i = 0; i < objectReferences.NestedReferences.Length; ++i) { var nestedObject = objectReferences.NestedReferences[i]; if (nestedObject == null) { continue; } GameObject nestedRoot = null; if (PrefabUtility.IsPartOfPrefabAsset(nestedObject)) { nestedRoot = PrefabUtility.LoadPrefabContents(AssetDatabase.GetAssetPath(objectReferences.NestedReferences[i])); nestedObject = nestedRoot.GetComponent <ObjectReferences>(); } ProcessObjectReferences(nestedObject, false); if (nestedRoot != null) { PrefabUtility.SaveAsPrefabAsset(nestedRoot, AssetDatabase.GetAssetPath(objectReferences.NestedReferences[i])); PrefabUtility.UnloadPrefabContents(nestedRoot); } } UnpackPrefab(objectReferences); Object.DestroyImmediate(objectReferences, true); }