예제 #1
0
            /// <summary>
            /// Initializes the object.
            /// </summary>
            /// <param name="characterLocomotion">The character that is being managed by the KinematicObjectManager.</param>
            public void Initialize(UltimateCharacterLocomotion characterLocomotion)
            {
                m_CharacterLocomotion = characterLocomotion;

                OnAttachLookSource(m_CharacterLocomotion.LookSource);
                EventHandler.RegisterEvent <ILookSource>(m_CharacterLocomotion.gameObject, "OnCharacterAttachLookSource", OnAttachLookSource);
                EventHandler.RegisterEvent <bool>(m_CharacterLocomotion.gameObject, "OnCharacterChangeUpdateLocation", OnChangeUpdateLocation);

                // The class is pooled so reset any variables.
                m_HorizontalMovement = m_ForwardMovement = m_DeltaYawRotation = 0;
                Initialize(characterLocomotion.transform);

                m_CharacterHandler = m_CharacterLocomotion.GetComponent <UltimateCharacterLocomotionHandler>();
                m_CharacterIK      = m_CharacterLocomotion.GetComponent <CharacterIKBase>();

                // Wait a moment before finishing with the initialization. This allows the character to be created at runtime.
                m_CompleteInitEvent = Scheduler.ScheduleFixed(Time.fixedDeltaTime / 2, () => {
                    if (m_CharacterHandler == null)
                    {
                        m_CharacterHandler = m_CharacterLocomotion.GetComponent <UltimateCharacterLocomotionHandler>();
                    }
                    if (m_CharacterIK == null)
                    {
                        m_CharacterIK = m_CharacterLocomotion.GetComponent <CharacterIKBase>();
                    }

                    var smoothedBones = m_CharacterLocomotion.SmoothedBones;
                    if (smoothedBones != null && smoothedBones.Length > 0)
                    {
                        var validBones = 0;
                        for (int i = 0; i < smoothedBones.Length; ++i)
                        {
                            if (smoothedBones[i] != null)
                            {
                                validBones++;
                            }
                        }
                        if (validBones > 0)
                        {
                            m_SmoothedBones = new SmoothFixedLocation[validBones];
                            var index       = 0;
                            for (int i = 0; i < smoothedBones.Length; ++i)
                            {
                                if (smoothedBones[i] == null)
                                {
                                    continue;
                                }
                                m_SmoothedBones[index] = GenericObjectPool.Get <SmoothFixedLocation>();
                                m_SmoothedBones[index].Initialize(smoothedBones[i]);
                                index++;
                            }
                        }
                    }
                    m_CompleteInitEvent = null;
                });
            }
예제 #2
0
 /// <summary>
 /// Finds an UltimateCharacterLocomotion and its Inventory and ItemCollection by GameObject name.
 /// If the name is blank, finds the GameObject tagged 'Player'.
 /// </summary>
 public static bool FindCharacterWithInventory(string characterName, out UltimateCharacterLocomotion character, out InventoryBase inventory, out ItemCollection itemCollection)
 {
     inventory      = null;
     itemCollection = null;
     character      = FindCharacter(characterName);
     if (character != null)
     {
         inventory      = character.GetComponent <InventoryBase>();
         itemCollection = UCCUtility.FindItemCollection(character.gameObject);
         if (inventory == null)
         {
             if (DialogueDebug.logWarnings)
             {
                 Debug.LogWarning("Dialogue System: Character '" + character.name + "' doesn't have an Inventory.", character);
             }
         }
         else if (itemCollection == null)
         {
             if (DialogueDebug.logWarnings)
             {
                 Debug.LogWarning("Dialogue System: Character '" + character.name + "' doesn't have access to an Item Set Manager or Item Collection.", character);
             }
         }
     }
     return(character != null && inventory != null && itemCollection != null);
 }