Exemplo n.º 1
0
 public void Start()
 {
     shipComponent = GetComponent <ShipComponent>();
     ship          = shipComponent.ParentShip;
     control       = ship.GetComponent <ShipControl>();
     control.AddThruster(this);
 }
Exemplo n.º 2
0
 protected void Start()
 {
     component = GetComponent <ShipComponent>();
     ship      = component.ParentShip;
     control   = ship.GetComponent <ShipControl>();
     control.AddWeapon(this);
 }
Exemplo n.º 3
0
 protected void Start()
 {
     component = GetComponent <ShipComponent>();
     ship      = component.ParentShip;
     control   = ship.GetComponent <ShipControl>();
     control.AddWeapon(this);
     animator = component.Blocks[new Vector2Int(0, 0)].GetComponent <Animator>();
 }
Exemplo n.º 4
0
 protected override void Start()
 {
     shipComponent                 = GetComponent <ShipComponent>();
     ship                          = shipComponent.ParentShip;
     control                       = ship.GetComponent <ShipControl>();
     laserBase                     = shipComponent.Blocks[new Vector2Int(0, 0)].GetComponent <Animator>();
     head                          = shipComponent.Blocks[new Vector2Int(0, 1)].GetComponent <Animator>();
     laserTriggeerDamage           = LaserGlow.GetComponent <LaserTriggerDamage>();
     laserTriggeerDamage.shipLaser = this;
     control.AddWeapon(this);
     base.Start();
 }
