zhengchen 1 سال پیش
والد
کامیت
9e4c0abf9e

+ 264 - 6
Assets/Resources/Cock/prefab_cock_1.prefab

@@ -333,6 +333,82 @@ Transform:
   m_Father: {fileID: 4724331093719414564}
   m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &538523679469303377
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 5000539523578392388}
+  - component: {fileID: 3045561330947043075}
+  - component: {fileID: 1633065916461766546}
+  m_Layer: 3
+  m_Name: Foreground
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!224 &5000539523578392388
+RectTransform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 538523679469303377}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 0.003, y: 0.003, z: 0.003}
+  m_ConstrainProportionsScale: 1
+  m_Children: []
+  m_Father: {fileID: 9125122459027006504}
+  m_RootOrder: 1
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+  m_AnchorMin: {x: 0, y: 0.5}
+  m_AnchorMax: {x: 0, y: 0.5}
+  m_AnchoredPosition: {x: 666.7, y: 0.85}
+  m_SizeDelta: {x: 200, y: 15}
+  m_Pivot: {x: 0, y: 0.5}
+--- !u!222 &3045561330947043075
+CanvasRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 538523679469303377}
+  m_CullTransparentMesh: 1
+--- !u!114 &1633065916461766546
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 538523679469303377}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Material: {fileID: 0}
+  m_Color: {r: 0, g: 1, b: 0.108231544, a: 1}
+  m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
+  m_Maskable: 1
+  m_OnCullStateChanged:
+    m_PersistentCalls:
+      m_Calls: []
+  m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
+  m_Type: 1
+  m_PreserveAspect: 0
+  m_FillCenter: 1
+  m_FillMethod: 4
+  m_FillAmount: 1
+  m_FillClockwise: 1
+  m_FillOrigin: 0
+  m_UseSpriteMesh: 0
+  m_PixelsPerUnitMultiplier: 1
 --- !u!1 &552410990046524905
 GameObject:
   m_ObjectHideFlags: 0
@@ -1106,6 +1182,82 @@ Transform:
   m_Father: {fileID: 5858679518435754502}
   m_RootOrder: 2
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &3889851953702532973
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 7779667572417376929}
+  - component: {fileID: 2720045510046152255}
+  - component: {fileID: 246438797345274161}
+  m_Layer: 3
+  m_Name: Background
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!224 &7779667572417376929
+RectTransform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3889851953702532973}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 0.003, y: 0.003, z: 0.003}
+  m_ConstrainProportionsScale: 1
+  m_Children: []
+  m_Father: {fileID: 9125122459027006504}
+  m_RootOrder: 0
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+  m_AnchorMin: {x: 0.5, y: 0.5}
+  m_AnchorMax: {x: 0.5, y: 0.5}
+  m_AnchoredPosition: {x: 0, y: 0.85}
+  m_SizeDelta: {x: 200, y: 15}
+  m_Pivot: {x: 0.5, y: 0.5}
+--- !u!222 &2720045510046152255
+CanvasRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3889851953702532973}
+  m_CullTransparentMesh: 1
+--- !u!114 &246438797345274161
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3889851953702532973}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Material: {fileID: 0}
+  m_Color: {r: 0, g: 0, b: 0, a: 1}
+  m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
+  m_Maskable: 1
+  m_OnCullStateChanged:
+    m_PersistentCalls:
+      m_Calls: []
+  m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
+  m_Type: 1
+  m_PreserveAspect: 0
+  m_FillCenter: 1
+  m_FillMethod: 4
+  m_FillAmount: 1
+  m_FillClockwise: 1
+  m_FillOrigin: 0
+  m_UseSpriteMesh: 0
+  m_PixelsPerUnitMultiplier: 1
 --- !u!1 &3962045871586526942
 GameObject:
   m_ObjectHideFlags: 0
@@ -1389,7 +1541,7 @@ GameObject:
   - component: {fileID: -8531684669894697885}
   - component: {fileID: 3261479113818730106}
   - component: {fileID: 301670950033994504}
-  - component: {fileID: -8522761524644147117}
+  - component: {fileID: 2183380708503071168}
   m_Layer: 3
   m_Name: prefab_cock_1
   m_TagString: cock
@@ -1416,6 +1568,7 @@ Transform:
   - {fileID: 3373053466674489722}
   - {fileID: 3169509252188027466}
   - {fileID: 7119851407046029862}
