예제 #1
0
        public Ship LoadShipWithData(SerializeShipData data)
        {
            byte[]     shipBytes  = SerializeHelp.ReadFile(Application.dataPath + "/Resources/Ship/" + data.shipCamp.ToString() + data.shipName + ".ship");
            ShipData   shipData   = SerializeHelp.ReadObjectData <ShipData>(shipBytes);
            GameObject shipObject = Instantiate(EmptyShip, (Vector3)data.position, Quaternion.Euler((Vector3)data.rotation));
            Ship       ship       = shipObject.GetComponent <Ship>();

            ship.ShipName = ship.name = shipData.ShipName;
            foreach (var component in shipData.Records)
            {
                ship.AddComponent(component.id, component.level, new Vector2Int((int)component.pos.x, (int)component.pos.y),
                                  (ShipEnum.ShipUnitRotation)Enum.ToObject(typeof(ShipEnum.ShipUnitRotation), component.rotation),
                                  (ShipEnum.ShipUnitMirror)Enum.ToObject(typeof(ShipEnum.ShipUnitMirror), component.mirror));
            }
            ship.SetCamp(data.shipCamp);
            foreach (Block block in ship.Blocks.Values)
            {
                BlockHealth health = block.GetComponent <BlockHealth>();
                if (health != null)
                {
                    health.ReceiveDamage(null, data.blockHealthData[(SerializableVector2Int)block.Pos].health);
                }
            }
            Debug.Log("debug太多免得我看不见所以才打这一行字" + data.mode.ToString());
            ship.control.mode = data.mode;
            Debug.Assert(ShipManager.Instance.enabled);
            ship.control.Sp = data.Sp;
            Debug.Assert(ShipManager.Instance.enabled);
            ship.control.SpColding = data.isColding;
            Debug.Assert(ShipManager.Instance.enabled);
            ShipManager.Instance.ships[data.shipCamp].Add(ship);
            Debug.Assert(ShipManager.Instance.enabled);
            return(ship);
        }
예제 #2
0
        public void LoadShipAtTransform(string shipName, Transform theTransform)
        {
            byte[]     shipBytes  = SerializeHelp.ReadFile(Application.dataPath + "/Resources/Ship/" + shipName);
            ShipData   shipData   = SerializeHelp.ReadObjectData <ShipData>(shipBytes);
            GameObject shipObject = Instantiate(EmptyShip, theTransform.position, theTransform.rotation);
            Ship       ship       = shipObject.GetComponent <Ship>();

            ship.ShipName = ship.name = shipData.ShipName;
            foreach (var component in shipData.Records)
            {
                ship.AddComponent(component.id, component.level, new Vector2Int((int)component.pos.x, (int)component.pos.y),
                                  (ShipEnum.ShipUnitRotation)Enum.ToObject(typeof(ShipEnum.ShipUnitRotation), component.rotation),
                                  (ShipEnum.ShipUnitMirror)Enum.ToObject(typeof(ShipEnum.ShipUnitMirror), component.mirror));
            }
        }
예제 #3
0
        public Ship LoadShipAtTransform(string shipName, Transform theTransform, GameCamp camp, ShipControlMode mode = ShipControlMode.Building)
        {
            byte[]     shipBytes  = SerializeHelp.ReadFile(Application.dataPath + "/Resources/Ship/" + camp.ToString() + shipName + ".ship");
            ShipData   shipData   = SerializeHelp.ReadObjectData <ShipData>(shipBytes);
            GameObject shipObject = Instantiate(EmptyShip, theTransform.position, theTransform.rotation);
            Ship       ship       = shipObject.GetComponent <Ship>();

            ship.ShipName = ship.name = shipData.ShipName;
            foreach (var component in shipData.Records)
            {
                ship.AddComponent(component.id, component.level, new Vector2Int((int)component.pos.x, (int)component.pos.y),
                                  (ShipEnum.ShipUnitRotation)Enum.ToObject(typeof(ShipEnum.ShipUnitRotation), component.rotation),
                                  (ShipEnum.ShipUnitMirror)Enum.ToObject(typeof(ShipEnum.ShipUnitMirror), component.mirror));
            }
            ship.SetCamp(camp);
            ShipManager.Instance.ships[camp].Add(ship);
            ship.control.mode = mode;
            return(ship);
        }