Esempio n. 1
0
 private static void Initialize()
 {
     ConditionalLogger.Log("<color=green><b>Initialize!</b></color>");
     _context.CreateFeatures();
     _context.Initialize();
     _context.FireEvent(new StartGameEvent());
 }
Esempio n. 2
0
 protected Context()
 {
     _entities = new List <IEntity>();
     _systems  = new List <ContextSystem>();
     _views    = new HashSet <View>();
     ConditionalLogger.Log($"<b>{GetType().Name}</b> has been created!");
 }
    public void GetIOSLocalNotification()
    {
        var notification = UnityEngine.iOS.NotificationServices.GetLocalNotification(0);

        ConditionalLogger.Log($"GetIOSLocalNotification. #0 ticks: {notification.fireDate.Ticks} alertBody: {notification.alertBody} ");
        ConditionalLogger.Log($"GetIOSLocalNotification local_length: {UnityEngine.iOS.NotificationServices.localNotificationCount}, scheduled_length: {UnityEngine.iOS.NotificationServices.scheduledLocalNotifications.Length}");
    }
        // дамаг поглощается в зависимости от препятствий.
        private void DamageAbsorption(ref float damagePower, Vector3 dir, float dist, Vector3 sourcePoint, Vector3 receivePoint)
        {
            Debug.DrawLine(sourcePoint, receivePoint, Color.blue, 10f);
            var hits = Physics.RaycastAll(sourcePoint, dir, dist);

            if (hits.Length > 0)
            {
                foreach (var hit in hits)
                {
                    // если уже весь дамаг поглощён, то смысл дальше считать что.
                    if (damagePower <= 0)
                    {
                        break;
                    }
                    var absorptionComp = hit.transform.parent?.GetComponent <ColliderView>()?.GetViewData <ViewDamageAbsorptionComponent>();
                    if (absorptionComp == null)
                    {
                        continue;
                    }
                    // была мысль чтобы дамаг поглощался анизотропно, но что-то пошло не так. так что по-простому тут.
                    var anisotropicAbsorption = absorptionComp.AnisotropicPower * ABSORPTION_ABSOLUTE_MULT;
                    ConditionalLogger.Log($"Damage absorbed <b>{hit.transform.parent.name}</b> by {anisotropicAbsorption.sqrMagnitude}");
                    damagePower -= anisotropicAbsorption.sqrMagnitude;
                }
            }
            else
            {
                ConditionalLogger.Log("<color=red>There is no hits for absorption.</color>");
            }
        }
Esempio n. 5
0
        protected override IEntity CreateEntity(PlayerView colliderActionView)
        {
            var e = base.CreateEntity(colliderActionView);
            var healthComponent = new HealthComponent(Random.Range(20, 50));

            ConditionalLogger.Log($"Create player with health <b> {healthComponent.CurrentHealth} </b>");
            e.AddComponent(healthComponent);
            return(e);
        }
Esempio n. 6
0
    internal void Initialize(Context context)
    {
        _context = context;
        _context.AddView(this);
        ConditionalLogger.Log($"<color=blue><b>{gameObject.name}</b></color> has been initialized!");
#if UNITY_EDITOR
        _isInitialized = true;
#endif
    }
Esempio n. 7
0
        public T CreateView <T>(GameObject viewOnGameObject) where T : View
        {
            var obj  = UnityEngine.Object.Instantiate(viewOnGameObject);
            var view = obj.GetComponent <T>();

            view.Initialize(this);
            ConditionalLogger.Log($"{view.GetType().Name} has been instantiated!");
            return(view);
        }
Esempio n. 8
0
 public void FireEvent <T>(T contextEvent)
 {
     ConditionalLogger.Log($"<b>{contextEvent.GetType().Name}</b> fired!");
     for (var index = 0; index < _systems.Count; index++)
     {
         var system = _systems[index];
         var s      = system as IEventListenerSystem <T>;
         s?.OnEvent(contextEvent);
     }
 }