+  - {fileID: 9125122459027006504}
   m_Father: {fileID: 0}
   m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -1451,7 +1604,9 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 53ba5bbda83e41628281d34f7cdb84b3, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  reduceHp: 0
   playerId: 0
+  cockId: 0
   rightForward: 0
   animator: {fileID: 2204423604733202173}
 --- !u!54 &-8531684669894697885
@@ -1579,8 +1734,8 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   Tag: "\u52A8\u6001\u7ED1\u5B9A"
---- !u!135 &-8522761524644147117
-SphereCollider:
+--- !u!64 &2183380708503071168
+MeshCollider:
   m_ObjectHideFlags: 0
   m_CorrespondingSourceObject: {fileID: 0}
   m_PrefabInstance: {fileID: 0}
@@ -1589,9 +1744,10 @@ SphereCollider:
   m_Material: {fileID: 0}
   m_IsTrigger: 0
   m_Enabled: 1
-  serializedVersion: 2
-  m_Radius: 0.43
-  m_Center: {x: 0, y: 0.7, z: 0}
+  serializedVersion: 4
+  m_Convex: 0
+  m_CookingOptions: 30
+  m_Mesh: {fileID: 2954858793080512207, guid: c8e1df4a0fedb9540896f08670fdd82a, type: 3}
 --- !u!1 &4965920312758957799
 GameObject:
   m_ObjectHideFlags: 0
@@ -3932,6 +4088,108 @@ Transform:
   m_Father: {fileID: 808342166560444552}
   m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &7646010537489203941
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 9125122459027006504}
+  - component: {fileID: 331119558107365927}
+  - component: {fileID: 4500051021289048141}
+  - component: {fileID: 375123488227861480}
+  m_Layer: 3
+  m_Name: Canvas
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!224 &9125122459027006504
+RectTransform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 7646010537489203941}
+  m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.7071068}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1.4836135, y: 1.4836135, z: 1.4836135}
+  m_ConstrainProportionsScale: 0
+  m_Children:
+  - {fileID: 7779667572417376929}
+  - {fileID: 5000539523578392388}
+  m_Father: {fileID: 5221786613589611655}
+  m_RootOrder: 7
+  m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
+  m_AnchorMin: {x: 0, y: 0}
+  m_AnchorMax: {x: 0, y: 0}
+  m_AnchoredPosition: {x: 0, y: 0}
+  m_SizeDelta: {x: 1334, y: 750}
+  m_Pivot: {x: 0.5, y: 0.5}
+--- !u!223 &331119558107365927
+Canvas:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 7646010537489203941}
+  m_Enabled: 1
+  serializedVersion: 3
+  m_RenderMode: 2
+  m_Camera: {fileID: 0}
+  m_PlaneDistance: 100
+  m_PixelPerfect: 0
+  m_ReceivesEvents: 1
+  m_OverrideSorting: 0
+  m_OverridePixelPerfect: 0
+  m_SortingBucketNormalizedSize: 0
+  m_AdditionalShaderChannelsFlag: 0
+  m_SortingLayerID: 0
+  m_SortingOrder: 0
+  m_TargetDisplay: 0
+--- !u!114 &4500051021289048141
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 7646010537489203941}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_UiScaleMode: 0
+  m_ReferencePixelsPerUnit: 100
+  m_ScaleFactor: 1
+  m_ReferenceResolution: {x: 800, y: 600}
+  m_ScreenMatchMode: 0
+  m_MatchWidthOrHeight: 0
+  m_PhysicalUnit: 3
+  m_FallbackScreenDPI: 96
+  m_DefaultSpriteDPI: 96
+  m_DynamicPixelsPerUnit: 1
+  m_PresetInfoIsWorld: 1
+--- !u!114 &375123488227861480
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 7646010537489203941}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_IgnoreReversedGraphics: 1
+  m_BlockingObjects: 0
+  m_BlockingMask:
+    serializedVersion: 2
+    m_Bits: 4294967295
 --- !u!1 &7778348277608727122
 GameObject:
   m_ObjectHideFlags: 0

+ 6 - 4
Assets/Scripts/Comp/BattleMainComp.cs

