Exemplo n.º 1
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_TrajectoryObject    = GetComponent <TrajectoryObject>();
            m_CharacterLocomotion = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();
            m_CharacterTransform  = m_CharacterLocomotion.transform;
#if ULTIMATE_CHARACTER_CONTROLLER_VR
            m_VRThrowableItem = GetComponent <IVRThrowableItem>();
#endif

            if (m_ThrownObject != null && m_TrajectoryObject != null)
            {
                // The object has to be instantiated for GetComponent to work.
                var instantiatedThrownObject = ObjectPool.Instantiate(m_ThrownObject);
                var trajectoryCollider       = instantiatedThrownObject.GetComponent <Collider>();
                if (trajectoryCollider != null)
                {
                    // Only sphere and capsules are supported.
                    if (trajectoryCollider is SphereCollider)
                    {
                        var trajectorySphereCollider = trajectoryCollider as SphereCollider;
                        var sphereCollider           = m_GameObject.AddComponent <SphereCollider>();
                        sphereCollider.center  = trajectorySphereCollider.center;
                        sphereCollider.radius  = trajectorySphereCollider.radius;
                        sphereCollider.enabled = false;
                    }
                    else if (trajectoryCollider is CapsuleCollider)
                    {
                        var trajectoryCapsuleCollider = trajectoryCollider as CapsuleCollider;
                        var capsuleCollider           = m_GameObject.AddComponent <CapsuleCollider>();
                        capsuleCollider.center    = trajectoryCapsuleCollider.center;
                        capsuleCollider.radius    = trajectoryCapsuleCollider.radius;
                        capsuleCollider.height    = trajectoryCapsuleCollider.height;
                        capsuleCollider.direction = trajectoryCapsuleCollider.direction;
                        capsuleCollider.enabled   = false;
                    }
                    else
                    {
                        Debug.LogError($"Error: The collider of type {trajectoryCollider.GetType()} is not supported on the trajectory object " + m_ThrownObject.name);
                    }
                    m_GameObject.layer = LayerManager.SubCharacter;
                }
                ObjectPool.Destroy(instantiatedThrownObject);
            }
            m_ThrowableItemPerpectiveProperties = m_ActivePerspectiveProperties as IThrowableItemPerspectiveProperties;

            if (m_ShowTrajectoryOnAim && m_TrajectoryObject == null)
            {
                Debug.LogError($"Error: A TrajectoryObject must be added to the {m_GameObject.name} GameObject in order for the trajectory to be shown.");
            }

            if (m_ThrownObject == null)
            {
                Debug.LogError($"Error: A ThrownObject must be assigned to the {m_GameObject.name} GameObject.");
            }

            EventHandler.RegisterEvent <bool, bool>(m_Character, "OnAimAbilityStart", OnAim);
            EventHandler.RegisterEvent(m_Character, "OnAnimatorReequipThrowableItem", ReequipThrowableItem);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts the item use.
        /// </summary>
        /// <param name="itemAbility">The item ability that is using the item.</param>
        public override void StartItemUse(ItemAbility itemAbility)
        {
            base.StartItemUse(itemAbility);

            // An Animator Audio State Set may prevent the item from being used.
            if (!IsItemInUse())
            {
                return;
            }

            if (!m_ThrowOnStopUse)
            {
                StartThrow();
            }

            // Instantiate the object that will actually be thrown.
            var location = m_ThrowableItemPerpectiveProperties.ThrowLocation;

            m_InstantiatedThrownObject = ObjectPool.Instantiate(m_ThrownObject, location.position, location.rotation, m_ObjectTransform.parent);
            m_InstantiatedThrownObject.transform.localScale = location.localScale;
            m_InstantiatedThrownObject.transform.SetLayerRecursively(m_StartLayer);
            m_InstantiatedTrajectoryObject = m_InstantiatedThrownObject.GetCachedComponent <TrajectoryObject>();
            if (m_InstantiatedTrajectoryObject == null)
            {
                Debug.LogError($"Error: {m_TrajectoryObject.name} must contain the TrajectoryObject component.");
                return;
            }
            if (m_InstantiatedTrajectoryObject is Destructible)
            {
                (m_InstantiatedTrajectoryObject as Destructible).InitializeDestructibleProperties(m_DamageAmount, m_ImpactForce, m_ImpactForceFrames,
                                                                                                  m_ImpactLayers, m_ImpactStateName, m_ImpactStateDisableTimer, m_SurfaceImpact);
            }
            // The trajectory object will be enabled when the object is thrown.
            m_InstantiatedTrajectoryObject.enabled = false;

            // Hide the object that isn't thrown.
            EnableObjectMeshRenderers(false);

            // The instantiated object may not immediately be visible.
            if (m_DisableVisibleObject)
            {
                m_InstantiatedThrownObject.SetActive(false);
                m_ActivateVisibleObject = false;
                m_Item.SetVisibleObjectActive(false, true);

                if (m_ActivateThrowableObjectEvent.WaitForAnimationEvent)
                {
                    EventHandler.RegisterEvent(m_Character, "OnAnimatorActivateThrowableObject", ActivateThrowableObject);
                }
                else
                {
                    Scheduler.ScheduleFixed(m_ActivateThrowableObjectEvent.Duration, ActivateThrowableObject);
                }
            }
        }
