Пример #1
0
 /// <summary>
 /// Default values
 /// </summary>
 public virtual void New()
 {
     if (!bInitialised)
     {
         bInitialised                     = true;
         DestructionTimeOut               = 2;
         PhysicsForceOptions              = new PhysicsOptions();
         PhysicsForceOptions.Radius       = 10f;
         PhysicsForceOptions.Force        = 20f;
         PhysicsForceOptions.UpwardsForce = 3f;
         PhysicsForceOptions.Mode         = ForceMode.Force;
         RandomSphere                     = new RandomSphereOptions();
         RandomSphere.IncludeX            = true;
         RandomSphere.IncludeY            = true;
         RandomSphere.IncludeZ            = true;
         RandomRotate                     = new RandomRotateOptions();
     }
 }
Пример #2
0
        /// <summary>
        /// Apply the spawn settings to the instantiated game object
        /// </summary>
        /// <param name="Instance"></param>
        /// <param name="PhysicsInstance"></param>
        protected void SetSpawnOptions(ref GameObject Instance, PhysicsOptions PhysicsInstance)
        {
            Instance.SetActive(false);                                                                         // ensure not active
            if (!KeepParent)                                                                                   // some spells such as teleport DO NOT want this setting
            {
                Instance.transform.parent = null;                                                              // clear
            }
            if (Offset != Vector3.zero)                                                                        // offset needed?
            {
                Instance.transform.position = Instance.transform.position + Offset;                            // add in the offset
            }
            if (Angle != Vector3.zero)                                                                         // angular offset needed?
            {
                Instance.transform.localRotation = Quaternion.Euler(Angle) * Instance.transform.localRotation; // alter the angle
            }
            RandomSphere.Apply(ref Instance);                                                                  // spawn randomly within sphere radius?
            RandomRotate.Apply(ref Instance);                                                                  // apply random rotation to the enabled axis's
            PhysicsInstance.Apply(Instance, Target);                                                           // explode with force?
            if (CheckSpaceIsEmpty(Instance))                                                                   // spawned within an empty space checked ok?
            {
                if (DestructionTimeOut > 0)                                                                    // max length of instance enabled
                {
                    if (GlobalFuncs.MAGICAL_POOL && !DoNotPool)                                                // pool enabled?
                    {
                        MagicPool_Return mr = Instance.GetComponent <MagicPool_Return>();                      // attempt get the pool return component
                        mr.Delay = DestructionTimeOut;                                                         // set the return to pool timeout
                    }
                    else
                    {
                        UnityEngine.Object.Destroy(Instance, DestructionTimeOut);  // set to destroy in 5,4,3...
                    }
                }
            }
            else  // space not empty
            {
                GlobalFuncs.ReturnToThePoolOrDestroy(PoolSlotId, Instance);  // send back to the pool (if enabled)
            }

            // all options set activate
            Instance.SetActive(true);
        }  // set the spawn options