Exemplo n.º 5
0
        /// <summary>
        /// 根据ID顺序排序
        /// </summary>
        /// <param name="obj">其它block</param>
        /// <returns>相对大小</returns>
        public int CompareTo(object obj)
        {
            ShipComponent other = obj as ShipComponent;

            if (other.Id > Id)
            {
                return(-1);
            }
            if (other.Id == Id)
            {
                return(0);
            }
            return(1);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 添加某个ID的组件
        /// </summary>
        /// <param name="id">组件ID</param>
        /// <param name="level">组件等级</param>
        /// <param name="pos">组件原点坐标</param>
        /// <param name="rotation">组件旋转</param>
        /// <param name="mirror">组件镜像</param>
        public ShipComponent AddComponent(int id, int level, Vector2Int pos, ShipUnitRotation rotation = ShipUnitRotation.d0, ShipUnitMirror mirror = ShipUnitMirror.Normal)
        {
            if (id == 0 && core != null)
            {
                return(null);
            }
            List <Vector2Int> whiteList = new List <Vector2Int>(), blackList = new List <Vector2Int>();
            ShipComponent     component = GetShipComponent(id, level);
            bool whiteCheck = false, blackCheck = true;

            foreach (var bk in component.BlockList)
            {
                if (!GetBlock(bk.id, level).CanAddWithoutList&&WhiteListPos.Contains(PosTrans(new Vector2Int(bk.posX, bk.posY), rotation, mirror) + pos))
                {
                    whiteCheck = true;
                }

                if (GetBlock(bk.id, level).CanAddWithoutList)
                {
                    whiteCheck = true;
                }
            }

            Debug.Log("white" + whiteCheck);
            foreach (var bk in component.BlockList)
            {
                if ((Blocks.ContainsKey(PosTrans(new Vector2Int(bk.posX, bk.posY), rotation, mirror) + pos)))
                {
                    blackCheck = false;
                }

                if (((BlackListPos.Contains(PosTrans(new Vector2Int(bk.posX, bk.posY), rotation, mirror) + pos)) &&
                     (!GetBlock(bk.id, level).CanAddOnBlackList)))
                {
                    blackCheck = false;
                }
                foreach (var p in GetBlock(bk.id, level).CheckPos)
                {
                    if (Blocks.ContainsKey(PosTrans(new Vector2Int(bk.posX, bk.posY) + p, rotation, mirror) + pos))
                    {
                        blackCheck = false;
                    }
                }
            }
            if (!whiteCheck || !blackCheck)
            {
                return(null);
            }

            var componentTransform = Instantiate(GetShipComponent(id, level).gameObject, transform).transform;
            var shipComponent      = componentTransform.GetComponent <ShipComponent>();

            componentTransform.localPosition = Block.GetLocalPositionFromShipPos(pos);
            var rot = Vector3.zero;

            //镜像处理
            switch (mirror)
            {
            case ShipUnitMirror.Normal:
                break;

            case ShipUnitMirror.MirrorX:
                rot.x = 180;
                break;

            case ShipUnitMirror.MirrorY:
                rot.y = 180;
                break;

            case ShipUnitMirror.MirrorBoth:
                rot.x = 180;
                rot.y = 180;
                break;
            }
            //旋转处理
            switch (rotation)
            {
            case ShipUnitRotation.d0:
                rot.z = 0;
                break;

            case ShipUnitRotation.d90:
                rot.z = 90;
                break;

            case ShipUnitRotation.d180:
                rot.z = 180;
                break;

            case ShipUnitRotation.d270:
                rot.z = 270;
                break;
            }
            componentTransform.rotation = Quaternion.Euler(rot);
            shipComponent.ParentShip    = this;
            shipComponent.pos           = pos;
            shipComponent.Rotation      = rotation;
            shipComponent.Mirror        = mirror;
            ShipComponents.Add(pos, shipComponent);
            shipComponent.Blocks.Clear();
            foreach (var bk in component.BlockList)
            {
                Block blo = ForceAddBlockAtPosition(bk.id, level, PosTrans(new Vector2Int(bk.posX, bk.posY), rotation, mirror) + pos, rotation, mirror);
                shipComponent.Blocks.Add(new Vector2Int(bk.posX, bk.posY), blo);
                if (blo != null)
                {
                    blo.ParentShipComponent = shipComponent;
                    blo.transform.parent    = shipComponent.transform;
                }
            }
            return(shipComponent);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 添加某个ID的组件
        /// </summary>
        /// <param name="id">组件ID</param>
        /// <param name="level">组件等级</param>
        /// <param name="pos">组件原点坐标</param>
        /// <param name="rotation">组件旋转</param>
        /// <param name="mirror">组件镜像</param>
        public ShipComponent AddComponent(int id, int level, Vector2Int pos, ShipUnitRotation rotation = ShipUnitRotation.d0, ShipUnitMirror mirror = ShipUnitMirror.Normal)
        {
            if (!ComponentPutable(id, level, pos, rotation, mirror))
            {
                return(null);
            }
            ShipComponent component          = GetShipComponent(id, level);
            var           componentTransform = Instantiate(GetShipComponent(id, level).gameObject, transform).transform;
            var           shipComponent      = componentTransform.GetComponent <ShipComponent>();

            componentTransform.localPosition = Block.GetLocalPositionFromShipPos(pos);
            var rot = Vector3.zero;

            //镜像处理
            switch (mirror)
            {
            case ShipUnitMirror.Normal:
                break;

            case ShipUnitMirror.MirrorX:
                rot.x = 180;
                break;

            case ShipUnitMirror.MirrorY:
                rot.y = 180;
                break;

            case ShipUnitMirror.MirrorBoth:
                rot.x = 180;
                rot.y = 180;
                break;
            }
            //旋转处理
            switch (rotation)
            {
            case ShipUnitRotation.d0:
                rot.z = 0;
                break;

            case ShipUnitRotation.d90:
                rot.z = 90;
                break;

            case ShipUnitRotation.d180:
                rot.z = 180;
                break;

            case ShipUnitRotation.d270:
                rot.z = 270;
                break;
            }
            componentTransform.rotation = Quaternion.Euler(rot);
            shipComponent.ParentShip    = this;
            shipComponent.pos           = pos;
            shipComponent.Rotation      = rotation;
            shipComponent.Mirror        = mirror;
            ShipComponents.Add(pos, shipComponent);
            shipComponent.Blocks.Clear();
            foreach (var bk in component.BlockList)
            {
                Block blo = ForceAddBlockAtPosition(bk.id, level, PosTrans(new Vector2Int(bk.posX, bk.posY), rotation, mirror) + pos, rotation, mirror);
                shipComponent.Blocks.Add(new Vector2Int(bk.posX, bk.posY), blo);
                if (blo != null)
                {
                    blo.ParentShipComponent = shipComponent;
                    blo.transform.parent    = shipComponent.transform;
                }
            }
            return(shipComponent);
        }
Exemplo n.º 8
0
        public bool ComponentPutable(int id, int level, Vector2Int pos, ShipUnitRotation rotation = ShipUnitRotation.d0,
                                     ShipUnitMirror mirror = ShipUnitMirror.Normal)
        {
            if (GetShipComponent(id, level) == null)
            {
                return(false);

                Debug.Log("1");
            }
            if (id == 0 && core != null)
            {
                return(false);

                Debug.Log("2");
            }
            List <Vector2Int> whiteList = new List <Vector2Int>(), blackList = new List <Vector2Int>();
            ShipComponent     component = GetShipComponent(id, level);
            bool whiteCheck = false, blackCheck = true;

            foreach (var bk in component.BlockList)
            {
                if (!GetBlock(bk.id, level).CanAddWithoutList&& WhiteListPos.Contains(PosTrans(new Vector2Int(bk.posX, bk.posY), rotation, mirror) + pos))
                {
                    whiteCheck = true;
                }

                if (GetBlock(bk.id, level).CanAddWithoutList)
                {
                    whiteCheck = true;
                }
            }

            Debug.Log("white" + whiteCheck);
            foreach (var bk in component.BlockList)
            {
                if ((Blocks.ContainsKey(PosTrans(new Vector2Int(bk.posX, bk.posY), rotation, mirror) + pos)))
                {
                    blackCheck = false;
                    Debug.Log("b1");
                }

                if (((BlackListPos.Contains(PosTrans(new Vector2Int(bk.posX, bk.posY), rotation, mirror) + pos)) &&
                     (!GetBlock(bk.id, level).CanAddOnBlackList)))
                {
                    blackCheck = false;
                    Debug.Log("b2");
                }
                foreach (var p in GetBlock(bk.id, level).CheckPos)
                {
                    if (Blocks.ContainsKey(PosTrans(new Vector2Int(bk.posX, bk.posY) + p, rotation, mirror) + pos))
                    {
                        blackCheck = false;
                        Debug.Log("b3");
                    }
                }
            }
            if (!whiteCheck || !blackCheck)
            {
                return(false);

                Debug.Log("3");
            }
            return(true);
        }