Beispiel #1
0
 public CircleState(ColorComponent color, PositionComponent pos, SizeComponent size, SpeedComponent speed)
 {
     colorComponent    = color;
     positionComponent = pos;
     sizeComponent     = size;
     speedComponent    = speed;
 }
        private void ResetTerrainArea(Entity building)
        {
            SizeComponent      sizeComponent      = building.Get <SizeComponent>();
            TransformComponent transformComponent = building.Get <TransformComponent>();

            this.ResetRangeOfGridPositions(transformComponent.X, transformComponent.Z, sizeComponent.Width, sizeComponent.Depth);
        }
Beispiel #3
0
        public static string GetRubbleAssetNameForEntity(SmartEntity entity)
        {
            SizeComponent sizeComp = entity.SizeComp;
            int           num      = Units.BoardToGridX(sizeComp.Width);
            int           num2     = Units.BoardToGridZ(sizeComp.Depth);
            string        uid;

            if (entity.BuildingComp.BuildingType.Type == BuildingType.Wall)
            {
                uid = string.Format("rebelRubbleWall1", new object[]
                {
                    num,
                    num2
                });
            }
            else
            {
                uid = string.Format("rebelRubble{0}", new object[]
                {
                    num,
                    num2
                });
            }
            BuildingTypeVO buildingTypeVO = Service.Get <IDataController>().Get <BuildingTypeVO>(uid);

            return(buildingTypeVO.AssetName);
        }
Beispiel #4
0
        public static GJKResult GJK(Vector3 aPos, Vector3 aOrientation, SizeComponent aSize,
                                    Vector3 bPos, Vector3 bOrientation, SizeComponent bSize)
        {
            var aVertices = GetVertices(aPos, aOrientation, aSize);
            var bVertices = GetVertices(bPos, bOrientation, bSize);

            return(GJK(aPos, aVertices, bPos, bVertices, true));
        }
        private void AddLoweredFootprint(SmartEntity building)
        {
            TransformComponent transformComp = building.TransformComp;
            Vector3            vector        = new Vector3(Units.BoardToWorldX(transformComp.X), 0f, Units.BoardToWorldZ(transformComp.Z));
            SizeComponent      sizeComp      = building.SizeComp;

            this.loweredFootprint.AddTiles(vector.x, vector.z, sizeComp.Width, sizeComp.Depth, building.WallComp != null);
        }
Beispiel #6
0
 public int CalculateWalkableGap(SizeComponent size)
 {
     if (Units.BoardToGridX(size.Width) > 1 && Units.BoardToGridZ(size.Depth) > 1)
     {
         return(1);
     }
     return(0);
 }
 public void Update(GameObjectComponent go, PositionComponent position, SizeComponent size, ColorComponent color)
 {
     go.transform.position   = position.value;
     go.transform.localScale = Vector2.one * Mathf.MoveTowards(go.transform.localScale.x, size.value * 11f, Mathf.Max(0.01f, Mathf.Abs(go.transform.localScale.x - size.value)) * 10f * Time.deltaTime);
     go.spriteRenderer.color = color.value;
     //go.trailRenderer.startColor = color.value;
     //go.trailRenderer.endColor = color.value;
 }
 public void Add(GameObjectComponent e, PositionComponent position, SizeComponent size, ColorComponent color)
 {
     e.gameObject            = new GameObject("Entity");
     e.transform             = e.gameObject.transform;
     e.transform.localScale  = Vector2.one * 0.001f;
     e.spriteRenderer        = e.gameObject.AddComponent <SpriteRenderer>();
     e.spriteRenderer.sprite = UnityEditor.AssetDatabase.GetBuiltinExtraResource <Sprite>("UI/Skin/Knob.psd");
     Update(e, position, size, color);
 }
