Пример #1
0
        /// <summary>
        /// Called when the core has finished running and is released
        /// </summary>
        /// <param name="rCore">The life core that raised the event</param>
        /// <param name="rUserData">User data returned</param>
        private void OnCoreReleased(ILifeCore rCore, object rUserData = null)
        {
            if (mProjectileCore != null)
            {
                mProjectileCore.Owner           = null;
                mProjectileCore.OnReleasedEvent = null;
                mProjectileCore.OnImpactEvent   = null;
                mProjectileCore.OnExpiredEvent  = null;
                mProjectileCore = null;
            }

            base.Deactivate();
        }
Пример #2
0
 /// <summary>
 /// Called when the object is selected in the editor
 /// </summary>
 private void OnEnable()
 {
     // Grab the serialized objects
     mTarget   = (ProjectileCore)target;
     mTargetSO = new SerializedObject(target);
 }
Пример #3
0
        /// <summary>
        /// Called when the action is first activated
        /// <param name="rPreviousSpellActionState">State of the action prior to this one activating</param>
        public override void Activate(int rPreviousSpellActionState = -1, object rData = null)
        {
            base.Activate(rPreviousSpellActionState, rData);

            if (mInstances != null && mInstances.Count > 0)
            {
                if (_Spell.ShowDebug)
                {
                    for (int i = 0; i < mInstances.Count; i++)
                    {
                        mInstances[i].hideFlags = HideFlags.None;
                    }
                }

                // Set the basics
                mInstances[0].transform.parent = null;

                // Now we want to launch the projectile
                mProjectileCore = mInstances[0].GetComponent <ProjectileCore>();
                if (mProjectileCore != null)
                {
                    mProjectileCore.Prefab             = _Prefab;
                    mProjectileCore.Owner              = _Spell.Owner;
                    mProjectileCore.Speed              = Speed;
                    mProjectileCore.MaxAge             = MaxAge;
                    mProjectileCore.MinRange           = MinDistance;
                    mProjectileCore.MaxRange           = MaxDistance;
                    mProjectileCore.transform.rotation = Spell.Owner.transform.rotation;
                    mProjectileCore.OnReleasedEvent    = OnCoreReleased;
                    mProjectileCore.OnImpactEvent      = OnImpact;
                    mProjectileCore.OnExpiredEvent     = OnExpired;
                    mProjectileCore.Launch(_HorizontalAngle, _VerticalAngle);

                    mProjectileCore.IsHoming = IsHoming;
                    if (mProjectileCore.IsHoming)
                    {
                        GameObject lTarget = GetBestTarget(1, rData, _Spell.Data);
                        if (lTarget != null)
                        {
                            mProjectileCore.Target       = lTarget.transform;
                            mProjectileCore.TargetOffset = TargetOffset;
                        }
                    }
                }

                // Determine how we release the spell
                if (_Spell.ReleaseFromCamera && Camera.main != null)
                {
                    Transform lTransform = Camera.main.transform;

                    mInstances[0].transform.position = lTransform.position + (lTransform.forward * _Spell.ReleaseDistance);
                    mInstances[0].transform.rotation = lTransform.rotation;

                    // Apply any rotation adjustment
                    Quaternion lRotation = Quaternion.AngleAxis(_HorizontalAngle, lTransform.up) * Quaternion.AngleAxis(_VerticalAngle, lTransform.right);
                    mInstances[0].transform.rotation = lRotation * lTransform.rotation;
                }
                else if (ReleaseFromCamera && Camera.main != null)
                {
                    Transform lTransform = Camera.main.transform;

                    mInstances[0].transform.position = lTransform.position + (lTransform.forward * _ReleaseDistance);
                    mInstances[0].transform.rotation = lTransform.rotation;

                    // Apply any rotation adjustment
                    Quaternion lRotation = Quaternion.AngleAxis(_HorizontalAngle, lTransform.up) * Quaternion.AngleAxis(_VerticalAngle, lTransform.right);
                    mInstances[0].transform.rotation = lRotation * lTransform.rotation;
                }
                else if (ReleaseFromCameraForward && Camera.main != null)
                {
                    Transform lTransform = Camera.main.transform;

                    // Apply any rotation adjustment
                    Quaternion lRotation = Quaternion.AngleAxis(_HorizontalAngle, lTransform.up) * Quaternion.AngleAxis(_VerticalAngle, lTransform.right);
                    mInstances[0].transform.rotation = lRotation * lTransform.rotation;
                }
            }
            else
            {
                Deactivate();
            }

            // Determine if we're returnning immediately
            if (_DeactivationIndex == EnumSpellActionDeactivation.IMMEDIATELY)
            {
                mIsShuttingDown = true;
                State           = EnumSpellActionState.SUCCEEDED;
            }
        }