This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,119 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 按键事件绑定到lua
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
[AddComponentMenu("NGUI/Button Message 4 Lua")]
public class CLButtonMsgLua : UIEventListener
{
public enum Trigger
{
OnClick,
OnMouseOver,
OnMouseOut,
OnPress,
OnRelease,
OnDoubleClick,
OnDrag,
OnDrop,
OnKey,
}
public CLPanelLua target;
public CLCellLua target2;
public Trigger trigger = Trigger.OnClick;
public string functionName = "";
void OnClick()
{
if (target != null && trigger == Trigger.OnClick) {
target.onClick4Lua(gameObject, functionName);
}
if (target2 != null && trigger == Trigger.OnClick) {
target2.onClick4Lua(gameObject, functionName);
}
}
void OnDoubleClick()
{
if (target != null && trigger == Trigger.OnDoubleClick)
target.onDoubleClick4Lua(gameObject, functionName);
if (target2 != null && trigger == Trigger.OnDoubleClick)
target2.onDoubleClick4Lua(gameObject, functionName);
}
void OnHover(bool isOver)
{
if (target != null) {
if (((isOver && trigger == Trigger.OnMouseOver) ||
(!isOver && trigger == Trigger.OnMouseOut))) {
target.onHover4Lua(gameObject, functionName, isOver);
}
}
if (target2 != null) {
if (((isOver && trigger == Trigger.OnMouseOver) ||
(!isOver && trigger == Trigger.OnMouseOut))) {
target2.onHover4Lua(gameObject, functionName, isOver);
}
}
}
void OnPress(bool isPressed)
{
if (target != null) {
if (((isPressed && trigger == Trigger.OnPress) ||
(!isPressed && trigger == Trigger.OnRelease)))
target.onPress4Lua(gameObject, functionName, isPressed);
}
if (target2 != null) {
if (((isPressed && trigger == Trigger.OnPress) ||
(!isPressed && trigger == Trigger.OnRelease)))
target2.onPress4Lua(gameObject, functionName, isPressed);
}
}
void OnSelect(bool isSelected)
{
if (target != null) {
if (enabled && (!isSelected || UICamera.currentScheme == UICamera.ControlScheme.Controller))
OnHover(isSelected);
}
}
void OnDrag(Vector2 delta)
{
if (target != null && trigger == Trigger.OnDrag)
target.onDrag4Lua(gameObject, functionName, delta);
if (target2 != null && trigger == Trigger.OnDrag)
target2.onDrag4Lua(gameObject, functionName, delta);
}
void OnDrop(GameObject go)
{
if (target != null && trigger == Trigger.OnDrop)
target.onDrop4Lua(gameObject, functionName, go);
if (target2 != null && trigger == Trigger.OnDrop)
target2.onDrop4Lua(gameObject, functionName, go);
}
void OnKey(KeyCode key)
{
if (target != null && trigger == Trigger.OnDrop)
target.onKey4Lua(gameObject, functionName, key);
if (target2 != null && trigger == Trigger.OnDrop)
target2.onKey4Lua(gameObject, functionName, key);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7263f9f1b1e174734b519cf575cd1f4a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,223 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 摇杆
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
/// <summary>
/// CL joystick.
/// </summary>
namespace Coolape
{
[RequireComponent(typeof(BoxCollider))]
public class CLJoystick : UIEventListener
{
public Transform joystickUI;
public float joystickMoveDis = 10;
object onPressCallback;
object onDragCallback;
object onClickCallback;
bool isCanMove = false;
Vector2 orgPos = Vector2.zero;
Vector2 dragDetla = Vector2.zero;
Vector3 joystickUIPos = Vector3.zero;
// GameObject empty = null;
bool isFinishStart = false;
void Start()
{
if (isFinishStart)
return;
isFinishStart = true;
// empty = new GameObject();
if (joystickUI != null) {
joystickUI.transform.parent.localScale = Vector3.one * 0.95f;
joystickUIPos = joystickUI.transform.parent.localPosition;
// empty.transform.parent = joystickUI.transform.parent;
orgPos = joystickUI.localPosition;
// empty.transform.localPosition = joystickUI.localPosition;
}
}
public void init(object onPress, object onClick, object onDrag)
{
onPressCallback = onPress;
onDragCallback = onDrag;
onClickCallback = onClick;
Start();
OnPress(false);
}
// RaycastHit lastHit;
MyMainCamera _mainCamera;
public MyMainCamera mainCamera
{
get {
if(_mainCamera == null)
{
_mainCamera = MyMainCamera.current;
}
return _mainCamera;
}
set
{
_mainCamera = value;
}
}
void OnClick()
{
if (mainCamera == null) return;
mainCamera.enabled = true;
mainCamera.Update();
mainCamera.LateUpdate();
// #if UNITY_EDITOR
// mainCamera.ProcessMouse();
// #else
// mainCamera.ProcessTouches();
//#endif
if (MyMainCamera.lastHit.collider != null) {
}
Utl.doCallback(onClickCallback);
}
void OnPress(bool isPressed)
{
if (!isPressed) {
// if(checkPressedJoy()) return;
CancelInvoke("doOnPress");
if (isCanMove) {
callOnPressCallback(isPressed);
}
isCanMove = false;
dragDetla = Vector2.zero;
if (joystickUI != null) {
joystickUI.localPosition = orgPos;
joyPosition = orgPos;
joystickUI.transform.parent.localPosition = joystickUIPos;
joystickUI.transform.parent.localScale = Vector3.one * 0.95f;
}
} else {
joyPosition = orgPos;
if (joystickUI != null) {
joystickUI.transform.parent.localScale = Vector3.one * 1.1f;
}
// Invoke ("doOnPress", 0.2f);
doOnPress();
}
}
void callOnPressCallback(bool isPressed)
{
Utl.doCallback(onPressCallback, isPressed);
}
void doOnPress()
{
// isCanMove = true;
if (joystickUI != null) {
joystickUI.transform.parent.position = UICamera.lastHit.point;
}
callOnPressCallback(true);
}
Vector3 joyPosition = Vector3.zero;
void OnDrag(Vector2 delta)
{
isCanMove = true;
joyPosition += new Vector3(delta.x, delta.y, 0);
if (joystickUI != null) {
if (joyPosition.magnitude > joystickMoveDis) {
joystickUI.transform.localPosition = Vector3.ClampMagnitude(joyPosition, joystickMoveDis);
} else {
joystickUI.transform.localPosition = joyPosition;
}
dragDetla = new Vector2((joystickUI.transform.localPosition.x - orgPos.x) / joystickMoveDis, (joystickUI.transform.localPosition.y - orgPos.y) / joystickMoveDis);
}
}
// void OnDragOver (GameObject draggedObject) //is sent to a game object when another object is dragged over its area.
// {
// Debug.LogError("OnDragOver");
// OnPress(false);
// }
// void OnDragOut (GameObject draggedObject) //is sent to a game object when another object is dragged out of its area.
// {
// Debug.LogError("OnDragOut");
// OnPress(false);
// }
void OnDragEnd()
{// is sent to a dragged object when the drag event finishes.
OnPress(false);
}
void OnDoubleClick()
{
}
void Update()
{
if (isCanMove) {
Utl.doCallback(onDragCallback, dragDetla);
}
#if UNITY_EDITOR || UNITY_STANDALONE
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D)) {
isCanMove = true;
dragDetla = new Vector2(1, 1);
} else if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A)) {
isCanMove = true;
dragDetla = new Vector2(-1, 1);
} else if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.S)) {
isCanMove = true;
dragDetla = new Vector2(0, 1);
} else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D)) {
isCanMove = true;
dragDetla = new Vector2(1, -1);
} else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A)) {
isCanMove = true;
dragDetla = new Vector2(-1, -1);
} else if (Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.D)) {
isCanMove = true;
dragDetla = new Vector2(1, 0);
} else if (Input.GetKey(KeyCode.W)) {
isCanMove = true;
dragDetla = new Vector2(0, 1);
} else if (Input.GetKey(KeyCode.S)) {
isCanMove = true;
dragDetla = new Vector2(0, -1);
} else if (Input.GetKey(KeyCode.A)) {
isCanMove = true;
dragDetla = new Vector2(-1, 0);
} else if (Input.GetKey(KeyCode.D)) {
isCanMove = true;
dragDetla = new Vector2(1, 0);
}
if (Input.GetKeyUp(KeyCode.A) ||
Input.GetKeyUp(KeyCode.D) ||
Input.GetKeyUp(KeyCode.W) ||
Input.GetKeyUp(KeyCode.S)) {
isCanMove = false;
Utl.doCallback(onPressCallback, false);
}
#endif
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 81240bae634f94869a0ffacaef7b7792
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Coolape
{
public class CLTweenColor : TweenColor
{
public Renderer render;
public bool isShardedMaterial = true;
public Material material {
get {
if (render == null)
return null;
if (isShardedMaterial) {
return render.sharedMaterial;
}
return render.material;
}
}
public string shaderPropName = "";
public Color value {
get {
if (material != null) {
if (string.IsNullOrEmpty (shaderPropName)) {
return material.color;
} else {
return material.GetColor (shaderPropName);
}
}
return Color.black;
}
set {
if (material != null) {
if (string.IsNullOrEmpty (shaderPropName)) {
material.color = value;
} else {
material.SetColor (shaderPropName, value);
}
}
}
}
protected override void OnUpdate (float factor, bool isFinished)
{
value = Color.Lerp (from, to, factor);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 04d9121d1bc89428fae7f741d30aef9c
timeCreated: 1497872053
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 82362119b0cbf4d8e86da1bd56ddffdb
timeCreated: 1448592612
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Coolape;
namespace Coolape
{
public class CLUIJumpLabel : UILabel
{
public bool isPlayJump = false;
public string orgStr = "";
public float speed = 0.25f;
int index = 0;
float timeCount = 0;
new public string text
{
get
{
return base.text;
}
set
{
base.text = value;
orgStr = base.processedText;
isPlayJump = true;
index = 0;
timeCount = Time.time;
base.text = PStr.b().a("[sub]").a(text).a("[/sub]").e();
}
}
// Update is called once per frame
void Update()
{
if (!isPlayJump || string.IsNullOrEmpty(orgStr)) return;
if (timeCount <= Time.time)
{
jump();
}
}
public void jump()
{
int len = orgStr.Length;
if (len < 2) {
return;
}
index++;
if (index >= len)
{
index = 0;
}
string left = StrEx.Left(orgStr, index);
string mid = StrEx.Mid(orgStr, index, 1);
string right = StrEx.Right(orgStr, len - index - 1);
string str = PStr.b()
.a("[sub]")
.a(left)
.a("[/sup]")
.a("[sup]").a(mid).a("[/sup]")
.a("[sub]")
.a(right)
.a("[/sup]")
.e();
base.text = str;
timeCount = Time.time + speed;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5814f6de564db4109a8dd39ecc599892
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,556 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 循环列表,只能是单排或单列
* 1、脚本放在Scroll View下面的UIGrid的那个物体上
* 2、Scroll View上面的UIPanel的Cull勾选上
* 3、每一个Item都放上一个UIWidget调整到合适的大小用它的Visiable 设置Dimensions
* 4、需要提前把Item放到Grid下不能动态加载进去
* 5、注意元素的个数要多出可视范围至少4个
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using XLua;
namespace Coolape
{
[RequireComponent (typeof(UIGrid))]
public class CLUILoopGrid : MonoBehaviour
{
public int cellCount = 10;
[HideInInspector]
public bool
isPlayTween = true;
public TweenType twType = TweenType.position;
public float tweenSpeed = 0.01f;
public float twDuration = 0.5f;
public UITweener.Method twMethod = UITweener.Method.EaseOut;
public List<UIWidget> itemList = new List<UIWidget> ();
private Vector4 posParam;
private Transform cachedTransform;
public UIGrid grid = null;
public UIPanel panel;
// void Awake ()
// {
// cachedTransform = this.transform;
// grid = this.GetComponent<UIGrid> ();
// float cellWidth = grid.cellWidth;
// float cellHeight = grid.cellHeight;
// posParam = new Vector4 (cellWidth, cellHeight,
// grid.arrangement == UIGrid.Arrangement.Horizontal ? 1 : 0,
// grid.arrangement == UIGrid.Arrangement.Vertical ? 1 : 0);
// }
bool isFinishInit = false;
int times = 0;
int RealCellCount = 0;
int wrapLineNum = 0;
Vector3 oldGridPosition = Vector3.zero;
Vector3 oldScrollViewPos = Vector3.zero;
Vector2 oldClipOffset = Vector2.zero;
UIScrollView _scrollView;
public UIScrollView scrollView {
get {
if (_scrollView == null) {
_scrollView = NGUITools.FindInParents<UIScrollView> (transform);
if (_scrollView != null) {
oldScrollViewPos = _scrollView.transform.localPosition;
panel = _scrollView.panel;
if(panel == null) {
panel = _scrollView.GetComponent<UIPanel>();
}
if (panel != null) {
oldClipOffset = panel.clipOffset;
}
panel.cullWhileDragging = true;
}
}
return _scrollView;
}
}
public void init ()
{
if (isFinishInit)
return;
cachedTransform = this.transform;
grid = this.GetComponent<UIGrid> ();
grid.sorting = UIGrid.Sorting.Alphabetic;
grid.hideInactive = true;
oldGridPosition = grid.transform.localPosition;
_scrollView = scrollView;
Transform prefab = cachedTransform.GetChild (0);
if (cachedTransform.childCount < cellCount) {
for (int i = cachedTransform.childCount; i < cellCount; i++) {
NGUITools.AddChild (gameObject, prefab.gameObject);
}
}
float cellWidth = grid.cellWidth;
float cellHeight = grid.cellHeight;
posParam = new Vector4 (cellWidth, cellHeight,
grid.arrangement == UIGrid.Arrangement.Horizontal ? -1 : 0,
grid.arrangement == UIGrid.Arrangement.Vertical ? 1 : 0);
wrapLineNum = grid.maxPerLine;
if (wrapLineNum > 0) {
posParam.z = -1;
posParam.w = 1;
}
for (int i = 0; i < cachedTransform.childCount; ++i) {
Transform t = cachedTransform.GetChild (i);
UIWidget uiw = t.GetComponent<UIWidget> ();
if (uiw != null)
{
uiw.name = NumEx.nStrForLen(itemList.Count, 6);
itemList.Add(uiw);
}
}
RealCellCount = itemList.Count;
grid.Reposition ();
isFinishInit = true;
if (itemList.Count < 3) {
Debug.Log ("The childCount < 3");
}
}
public void setOldClip (Vector2 oldClipOffset, Vector3 oldScrollViewPos, Vector3 oldGridPosition)
{
this.oldClipOffset = oldClipOffset;
this.oldScrollViewPos = oldScrollViewPos;
this.oldGridPosition = oldGridPosition;
}
public void resetClip ()
{
if (scrollView != null) {
scrollView.ResetPosition ();
if (panel != null) {
panel.clipOffset = oldClipOffset;
}
scrollView.transform.localPosition = oldScrollViewPos;
}
grid.transform.localPosition = oldGridPosition;
}
object data = null;
public ArrayList list = null;
object initCellCallback;
object onEndListCallback;
object onHeadListCallback;
public void refreshContentOnly ()
{
refreshContentOnly (list);
}
public void refreshContentOnly (object data)
{
refreshContentOnly (data, true);
}
public void refreshContentOnly (object data, bool UpdatePosition)
{
list = wrapList (data);
UIWidget t = null;
int tmpIndex = 0;
CLCellBase cell = null;
int maxIndex = -1;
bool isActivedAllItems = true;
bool needScrollReposiont = false;
for (int i = 0; i < itemList.Count; ++i) {
t = itemList [i];
if (!t.gameObject.activeSelf) {
isActivedAllItems = false;
continue;
}
tmpIndex = int.Parse (t.name);
maxIndex = (maxIndex < tmpIndex) ? tmpIndex : maxIndex;
cell = t.GetComponent<CLCellBase> ();
if (cell != null) {
if (tmpIndex >= list.Count) {
NGUITools.SetActive (cell.gameObject, false);
needScrollReposiont = true;
} else {
NGUITools.SetActive (cell.gameObject, true);
Utl.doCallback (this.initCellCallback, cell, list [tmpIndex]);
}
}
}
if (maxIndex < list.Count && !isActivedAllItems) {
tmpIndex = maxIndex;
for (int i = 0; i < itemList.Count; ++i) {
t = itemList [i];
if (!t.gameObject.activeSelf) {
tmpIndex++;
if (tmpIndex < list.Count) {
cell = t.GetComponent<CLCellBase> ();
if (cell != null) {
cell.name = NumEx.nStrForLen (tmpIndex, 6);
NGUITools.SetActive (cell.gameObject, true);
Utl.doCallback (this.initCellCallback, cell, list [tmpIndex]);
}
}
}
}
// grid.Reposition ();
//
// if (scrollView != null) {
// scrollView.ResetPosition ();
// }
}
if (UpdatePosition && scrollView != null) {
scrollView.RestrictWithinBounds (true);
scrollView.UpdateScrollbars ();
scrollView.UpdatePosition ();
}
// if (needScrollReposiont && scrollView != null) {
// grid.Reposition ();
// scrollView.ResetPosition ();
// }
}
ArrayList wrapList (object data)
{
ArrayList _list = null;
if (data is LuaTable) {
_list = CLUtlLua.luaTableVals2List ((LuaTable)data);
} else if (data is ArrayList) {
_list = (ArrayList)data;
} else if (data is object[]) {
_list = new ArrayList ();
_list.AddRange ((object[])data);
}
if (_list == null) {
_list = new ArrayList ();
}
return _list;
}
public void insertList (object data)
{
ArrayList _list = null;
_list = wrapList (data);
UIWidget uiw = null;
int newDataCount = _list.Count;
int _startIndex = 0;
if (itemList != null && itemList.Count > 0) {
_startIndex = NumEx.stringToInt (itemList [0].name);
for (int i = 0; i < itemList.Count; i++) {
uiw = itemList [i];
if (uiw == null)
continue;
uiw.name = NumEx.nStrForLen (newDataCount + _startIndex + i, 6);
}
}
if (list != null) {
_list.AddRange (list);
}
list = _list;
refreshContentOnly ();
}
public void setListData (object data, object initCellCallback, bool isFirst)
{
if (isFirst) {
setList (data, initCellCallback, null, null, true);
} else if (data != null) {
refreshContentOnly (data);
} else {
refreshContentOnly ();
}
}
public void setList (object data, object initCellCallback)
{
setList (data, initCellCallback, null, null, true);
}
public void setList (object data, object initCellCallback, object onEndListCallback)
{
setList (data, initCellCallback, null, onEndListCallback, true);
}
public void setList (object data, object initCellCallback, object onHeadListCallback, object onEndListCallback)
{
setList (data, initCellCallback, onHeadListCallback, onEndListCallback, true);
}
public void setList (object data, object initCellCallback, object onHeadListCallback, object onEndListCallback, bool isNeedRePosition)
{
setList (data, initCellCallback, onHeadListCallback, onEndListCallback, isNeedRePosition, isPlayTween);
}
public void setList (object data, object initCellCallback, object onHeadListCallback, object onEndListCallback, bool isNeedRePosition, bool isPlayTween)
{
setList (data, initCellCallback, onHeadListCallback, onEndListCallback, isNeedRePosition, isPlayTween, tweenSpeed);
}
public void setList (object data, object initCellCallback, object onHeadListCallback, object onEndListCallback, bool isNeedRePosition, bool isPlayTween,
float tweenSpeed)
{
setList (data, initCellCallback, onHeadListCallback, onEndListCallback, isNeedRePosition, isPlayTween, tweenSpeed, twDuration);
}
public void setList (object data, object initCellCallback, object onHeadListCallback, object onEndListCallback, bool isNeedRePosition, bool isPlayTween,
float tweenSpeed, float twDuration)
{
setList (data, initCellCallback, onHeadListCallback, onEndListCallback, isNeedRePosition, isPlayTween, tweenSpeed, twDuration, twMethod);
}
public void setList (object data, object initCellCallback, object onHeadListCallback, object onEndListCallback, bool isNeedRePosition, bool isPlayTween,
float tweenSpeed, float twDuration, UITweener.Method twMethod)
{
setList (data, initCellCallback, onHeadListCallback, onEndListCallback, isNeedRePosition, isPlayTween, tweenSpeed, twDuration, twMethod, twType);
}
public void appendList (object data)
{
ArrayList _list = wrapList (data);
if (_list != null) {
if (list == null) {
list = new ArrayList ();
}
list.AddRange (_list);
}
// if (itemList.Count < RealCellCount) {
// _appendList (_list);
// grid.Reposition ();
// }
refreshContentOnly ();
}
void _appendList (ArrayList list)
{
if (list.Count == 0)
return;
int dataIndex = 0;
int tmpIndex = itemList.Count;
UIWidget uiw = null;
//Transform t = null;
for (int i = 0; i < itemList.Count; i++) {
if (dataIndex >= list.Count) {
break;
}
//t = cachedTransform.GetChild (i);
//if (t.gameObject.activeSelf)
// continue;
uiw = itemList[i];
if (uiw == null)
continue;
if (uiw.gameObject.activeSelf)
continue;
uiw.name = NumEx.nStrForLen (tmpIndex + dataIndex, 6);
NGUITools.SetActive (uiw.gameObject, true);
Utl.doCallback (this.initCellCallback, uiw.GetComponent<CLCellBase> (), list [dataIndex]);
NGUITools.updateAll (uiw.transform);
// itemList.Add (uiw);
dataIndex++;
}
}
public void setList (object data, object initCellCallback, object onHeadListCallback, object onEndListCallback, bool isNeedRePosition, bool isPlayTween,
float tweenSpeed, float twDuration, UITweener.Method twMethod, TweenType twType)
{
_setList (data, initCellCallback, onHeadListCallback, onEndListCallback, isNeedRePosition, isPlayTween, tweenSpeed, twDuration, twMethod, twType);
}
void _setList (object data, object initCellCallback, object onHeadListCallback, object onEndListCallback, bool isNeedRePosition, bool isPlayTween, float tweenSpeed,
float twDuration, UITweener.Method twMethod, TweenType twType)
{
try {
this.data = data;
this.list = wrapList (data);
this.initCellCallback = initCellCallback;
this.onEndListCallback = onEndListCallback;
this.onHeadListCallback = onHeadListCallback;
if (!isFinishInit) {
init ();
} else {
for (int i = 0; i < itemList.Count; i++) {
itemList [i].name = NumEx.nStrForLen (i, 6);
}
}
int tmpIndex = 0;
times = 0;
// itemList.Clear ();
for (int i = 0; i < itemList.Count; i++) {
// Transform t = cachedTransform.GetChild (i);
UIWidget uiw = itemList [i];
tmpIndex = i;
uiw.name = NumEx.nStrForLen (tmpIndex, 6);
if (tmpIndex >= 0 && tmpIndex < this.list.Count) {
NGUITools.SetActive (uiw.gameObject, true);
Utl.doCallback (this.initCellCallback, uiw.GetComponent<CLCellBase> (), list [tmpIndex]);
NGUITools.updateAll (uiw.transform);
// itemList.Add (uiw);
} else {
NGUITools.SetActive (uiw.gameObject, false);
}
}
if (isNeedRePosition) {
resetClip ();
if (!isPlayTween || twType == TweenType.alpha || twType == TweenType.scale) {
grid.Reposition ();
// scrollView.ResetPosition();
}
if (isPlayTween) {
for (int i = 0; i < itemList.Count; i++) {
CLUIUtl.resetCellTween (i, grid, itemList [i].gameObject, tweenSpeed, twDuration, twMethod, twType);
}
}
}
isCanCallOnEndList = true;
isCanCallOnHeadList = true;
} catch (System.Exception e) {
Debug.LogError (e);
}
}
int sourceIndex = -1;
int targetIndex = -1;
int sign = 0;
bool firstVislable = false;
bool lastVisiable = false;
UIWidget head;
UIWidget tail;
UIWidget checkHead;
UIWidget checkTail;
bool isCanCallOnEndList = true;
bool isCanCallOnHeadList = true;
int checkLineSize = 1;
int tmpIndex = 0;
// void LateUpdate ()
public void Update ()
{
if (!isFinishInit || itemList.Count < 3) {
return;
}
sourceIndex = -1;
targetIndex = -1;
sign = 0;
head = itemList [0];
tail = itemList [itemList.Count - 1];
checkHead = itemList [wrapLineNum * checkLineSize];
if (list.Count > 0 && int.Parse (tail.name) > list.Count) {
tail = transform.Find (NumEx.nStrForLen (list.Count - 1, 6)).GetComponent<UIWidget> ();// itemList [list.Count - 1];
tmpIndex = itemList.IndexOf (tail) - (wrapLineNum * checkLineSize);
tmpIndex = tmpIndex < 0 ? 0 : tmpIndex;
checkTail = itemList [tmpIndex];
} else {
tail = itemList [itemList.Count - 1];
checkTail = itemList [itemList.Count - 1 - (wrapLineNum * checkLineSize)];
}
firstVislable = checkHead.isVisible;
lastVisiable = checkTail.isVisible;
// if first and last both visiable or invisiable then return
// if (firstVislable == lastVisiable) {
// return;
// }
// Debug.Log (int.Parse (head.name) + "=11===" + (list.Count - 1) + "===" + firstVislable);
// Debug.Log (int.Parse (tail.name) + "=22===" + (list.Count - 1) + "===" + lastVisiable);
if (firstVislable && int.Parse (head.name) > 0) {
isCanCallOnEndList = true;
isCanCallOnHeadList = true;
times--;
// move last to first one
sourceIndex = itemList.Count - 1;
targetIndex = 0;
sign = 1;
} else if (lastVisiable && int.Parse (tail.name) < list.Count - 1) {
isCanCallOnEndList = true;
isCanCallOnHeadList = true;
times++;
// move first to last one
sourceIndex = 0;
targetIndex = itemList.Count - 1;
sign = -1;
} else {
if (firstVislable && int.Parse (head.name) == 0) {
if (isCanCallOnHeadList) {
isCanCallOnHeadList = false;
Utl.doCallback (this.onHeadListCallback, head);
}
} else {
isCanCallOnHeadList = true;
}
if (lastVisiable && int.Parse (tail.name) == list.Count - 1) {
//说明已经到最后了
if (isCanCallOnEndList) {
isCanCallOnEndList = false;
Utl.doCallback (this.onEndListCallback, tail);
}
} else {
isCanCallOnEndList = true;
}
}
if (sourceIndex > -1) {
int lineNum = wrapLineNum <= 0 ? 1 : wrapLineNum;
for (int j = 0; j < lineNum; j++) {
UIWidget movedWidget = itemList [sourceIndex];
int oldIndex = int.Parse (movedWidget.name);
int newIndex = 0;
if (sign < 0) {
newIndex = oldIndex + RealCellCount;
} else {
newIndex = oldIndex - RealCellCount;
}
movedWidget.name = NumEx.nStrForLen (newIndex, 6);
moveCellPos (movedWidget, itemList [targetIndex], newIndex, newIndex + sign);
itemList.RemoveAt (sourceIndex);
itemList.Insert (targetIndex, movedWidget);
if (newIndex >= list.Count) {
NGUITools.SetActive (movedWidget.gameObject, false);
} else {
NGUITools.SetActive (movedWidget.gameObject, true);
Utl.doCallback (this.initCellCallback, movedWidget.GetComponent<CLCellBase> (), this.list [newIndex]);
}
}
}
}
// 从原顺序位置移动到指定位置
void moveCellPos (UIWidget moved, UIWidget target, int newIdx, int targetIdx)
{
int offx = 0;
int offy = 0;
if (wrapLineNum > 0) {
if (grid.arrangement == UIGrid.Arrangement.Vertical) {
offx = (targetIdx / wrapLineNum) - (newIdx / wrapLineNum);
offy = (targetIdx % wrapLineNum) - (newIdx % wrapLineNum);
} else {
offx = (targetIdx % wrapLineNum) - (newIdx % wrapLineNum);
offy = (targetIdx / wrapLineNum) - (newIdx / wrapLineNum);
}
} else {
offx = targetIdx - newIdx;
offy = offx;
}
Vector3 offset = new Vector3 (offx * posParam.x * posParam.z, offy * posParam.y * posParam.w, 0);
moved.cachedTransform.localPosition = target.cachedTransform.localPosition + offset;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: da6df6b770ac942ab8916dc960507b8f
timeCreated: 1467355419
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
namespace Coolape
{
public class CLUILoopItems : UIWrapContent
{
public ArrayList list;
public object initCellFunc;
bool isInited = false;
// Use this for initialization
protected override void Start ()
{
if (isInited)
return;
isInited = true;
onInitializeItem = initCell;
base.Start ();
}
ArrayList wrapList (object data)
{
ArrayList _list = null;
if (data is LuaTable) {
_list = CLUtlLua.luaTableVals2List ((LuaTable)data);
} else if (data is ArrayList) {
_list = (ArrayList)data;
} else if (data is object[]) {
_list = new ArrayList ();
_list.AddRange ((object[])data);
}
if (_list == null) {
_list = new ArrayList ();
}
return _list;
}
public void setList (object dataList, object initCell)
{
Start ();
this.list = wrapList (dataList);
this.initCellFunc = initCell;
// if (list != null && list.Count > 1) {
// minIndex = 0;
// maxIndex = list.Count;
// }
WrapContent ();
}
void initCell (GameObject go, int wrapIndex, int realIndex)
{
Debug.Log (wrapIndex + "========" + realIndex);
if (initCellFunc != null && realIndex >= 0 && list != null && realIndex < list.Count) {
Utl.doCallback (initCellFunc, go.GetComponent<CLCellBase> (), list [realIndex]);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 44d5425beb64f4f02b26df058b549978
timeCreated: 1498718176
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,707 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 循环列表,只能是单排或单列
* 1、脚本放在Scroll View下面的UIGrid的那个物体上
* 2、Scroll View上面的UIPanel的Cull勾选上
* 3、每一个Item都放上一个CLUILoopTableCell调整到合适的大小用它的Visiable 设置Dimensions
* 4、需要提前把Item放到Grid下不能动态加载进去
* 5、注意元素的个数要多出可视范围至少4个
* 6、特别注意因为使用的是ngui的Widget来处理排列的
* 因此在编辑cell里要保证通过计算后widget可以全部覆盖完整个cell可以使用anchor来处理
* 7、特别注意Table.CellAlignment要设置正确不然可能单元的位置计算有会问题
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using XLua;
namespace Coolape
{
[RequireComponent (typeof(UITable))]
public class CLUILoopTable : MonoBehaviour
{
public int cellCount = 10;
public Vector2 mOffset = Vector2.zero;
private List<CLUILoopTableCell> itemList = new List<CLUILoopTableCell> ();
private Transform cachedTransform;
UITable table = null;
bool isFinishInit = false;
int times = 0;
int RealCellCount = 0;
Vector3 oldGridPosition = Vector3.zero;
Vector3 oldScrollViewPos = Vector3.zero;
Vector2 oldClipOffset = Vector2.zero;
UIScrollView _scrollView;
public UIScrollView scrollView {
get {
if (_scrollView == null) {
_scrollView = NGUITools.FindInParents<UIScrollView> (transform);
if (_scrollView != null) {
oldScrollViewPos = _scrollView.transform.localPosition;
oldClipOffset = _scrollView.panel.clipOffset;
_scrollView.panel.cullWhileDragging = true;
}
}
return _scrollView;
}
}
public void init ()
{
if (isFinishInit)
return;
cachedTransform = this.transform;
table = this.GetComponent<UITable> ();
table.hideInactive = true;
table.sorting = UITable.Sorting.Alphabetic;
oldGridPosition = table.transform.localPosition;
_scrollView = scrollView;
Transform prefab = cachedTransform.GetChild (0);
CLUILoopTableCell prefabCell = prefab.GetComponent<CLUILoopTableCell> ();
table.cellAlignment = prefabCell.widget.pivot;
if (cachedTransform.childCount < cellCount) {
for (int i = cachedTransform.childCount; i < cellCount; i++) {
NGUITools.AddChild (gameObject, prefab.gameObject);
}
}
for (int i = 0; i < cachedTransform.childCount; ++i) {
Transform t = cachedTransform.GetChild (i);
CLUILoopTableCell uiw = t.GetComponent<CLUILoopTableCell> ();
// uiw.name = string.Format ("{0:D5}", itemList.Count);
uiw.name = NumEx.nStrForLen (itemList.Count, 6);
itemList.Add (uiw);
}
RealCellCount = itemList.Count;
table.Reposition ();
isFinishInit = true;
if (itemList.Count < 3) {
Debug.LogError ("The childCount < 3");
}
}
public void setOldClip (Vector2 oldClipOffset, Vector3 oldScrollViewPos, Vector3 oldGridPosition)
{
this.oldClipOffset = oldClipOffset;
this.oldScrollViewPos = oldScrollViewPos;
this.oldGridPosition = oldGridPosition;
}
public void resetClip ()
{
scrollView.panel.clipOffset = oldClipOffset;
scrollView.transform.localPosition = oldScrollViewPos;
table.transform.localPosition = oldGridPosition;
}
object data = null;
ArrayList list = null;
object initCellCallback;
object onEndListCallback;
public void refreshContentOnly ()
{
refreshContentOnly (list);
}
public void refreshContentOnly(object data){
refreshContentOnly(data, false);
}
public void refreshContentOnly (object data, bool isRePositionTable)
{
ArrayList _list = null;
if (data == null) {
_list = new ArrayList ();
} else if (data is LuaTable) {
_list = CLUtlLua.luaTableVals2List ((LuaTable)data);
} else if (data is ArrayList) {
_list = (ArrayList)data;
} else if (data is object[]) {
_list = new ArrayList ();
_list.AddRange ((object[])data);
} else {
_list = new ArrayList ();
}
list = _list;
if (RealCellCount > itemList.Count) {
setList (list, this.initCellCallback);
} else {
Transform t = null;
int tmpIndex = 0;
CLUILoopTableCell cell = null;
CLUILoopTableCell preCell = null;
//for (int i = 0; i < cachedTransform.childCount; ++i) {
for (int i = 0; i < itemList.Count; i++){
//t = cachedTransform.GetChild (i);
cell = itemList[i];
if (!cell.gameObject.activeSelf)
continue;
tmpIndex = int.Parse (cell.name);
//cell = t.GetComponent<CLUILoopTableCell> ();
if (cell != null) {
Utl.doCallback (this.initCellCallback, cell, list [tmpIndex]);
}
if (cell.isSetWidgetSize)
{
BoxCollider box = cell.GetComponent<BoxCollider>();
if (box != null)
{
box.size = Vector2.zero;
}
cell.widget.SetDimensions(0, 0);
}
NGUITools.updateAll(cell.transform);
if (cell.isSetWidgetSize)
{
Bounds bound = NGUIMath.CalculateRelativeWidgetBounds(t, false);
cell.widget.SetDimensions((int)(bound.size.x), (int)(bound.size.y));
}
if (isRePositionTable)
{
if (preCell != null)
{
setPosition(cell, preCell, table.direction);
}
}
preCell = cell;
}
}
}
public void setList (object data, object initCellCallback)
{
setList (data, initCellCallback, null);
}
public void setList (object data, object initCellCallback, object onEndListCallback)
{
setList (data, initCellCallback, onEndListCallback, true);
}
public void setList (object data, object initCellCallback, object onEndListCallback, bool isNeedRePosition)
{
_setList (data, initCellCallback, onEndListCallback, isNeedRePosition);
}
public void setList (object data, object initCellCallback, object onEndListCallback, bool isNeedRePosition, bool isCalculatePosition)
{
_setList (data, initCellCallback, onEndListCallback, isNeedRePosition, isCalculatePosition);
}
void _setList (object data, object initCellCallback, object onEndListCallback, bool isNeedRePosition, bool isCalculatePosition = false)
{
ArrayList _list = null;
if (data == null) {
_list = new ArrayList ();
} else if (data is LuaTable) {
_list = CLUtlLua.luaTableVals2List ((LuaTable)data);
} else if (data is ArrayList) {
_list = (ArrayList)data;
} else if (data is object[]) {
_list = new ArrayList ();
_list.AddRange ((object[])data);
} else {
_list = new ArrayList ();
}
try {
this.data = data;
this.list = _list;
this.initCellCallback = initCellCallback;
this.onEndListCallback = onEndListCallback;
if (!isFinishInit) {
init ();
}
int tmpIndex = 0;
times = 0;
itemList.Clear ();
for (int i = 0; i < cachedTransform.childCount; ++i) {
Transform t = cachedTransform.GetChild (i);
CLUILoopTableCell uiw = t.GetComponent<CLUILoopTableCell> ();
tmpIndex = i;
// uiw.name = string.Format ("{0:D5}", tmpIndex);
uiw.name = NumEx.nStrForLen (tmpIndex, 6);
if (tmpIndex >= 0 && tmpIndex < this.list.Count) {
NGUITools.SetActive (t.gameObject, true);
Utl.doCallback (this.initCellCallback, t.GetComponent<CLCellBase> (), list [tmpIndex]);
if (uiw.isSetWidgetSize) {
BoxCollider box = uiw.GetComponent<BoxCollider> ();
if (box != null) {
box.size = Vector2.zero;
}
uiw.widget.SetDimensions (0, 0);
}
NGUITools.updateAll (uiw.transform);
if (uiw.isSetWidgetSize) {
Bounds bound = NGUIMath.CalculateRelativeWidgetBounds (t, false);
uiw.widget.SetDimensions ((int)(bound.size.x), (int)(bound.size.y));
}
if (!isNeedRePosition) {
if (itemList.Count > 0) {
CLUILoopTableCell targetUIW = itemList [itemList.Count - 1];
setPosition (uiw, targetUIW, table.direction);
}
}
itemList.Add (uiw);
} else {
NGUITools.SetActive (t.gameObject, false);
}
}
if (isNeedRePosition) {
resetClip ();
table.Reposition ();
if (scrollView != null) {
scrollView.ResetPosition ();
}
}
} catch (System.Exception e) {
Debug.LogError (e);
}
}
public void insertList (object data, bool isNeedRePosition, bool isCalculatePosition)
{
ArrayList _list = null;
if (data is LuaTable) {
_list = CLUtlLua.luaTableVals2List ((LuaTable)data);
} else if (data is ArrayList) {
_list = (ArrayList)data;
} else if (data is object[]) {
_list = new ArrayList ();
_list.AddRange ((object[])data);
}
times = (int)(_list.Count / RealCellCount);
//------------------------------------------------
CLUILoopTableCell uiw = null;
CLUILoopTableCell targetUIW = null;
int newDataCount = _list.Count;
Transform t = null;
int _startIndex = 0;
if (itemList != null && itemList.Count > 0) {
_startIndex = NumEx.stringToInt (itemList [0].name);
for (int i = 0; i < itemList.Count; i++) {
uiw = itemList [i];
if (uiw == null)
continue;
uiw.name = NumEx.nStrForLen (newDataCount + _startIndex + i, 6);
}
}
//------------------------------------------------
if (RealCellCount > itemList.Count) {
Debug.Log ("说明之前加载的数据没有占用完所有单元");
//说明之前加载的数据没有占用完所有单元
_insertList (_list, isCalculatePosition);
if (isNeedRePosition) {
table.Reposition ();
}
}
//------------------------------------------------
if (list != null) {
_list.AddRange (list);
}
list = _list;
}
void _insertList (ArrayList list, bool isCalculatePosition)
{
if (list.Count == 0)
return;
int dataIndex = list.Count - 1;
// int tmpIndex = itemList.Count;
CLUILoopTableCell uiw = null;
CLUILoopTableCell targetUIW = null;
Transform t = null;
for (int i = 0; i < cachedTransform.childCount; i++) {
if (dataIndex < 0) {
break;
}
t = cachedTransform.GetChild (i);
if (t.gameObject.activeSelf)
continue;
uiw = t.GetComponent<CLUILoopTableCell> ();
if (uiw == null)
continue;
// uiw.name = string.Format ("{0:D5}", (tmpIndex + dataIndex));
uiw.name = NumEx.nStrForLen (dataIndex, 6);
NGUITools.SetActive (t.gameObject, true);
Utl.doCallback (this.initCellCallback, t.GetComponent<CLCellBase> (), list [dataIndex]);
if (uiw.isSetWidgetSize) {
BoxCollider box = uiw.GetComponent<BoxCollider> ();
if (box != null) {
box.size = Vector2.zero;
}
uiw.widget.SetDimensions (0, 0);
}
NGUITools.updateAll (uiw.transform);
if (uiw.isSetWidgetSize) {
Bounds bound = NGUIMath.CalculateRelativeWidgetBounds (t, false);
uiw.widget.SetDimensions ((int)(bound.size.x), (int)(bound.size.y));
}
if (isCalculatePosition) {
if (itemList.Count > 0) {
targetUIW = itemList [0];
UITable.Direction dir = table.direction;
if (table.direction == UITable.Direction.Up) {
dir = UITable.Direction.Down;
} else {
dir = UITable.Direction.Up;
}
setPosition (uiw, targetUIW, dir);
}
}
itemList.Insert (0, uiw);
dataIndex--;
}
}
public void appendList (object data, bool isNeedRePosition, bool isCalculatePosition)
{
ArrayList _list = null;
if (data is LuaTable) {
_list = CLUtlLua.luaTableVals2List ((LuaTable)data);
} else if (data is ArrayList) {
_list = (ArrayList)data;
} else if (data is object[]) {
_list = new ArrayList ();
_list.AddRange ((object[])data);
}
if (_list != null) {
list.AddRange (_list);
}
if (RealCellCount > itemList.Count) {
//说明之前加载的数据没有占用完所有单元
_appendList (_list, isCalculatePosition);
if (isNeedRePosition) {
table.Reposition ();
}
}
}
void _appendList (ArrayList list, bool isCalculatePosition)
{
if (list.Count == 0)
return;
int dataIndex = 0;
int tmpIndex = itemList.Count;
CLUILoopTableCell uiw = null;
CLUILoopTableCell targetUIW = null;
Transform t = null;
for (int i = 0; i < cachedTransform.childCount; i++) {
if (dataIndex >= list.Count) {
break;
}
t = cachedTransform.GetChild (i);
if (t.gameObject.activeSelf)
continue;
uiw = t.GetComponent<CLUILoopTableCell> ();
if (uiw == null)
continue;
// uiw.name = string.Format ("{0:D5}", (tmpIndex + dataIndex));
uiw.name = NumEx.nStrForLen (tmpIndex + dataIndex, 6);
NGUITools.SetActive (t.gameObject, true);
Utl.doCallback (this.initCellCallback, t.GetComponent<CLCellBase> (), list [dataIndex]);
if (uiw.isSetWidgetSize) {
BoxCollider box = uiw.GetComponent<BoxCollider> ();
if (box != null) {
box.size = Vector2.zero;
}
uiw.widget.SetDimensions (0, 0);
}
NGUITools.updateAll (uiw.transform);
if (uiw.isSetWidgetSize) {
Bounds bound = NGUIMath.CalculateRelativeWidgetBounds (t, false);
uiw.widget.SetDimensions ((int)(bound.size.x), (int)(bound.size.y));
}
if (isCalculatePosition) {
if (itemList.Count > 0) {
targetUIW = itemList [itemList.Count - 1];
setPosition (uiw, targetUIW, table.direction);
}
}
itemList.Add (uiw);
dataIndex++;
}
}
void setPosition (CLUILoopTableCell movement, CLUILoopTableCell target, UITable.Direction direction)
{
Vector3 v3Offset = Vector3.zero;
int flag = 1;
if (table.columns == 1) {
if (direction == UITable.Direction.Down) {
flag = -1;
switch (table.cellAlignment) {
case UIWidget.Pivot.Bottom:
v3Offset = new Vector3 (0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.BottomLeft:
v3Offset = new Vector3 (0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.BottomRight:
v3Offset = new Vector3 (0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.Center:
v3Offset = new Vector3 (0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.Left:
v3Offset = new Vector3 (0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.Right:
v3Offset = new Vector3 (0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.Top:
v3Offset = new Vector3 (0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.TopLeft:
v3Offset = new Vector3 (0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.TopRight:
v3Offset = new Vector3 (0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
}
} else {
flag = 1;
switch (table.cellAlignment) {
case UIWidget.Pivot.Bottom:
v3Offset = new Vector3 (0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.BottomLeft:
v3Offset = new Vector3 (0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.BottomRight:
v3Offset = new Vector3 (0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.Center:
v3Offset = new Vector3 (0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.Left:
v3Offset = new Vector3 (0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.Right:
v3Offset = new Vector3 (0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.Top:
v3Offset = new Vector3 (0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.TopLeft:
v3Offset = new Vector3 (0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
case UIWidget.Pivot.TopRight:
v3Offset = new Vector3 (0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0);
break;
}
}
} else if (table.columns == 0) {
flag = 1;
if (direction == UITable.Direction.Down) {
switch (table.cellAlignment) {
case UIWidget.Pivot.Bottom:
v3Offset = new Vector3 (flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.BottomLeft:
v3Offset = new Vector3 (flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.BottomRight:
v3Offset = new Vector3 (flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.Center:
v3Offset = new Vector3 (flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.Left:
v3Offset = new Vector3 (flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.Right:
v3Offset = new Vector3 (flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.Top:
v3Offset = new Vector3 (flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.TopLeft:
v3Offset = new Vector3 (flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.TopRight:
v3Offset = new Vector3 (flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
}
} else {
flag = -1;
switch (table.cellAlignment) {
case UIWidget.Pivot.Bottom:
v3Offset = new Vector3 (flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.BottomLeft:
v3Offset = new Vector3 (flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.BottomRight:
v3Offset = new Vector3 (flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.Center:
v3Offset = new Vector3 (flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.Left:
v3Offset = new Vector3 (flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.Right:
v3Offset = new Vector3 (flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.Top:
v3Offset = new Vector3 (flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.TopLeft:
v3Offset = new Vector3 (flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
case UIWidget.Pivot.TopRight:
v3Offset = new Vector3 (flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0);
break;
}
}
} else {
Debug.LogError ("The loop table cannot suport this setting! columes must in (0, 1)");
}
movement.transform.localPosition = target.transform.localPosition + v3Offset;
}
int sourceIndex = -1;
int targetIndex = -1;
bool forward = true;
bool firstVislable = false;
bool lastVisiable = false;
CLUILoopTableCell head;
CLUILoopTableCell tail;
CLUILoopTableCell checkHead;
CLUILoopTableCell checkTail;
bool isCanCallOnEndList = true;
CLUILoopTableCell movedWidget = null;
CLUILoopTableCell targetWidget = null;
BoxCollider _boxCollidr;
Bounds _bound;
Vector3 _offset;
// void LateUpdate ()
void Update ()
{
if (itemList.Count < 3) {
return;
}
sourceIndex = -1;
targetIndex = -1;
// sign = 0;
head = itemList [0];
tail = itemList [itemList.Count - 1];
checkHead = itemList [1];
checkTail = itemList [itemList.Count - 2];
firstVislable = checkHead.widget.isVisible;
lastVisiable = checkTail.widget.isVisible;
// if first and last both visiable or invisiable then return
if (firstVislable == lastVisiable) {
return;
}
if (firstVislable && int.Parse (head.name) > 0) {
isCanCallOnEndList = true;
times--;
// move last to first one
sourceIndex = itemList.Count - 1;
targetIndex = 0;
forward = false;
} else if (lastVisiable && int.Parse (tail.name) < list.Count - 1) {
isCanCallOnEndList = true;
times++;
// move first to last one
sourceIndex = 0;
targetIndex = itemList.Count - 1;
forward = true;
} else if (lastVisiable && int.Parse (tail.name) == list.Count - 1) {
//说明已经到最后了
if (isCanCallOnEndList) {
isCanCallOnEndList = false;
#if UNITY_EDITOR
Debug.Log ("说明已经到最后了");
#endif
Utl.doCallback (this.onEndListCallback);
}
} else {
isCanCallOnEndList = true;
}
if (sourceIndex > -1) {
movedWidget = itemList [sourceIndex];
if (forward) {
// movedWidget.name = string.Format ("{0:D5}",);
movedWidget.name = NumEx.nStrForLen (NumEx.stringToInt (tail.name) + 1, 6);
// movedWidget.name = NumEx.nStrForLen( ((times - 1) / RealCellCount + 1) * RealCellCount + int.Parse (movedWidget.name) % RealCellCount, 6);
} else {
movedWidget.name = NumEx.nStrForLen (NumEx.stringToInt (head.name) - 1, 6);
// movedWidget.name = string.Format ("{0:D5}", ((times) / RealCellCount) * RealCellCount + int.Parse (movedWidget.name) % RealCellCount);
// movedWidget.name = NumEx.nStrForLen(((times) / RealCellCount) * RealCellCount + int.Parse (movedWidget.name) % RealCellCount, 6);
}
int index = int.Parse (movedWidget.name);
Utl.doCallback (this.initCellCallback, movedWidget.GetComponent<CLCellBase> (), this.list [index]);
// ***after init call, then set the position***
if (movedWidget.isSetWidgetSize) {
_boxCollidr = movedWidget.GetComponent<BoxCollider> ();
if (_boxCollidr != null) {
_boxCollidr.size = Vector2.zero;
}
movedWidget.widget.SetDimensions (0, 0);
}
NGUITools.updateAll (movedWidget.transform);
if (movedWidget.isSetWidgetSize) {
_bound = NGUIMath.CalculateRelativeWidgetBounds (movedWidget.transform, false);
movedWidget.widget.SetDimensions ((int)(_bound.size.x), (int)(_bound.size.y));
}
targetWidget = itemList [targetIndex];
if (forward) {
setPosition (movedWidget, targetWidget, table.direction);
} else {
UITable.Direction dir = table.direction;
if (table.direction == UITable.Direction.Up) {
dir = UITable.Direction.Down;
} else {
dir = UITable.Direction.Up;
}
setPosition (movedWidget, targetWidget, dir);
}
// change item index
itemList.RemoveAt (sourceIndex);
itemList.Insert (targetIndex, movedWidget);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c836bacfb7c7042ccb836a30d9ca1dca
timeCreated: 1488246670
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-02-28
*Description: ui列表元素 绑定lua
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using Coolape;
namespace Coolape
{
public class CLUILoopTableCell: CLCellLua
{
public UIWidget widget;
public bool isSetWidgetSize = false;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cd99264078f0945948568c0cff393235
timeCreated: 1488287470
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 包装NGUI播放音效,支持只保存音效名方便在打包成ab时不把音效文件打进去
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class CLUIPlaySound : UIPlaySound
{
[HideInInspector]
public string soundFileName = "Tap.ogg";
public string soundName = "Tap";
public override void Play ()
{
SoundEx.playSound (soundName, volume, 1);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2dd29bf6a1a4e4959964dd9f42dd62cc
timeCreated: 1449279984
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,289 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Coolape;
namespace Coolape
{
public class CLUITextureUseAtlas : UITexture
{
public bool isSharedMaterial = true;
public string atlasName = "";
UIAtlas _atlas;
public UIAtlas mAtlas {
get {
if (_atlas == null) {
if (!string.IsNullOrEmpty (atlasName)) {
_atlas = CLUIInit.self.getAtlasByName (atlasName);
} else {
_atlas = CLUIInit.self.emptAtlas;
}
} else if (!string.IsNullOrEmpty (atlasName) && atlasName != _atlas.name) {
_atlas = CLUIInit.self.getAtlasByName (atlasName);
}
return _atlas;
}
set {
_atlas = value;
}
}
string _spriteName = "";
public Hashtable subTextureMap = new Hashtable ();
public Hashtable subTextureNameMap = new Hashtable ();
public Texture2D newTexture;
UIPanel _panel;
public UIPanel panel {
get {
if (_panel == null) {
_panel = GetComponentInParent<UIPanel> ();
}
return _panel;
}
}
public override float alpha {
get {
return base.alpha;
}
set {
base.alpha = value;
MarkAsChanged ();
}
}
protected override void Awake ()
{
base.Awake ();
if (!isSharedMaterial) {
if (material != null) {
#if UNITY_EDITOR
if (Application.isPlaying) {
material = GameObject.Instantiate<Material> (material);
}
#else
material = GameObject.Instantiate<Material> (material);
#endif
}
}
}
void OnEnable ()
{
try {
if (!string.IsNullOrEmpty (spriteName)) {
setMainTexture (spriteName);
MarkAsChanged ();
}
Texture tt = null;
string _spName = "";
ArrayList list = MapEx.keys2List (subTextureNameMap);
for (int i = 0; i < list.Count; i++) {
_spName = subTextureNameMap [list [i]] as string;
setTexture (list [i].ToString (), _spName);
}
list.Clear ();
list = null;
} catch (System.Exception e) {
Debug.LogError (e);
}
}
void OnDisable ()
{
try {
if (!string.IsNullOrEmpty (spriteName)) {
mAtlas.returnSpriteByname (_spriteName);
if (newTexture != null) {
material.mainTexture = null;
Texture2D.DestroyImmediate (newTexture);
newTexture = null;
}
MarkAsChanged ();
}
Texture tt = null;
string _spName = "";
foreach (DictionaryEntry cell in subTextureMap) {
tt = cell.Value as Texture;
if (tt != null) {
_spName = subTextureNameMap [cell.Key] as string;
if (mAtlas != null) {
mAtlas.returnSpriteByname (_spName);
}
}
}
subTextureMap.Clear ();
} catch (System.Exception e) {
Debug.LogError (e);
}
}
public string spriteName {
get {
return _spriteName;
}
set {
try {
if (!string.IsNullOrEmpty (_spriteName) && _spriteName != value) {
if (gameObject.activeInHierarchy) {
mAtlas.returnSpriteByname (_spriteName);
if (newTexture != null) {
material.mainTexture = null;
Texture2D.DestroyImmediate (newTexture);
newTexture = null;
}
}
}
if (_spriteName != value) {
_spriteName = value;
if (!string.IsNullOrEmpty (_spriteName)) {
setMainTexture (_spriteName);
}
}
} catch (System.Exception e) {
Debug.LogError (e);
}
}
}
void setMainTexture (string spriteName)
{
if (!gameObject.activeInHierarchy)
return;
UISpriteData sd = mAtlas.getSpriteBorrowMode (spriteName);
if (sd != null && UIAtlas.assetBundleMap [sd.path] != null) {
mAtlas.borrowSpriteByname (spriteName, null, (Callback)onGetMainTexture2, null);
} else {
mAtlas.borrowSpriteByname (spriteName, null, (Callback)onGetMainTexture, null);
}
}
void onGetMainTexture (params object[] paras)
{
string _spName = paras [1] as string;
UISpriteData sd = mAtlas.getSpriteBorrowMode (_spName);
if (sd != null && UIAtlas.assetBundleMap [sd.path] != null) {
setMainTexture (_spName);
} else {
Debug.LogError (_spName + ":get spriteData is null!");
}
}
void onGetMainTexture2 (params object[] paras)
{
string _spName = paras [1] as string;
if (_spName.Equals (spriteName)) {
UISpriteData sd = mAtlas.getSpriteBorrowMode (spriteName);
if (sd != null) {
Texture2D tt = UIAtlas.assetBundleMap [sd.path] as Texture2D;
if (sd.x == 0 && sd.y == 0 && tt.height == sd.height && tt.width == sd.width) {
material.mainTexture = tt;
mainTexture = tt;
} else {
//Debug.LogError ("@@@@@@@@@@@@@@@@@@@@");
Color[] colors = tt.GetPixels (sd.x, tt.height - sd.y - sd.height, sd.width, sd.height);
newTexture = new Texture2D (sd.width, sd.height);
newTexture.SetPixels (colors);
newTexture.Apply ();
material.mainTexture = newTexture;
mainTexture = newTexture;
}
MarkAsChanged ();
panel.Refresh ();
}
} else {
mAtlas.returnSpriteByname (_spName);
if (newTexture != null) {
material.mainTexture = null;
Texture2D.DestroyImmediate (newTexture);
newTexture = null;
}
}
}
public void setTexture (string propName, string spriteName)
{
try {
if (string.IsNullOrEmpty (spriteName)) {
Debug.Log (spriteName + "<<setTexture null spriteName>>" + propName);
return;
}
Texture tt = subTextureMap [propName] as Texture;
if (tt == null) {
subTextureNameMap [propName] = spriteName;
if (!gameObject.activeInHierarchy) {
return;
}
UISpriteData sd = mAtlas.getSpriteBorrowMode (spriteName);
if (sd != null && UIAtlas.assetBundleMap [sd.path] != null) {
mAtlas.borrowSpriteByname (spriteName, null, (Callback)onGetSubTexture2, propName);
} else {
mAtlas.borrowSpriteByname (spriteName, null, (Callback)onGetSubTexture, propName);
}
} else {
string _spName = subTextureNameMap [propName] as string;
if (_spName == spriteName) {
material.SetTexture (propName, tt);
MarkAsChanged ();
panel.Refresh ();
} else {
mAtlas.returnSpriteByname (_spName);
subTextureMap.Remove (propName);
subTextureNameMap.Remove (propName);
subTextureNameMap [propName] = spriteName;
if (!gameObject.activeInHierarchy) {
return;
}
UISpriteData sd = mAtlas.getSpriteBorrowMode (spriteName);
if (sd != null && UIAtlas.assetBundleMap [sd.path] != null) {
mAtlas.borrowSpriteByname (spriteName, null, (Callback)onGetSubTexture2, propName);
} else {
mAtlas.borrowSpriteByname (spriteName, null, (Callback)onGetSubTexture, propName);
}
}
}
} catch (System.Exception e) {
Debug.LogError (e);
}
}
void onGetSubTexture (params object[] paras)
{
string _spName = paras [1] as string;
string propName = paras [2] as string;
UISpriteData sd = mAtlas.getSpriteBorrowMode (_spName);
if (sd != null && UIAtlas.assetBundleMap [sd.path] != null) {
setTexture (propName, _spName);
} else {
Debug.LogError (_spName + ":get spriteData is null!");
}
}
void onGetSubTexture2 (params object[] paras)
{
string _spName = paras [1] as string;
string propName = paras [2] as string;
if (_spName.Equals (subTextureNameMap [propName] as string)) {
UISpriteData sd = mAtlas.getSpriteBorrowMode (_spName);
if (sd != null) {
Texture tt = UIAtlas.assetBundleMap [sd.path] as Texture;
subTextureMap [propName] = tt;
material.SetTexture (propName, tt);
MarkAsChanged ();
panel.Refresh ();
}
} else {
mAtlas.returnSpriteByname (_spName);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b61ef0b3771ed4c95826e899a38fbcc4
timeCreated: 1492664803
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,87 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: wangkaiyuan
*Version: 2.0
*Date: 2017-01-09
*Description: tween spriteFill
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
[AddComponentMenu ("NGUI/Tween/Tween Sprite Fill")]
public class TweenSpriteFill : UITweener
{
[Range (0f, 1f)]
public float from;
[Range (0f, 1f)]
public float to;
UISprite mSprite;
public float value {
get {
return mSprite.fillAmount;
}
set {
mSprite.fillAmount = value;
}
}
void Awake ()
{
mSprite = GetComponent<UISprite> ();
}
protected override void OnUpdate (float factor, bool isFinished)
{
value = from * (1f - factor) + to * factor;
}
static public TweenSpriteFill Begin (GameObject go, float duration, float amount)
{
TweenSpriteFill comp = UITweener.Begin<TweenSpriteFill> (go, duration);
comp.from = comp.value;
comp.to = amount;
if (duration <= 0f) {
comp.Sample (1f, true);
comp.enabled = false;
}
return comp;
}
[ContextMenu ("Set 'From' to current value")]
public override void SetStartToCurrentValue ()
{
from = value;
}
[ContextMenu ("Set 'To' to current value")]
public override void SetEndToCurrentValue ()
{
to = value;
}
[ContextMenu ("Assume value of 'From'")]
void SetCurrentValueToStart ()
{
value = from;
}
[ContextMenu ("Assume value of 'To'")]
void SetCurrentValueToEnd ()
{
value = to;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d662b267e38f14b61a3524bbeb9a94cf
timeCreated: 1484025821
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: wangkaiyuan
*Version: 2.0
*Date: 2017-01-09
*Description: 拖动滑动一页比如可以用在关卡地图页面绑定lua
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using XLua;
namespace Coolape
{
[RequireComponent (typeof(CLCellLua))]
public class UIDragPage4Lua : UIDragPageContents
{
public CLCellLua uiLua;
bool isFinishInit = false;
LuaFunction lfInit = null;
LuaFunction lfrefresh = null;
LuaFunction lfrefreshCurrent = null;
public override void init (object obj, int index)
{
if (!isFinishInit) {
isFinishInit = true;
if (uiLua != null) {
uiLua.setLua ();
lfInit = uiLua.getLuaFunction ("init");
lfrefresh = uiLua.getLuaFunction ("refresh");
lfrefreshCurrent = uiLua.getLuaFunction ("refreshCurrent");
}
if (lfInit != null) {
uiLua.call(lfInit, uiLua);
}
}
if (lfrefresh != null) {
uiLua.call (lfrefresh, obj, index);
}
}
public override void refreshCurrent (int pageIndex, object obj)
{
init (obj, pageIndex);
if (lfrefreshCurrent != null) {
uiLua.call (lfrefreshCurrent, pageIndex, obj);
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e7a31b95fa2894ff1b1ad1f5cc40ed5b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,72 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: wangkaiyuan
*Version: 2.0
*Date: 2017-01-09
*Description: 拖动滑动一页比如可以用在关卡地图页面绑定lua
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class UIDragPageContents : UIDragScrollView
{
Transform tr;
public Transform transform {
get {
if (tr == null) {
tr = gameObject.transform;
}
return tr;
}
}
public UIGridPage _gridPage;
public UIGridPage gridPage {
get {
if (_gridPage == null) {
_gridPage = transform.parent.GetComponent<UIGridPage> ();
}
return _gridPage;
}
}
public void OnPress (bool isPressed)
{
if (!enabled || !NGUITools.GetActive(this))
return;
if (isPressed) {
base.OnPress (isPressed);
}
gridPage.onPress (isPressed);
}
public void OnDrag (Vector2 delta)
{
if (!enabled || !NGUITools.GetActive(this))
return;
base.OnDrag (delta);
gridPage.onDrag (delta);
}
/// <summary>
/// Init the specified obj.初始化页面数据
/// </summary>
/// <param name="obj">Object.</param>
public virtual void init (object obj, int index){}
/// <summary>
/// Refreshs the current.初始化当前页面数据
/// </summary>
/// <param name="pageIndex">Page index.</param>
/// <param name="obj">Object.</param>
public virtual void refreshCurrent (int pageIndex, object obj){}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2466f719a614d466c912caf920a292af
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,411 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: wangkaiyuan
*Version: 2.0
*Date: 2017-01-09
*Description: 滑动页面,比如可以用在关卡地图页面
* 注意使用时每个page都要继承UIDragPageContents(如果是lua时可以直接使用UIDragPage4Lua)
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using XLua;
namespace Coolape
{
[ExecuteInEditMode]
[RequireComponent (typeof(UIMoveToCell))]
public class UIGridPage : UIGrid
{
int cacheNum = 3;
public bool isLimitless = false;
//缓存数
public bool isReverse = false;
public float dragSensitivity = 10f;
//拖动敏感度
public UIDragPageContents page1;
public UIDragPageContents page2;
public UIDragPageContents page3;
[HideInInspector]
public int currCell = 0;
int oldCurrCell = -1;
UIMoveToCell _moveToCell;
public LoopPage currPage;
LoopPage pages;
bool canDrag = true;
int flag = 1;
UIScrollView _scrollView;
public UIScrollView scrollView {
get {
if (_scrollView == null) {
_scrollView = GetComponent<UIScrollView> ();
if (_scrollView == null) {
_scrollView = transform.parent.GetComponent<UIScrollView> ();
}
}
return _scrollView;
}
}
public class LoopPage
{
public UIDragPageContents data;
public LoopPage prev;
public LoopPage next;
}
bool isFinishInit = false;
public override void Start ()
{
if (isFinishInit) {
return;
}
base.Start ();
_init ();
}
void _init ()
{
if (isFinishInit) {
return;
}
isFinishInit = true;
dragSensitivity = dragSensitivity <= 0 ? 1 : dragSensitivity;
pages = new LoopPage ();
pages.data = page1;
pages.next = new LoopPage ();
pages.next.data = page2;
pages.next.next = new LoopPage ();
pages.next.next.data = page3;
pages.next.next.next = pages;
pages.prev = pages.next.next;
pages.next.prev = pages;
pages.next.next.prev = pages.next;
currPage = pages;
}
public UIMoveToCell moveToCell {
get {
if (_moveToCell == null) {
_moveToCell = GetComponent<UIMoveToCell> ();
}
return _moveToCell;
}
}
object data;
object[] dataList;
object onRefreshCurrentPage;
/// <summary>
/// Init the specified pageList, initPage, initCell and defalt.初始化滑动页面
/// </summary>
/// <param name="pageList">Page list.
/// 数据是list里面套list外层list是页面的数据内层的数据是每个页面里面的数据
/// </param>
/// <param name="onRefreshCurrentPage">onRefreshCurrentPage.
/// 当显示当前page时的回调
/// </param>
/// <param name="defaltPage">defaltPage.
/// 初始化时默认页0表示第一页1表示第2页
/// </param>
public void init (object pageList, object onRefreshCurrentPage, int defaltPage)
{
if (pageList == null) {
Debug.LogError ("Data is null");
return;
}
_initList (pageList, onRefreshCurrentPage, defaltPage);
}
void _initList (object data, object onRefreshCurrentPage, int defaltPage)
{
Start ();
canDrag = true;
if (isReverse) {
flag = -1;
}
object[] list = null;
if (data is LuaTable) {
ArrayList _list = CLUtlLua.luaTableVals2List ((LuaTable)data);
list = _list.ToArray ();
_list.Clear ();
_list = null;
} else if (data is ArrayList) {
list = ((ArrayList)data).ToArray ();
}
this.data = data;
this.dataList = list;
this.onRefreshCurrentPage = onRefreshCurrentPage;
if (defaltPage >= list.Length || defaltPage < 0) {
return;
}
currCell = defaltPage;
initCellPos (currCell);
}
void initCellPos (int index)
{
NGUITools.SetActive (page1.gameObject, true);
NGUITools.SetActive (page2.gameObject, true);
NGUITools.SetActive (page3.gameObject, true);
Update ();
repositionNow = true;
Update ();
currPage = pages;
int pageCount = dataList.Length;
if (pageCount <= 3) {
#region
//此段处理是为了让ngpc这种三个页面显示的数据不同的那种让三个页面的位置固定
switch (currCell) {
case 0:
currPage = pages;
NGUITools.SetActive (page1.gameObject, true);
break;
case 1:
currPage = pages.next;
break;
case 2:
currPage = pages.prev;
break;
default:
break;
}
switch (pageCount) {
case 1:
NGUITools.SetActive (page1.gameObject, true);
NGUITools.SetActive (page2.gameObject, false);
NGUITools.SetActive (page3.gameObject, false);
break;
case 2:
NGUITools.SetActive (page1.gameObject, true);
NGUITools.SetActive (page2.gameObject, true);
NGUITools.SetActive (page3.gameObject, false);
break;
case 3:
NGUITools.SetActive (page1.gameObject, true);
NGUITools.SetActive (page2.gameObject, true);
NGUITools.SetActive (page3.gameObject, true);
break;
default:
NGUITools.SetActive (page1.gameObject, false);
NGUITools.SetActive (page2.gameObject, false);
NGUITools.SetActive (page3.gameObject, false);
break;
}
#endregion
} else {
Vector3 toPos = Vector3.zero;
if (arrangement == UIGrid.Arrangement.Horizontal) {
toPos.x = flag * cellWidth * (index);
currPage.data.transform.localPosition = toPos;
toPos.x = flag * cellWidth * (index - 1);
currPage.prev.data.transform.localPosition = toPos;
toPos.x = flag * cellWidth * (index + 1);
currPage.next.data.transform.localPosition = toPos;
} else {
toPos.y = -flag * cellHeight * index;
currPage.data.transform.localPosition = toPos;
toPos.y = -flag * cellHeight * (index - 1);
currPage.prev.data.transform.localPosition = toPos;
toPos.y = -flag * cellHeight * (index + 1);
currPage.next.data.transform.localPosition = toPos;
}
}
oldCurrCell = currCell;
moveToCell.moveTo (index, isReverse, false);
//刷新数据
if (currCell <= 0) {
NGUITools.SetActive (currPage.prev.data.gameObject, false);
}
if (currCell - 1 >= 0 && currCell - 1 < pageCount) {
currPage.prev.data.init (dataList [currCell - 1], currCell - 1);//刷新数据
} else {
currPage.prev.data.init (null, currCell - 1);//刷新数据
}
if (currCell + 1 < pageCount && (currCell + 1) >= 0) {
currPage.next.data.init (dataList [currCell + 1], currCell + 1);//刷新数据
} else {
currPage.next.data.init (null, currCell + 1);//刷新数据
}
if(dataList.Length > currCell && currCell >= 0) {
currPage.data.refreshCurrent (currCell, dataList [currCell]);//刷新数据(放在最后)
doCallback (dataList [currCell]);
} else {
currPage.data.refreshCurrent (currCell, null);//刷新数据(放在最后)
doCallback (null);
}
}
void onFinishMoveto (params object[] paras)
{
canDrag = true;
}
void doCallback (object data)
{
Utl.doCallback (onRefreshCurrentPage, currCell, data, currPage.data);
}
public void moveTo (bool force = false)
{
canDrag = false;
Callback cb = onFinishMoveto;
moveToCell.moveTo (currCell, isReverse, false, cb);
if (oldCurrCell != currCell || force) {
int diff = currCell - oldCurrCell;
int absDiff = Mathf.Abs (diff);
int _flag = diff / absDiff;
for (int i = 0; i < absDiff; i++) {
resetCell (force);
oldCurrCell += _flag;
}
oldCurrCell = currCell;
//刷新数据==================
int pageCount = dataList.Length;
if (currCell - 1 >= 0 && currCell - 1 < pageCount) {
currPage.prev.data.init (dataList [currCell - 1], currCell - 1);//刷新数据
} else {
currPage.prev.data.init (null, currCell - 1);//刷新数据
}
if (currCell + 1 < pageCount && (currCell+1) >= 0) {
currPage.next.data.init (dataList [currCell + 1], currCell + 1);//刷新数据
} else {
currPage.next.data.init (null, currCell + 1);//刷新数据
}
if(dataList.Length > currCell && currCell >= 0) {
currPage.data.refreshCurrent (currCell, dataList [currCell]);//刷新数据(放在最后)
doCallback (dataList [currCell]);
} else {
currPage.data.refreshCurrent (currCell, null);//刷新数据(放在最后)
doCallback (null);
}
}
}
void resetCell (bool isForce)
{
if (currCell > 0) {
NGUITools.SetActive (currPage.prev.data.gameObject, true);
}
//处理边界
int pageCount = dataList.Length;
//移动位置
UIDragPageContents cell;
Vector3 toPos = Vector3.zero;
if (oldCurrCell < currCell) {
cell = currPage.prev.data;
if (arrangement == UIGrid.Arrangement.Horizontal) {
toPos = currPage.data.transform.localPosition;
toPos.x += flag * cellWidth * 2;
} else {
toPos = currPage.data.transform.localPosition;
toPos.y -= flag * cellHeight * 2;
}
} else {
cell = currPage.next.data;
if (arrangement == UIGrid.Arrangement.Horizontal) {
toPos = currPage.data.transform.localPosition;
toPos.x -= flag * cellWidth * 2;
} else {
toPos = currPage.data.transform.localPosition;
toPos.y += flag * cellHeight * 2;
}
}
cell.transform.localPosition = toPos;
if (isLimitless || (!isLimitless && (oldCurrCell != -1 || currCell != 0))) {
if (oldCurrCell < currCell) {
currPage = currPage.next;
} else {
currPage = currPage.prev;
}
}
}
public void onPress (bool isPressed)
{
//===============
if (!isPressed) {
if (canDrag) {
procMoveCell ();
}
} else {
totalDelta = Vector2.zero;
}
}
Vector2 totalDelta = Vector2.zero;
public void onDrag (Vector2 delta)
{
totalDelta += delta;
}
//处理移动单元
public void procMoveCell ()
{
int index = currCell;
if (dataList == null || dataList.Length <= 0) {
return;
}
float delta = 0;
float sensitivity = dragSensitivity <= 0 ? 1 : dragSensitivity;
if (arrangement == Arrangement.Horizontal) {
delta = totalDelta.x;
if (Mathf.Abs (delta) >= cellWidth / dragSensitivity) {
if (flag * delta > 0) {
index--;
} else {
index++;
}
}
} else {
delta = totalDelta.y;
if (Mathf.Abs (delta) >= cellHeight / dragSensitivity) {
if (flag * delta > 0) {
index++;
} else {
index--;
}
}
}
if (scrollView.dragEffect == UIScrollView.DragEffect.Momentum) {
if ((index < 0 || index >= dataList.Length) && !isLimitless) {
return;
}
}
moveTo (index);
}
public void moveTo (int index)
{
currCell = index;
if(!isLimitless) {
currCell = currCell < 0 ? 0 : currCell;
currCell = currCell >= dataList.Length ? dataList.Length - 1 : currCell;
}
moveTo ();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 40cac2ee22ec241d393cdeb505a161cd
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,150 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 移动列表显示指定的单元
* 注意将该脚本绑在grid层
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class UIMoveToCell : MonoBehaviour
{
public float speed = 1.5f;
public AnimationCurve moveCurve = new AnimationCurve (new Keyframe (0, 0), new Keyframe (1, 1));
Vector3 fromListPos = Vector3.zero;
// Vector4 fromClipRage = Vector4.zero;
Vector2 fromOffset = Vector2.zero;
Vector3 toListPos = Vector3.zero;
// Vector4 toClipRage = Vector4.zero;
Vector2 toOffset = Vector2.zero;
Vector3 diffListPos = Vector3.zero;
Vector2 diffOffset = Vector4.zero;
bool isMoveToNow = false;
object finishCallback;
UIGrid _grid;
UIGrid grid {
get {
if (_grid == null) {
_grid = GetComponent<UIGrid> ();
}
return _grid;
}
}
UIPanel _panelList;
UIPanel panelList {
get {
if (_panelList == null && grid != null) {
_panelList = grid.transform.parent.GetComponent<UIPanel> ();
}
return _panelList;
}
}
float times = 0;
// Update is called once per frame
void FixedUpdate ()
{
if (isMoveToNow) {
times += speed * Time.unscaledDeltaTime;
if (times > 1) {
times = 1;
isMoveToNow = false;
Utl.doCallback (finishCallback, this);
}
panelList.transform.localPosition = fromListPos + diffListPos * moveCurve.Evaluate (times);
panelList.clipOffset = fromOffset + diffOffset * moveCurve.Evaluate (times);
}
}
/// <summary>
/// Moves the list show specific cell.
/// </summary>移动列表显示指定的单元
/// <param name='parentOfCell'>
/// Parent of cell.
/// </param>
/// <param name='specificCell'>
/// Specific cell.指定的单元
/// </param>
/// <param name='arrangeMent'>
/// Arrange ment. 1水平滑动 2垂直滑动
/// </param>
public void moveTo (GameObject specificCell, bool isReverse)
{
if (grid == null || panelList == null || specificCell == null) {
return;
}
int index = 0;
try {
index = int.Parse (specificCell.name);
} catch {
return;
}
moveTo (index, isReverse, false);
}
public void moveTo (int index, bool isReverse, bool reset, object finishCallback = null)
{
this.finishCallback = finishCallback;
int flag = 1;
if (isReverse) {
flag = -1;
}
if (grid == null || panelList == null) { // || index < 0) {
return;
}
if (reset)
grid.resetPosition ();
Vector4 clip = panelList.baseClipRegion;
Vector2 newOffset = panelList.clipOffset;
Vector3 newListPos = panelList.transform.localPosition;
fromOffset = newOffset;
fromListPos = newListPos;
newOffset = grid.oldParentClipOffset;
newListPos = grid.oldParentPos;
float cellSize = 0;
int cellMaxPerLine = grid.maxPerLine;
cellMaxPerLine = cellMaxPerLine == 0 ? 1 : cellMaxPerLine;
if ((grid.arrangement == UIGrid.Arrangement.Horizontal && cellMaxPerLine == 1) ||
(grid.arrangement == UIGrid.Arrangement.Vertical && cellMaxPerLine > 1)) {
cellSize = grid.cellWidth;
float x = flag * (index / cellMaxPerLine) * cellSize;
if ((grid.Count () / cellMaxPerLine) * cellSize < clip.z) {
return;
}
newListPos.x = grid.oldParentPos.x - x;
newOffset.x = grid.oldParentClipOffset.x + x;
} else {
cellSize = grid.cellHeight;
float y = flag * (index / cellMaxPerLine) * cellSize;
if ((grid.Count () / cellMaxPerLine) * cellSize < clip.w) {
return;
}
// newListPos.y += y;
// newClipRage.y -= y;
newListPos.y = grid.oldParentPos.y + y;
newOffset.y = grid.oldParentClipOffset.y - y;
}
toListPos = newListPos;
toOffset = newOffset;
diffListPos = toListPos - fromListPos;
diffOffset = toOffset - fromOffset;
times = 0;
isMoveToNow = true;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ddc557079ce844e7c935ca3f8bf4a6c5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,143 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: wangkaiyuan
*Version: 2.0
*Date: 2017-01-09
*Description: 正常的九宫格sprite是四个角保持不变拉伸中间。
* 而该脚本正好反过来的效果,九宫格中间不变,四边接伸。
* 可以达到很完善的遮罩效果.
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
namespace Coolape
{
public class UISlicedSprite : UISprite
{
[ContextMenu("Execute")]
public void refreshCenter() {
mChanged = true;
MarkAsChanged();
}
// Type --> Sliced
[SerializeField]
public UIWidget mCenter = null;
/// <summary>
/// Virtual function called by the UIPanel that fills the buffers.
/// </summary>
protected override void SlicedFill (BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
{
Vector4 br = border * pixelSize;
if (br.x == 0f && br.y == 0f && br.z == 0f && br.w == 0f) {
SimpleFill (verts, uvs, cols);
return;
}
Color32 c = drawingColor;
Vector4 v = drawingDimensions;
if (mCenter != null) {
Vector4 h = mCenter.drawingDimensions;
/// X = left, Y = bottom, Z = right, W = top.
Vector3 offset = mCenter.transform.localPosition;
// print ("center pos = " + offset );
h.x += offset.x;
h.y += offset.y;
h.z += offset.x;
h.w += offset.y;
// print ("h = " + h );
// print ("v = " + v );
br.x = -(v.x - h.x);
br.y = -(v.y - h.y);
br.z = (v.z - h.z);
br.w = (v.w - h.w);
// print ("br = " + br );
// print ("br w= " + (br.z - br.x).ToString() );
// print ("br h= " + (br.w - br.y).ToString() );
if (br.x < 0f)
br.x = 0f;
if (br.y < 0f)
br.y = 0f;
if (br.z < 0f)
br.z = 0f;
if (br.w < 0f)
br.w = 0f;
}
mTempPos [0].x = v.x;
mTempPos [0].y = v.y;
mTempPos [3].x = v.z;
mTempPos [3].y = v.w;
if (mFlip == Flip.Horizontally || mFlip == Flip.Both) {
mTempPos [1].x = mTempPos [0].x + br.z;
mTempPos [2].x = mTempPos [3].x - br.x;
mTempUVs [3].x = mOuterUV.xMin;
mTempUVs [2].x = mInnerUV.xMin;
mTempUVs [1].x = mInnerUV.xMax;
mTempUVs [0].x = mOuterUV.xMax;
} else {
mTempPos [1].x = mTempPos [0].x + br.x;
mTempPos [2].x = mTempPos [3].x - br.z;
mTempUVs [0].x = mOuterUV.xMin;
mTempUVs [1].x = mInnerUV.xMin;
mTempUVs [2].x = mInnerUV.xMax;
mTempUVs [3].x = mOuterUV.xMax;
}
if (mFlip == Flip.Vertically || mFlip == Flip.Both) {
mTempPos [1].y = mTempPos [0].y + br.w;
mTempPos [2].y = mTempPos [3].y - br.y;
mTempUVs [3].y = mOuterUV.yMin;
mTempUVs [2].y = mInnerUV.yMin;
mTempUVs [1].y = mInnerUV.yMax;
mTempUVs [0].y = mOuterUV.yMax;
} else {
mTempPos [1].y = mTempPos [0].y + br.y;
mTempPos [2].y = mTempPos [3].y - br.w;
mTempUVs [0].y = mOuterUV.yMin;
mTempUVs [1].y = mInnerUV.yMin;
mTempUVs [2].y = mInnerUV.yMax;
mTempUVs [3].y = mOuterUV.yMax;
}
for (int x = 0; x < 3; ++x) {
int x2 = x + 1;
for (int y = 0; y < 3; ++y) {
if (centerType == AdvancedType.Invisible && x == 1 && y == 1)
continue;
int y2 = y + 1;
verts.Add (new Vector3 (mTempPos [x].x, mTempPos [y].y));
verts.Add (new Vector3 (mTempPos [x].x, mTempPos [y2].y));
verts.Add (new Vector3 (mTempPos [x2].x, mTempPos [y2].y));
verts.Add (new Vector3 (mTempPos [x2].x, mTempPos [y].y));
uvs.Add (new Vector2 (mTempUVs [x].x, mTempUVs [y].y));
uvs.Add (new Vector2 (mTempUVs [x].x, mTempUVs [y2].y));
uvs.Add (new Vector2 (mTempUVs [x2].x, mTempUVs [y2].y));
uvs.Add (new Vector2 (mTempUVs [x2].x, mTempUVs [y].y));
cols.Add (c);
cols.Add (c);
cols.Add (c);
cols.Add (c);
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2a290e7d1dbe84350bd0fdec7f568a66
timeCreated: 1484103654
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: