public override void Enter() { // Search base on the map. var go = GameObject.Find("Base"); if (go != null) { // This action called if we don't see the base. // So try to find base select random position around // the base until we will found it. var basePos = go.transform.position; _targetPos = new Vector3( basePos.x + AntMath.RandomRangeFloat(-2.0f, 2.0f), basePos.y + AntMath.RandomRangeFloat(-2.0f, 2.0f), 0.0f ); // Calc target angle. _targetAngle = AntMath.AngleDeg(_t.position, _targetPos); _t.rotation = Quaternion.Euler(_t.rotation.x, _t.rotation.y, _targetAngle); _targetAngle *= Mathf.Deg2Rad; } else { Debug.Log("Base not found!"); Finish(); } }
public void Play() { _isPlaying = true; var pos = new Vector3( _transform.position.x + _positionOffset.x, _transform.position.y + _positionOffset.y, _transform.position.z ); _effect = AntEffectEngine.GetEffect(_settings.prefab.name, pos); _effect.EventComplete += EffectCompleteHandler; _effect.Angle = (_settings.isInheritAngle) ? _angle + _transform.rotation.eulerAngles.z : _angle; if (_settings.customDelay) { _effect.startDelay = _settings.delay + AntMath.RandomRangeFloat(_settings.rndToDelay); } if (_settings.customLifeTime) { _effect.isLooping = false; _effect.lifeTime = _settings.lifeTime + AntMath.RandomRangeFloat(_settings.rndToLifeTime); } _effect.Reset(); _effect.Play(); }
private void DropItem(ItemKind aKind, Vector3 aPosition) { GameObject go = null; switch (aKind) { case ItemKind.Bomb: go = GameObject.Instantiate((GameObject)_gameCore.bombItemPrefab); break; case ItemKind.Gun: go = GameObject.Instantiate((GameObject)_gameCore.gunItemPrefab); break; case ItemKind.Ammo: go = GameObject.Instantiate((GameObject)_gameCore.ammoItemPrefab); break; case ItemKind.Heal: go = GameObject.Instantiate((GameObject)_gameCore.healItemPrefab); break; } if (go != null) { float angle = AntMath.DegToRad(AntMath.RandomRangeFloat(-180, 180)); Vector2 force = new Vector2(); force.x = 0.5f * Mathf.Cos(angle); force.y = 0.5f * Mathf.Sin(angle); go.GetComponent <Transform>().position = aPosition; go.GetComponent <Rigidbody2D>().AddForce(force, ForceMode2D.Impulse); Engine.AddEntity(go.GetComponent <AntEntity>()); } }
public bool NewParticleIsReady() { if (_spawnInterval <= 0.0f) { _spawnInterval = _preset.spawnInterval + AntMath.RandomRangeFloat(_preset.rndToSpawnInterval); return(true); } return(false); }
public void Reset(AntEmitter aEmitter) { IsActive = true; _preset = Preset.trail; _startTime = _preset.startTime + AntMath.RandomRangeFloat(_preset.rndToStartTime); _trail.widthMultiplier = _preset.startWidth + AntMath.RandomRangeFloat(_preset.rndToStartWidth); _trail.widthCurve = _preset.widthCurve; _trail.colorGradient = _preset.gradient; _trail.Clear(); _needToInit = true; }
public void Reset(AntEmitter aEmitter) { _duration = Preset.lifeTime.duration; _duration += AntMath.RandomRangeFloat(Preset.lifeTime.rndToDuration); if (_duration <= 0.0f) { _duration = 0.1f; } _particle.LifeTime = _duration; IsActive = true; }
public void Reset(AntEmitter aEmitter) { var center = _transform.position; var spawn = Preset.position; center.x = spawn.position.x + AntMath.RandomRangeFloat(spawn.rndToPositionX); center.y = spawn.position.y + AntMath.RandomRangeFloat(spawn.rndToPositionY); float lowerAngle = spawn.initialAngle + spawn.lowerAngle; float upperAngle = spawn.initialAngle + spawn.upperAngle; if (spawn.inheritRotation) { center = AntMath.RotatePointDeg(center, Vector2.zero, _particle.Effect.Angle); lowerAngle += _particle.Effect.Angle; upperAngle += _particle.Effect.Angle; } center.x += _particle.Effect.Position.x; center.y += _particle.Effect.Position.y; var pos = Vector2.zero; float curAngle; float dist = spawn.distance + AntMath.RandomRangeFloat(spawn.rndToDistance); if (spawn.strongOrder && spawn.countParticles > 0) { aEmitter.SpawnCount++; float step = Mathf.DeltaAngle(lowerAngle, upperAngle) / (spawn.countParticles - 1); curAngle = (lowerAngle + (step * aEmitter.SpawnCount)) * AntMath.RADIANS; pos.x = center.x + dist * Mathf.Cos(curAngle); pos.y = center.y + dist * Mathf.Sin(curAngle); if (aEmitter.SpawnCount >= spawn.countParticles) { aEmitter.SpawnCount = 0; } } else { curAngle = AntMath.RandomRangeFloat(lowerAngle, upperAngle) * AntMath.RADIANS; pos.x = center.x + dist * Mathf.Cos(curAngle); pos.y = center.y + dist * Mathf.Sin(curAngle); } if (spawn.rotate) { Angle = curAngle * AntMath.DEGREES; } _transform.position = pos; IsActive = false; // Выкл. обработку компонента. }
public void Reset(AntEmitter aEmitter) { IsActive = true; _movement = Preset.movement; _speed = _movement.speed + AntMath.RandomRangeFloat(_movement.rndToSpeed); _startSpeed = _speed; _endSpeed = _movement.endSpeed; _angle = Angle * AntMath.RADIANS; _velocity.x = _speed * Mathf.Cos(_angle); _velocity.y = _speed * Mathf.Sin(_angle); }
public override void Enter() { // Spawn cargo again on the map in the random pos. _cargoRef.transform.position = new Vector3( _initialPos.x + AntMath.RandomRangeFloat(-2.0f, 2.0f), _initialPos.y + AntMath.RandomRangeFloat(-2.0f, 2.0f), 0.0f ); _cargoRef.SetActive(true); _control.HasCargo = false; Finish(); }
public void Reset(AntEmitter aEmitter) { _sprite = (Preset.actor.useChildActor) ? _particle.GameObject.GetComponentInChildren <SpriteRenderer>() : _particle.GameObject.GetComponent <SpriteRenderer>(); _actor = (Preset.actor.useChildActor) ? _particle.GameObject.GetComponentInChildren <AntActor>() : _particle.GameObject.GetComponent <AntActor>(); _actor.timeScale = Preset.actor.timeScale + AntMath.RandomRangeFloat(Preset.actor.rndToTimeScale); _sprite.flipX = (Preset.actor.rndFlipX) ? (AntMath.RandomRangeInt(0, 1) == 1) : Preset.actor.flipX; _sprite.flipY = (Preset.actor.rndFlipY) ? (AntMath.RandomRangeInt(0, 1) == 1) : Preset.actor.flipY; _actor.reverse = Preset.actor.reverse; _actor.loop = Preset.actor.loop; _actor.loopDelay = Preset.actor.loopDelay + AntMath.RandomRangeFloat(Preset.actor.rndToLoopDelay); if (Preset.actor.playAnimation) { if (Preset.actor.selectRandomFrame) { _actor.PlayRandomFrame(); } else { _actor.GotoAndPlay(Preset.actor.startFrame); } } else { if (Preset.actor.selectRandomFrame) { _actor.GotoAndStop(AntMath.RandomRangeInt(1, _actor.TotalFrames)); } else { _actor.GotoAndStop(Preset.actor.startFrame); } } IsActive = false; // Выкл. обработку компонента. }
public void Reset(AntEmitter aEmitter) { IsActive = (Preset.rotation.enableRotation || Preset.rotation.animateAngle); _startAngle = Preset.rotation.startAngle + AntMath.RandomRangeFloat(Preset.rotation.rndToAngle); _endAngle = Preset.rotation.endAngle; _angularSpeed = Preset.rotation.angularSpeed + AntMath.RandomRangeFloat(Preset.rotation.rndToAngularSpeed); _enableRotation = Preset.rotation.enableRotation; _animateAngle = Preset.rotation.animateAngle; _accel = Preset.rotation.accel; _drag = Preset.rotation.drag; _curve = Preset.rotation.curveAngle; if (Preset.rotation.inheritRotation) { _startAngle += _particle.Effect.Angle; _endAngle += _particle.Effect.Angle; } Angle = _startAngle; }
public void Reset(AntEmitter aEmitter) { IsActive = Preset.scale.animateScale; _endScale = Preset.scale.endScale; _startScale = Vector2.zero; _startScale.x = Preset.scale.startScale.x + AntMath.RandomRangeFloat(Preset.scale.rndToScaleX); _startScale.y = Preset.scale.startScale.y + AntMath.RandomRangeFloat(Preset.scale.rndToScaleY); _curveX = Preset.scale.scaleCurveX; _curveY = Preset.scale.scaleCurveY; _useChild = Preset.scale.useChildSprite; _proportional = Preset.scale.proportional; if (Preset.scale.effectLifeTime && !AntMath.Equal(_particle.Effect.lifeTime, 0.0f)) { _delta = _particle.Effect.Duration / _particle.Effect.TotalDuration; _delta = AntMath.TrimToRange(_delta, 0.0f, 1.0f); _startScale.x = AntMath.Lerp(_startScale.x, Preset.scale.endScale.x, _curveX.Evaluate(_delta)); _startScale.y = AntMath.Lerp(_startScale.y, Preset.scale.endScale.y, _curveY.Evaluate(_delta)); } if (Preset.scale.useChildSprite) { _childTransform.localScale = new Vector3( _startScale.x, (Preset.scale.proportional) ? _startScale.x : _startScale.y, 1.0f ); } else { _transform.localScale = new Vector3( _startScale.x, (Preset.scale.proportional) ? _startScale.x : _startScale.y, 1.0f ); } }
public override void Start() { // Задаем случайный промежуток времени. _delay = AntMath.RandomRangeFloat(2.0f, 5.0f); }
public void Reset(AntEmitter aEmitter) { IsActive = true; _preset = Preset.emission; _spawnInterval = _preset.spawnInterval + AntMath.RandomRangeFloat(_preset.rndToSpawnInterval); }