Beispiel #9
0
        private static List <Vector3> GetVertices(Vector3 pos, Vector3 orientation, SizeComponent size)
        {
            var transform =
                Matrix4x4.CreateScale(size.Width, size.Height, 1) *
                Matrix4x4.CreateFromQuaternion(orientation.ToQuaternian()) *
                Matrix4x4.CreateTranslation(pos);

            return(Vertices.Select(vertex => Vector3.Transform(vertex, transform)).ToList());
        }
Beispiel #10
0
        public static string GetDebrisAssetNameForEntity(SmartEntity entity, bool isBuilding)
        {
            SizeComponent sizeComp = entity.SizeComp;
            int           val      = Units.BoardToGridX(sizeComp.Width);
            int           val2     = Units.BoardToGridZ(sizeComp.Depth);
            int           num      = Math.Min(val, val2);
            string        uid;

            if (isBuilding)
            {
                BuildingTypeVO buildingType = entity.BuildingComp.BuildingType;
                string         text         = string.IsNullOrEmpty(buildingType.DestructFX) ? "fx_debris_{0}x{1}" : buildingType.DestructFX;
                BuildingType   type         = buildingType.Type;
                if (type != BuildingType.Wall)
                {
                    if (type != BuildingType.Turret)
                    {
                        if (type != BuildingType.ShieldGenerator)
                        {
                            uid = string.Format(text, new object[]
                            {
                                num,
                                num
                            });
                        }
                        else
                        {
                            uid = "fx_debris_6x6";
                        }
                    }
                    else
                    {
                        uid = ((buildingType.Faction == FactionType.Tusken) ? "effect176" : string.Format(text, new object[]
                        {
                            num,
                            num
                        }));
                    }
                }
                else
                {
                    uid = "effect176";
                }
            }
            else
            {
                uid = string.Format("fx_vehdebris_{0}x{1}", new object[]
                {
                    num,
                    num
                });
            }
            EffectsTypeVO effectsTypeVO = Service.Get <IDataController>().Get <EffectsTypeVO>(uid);

            return(effectsTypeVO.AssetName);
        }
Beispiel #11
0
        public void Update(PositionComponent sourcePosition, SizeComponent sourceSize, PositionComponent targetPosition, SizeComponent targetSize, Entity.Entity target)
        {
            float sizeSum = sourceSize.value + targetSize.value + 0.05f;

            if ((sourcePosition.value - target.position.value).sqrMagnitude < sizeSum * sizeSum)
            {
                //sourceSize.value = Mathf.Sqrt(sourceSize.value * sourceSize.value + targetSize.value * targetSize.value);
                Kill(target, sourcePosition);
            }
        }
 private void AddLiftedFootprint(SmartEntity building)
 {
     if (!this.liftedFootprints.ContainsKey(building))
     {
         SizeComponent sizeComp  = building.SizeComp;
         Footprint     footprint = new Footprint(this.LIFTED_FOOTPRINT_NAME, 3f);
         footprint.AddTiles(0f, 0f, sizeComp.Width, sizeComp.Depth, building.WallComp != null);
         footprint.GenerateMesh(true, true);
         this.liftedFootprints.Add(building, footprint);
     }
 }
Beispiel #13
0
        public Entity CreateTransportEntity(TransportTypeVO transportType)
        {
            Entity        entity    = this.NewEntity();
            SizeComponent component = Units.SizeCompFromGrid(transportType.SizeX, transportType.SizeY);

            entity.Add(component);
            TransportComponent component2 = new TransportComponent(transportType);

            entity.Add(component2);
            Service.Get <EntityViewManager>().LoadEntityAsset(entity);
            return(entity);
        }
