/// <summary>
        /// Randomizes the scale
        /// </summary>
        protected virtual void ProcessRandomizeScale()
        {
            if (!RandomizeScale)
            {
                return;
            }
            Vector3 randomScale = MMMaths.RandomVector3(MinRandomScale, MaxRandomScale);

            this.transform.localScale = randomScale;
        }
        /// <summary>
        /// Randomizes the position
        /// </summary>
        protected virtual void ProcessRandomizePosition()
        {
            if (!RandomizePosition)
            {
                return;
            }
            Vector3 randomPosition = MMMaths.RandomVector3(MinRandomPosition, MaxRandomPosition);

            this.transform.localPosition += randomPosition;
        }
        /// <summary>
        /// Randomizes the rotation
        /// </summary>
        protected virtual void ProcessRandomizeRotation()
        {
            if (!RandomizeRotation)
            {
                return;
            }
            Vector3 randomRotation = MMMaths.RandomVector3(MinRandomRotation, MaxRandomRotation);

            this.transform.localRotation = Quaternion.Euler(randomRotation);
        }
        /// <summary>
        /// Spawns a random object from the pool of choices
        /// </summary>
        public virtual void InstantiateRandomObject()
        {
            // if the pool is empty we do nothing and exit
            if (RandomPool.Count == 0)
            {
                return;
            }

            // pick a random object and instantiates it
            int        randomIndex = Random.Range(0, RandomPool.Count);
            GameObject obj         = Instantiate(RandomPool[randomIndex], this.transform.position, this.transform.rotation);

            SceneManager.MoveGameObjectToScene(obj.gameObject, this.gameObject.scene);

            // we pick a random point within the bounds then move it to account for rotation/scale
            obj.transform.position = MMBoundsExtensions.MMRandomPointInBounds(_collider.bounds);
            obj.transform.position = _collider.ClosestPoint(obj.transform.position);

            // we name and parent our object
            obj.name = InstantiatedObjectName;
            if (ParentInstantiatedToThisObject)
            {
                obj.transform.SetParent(this.transform);
            }

            // we rescale the object
            switch (ScaleMode)
            {
            case ScaleModes.Uniform:
                float newScale = Random.Range(MinScale, MaxScale);
                obj.transform.localScale = Vector3.one * newScale;
                break;

            case ScaleModes.Vector3:
                _newScale = MMMaths.RandomVector3(MinVectorScale, MaxVectorScale);
                obj.transform.localScale = _newScale;
                break;
            }

            // we add it to our list
            _instantiatedGameObjects.Add(obj);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Spawns a new floating text
        /// </summary>
        /// <param name="value"></param>
        /// <param name="position"></param>
        /// <param name="direction"></param>
        /// <param name="intensity"></param>
        /// <param name="forceLifetime"></param>
        /// <param name="lifetime"></param>
        /// <param name="forceColor"></param>
        /// <param name="animateColorGradient"></param>
        protected virtual void Spawn(string value, Vector3 position, Vector3 direction, float intensity = 1f,
                                     bool forceLifetime = false, float lifetime = 1f, bool forceColor = false, Gradient animateColorGradient = null)
        {
            if (!CanSpawn)
            {
                return;
            }

            _direction = (direction != Vector3.zero) ? direction + this.transform.up : this.transform.up;

            this.transform.position = position;

            GameObject nextGameObject = _pooler.GetPooledGameObject();

            float lifetimeMultiplier = IntensityImpactsLifetime ? intensity * IntensityLifetimeMultiplier : 1f;
            float movementMultiplier = IntensityImpactsMovement ? intensity * IntensityMovementMultiplier : 1f;
            float scaleMultiplier    = IntensityImpactsScale ? intensity * IntensityScaleMultiplier : 1f;

            _lifetime      = UnityEngine.Random.Range(Lifetime.x, Lifetime.y) * lifetimeMultiplier;
            _spawnOffset   = MMMaths.RandomVector3(SpawnOffsetMin, SpawnOffsetMax);
            _animateColor  = AnimateColor;
            _colorGradient = AnimateColorGradient;

            float remapXZero       = UnityEngine.Random.Range(RemapXZero.x, RemapXZero.y);
            float remapXOne        = UnityEngine.Random.Range(RemapXOne.x, RemapXOne.y) * movementMultiplier;
            float remapYZero       = UnityEngine.Random.Range(RemapYZero.x, RemapYZero.y);
            float remapYOne        = UnityEngine.Random.Range(RemapYOne.x, RemapYOne.y) * movementMultiplier;
            float remapZZero       = UnityEngine.Random.Range(RemapZZero.x, RemapZZero.y);
            float remapZOne        = UnityEngine.Random.Range(RemapZOne.x, RemapZOne.y) * movementMultiplier;
            float remapOpacityZero = UnityEngine.Random.Range(RemapOpacityZero.x, RemapOpacityZero.y);
            float remapOpacityOne  = UnityEngine.Random.Range(RemapOpacityOne.x, RemapOpacityOne.y);
            float remapScaleZero   = UnityEngine.Random.Range(RemapScaleZero.x, RemapOpacityZero.y);
            float remapScaleOne    = UnityEngine.Random.Range(RemapScaleOne.x, RemapScaleOne.y) * scaleMultiplier;

            if (forceLifetime)
            {
                _lifetime = lifetime;
            }

            if (forceColor)
            {
                _animateColor  = true;
                _colorGradient = animateColorGradient;
            }

            // mandatory checks
            if (nextGameObject == null)
            {
                return;
            }

            // we activate the object
            nextGameObject.gameObject.SetActive(true);
            nextGameObject.gameObject.MMGetComponentNoAlloc <MMPoolableObject>().TriggerOnSpawnComplete();

            // we position the object
            nextGameObject.transform.position = this.transform.position + _spawnOffset;

            _floatingText = nextGameObject.MMGetComponentNoAlloc <MMFloatingText>();
            _floatingText.ResetPosition();
            _floatingText.SetProperties(value, _lifetime, _direction, AnimateMovement,
                                        AlignmentMode, FixedAlignment, AlwaysFaceCamera, TargetCamera,
                                        AnimateX, AnimateXCurve, remapXZero, remapXOne,
                                        AnimateY, AnimateYCurve, remapYZero, remapYOne,
                                        AnimateZ, AnimateZCurve, remapZZero, remapZOne,
                                        AnimateOpacity, AnimateOpacityCurve, remapOpacityZero, remapOpacityOne,
                                        AnimateScale, AnimateScaleCurve, remapScaleZero, remapScaleOne,
                                        _animateColor, _colorGradient);
        }
Ejemplo n.º 6
0
        protected virtual void RandomizeScale()
        {
            Vector3 randomScale = MMMaths.RandomVector3(MinRandomScale, MaxRandomScale);

            this.transform.localScale = randomScale;
        }
Ejemplo n.º 7
0
        protected virtual void RandomizeRotation()
        {
            Vector3 randomRotation = MMMaths.RandomVector3(MinRandomRotation, MaxRandomRotation);

            this.transform.localRotation = Quaternion.Euler(randomRotation);
        }
Ejemplo n.º 8
0
        protected virtual void RandomizePosition()
        {
            Vector3 randomPosition = MMMaths.RandomVector3(MinRandomPosition, MaxRandomPosition);

            this.transform.localPosition += randomPosition;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Returns the rotation at which the object should spawn
 /// </summary>
 /// <param name="props"></param>
 /// <returns></returns>
 public static Quaternion SpawnAroundRotation(MMSpawnAroundProperties props)
 {
     return(Quaternion.Euler(MMMaths.RandomVector3(props.MinimumRotation, props.MaximumRotation)));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Returns the scale at which the object should spawn
 /// </summary>
 /// <param name="props"></param>
 /// <returns></returns>
 public static Vector3 SpawnAroundScale(MMSpawnAroundProperties props)
 {
     return(MMMaths.RandomVector3(props.MinimumScale, props.MaximumScale));
 }