赞
踩
目前参与一款在研SLG研发,目前在开发实时战斗部分的表现,今天要分享的是实时战斗头像自动排布算法的实现。
PotraitBoard 可以放在UI任意节点,指定好控制参数,即可在Enable Disable时自动注册和反注册
PotraitManager挂载于场景常驻节点
PotraitManager._root需要为UI节点下AnchorPreset为Strench/Strench(铺满全屏)
PotraitManager.areasCount为屏幕空间拆分的行列数
代码略长,不过注释充分,直接贴上了……
- using System.Collections.Generic;
- using System.Text;
- using DG.Tweening;
- using UnityEngine;
- using XLua;
-
- public class PotraitBoard : MonoBehaviour
- {
- [LuaCallCSharp]
- public enum DefaultPos
- {
- Left = 1,
- Right = 2,
- }
-
- /// <summary>
- /// controll target
- /// </summary>
- public RectTransform target;
-
- /// <summary>
- /// available points
- /// </summary>
- public List<RectTransform> availablePoints = new List<RectTransform>();
-
- /// <summary>
- /// best sort of points
- /// </summary>
- public List<int> bestSortOfPoints = new List<int>();
-
- /// <summary>
- /// position illegle check duration
- /// </summary>
- private float checkDuration = 2f;
-
- /// <summary>
- /// pos of potrait sets
- /// </summary>
- private int curPos = 0;
-
- /// <summary>
- /// pos of potrait sets
- /// </summary>
- private int curIndex = 0;
-
- /// <summary>
- /// troop`s direction
- /// </summary>
- private Vector2 direction = Vector2.left;
-
- /// <summary>
- /// move to next pos
- /// </summary>
- /// <param name="nextPos"></param>
- private void MoveToNext(int nextPos)
- {
- target.DOLocalMove(availablePoints[nextPos].localPosition, 0.5f).SetEase(Ease.OutQuad);
- }
-
- /// <summary>
- /// move to next available point in availablePoints in default sequence, if cur is not available
- /// </summary>
- private void MoveToNextIfNotAvailable()
- {
- if (PotraitBoardManager.Instance.IsPointAvailable(availablePoints[curPos]))
- return;
-
- int sign = curPos;
- while (!PotraitBoardManager.Instance.IsPointAvailable(availablePoints[curPos]))
- {
- curPos++;
- curPos = curPos % availablePoints.Count;
- if (sign == curPos)
- return;
- }
-
- //Debug.Log("PotraitBoard MoveToNextIfNotAvailable Move From [" + sign + "] To Pos: [" + curPos + "]");
-
- PotraitBoardManager.Instance.UnRegisterPotrait(curIndex,availablePoints[sign]);
- curIndex = PotraitBoardManager.Instance.RegisterPotrait(availablePoints[curPos]);
-
- MoveToNext(curPos);
- }
-
- /// <summary>
- /// move to next best point available
- /// </summary>
- private void MoveToNextBestAvailable()
- {
- if (bestSortOfPoints.Count <= 0)
- ReSortPoints();
-
- int pIndex = 0;
-
- for (int i = 0; i < bestSortOfPoints.Count; i++)
- {
- if (Potra
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。