Exemplo n.º 3
0
 private static void ProcessExpiredEffect(TrajectoryObject trajectoryObj)
 {
     if (pool.Count < TRAJECTORY_POOL_SIZE)
     {
         pool.Add(trajectoryObj);
     }
     else
     {
         trajectoryObj.Destroy();
     }
 }
Exemplo n.º 4
0
    private static TrajectoryObject FetchFromPool()
    {
        if (pool.Count > 0)
        {
            TrajectoryObject last = pool[pool.Count - 1];
            pool.RemoveAt(pool.Count - 1);

            return(last);
        }

        return(null);
    }
Exemplo n.º 5
0
    public void Play()
    {
        if (trajectoryObj == null && !string.IsNullOrEmpty(data) && from != null && to != null && go != null)
        {
            var cfgLoader = ConfigManager.Get <TrajectoryCfgLoader>();
            cfgLoader.SetTempConfig(-1, new TrajectoryCfg()
            {
                ID = -1, Data = data
            });

            trajectoryObj = TrajectoryManager.Play(-1, from.position, to.position);
        }
    }
Exemplo n.º 6
0
    public static TrajectoryObject Play(int id, Vector3 from, Transform to, System.Action onReachTarget = null)
    {
        TrajectoryObject trajectoryObj = FetchTrajectoryObject(id);

        if (trajectoryObj == null)
        {
            return(null);
        }

        activeTrajectories.AddLast(trajectoryObj);

        trajectoryObj.Start(from, to, onReachTarget);

        return(trajectoryObj);
    }
Exemplo n.º 7
0
    void Update()
    {
        if (trajectoryObj != null)
        {
            trajectoryObj.AlignTransform(go.transform);

            if (trajectoryObj.Finished)
            {
                trajectoryObj.Stop();
                trajectoryObj = null;
                return;
            }
        }

        //if (Input.GetKeyDown(KeyCode.P))
        //{
        //    Play();
        //}
    }
Exemplo n.º 8
0
    private static TrajectoryObject FetchTrajectoryObject(int id)
    {
        TrajectoryCfg config = trajectoryConfigLoader.GetConfig(id);

        if (config == null)
        {
            Debug.LogErrorFormat("Failed to find config of trajectory {0}", id);
            return(null);
        }

        TrajectoryObject trajectoryObj = FetchFromPool();

        if (trajectoryObj == null)
        {
            trajectoryObj = CreateTrajectoryObject();
        }

        trajectoryObj.SetConfig(config);

        return(trajectoryObj);
    }
 /// <summary>
 /// The inspector has been enabled.
 /// </summary>
 protected virtual void OnEnable()
 {
     m_TrajectoryObject = target as TrajectoryObject;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_TrajectoryObject = gameObject.GetCachedComponent <TrajectoryObject>();
        }