Beispiel #14
0
        public BoardCell <Entity> AddBuildingToBoard(Entity building, int boardX, int boardZ, bool sendEvent)
        {
            BoardItemComponent boardItemComponent = building.Get <BoardItemComponent>();
            BoardItem <Entity> boardItem          = boardItemComponent.BoardItem;
            SizeComponent      size = boardItem.Size;
            BuildingComponent  buildingComponent = building.Get <BuildingComponent>();
            BuildingTypeVO     buildingType      = buildingComponent.BuildingType;
            bool      flag        = buildingType.Type == BuildingType.Clearable || buildingType.Type == BuildingType.Trap || buildingType.Type == BuildingType.ChampionPlatform;
            bool      flag2       = buildingType.Type == BuildingType.Blocker;
            int       walkableGap = flag2 ? 0 : this.CalculateWalkableGap(size);
            FlagStamp flagStamp   = this.CreateFlagStamp(building, buildingType, size, walkableGap);

            if (!flag)
            {
                this.AddUnWalkableUnDestructibleFlags(flagStamp, size, walkableGap, flag2);
            }
            boardItem.FlagStamp = flagStamp;
            BoardController    boardController = Service.Get <BoardController>();
            BoardCell <Entity> boardCell       = boardController.Board.AddChild(boardItem, boardX, boardZ, building.Get <HealthComponent>(), !flag2);

            if (boardCell == null)
            {
                Service.Get <StaRTSLogger>().ErrorFormat("Failed to add building {0}:{1} at ({2},{3})", new object[]
                {
                    buildingComponent.BuildingTO.Key,
                    buildingComponent.BuildingTO.Uid,
                    boardX,
                    boardZ
                });
                return(null);
            }
            TransformComponent transformComponent = building.Get <TransformComponent>();

            transformComponent.X = boardX;
            transformComponent.Z = boardZ;
            DamageableComponent damageableComponent = building.Get <DamageableComponent>();

            if (damageableComponent != null)
            {
                damageableComponent.Init();
            }
            buildingComponent.BuildingTO.SyncWithTransform(transformComponent);
            if (sendEvent)
            {
                Service.Get <EventManager>().SendEvent(EventId.BuildingPlacedOnBoard, building);
            }
            if (buildingType.Type == BuildingType.DroidHut)
            {
                this.DroidHut = building;
            }
            return(boardCell);
        }
Beispiel #15
0
        public FlagStamp CreateFlagStampForShield(ShieldGeneratorComponent sgc, SizeComponent size, int walkableGap)
        {
            int       num       = 1;
            int       num2      = 1;
            int       num3      = (num2 + num + sgc.CurrentRadius) * 2 - 1;
            FlagStamp flagStamp = new FlagStamp(num3, num3, 0u, true);

            flagStamp.SetFlagsInRectCenter(size.Width - walkableGap + 2, size.Depth - walkableGap + 2, 4u);
            flagStamp.FillCircle(sgc.CurrentRadius + num, 16u, true);
            flagStamp.StrokeHull(8u, 16u);
            flagStamp.FillCircle(sgc.CurrentRadius + num2, 16u, true);
            return(flagStamp);
        }
 private void PaintTerrainPlacedArea(Entity building)
 {
     if (building != null)
     {
         SizeComponent      sizeComponent      = building.Get <SizeComponent>();
         TransformComponent transformComponent = building.Get <TransformComponent>();
         BuildingComponent  buildingComponent  = building.Get <BuildingComponent>();
         if (buildingComponent.BuildingType.Type != BuildingType.Trap && buildingComponent.BuildingType.Type != BuildingType.Clearable)
         {
             this.PaintRangeOfGridPositions(transformComponent.X, transformComponent.Z, sizeComponent.Width, sizeComponent.Depth, TerrainBlendController.TERRAIN_PLACEMENT_COLOR);
         }
     }
 }
        public static void BuildingBoardToWorld(Entity building, int boardX, int boardZ, out float worldX, out float worldZ)
        {
            SizeComponent     sizeComp     = ((SmartEntity)building).SizeComp;
            BuildingComponent buildingComp = ((SmartEntity)building).BuildingComp;
            int num = 0;

            if (buildingComp.BuildingType.Type != BuildingType.Blocker && sizeComp.Width > 1 && sizeComp.Depth > 1)
            {
                num = 1;
            }
            worldX = Units.BoardToWorldX((float)boardX + (float)(sizeComp.Width - num) * 0.5f);
            worldZ = Units.BoardToWorldZ((float)boardZ + (float)(sizeComp.Depth - num) * 0.5f);
        }