@@ -57,13 +57,15 @@ namespace Comp
             GamePlayer localPlayer, antiPlayer;
             if (localPlayerId == obj.fromPlayer)
             {
-                localPlayer = new GamePlayer() { cockId = obj.fromCock, playerId = obj.fromPlayer };
-                antiPlayer = new GamePlayer() { cockId = obj.toCock, playerId = obj.toPlayer };
+                localPlayer = new GamePlayer()
+                    { cockId = obj.fromCock, playerId = obj.fromPlayer, hp = obj.fromPlayerHp };
+                antiPlayer = new GamePlayer() { cockId = obj.toCock, playerId = obj.toPlayer, hp = obj.toPlayerHp };
             }
             else
             {
-                localPlayer = new GamePlayer() { cockId = obj.toCock, playerId = obj.toPlayer };
-                antiPlayer = new GamePlayer() { cockId = obj.fromCock, playerId = obj.fromPlayer };
+                localPlayer = new GamePlayer() { cockId = obj.toCock, playerId = obj.toPlayer, hp = obj.toPlayerHp };
+                antiPlayer = new GamePlayer()
+                    { cockId = obj.fromCock, playerId = obj.fromPlayer, hp = obj.fromPlayerHp };
             }
 
             Debug.Log("local player is " + localPlayer.playerId + "==== anti player is " + antiPlayer.playerId);

+ 66 - 0
Assets/Scripts/Comp/CockActionComp.cs

@@ -3,15 +3,59 @@ using System.Collections;
 using Game;
 using Sound;
 using UnityEngine;
+using UnityEngine.UI;
 
 namespace Comp
 {
     public class CockActionComp : MonoBehaviour
     {
+        private static readonly Color HpGreen = new Color(0.06f, 0.9f, 0.18f);
+        private static readonly Color HpYellow = new Color(0.9f, 0.9f, 0.18f);
+        private static readonly Color HpRed = new Color(0.9f, 0.18f, 0.18f);
+
         private const string CockTag = "cock";
 
         private ICockController _cockController;
 
+        // 血量条组件
+        private Image _backgroundImage, _foregroundImage;
+
+        private int _maxHp, _curHp;
+
+        public int reduceHp; // 需要扣除的Hp
+
+        public int MaxHp
+        {
+            set
+            {
+                _maxHp = value;
+                _curHp = _maxHp;
+            }
+        }
+
+        private void ReduceCurHp(int hp)
+        {
+            _curHp -= hp;
+            var hpPercent = (float)_curHp / _maxHp;
+            if (hpPercent > 0.5f)
+            {
+                _foregroundImage.color = HpGreen;
+            }
+            else if (hpPercent is >= 0.25f and <= 0.5f)
+            {
+                _foregroundImage.color = HpYellow;
+            }
+            else
+            {
+                _foregroundImage.color = HpRed;
+            }
+
+            var backgroundSize = _backgroundImage.rectTransform.sizeDelta;
+            var foregroundSize = _foregroundImage.rectTransform.sizeDelta;
+            var newForegroundWidth = backgroundSize.x * hpPercent;
+            _foregroundImage.rectTransform.sizeDelta = new Vector2(newForegroundWidth, foregroundSize.y);
+        }
+
         // 跑步跟切换待机状态相关参数
 
         private bool _firstTrigger = true; // 第一次碰撞切换为待机
@@ -79,6 +123,21 @@ namespace Comp
         private void Start()
         {
             _missPrefab = Resources.Load<GameObject>("Prefab/prefab_miss");
+            // 获取血条的填充图片
+            var images = GetComponentsInChildren<Image>();
+            foreach (var image in images)
+            {
+                if (image.name == "Background")
+                {
+                    _backgroundImage = image;
+                }
+                if (image.name == "Foreground")
+                {
+                    _foregroundImage = image;
+                }
+            }
+
+            // 获取最低Y坐标
             _miniY = transform.position.y;
             // 跳跃相关
             _lowData = new CockJumpData(0.5f, 0.45f, false);
@@ -104,6 +163,12 @@ namespace Comp
                 _createMiss = false;
                 CreateMissText();
             }
+
+            if (reduceHp != 0)
+            {
+                ReduceCurHp(reduceHp);
+                reduceHp = 0;
+            }
         }
 
         private void FixedUpdate()
@@ -215,6 +280,7 @@ namespace Comp
             {
                 return Vector3.zero;
             }
+
             // 计算重力
             _jumpDirection.y += _gravity * Time.deltaTime;
             _curJumpTime -= Time.deltaTime;

+ 11 - 16
Assets/Scripts/Game/GameBattleState.cs

@@ -88,21 +88,12 @@ namespace Game
                 return;
             ExecuteBattleObj(_gameCore.battleDetailObjs.Last.Value);
             _gameCore.battleDetailObjs.RemoveLast();
-            // if (_gameCore.battleDetailObjs.Count < 0)
-            // {
-            //     Debug.Log("end battle");
-            //     _gameCore.battleMainComp.end = true;
-            //     _battleTimer.Dispose();
-            // }
-            // else
-            if (_gameCore.battleDetailObjs.Count == 0)
-            {
-                ExecuteLastBattleObj();
-                Debug.Log("end battle");
-                _gameCore.battleMainComp.end = true;
-                _battleTimer.Dispose();
-                _battleTimer = null;
-            }
+            if (_gameCore.battleDetailObjs.Count != 0) return;
+            Debug.Log("end battle");
+            ExecuteLastBattleObj();
+            _gameCore.battleMainComp.end = true;
+            _battleTimer.Dispose();
+            _battleTimer = null;
         }
 
         private void ExecuteBattleObj(BattleDetailObj battleDetailObj)
