Exemplo n.º 1
0
        /// <summary>
        /// Searches for an adds any Effects available in the project.
        /// </summary>
        private static void PopulateAbilityStarterTypes()
        {
            if (s_AbilityStarterTypeCache != null)
            {
                return;
            }

            s_AbilityStarterTypeCache = new List <System.Type>();
            s_AbilityStarterTypeName  = new List <string>();
            var assemblies = System.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 AbilityStarter.
                    if (!typeof(AbilityStarter).IsAssignableFrom(assemblyTypes[j]))
                    {
                        continue;
                    }

                    // Ignore abstract classes.
                    if (assemblyTypes[j].IsAbstract)
                    {
                        continue;
                    }

                    s_AbilityStarterTypeCache.Add(assemblyTypes[j]);
                    s_AbilityStarterTypeName.Add(InspectorUtility.DisplayTypeName(assemblyTypes[j], false));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws all of the added view types.
        /// </summary>
        private void OnViewTypeListDraw(Rect rect, int index, bool isActive, bool isFocused)
        {
            // The index may be out of range if the component was copied.
            if (index >= m_CameraController.ViewTypes.Length)
            {
                m_ReorderableViewTypeList.index = -1;
                EditorPrefs.SetInt(SelectedViewTypeIndexKey, m_ReorderableViewTypeList.index);
                return;
            }

            var viewType = m_CameraController.ViewTypes[index];

            if (viewType == null)
            {
                var viewTypes = new List <ViewType>(m_CameraController.ViewTypes);
                viewTypes.RemoveAt(index);
                m_CameraController.ViewTypes = viewTypes.ToArray();
                SerializeViewTypes();
                return;
            }
            var label = InspectorUtility.DisplayTypeName(viewType.GetType(), true);

            // Reduce the rect width so the active toggle can be added.
            var activeRect = rect;

            activeRect.width -= 20;
            EditorGUI.LabelField(activeRect, label);

            // Draw the active toggle and serialize if there is a change.
            if (!(m_CameraController.ViewTypes[index] is UltimateCharacterController.Camera.ViewTypes.Transition))
            {
                EditorGUI.BeginChangeCheck();
                activeRect       = rect;
                activeRect.x    += activeRect.width - 32;
                activeRect.width = 20;
                EditorGUI.Toggle(activeRect, m_CameraController.ViewTypeFullName == viewType.GetType().FullName, EditorStyles.radioButton);
                if (EditorGUI.EndChangeCheck())
                {
                    m_CameraController.ViewTypeFullName = PropertyFromName("m_ViewTypeFullName").stringValue = viewType.GetType().FullName;
                    if (m_CameraController.ViewTypes[index].FirstPersonPerspective)
                    {
                        m_CameraController.FirstPersonViewTypeFullName = PropertyFromName("m_FirstPersonViewTypeFullName").stringValue = m_CameraController.ViewTypeFullName;
                    }
                    else
                    {
                        m_CameraController.ThirdPersonViewTypeFullName = PropertyFromName("m_ThirdPersonViewTypeFullName").stringValue = m_CameraController.ViewTypeFullName;
                    }
                    serializedObject.ApplyModifiedProperties();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the default first/third view type based on the view types availabe on the camera controller.
        /// </summary>
        private void UpdateDefaultViewTypes()
        {
            // The view type may not exist anymore.
            if (Shared.Utility.TypeUtility.GetType(m_CameraController.FirstPersonViewTypeFullName) == null)
            {
                m_CameraController.FirstPersonViewTypeFullName = string.Empty;
                Shared.Editor.Utility.EditorUtility.SetDirty(target);
            }
            if (Shared.Utility.TypeUtility.GetType(m_CameraController.ThirdPersonViewTypeFullName) == null)
            {
                m_CameraController.ThirdPersonViewTypeFullName = string.Empty;
                Shared.Editor.Utility.EditorUtility.SetDirty(target);
            }

            var hasSelectedViewType      = false;
            var firstPersonViewTypes     = new List <Type>();
            var thirdPersonViewTypes     = new List <Type>();
            var firstPersonViewTypeNames = new List <string>();
            var thirdPersonViewTypeNames = new List <string>();
            var viewTypes = m_CameraController.ViewTypes;

            if (viewTypes != null)
            {
                for (int i = 0; i < viewTypes.Length; ++i)
                {
                    if (viewTypes[i] == null)
                    {
                        continue;
                    }
                    // Transition view types are not limited to one perspective.
                    if (viewTypes[i] is UltimateCharacterController.Camera.ViewTypes.Transition)
                    {
                        continue;
                    }
                    if (viewTypes[i].FirstPersonPerspective)
                    {
                        // Use the view type if the type is currently empty.
                        if (string.IsNullOrEmpty(m_CameraController.FirstPersonViewTypeFullName))
                        {
                            m_CameraController.FirstPersonViewTypeFullName = viewTypes[i].GetType().FullName;
                        }
                        firstPersonViewTypes.Add(viewTypes[i].GetType());
                        firstPersonViewTypeNames.Add(InspectorUtility.DisplayTypeName(viewTypes[i].GetType(), false));
                    }
                    else     // Third Person.
                    // Use the view type if the type is currently empty.
                    {
                        if (string.IsNullOrEmpty(m_CameraController.ThirdPersonViewTypeFullName))
                        {
                            m_CameraController.ThirdPersonViewTypeFullName = viewTypes[i].GetType().FullName;
                        }
                        thirdPersonViewTypes.Add(viewTypes[i].GetType());
                        thirdPersonViewTypeNames.Add(InspectorUtility.DisplayTypeName(viewTypes[i].GetType(), false));
                    }

                    if (m_CameraController.ViewTypeFullName == viewTypes[i].GetType().FullName)
                    {
                        hasSelectedViewType = true;
                    }
                }
            }
            m_FirstPersonViewTypes     = firstPersonViewTypes.ToArray();
            m_ThirdPersonViewTypes     = thirdPersonViewTypes.ToArray();
            m_FirstPersonViewTypeNames = firstPersonViewTypeNames.ToArray();
            m_ThirdPersonViewTypeNames = thirdPersonViewTypeNames.ToArray();

            // If the selected ViewType no longer exists in the list then select the next view type.
            if (!hasSelectedViewType)
            {
                m_CameraController.ViewTypeFullName = string.Empty;
                if (viewTypes != null && viewTypes.Length > 0)
                {
                    for (int i = 0; i < viewTypes.Length; ++i)
                    {
                        // Transition ViewTypes cannot be selected.
                        if (viewTypes[i] is UltimateCharacterController.Camera.ViewTypes.Transition)
                        {
                            continue;
                        }

                        m_CameraController.ViewTypeFullName = viewTypes[i].GetType().FullName;
                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <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)
            {
                try {
                    var assemblyTypes = assemblies[i].GetTypes();
                    for (int j = 0; j < assemblyTypes.Length; ++j)
                    {
                        // Must derive from ViewType.
                        if (!typeof(UltimateCharacterController.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]);
                        }
                    }
                } catch (Exception) {
                    continue;
                }
            }

            // 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;
                }
            }
        }
Exemplo n.º 5
0
        /// <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--;
        }