Beispiel #18
0
        private void PrepareGameObject(SmartEntity entity, GameObject gameObject, bool createCollider)
        {
            SizeComponent sizeComp = entity.SizeComp;

            if (sizeComp != null && createCollider)
            {
                if (gameObject.GetComponent <BoxCollider>() == null)
                {
                    gameObject.AddComponent <BoxCollider>();
                }
                this.SetColliderHelper(gameObject, sizeComp, true);
            }
            this.PrepareEntityView(entity, gameObject);
        }
Beispiel #19
0
    private float lastSpacePressTime = 0f;//on ne peut pas appuyer sur espace pendant les deux premières secondes

    public void UpdateSystem()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (Time.time - lastSpacePressTime < 2f)
            {
                string timeRemaining = (2f - (Time.time - lastSpacePressTime)).ToString();
                Debug.Log("Wait until the cooldown is over; time remaining in seconds : " + timeRemaining);
            }

            else
            {
                lastSpacePressTime = Time.time;
                Debug.Log("Space button pressed; activating 2 seconds cooldown");

                for (int i = 0; i < world.PastPositionsComponents.Count; i++)
                {
                    PositionComponent posC   = new PositionComponent();
                    ColorComponent    colorC = new ColorComponent();
                    SizeComponent     sizeC  = new SizeComponent();
                    SpeedComponent    speedC = new SpeedComponent();

                    posC.id   = world.PositionComponents[i].id;
                    colorC.id = world.ColorComponents[i].id;
                    sizeC.id  = world.SizeComponents[i].id;
                    speedC.id = world.SpeedComponents[i].id;

                    posC.pos = world.PastPositionsComponents[i].pos.Dequeue();
                    world.PositionComponents[i] = posC;
                    world.PastPositionsComponents[i].timestamps.Dequeue();
                    manager.UpdateShapePosition(world.PositionComponents[i].id, world.PositionComponents[i].pos);

                    colorC.color             = world.PastColorsComponents[i].colors.Dequeue();
                    world.ColorComponents[i] = colorC;
                    world.PastColorsComponents[i].timestamps.Dequeue();
                    manager.UpdateShapeColor(world.ColorComponents[i].id, world.ColorComponents[i].color);

                    sizeC.size = world.PastSizesComponents[i].sizes.Dequeue();
                    world.SizeComponents[i] = sizeC;
                    world.PastSizesComponents[i].timestamps.Dequeue();
                    manager.UpdateShapeSize(world.SizeComponents[i].id, world.SizeComponents[i].size);

                    speedC.speed             = world.PastSpeedsComponents[i].speeds.Dequeue();
                    world.SpeedComponents[i] = speedC;
                    world.PastSpeedsComponents[i].timestamps.Dequeue();
                }
            }
        }
    }
Beispiel #20
0
        internal Actor(ulong id) : base()
        {
            DataContext      = this;
            IsHitTestVisible = false;   //使内容不接收输入事件
            Id     = id;
            ACP    = new UIActorControlPoint(this);
            Width  = 100;
            Height = 100;

            _object       = new ObjectComponent(this);
            _size         = new SizeComponent(this);
            _tran         = new TransformComponent(this);
            _transparency = new TransparencyComponent(this);
            AddComponents(_object, _size, _tran, _transparency);
        }
Beispiel #21
0
        private SmartEntity CreateWalkerBaseEntity(IntPosition boardPosition, int sizeX, int sizeY)
        {
            Entity             entity    = this.NewEntity();
            int                num       = sizeX / 2;
            TransformComponent component = new TransformComponent(boardPosition.x - num, boardPosition.z - num, 0f, false, sizeX, sizeX);

            entity.Add(component);
            SizeComponent component2 = Units.SizeCompFromGrid(sizeX, sizeY);

            entity.Add(component2);
            BoardItem <Entity> boardItem  = new BoardItem <Entity>(Units.SizeCompFromGrid(1, 1), entity, CollisionFilters.TROOP);
            BoardItemComponent component3 = new BoardItemComponent(boardItem);

            entity.Add(component3);
            return((SmartEntity)entity);
        }