@@ -112,11 +103,15 @@ namespace Game
                 var log = battleDetailObj.logs[i];
                 var fromComp = _gameCore.GetCockActionCompByPlayerId(log.from);
                 fromComp.SetHighJump(i == 0);
+                var toComp = _gameCore.GetCockActionCompByPlayerId(log.to);
                 if (i == 0 && log.value == 0) // 攻击落空了
                 {
-                    var toComp = _gameCore.GetCockActionCompByPlayerId(log.to);
                     toComp.CreateMiss();
                 }
+                else
+                {
+                    toComp.reduceHp = log.value;
+                }
 
                 switch (log.type)
                 {

+ 11 - 5
Assets/Scripts/Game/GamePendingState.cs

@@ -32,7 +32,6 @@ namespace Game
 
         public override void ExitBattle()
         {
-           
         }
 
         public override void EndBattle()
@@ -41,19 +40,26 @@ namespace Game
         }
 
         public override void EnterState()
-        {   
+        {
             Debug.Log("enter pending state");
             // 处理鸡模型
             var localCockPrefab = CockFactory.Instance.GenerateCockPrefab(_gameCore.localPlayer.cockId);
             var antiCockPrefab = CockFactory.Instance.GenerateCockPrefab(_gameCore.antiPlayer.cockId);
             var localCock = Object.Instantiate(localCockPrefab);
             var antiCock = Object.Instantiate(antiCockPrefab);
+            // 处理鸡组件
             var localCockActionComp = localCock.GetComponent<CockActionComp>();
-            localCockActionComp.cockId = _gameCore.localPlayer.cockId;
             var antiCockActionComp = antiCock.GetComponent<CockActionComp>();
+
+            localCockActionComp.cockId = _gameCore.localPlayer.cockId;
             antiCockActionComp.cockId = _gameCore.antiPlayer.cockId;
+
             localCockActionComp.playerId = _gameCore.localPlayer.playerId;
             antiCockActionComp.playerId = _gameCore.antiPlayer.playerId;
+
+            localCockActionComp.MaxHp = _gameCore.localPlayer.hp;
+            antiCockActionComp.MaxHp = _gameCore.antiPlayer.hp;
+
             _gameCore.cockDict.Add(_gameCore.localPlayer.playerId, localCockActionComp);
             _gameCore.cockDict.Add(_gameCore.antiPlayer.playerId, antiCockActionComp);
 
@@ -69,7 +75,7 @@ namespace Game
                 new Vector3(CockInitialX - StaticOffset, antiCock.transform.position.y, antiCock.transform.position.z);
             localCock.transform.parent = _gameCore.parent.transform;
             antiCock.transform.parent = _gameCore.parent.transform;
-            
+
             // 处理主人模型
             var masterPrefab = Resources.Load<GameObject>("Human/prefab_master");
             var localMaster = Object.Instantiate(masterPrefab);
@@ -83,7 +89,7 @@ namespace Game
             antiMaster.transform.eulerAngles = new Vector3(0, -90f, 0);
             localMaster.transform.parent = _gameCore.parent.transform;
             antiMaster.transform.parent = _gameCore.parent.transform;
-            
+
             var localMasterActionComp = localMaster.GetComponent<MasterActionComp>();
             localMasterActionComp.playerId = _gameCore.localPlayer.playerId;
             var antiMasterActionComp = antiMaster.GetComponent<MasterActionComp>();

+ 2 - 0
Assets/Scripts/Game/GamePlayer.cs

@@ -10,6 +10,8 @@ namespace Game
 
         public int cockId;
 
+        public int hp;
+
         public bool IsLocalPlayer()
         {
             return false;