public void Run()
        {
            if (_tag.IsEmpty())
            {
                return;
            }

            foreach (var i in _players)
            {
                if (_playerApi.PlayerData.TryGetValue(_players.Get1[i].Name, out Player p))
                {
                    _players.Get1[i].HP    = p.HP;
                    _players.Get1[i].Power = p.Power;
                    if (_players.Get1[i].Location != p.Location)
                    {
                        _players.Get1[i].Location = p.Location;
                        _players.Entities[i].Set <UpdatePlayerPointTag>();
                    }
                }
                else
                {
                    if (_players.Get1[i].Name.Equals(_playerApi.PlayerName))
                    {
                        UICoreECS.ShowScreenTag screen = _world.NewEntity().Set <UICoreECS.ShowScreenTag>();
                        screen.ID    = 2;
                        screen.Layer = 0;
                        UnityEngine.PlayerPrefs.DeleteKey("token");
                        UnityEngine.PlayerPrefs.DeleteKey("username");
                        UnityEngine.PlayerPrefs.Save();
                    }
                    EcsEntity explosionEntity = _world.NewEntity();

                    Positioning.Components.Position pos = explosionEntity.Set <Positioning.Components.Position>();
                    pos.Point = _players.Entities[i].Get <Positioning.Components.Position>().Point;
                    explosionEntity.Set <AllocateView>().id = "Explosion";
                    _players.Entities[i].Destroy();
                }
            }

            foreach (var i in _user)
            {
                if (_user.Get2[i].HP <= 0)
                {
                    EcsEntity explosionEntity = _world.NewEntity();

                    Positioning.Components.Position pos = explosionEntity.Set <Positioning.Components.Position>();
                    pos.Point = _user.Entities[i].Get <Positioning.Components.Position>().Point;
                    explosionEntity.Set <AllocateView>().id = "Explosion";

                    UICoreECS.ShowScreenTag screen = _world.NewEntity().Set <UICoreECS.ShowScreenTag>();
                    screen.ID    = 2;
                    screen.Layer = 0;
                    UnityEngine.PlayerPrefs.DeleteKey("token");
                    UnityEngine.PlayerPrefs.DeleteKey("username");
                    UnityEngine.PlayerPrefs.Save();
                    _user.Entities[i].Destroy();
                }
            }
        }
 public void Run()
 {
     foreach (var i in _filter)
     {
         UMeshData     offset = _filter.Get2[i];
         URenderMatrix matrix = _filter.Get1[i];
         Positioning.Components.Position pos = _filter.Get3[i];
         for (int j = 0; j < offset.Offset.Length; j++)
         {
             matrix.Matrix[j] = Matrix4x4.TRS(pos.Point + offset.Offset[j], offset.RotationOffset[j], offset.Scale[j]);
         }
     }
 }
Ejemplo n.º 3
0
        public void Init()
        {
            EcsEntity cameraEntity = _world.NewEntity();

            CameraComponent cameraComponent = cameraEntity.Set <CameraComponent>();

            cameraComponent.MainCamera = Camera.main;

            Positioning.Components.Position position = cameraEntity.Set <Positioning.Components.Position>();
            position.Point         = cameraComponent.MainCamera.transform.position;
            position.EulerRotation = cameraComponent.MainCamera.transform.eulerAngles;

            UnityView unityView = cameraEntity.Set <UnityView>();

            unityView.GameObject = cameraComponent.MainCamera.gameObject;
            unityView.Transform  = cameraComponent.MainCamera.transform;

            _camPosition = position;
        }
Ejemplo n.º 4
0
        public void ParseWorldNodes(JSONNode node, EcsWorld ecsWorld)
        {
            foreach (var point in node["data"]["points"])
            {
                EcsEntity entity = ecsWorld.NewEntity();
                
                // parse worldpoint entry
                WorldPoint worldPoint = entity.Set<WorldPoint>();
                worldPoint.PointID = int.Parse(point.Key);
                worldPoint.PointType = (WorldPointType) point.Value["loc_type"].AsInt;

                // Set Object rotation
                RotatingObject rObject = entity.Set<RotatingObject>();
                rObject.RotatingSpeedX = Random.Range(-0.2f, 0.2f);
                rObject.RotatingSpeedY = Random.Range(-0.2f, 0.2f);
                rObject.RotatingSpeedZ = Random.Range(-0.2f, 0.2f);

                ObjectOwner objOwner = entity.Set<ObjectOwner>();
                objOwner.OwnerUsername = point.Value["owned_by"];
                objOwner.IsOwned = (objOwner.OwnerUsername) == "" ? false : true;
                
                // parse position
                Positioning.Components.Position pos = entity.Set<Positioning.Components.Position>();
                pos.Point.Set(point.Value["position"]["x"].AsInt, Random.Range(-10.0f, 10.0f), point.Value["position"]["y"].AsInt);
                IDtoPoint.Add(worldPoint.PointID, pos.Point);
                
                // parse point type
                switch (worldPoint.PointType)
                {
                    case WorldPointType.Asteroid:
                        entity.Set<AllocateView>().id = "Asteroid";
                        break;
                    case WorldPointType.Planet:
                        entity.Set<AllocateView>().id = "Planet";
                        break;
                    case WorldPointType.Station:
                        entity.Set<AllocateView>().id = "Station";
                        rObject.RotatingSpeedX = 0.0f;
                        rObject.RotatingSpeedZ = 0.0f;
                        break;
                }

            }

            // Generating lines
            foreach (var point in node["data"]["points"]) {
                int pID = int.Parse(point.Key);

                foreach (var neighbour in point.Value["adjacent"])
                {
                    int nKey = int.Parse(neighbour.Value);
                    if (nKey < pID) {
                        EcsEntity lineEntity = ecsWorld.NewEntity();

                        LineConnection lConnection = lineEntity.Set<LineConnection>();
                        lConnection.PositionA = IDtoPoint[pID];
                        lConnection.PositionB = IDtoPoint[nKey];

                        lineEntity.Set<AllocateView>().id = "Line";
                    }
                    
                }
            }

        }