Esempio n. 9
0
        void IEventListenerSystem <TSpawnEvent> .OnEvent(TSpawnEvent contextEvent)
        {
            var colliderActionView = context.CreateView <TView>(_viewResource);

            ConditionalLogger.Log($"Get point in bounds of ground {contextEvent.SpawnPoint}");
            colliderActionView.transform.position = contextEvent.SpawnPoint;

            var entity = CreateEntity(colliderActionView);

            colliderActionView.SetAction(arg1 => SetOnCollisionAction(arg1, entity));
        }
Esempio n. 10
0
 private void ClickCheck()
 {
     if (GetInput())
     {
         RaycastHit hit;
         var        ray = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
         if (Physics.Raycast(ray, out hit))
         {
             ConditionalLogger.Log($"User click on {hit.point}");
             var spawnEvent = (TSpawnEvent)Activator.CreateInstance(typeof(TSpawnEvent), hit.point);
             context.FireEvent(spawnEvent);
         }
     }
 }
        void IEventListenerSystem <StartGameEvent> .OnEvent(StartGameEvent contextEvent)
        {
            _levelView = context.GetView <LevelView>();
            if (_levelView == null)
            {
                ConditionalLogger.LogError("Fatal error because there is no level view!");
                return;
            }

            _spawnAreaView   = context.GetView <SpawnAreaView>();
            _spawnAreaBounds = _spawnAreaView.Collider.bounds;
            ConditionalLogger.Log($"Bounds of level {_levelView.gameObject.name} is {_spawnAreaBounds.size}");
            StartSpawn();
        }
        protected virtual IList <IEntity> SelectDamagables(TDamageComponent damageSource, TCollisionEvent contextEvent)
        {
            var bombView = contextEvent.Entity.GetComponent <View>();

            ConditionalLogger.Log($"Try select damagables around spherical bomb collision at point <b> {bombView.transform.position} </b>");

            // тут уже в зависимости от теоретического количества объектов может быть и быстрее делать выборку и через PhysicsOverlapSphere.
            var entities       = context.GetEntitiesWithComponents(typeof(HealthComponent));
            var properEntities = entities.Where(_ => Vector3.Distance(_.GetComponent <View>().transform.position, bombView.transform.position) <= damageSource.range).ToList();

            contextEvent.Entity.AddComponent(new HealthComponent(0));

            ConditionalLogger.Log($"Select all {properEntities.Count} entities!");
            return(properEntities);
        }
        protected virtual void ApplyDamage(IEntity damagable, TDamageComponent damageSource, TCollisionEvent collisionEvent)
        {
            ConditionalLogger.Log($"{damagable.GetComponent<View>().transform.name} receive damage from {collisionEvent.Entity.GetComponent<View>()}!");
            var healthComp = damagable.GetComponent <HealthComponent>();
            var damage     = damageSource.power;

            var sourceDamageSourcePoint = collisionEvent.Entity.GetComponent <ColliderView>().Collider.transform.position;
            var damagablePoint          = damagable.GetComponent <ColliderView>().Collider.transform.position;
            var dir  = damagablePoint - sourceDamageSourcePoint;
            var dist = Vector3.Distance(sourceDamageSourcePoint, damagablePoint);

            DistanceInfluence(ref damage, dist, damageSource.range);
            DamageAbsorption(ref damage, dir, dist, sourceDamageSourcePoint, damagablePoint);

            if (damage <= 0)
            {
                return;
            }
            healthComp.AddDelta(-damage);
            ConditionalLogger.Log($"Apply <b> {damage}</b> of damage for <b> {damagable.GetComponent<View>().name} </b>");
        }
 public void GetVersion()
 {
     ConditionalLogger.Log($"<b>LoggerFuncs.GetVersion</b> bundle: {Application.identifier}(version: {Application.version}) unity_version: {Application.unityVersion}");
 }
 // дамаг уменьшается в зависимости от дистанции.
 private void DistanceInfluence(ref float damagePower, float dist, float range)
 {
     damagePower = Mathf.Lerp(damagePower, 0, dist / range);
     ConditionalLogger.Log($"Damage after <b> {dist} </b> units of distance is <b> {damagePower} </b>");
 }
Esempio n. 16
0
 protected ContextSystem(Context context)
 {
     ConditionalLogger.Log($"<b>{GetType().Name}</b> has been created!");
     this.context = context;
 }