Explorar el Código

弓和其镜头脚本修改

lvjincheng hace 4 años
padre
commit
9ea053668f
Se han modificado 2 ficheros con 43 adiciones y 19 borrados
  1. 28 14
      Assets/BowArrow/Scripts/Game/ArmBow.cs
  2. 15 5
      Assets/BowArrow/Scripts/Game/BowCamera.cs

+ 28 - 14
Assets/BowArrow/Scripts/Game/ArmBow.cs

@@ -1,4 +1,5 @@
-using System.Collections;
+using System;
+using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 /* 弓对象 */
@@ -7,35 +8,48 @@ public class ArmBow : MonoBehaviour
     [SerializeField] AnimationPlayer AP_arm;
     [SerializeField] AnimationPlayer AP_bow;
     [SerializeField] GameObject arrow;
-    [SerializeField] BowCamera bowCamera;
+    BowCamera _bowCamera;
+    BowCamera bowCamera {
+        get {
+            if (!_bowCamera) _bowCamera = GetComponentInParent<BowCamera>();
+            return _bowCamera; 
+        }
+    }
     public HashSet<TargetBody> validTargets = new HashSet<TargetBody>();
+    
+    //射箭姿态记录索引倒退数,根据射击难度制造误差
+    [NonSerialized] public int shootBackTime = 0;
 
-    public int shootBackTime = 0;
+    bool canShoot = false;
+    bool pulling = false;
+    bool readying = false;
 
-    private bool canShoot = false;
-    private bool pulling = false;
-    private bool readying = false;
     //禁止准备的外部接口
-    public bool banReady = false;
+    [NonSerialized] public bool banReady = false;
     //禁止射击的外部接口
-    public bool banShoot = false;
+    [NonSerialized] public bool banShoot = false;
+
+    //九轴姿态记录
+    [NonSerialized] public Quaternion[] recordRotations = new Quaternion[100];
+    float[] recordRotationVars = new float[99];
+    [NonSerialized] public int recordCount = 0;
 
     public static ArmBow ins;
-    public Quaternion[] recordRotations = new Quaternion[100];
-    public float[] recordRotationVars = new float[99];
-    public int recordCount = 0;
 
-    void Start()
+    void Awake()
     {
         ins = this;
-        this.readyShoot();
-
         //initdata
         int currentShootLevel = LoginMgr.myUserInfo.shootLevel;
         int[] shootBackTimes = {0, 1, 5};
         shootBackTime = shootBackTimes[currentShootLevel];
     }
 
+    void Start()
+    {
+        this.readyShoot();
+    }
+
     void FixedUpdate()
     {
         if (this.canShoot)

+ 15 - 5
Assets/BowArrow/Scripts/Game/BowCamera.cs

@@ -5,20 +5,30 @@ using UnityEngine.EventSystems;
 public class BowCamera : MonoBehaviour
 {
     //相机组件
-    Camera cameraComp;
+    Camera _cameraComp;
+    Camera cameraComp {
+        get {
+            if (!_cameraComp) _cameraComp = GetComponent<Camera>();
+            return _cameraComp;
+        }
+    }
+    //控制的手臂弓
+    ArmBow _armBow;
+    ArmBow armBow {
+        get {
+            if (!_armBow) _armBow = GetComponentInChildren<ArmBow>();
+            return _armBow;
+        }
+    }
     //本地欧拉角记录值
     Vector3 localEulerAngles;
-    //控制的手臂弓
-    ArmBow armBow;
     //触摸模式开关
     bool isTouchMode = true;
     public static BowCamera ins;
 
     void Awake() {
         ins = this;
-        cameraComp = GetComponent<Camera>();
         localEulerAngles = transform.localEulerAngles;
-        armBow = GetComponentInChildren<ArmBow>();
     }
 
     void Update()