Beispiel #22
0
        private void SetColliderHelper(GameObject gameObject, SizeComponent size, bool flat)
        {
            BoxCollider component = gameObject.GetComponent <BoxCollider>();

            if (component == null)
            {
                return;
            }
            float y    = gameObject.transform.position.y;
            float num  = Units.BoardToWorldX(size.Depth);
            float num2 = Units.BoardToWorldX(size.Width);
            float num3 = (!flat) ? ((num + num2) * 0.5f + y) : 0.25f;

            component.size   = new Vector3(num, num3, num2);
            component.center = new Vector3(0f, num3 * 0.5f - y, 0f);
        }
Beispiel #23
0
        public void SetCollider(Entity entity, bool flat)
        {
            GameObjectViewComponent gameObjectViewComponent = entity.Get <GameObjectViewComponent>();

            if (gameObjectViewComponent == null)
            {
                return;
            }
            SizeComponent sizeComponent = entity.Get <SizeComponent>();

            if (sizeComponent == null)
            {
                return;
            }
            this.SetColliderHelper(gameObjectViewComponent.MainGameObject, sizeComponent, flat);
        }
Beispiel #24
0
        public void GJK_WhenColliding_ReturnsTrue()
        {
            var aPos         = new Vector3(0, 0, 0);
            var aOrientation = new Vector3(0, 0, 0);
            var aSize        = new SizeComponent {
                Width = 10, Height = 10
            };
            var bPos         = new Vector3(0, -8, 0);
            var bOrientation = new Vector3(0, 0, 0);
            var bSize        = new SizeComponent {
                Width = 100, Height = 10
            };

            var result = Algorithms.GJK(aPos, aOrientation, aSize, bPos, bOrientation, bSize);

            Assert.IsTrue(result.Collision);
        }
Beispiel #25
0
        public void SetTarget(Entity target)
        {
            if (!this.assetReady)
            {
                this.pendingTarget = target;
                return;
            }
            TransformComponent transformComponent = target.Get <TransformComponent>();

            if (transformComponent == null)
            {
                return;
            }
            SizeComponent sizeComponent = target.Get <SizeComponent>();

            this.SetWorldTarget(transformComponent.CenterX(), transformComponent.CenterZ(), (float)sizeComponent.Width, (float)sizeComponent.Depth);
            this.StartLockon();
        }
    public void Update(PositionComponent pos1, SizeComponent size1, PositionComponent pos2, SizeComponent size2)
    {
        Vector2 center             = Vector2.Lerp(pos1.value, pos2.value, size1.value / (size1.value + size2.value));
        Vector2 offest             = pos1.value - center;
        float   offestSqrMagnitude = offest.sqrMagnitude;
        float   sqrRadius          = size1.value * size1.value;

        if (offestSqrMagnitude < sqrRadius)
        {
            float offestMagnitude = Mathf.Sqrt(offestSqrMagnitude);
            if (offestMagnitude == 0)
            {
                offestMagnitude = 0.01f;
            }
            float pushMul = Mathf.Min(size1.value - offestMagnitude, (1 - offestMagnitude / size1.value) * Time.deltaTime * 10f);
            pos1.value += offest.normalized * pushMul;
        }
    }
Beispiel #27
0
        public void EPA_WhenColliding_ReturnsPenetrationVector()
        {
            var aPos         = new Vector3(0, 0, 0);
            var aOrientation = new Vector3(0, 0, 0);
            var aSize        = new SizeComponent {
                Width = 10, Height = 10
            };
            var bPos         = new Vector3(2, -8, 0);
            var bOrientation = new Vector3(0, 0, 0);
            var bSize        = new SizeComponent {
                Width = 10, Height = 10
            };

            var gjkResult = Algorithms.GJK(aPos, aOrientation, aSize, bPos, bOrientation, bSize);
            var epaResult = Algorithms.EPA(gjkResult);

            Assert.AreEqual(0, epaResult.X);
            Assert.AreEqual(-2, epaResult.Y);
            Assert.AreEqual(0, epaResult.Z);
        }
