123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using UnityEngine;
- using System.Collections;
- public class SwapManager
- {
- public const float PREPARING_SWAP_DURATION = 3f;
- public const float SWAP_CD = 3f;
- public int targetSwapId;
- public bool isPreparingSwap;
- public float preparingSwapStartTime;
- public bool requestedSwap;
- public float lastSwapTime;
- private Craft craft;
- public SwapManager(Craft craft)
- {
- this.craft = craft;
- lastSwapTime = GameTime.time;
- }
- public void PrepareSwap(int targetSwapId)
- {
- this.targetSwapId = targetSwapId;
- isPreparingSwap = true;
- preparingSwapStartTime = GameTime.time;
- craft.StopMove();
- }
-
- public float GetPreparingSwapTime()
- {
- if(preparingSwapStartTime < 0)
- return 0;
- return Mathf.Min(GameTime.time - preparingSwapStartTime, PREPARING_SWAP_DURATION);
- }
-
- public bool IsReadySwap()
- {
- return GetPreparingSwapTime() == PREPARING_SWAP_DURATION;
- }
-
- public void AbortSwap()
- {
- if(requestedSwap)
- return;
-
- preparingSwapStartTime = -1f;
- isPreparingSwap = false;
- craft.GetHeadBar().HideSpell();
- }
-
- public int GetTargetSwapId()
- {
- return targetSwapId;
- }
-
- public void RequestedSwap()
- {
- preparingSwapStartTime = -1f;
- requestedSwap = true;
- }
-
- public void Swap(Craft newCraft, int craftId, CraftEquipModify equipModify)
- {
- if(craft.IsDead())
- return;
- lastSwapTime = GameTime.time;
-
- craft.GetHeadBar().HideSpell();
- isPreparingSwap = false;
- requestedSwap = false;
- craft.SetEquipModify (equipModify);
- craft.SetCraftId (craftId);
-
- craft.bodyTrans.SetParent(null);
- GameObject.Destroy(craft.bodyTrans.gameObject);
-
- Transform newBody = newCraft.transform.Find("Body");
- newBody.SetParent(craft.transform);
- newBody.localPosition = Vector3.zero;
- newBody.localScale = new Vector3(1f, 1f, 1f);
-
- craft.textureArr = newCraft.textureArr;
-
- GameObject.Destroy(newCraft.gameObject);
-
- craft.Init();
-
- craft.team = craft.team;
- craft.SwapComplete();
- }
- public float GetSwapCoolDown()
- {
- return Mathf.Min(GameTime.time - lastSwapTime, SWAP_CD);
- }
- }
|