Beispiel #28
0
        public FlagStamp CreateFlagStamp(Entity building, BuildingTypeVO buildingVO, SizeComponent size, int walkableGap)
        {
            ShieldGeneratorComponent shieldGeneratorComponent = null;
            BuildingComponent        buildingComponent        = null;

            if (building != null)
            {
                shieldGeneratorComponent = building.Get <ShieldGeneratorComponent>();
                buildingComponent        = building.Get <BuildingComponent>();
            }
            if (shieldGeneratorComponent != null)
            {
                return(Service.Get <ShieldController>().CreateFlagStampForShield(shieldGeneratorComponent, size, walkableGap));
            }
            uint num;

            if (buildingVO != null && buildingVO.Type == BuildingType.Trap)
            {
                num = 0u;
            }
            else
            {
                num = 4u;
            }
            if (buildingVO != null && buildingVO.AllowDefensiveSpawn)
            {
                num |= 32u;
            }
            if (buildingComponent != null && buildingComponent.BuildingType.SpawnProtection > 0)
            {
                int num2 = buildingComponent.BuildingType.SpawnProtection;
                int num3 = num2 - (size.Width - walkableGap);
                if (num3 % 2 == 1)
                {
                    num2++;
                }
                return(new FlagStamp(num2, num2, num, false));
            }
            return(new FlagStamp(size.Width - walkableGap + 2, size.Depth - walkableGap + 2, num, false));
        }
 public Entity()
 {
     gameObject = new GameObjectComponent()
     {
         entity = this
     };
     position = new PositionComponent()
     {
         entity = this
     };
     size = new SizeComponent()
     {
         entity = this
     };
     color = new ColorComponent()
     {
         entity = this
     };
     team = new TeamComponent()
     {
         entity = this
     };
 }
 public void Add(GameObjectComponent e, PositionComponent position, SizeComponent size, ColorComponent color, bool isplayer = false)
 {
     e.gameObject           = new GameObject("Entity");
     e.transform            = e.gameObject.transform;
     e.transform.localScale = Vector2.one * 0.001f;
     e.spriteRenderer       = e.gameObject.AddComponent <SpriteRenderer>();
     //e.spriteRenderer.sprite = UnityEditor.AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd");
     if (isplayer == false)
     {
         e.spriteRenderer.sprite = Resources.Load <Sprite>("ball");
     }
     else
     {
         e.spriteRenderer.sprite = Resources.Load <Sprite>("player");
     }
     //e.lineRenderer = e.gameObject.AddComponent<LineRenderer>();
     ////e.lineRenderer.material = UnityEditor.AssetDatabase.GetBuiltinExtraResource<Material>("Sprites-Default");
     //e.lineRenderer.material = Resources.Load<Material>("1");
     //e.lineRenderer.useWorldSpace = false;
     //e.lineRenderer.startWidth = 0.1f;
     //e.lineRenderer.endWidth = 0;
     //e.lineRenderer.numCapVertices = 5;
     //e.trailRenderer = e.gameObject.AddComponent<TrailRenderer>();
     //e.trailRenderer.material = Resources.Load<Material>("1");
     //e.trailRenderer.startWidth = 0.1f;
     //e.trailRenderer.endWidth = 0;
     //e.trailRenderer.numCapVertices = 5;
     if (isplayer)
     {
         //添加蛇尾
         //var trail = new GameObject("TRAIL");
         var trail = GameObject.Instantiate(Resources.Load <GameObject>("trail"), e.gameObject.transform);
         trail.transform.localPosition = Vector3.zero;
         //trail.transform.parent = e.gameObject.transform;
     }
     Update(e, position, size, color);
 }