1 Star 0 Fork 3

wayfarer/rongYaoDaLuCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
UICheckboxX.cs 4.64 KB
一键复制 编辑 原始数据 按行查看 历史
liyonghelpme 提交于 2015-05-19 23:14 +08:00 . rong Yao Da Lu Some Code For Game
using AnimationOrTween;
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
[AddComponentMenu("NGUI/Interaction/CheckboxX")]
public class UICheckboxX : MonoBehaviour
{
public Animation checkAnimation;
public UISprite checkSprite;
public static UICheckboxX current;
public GameObject eventReceiver;
public string functionName = "OnActivate";
public bool instantTween;
private UILabel label;
private bool mChecked = true;
private bool mStarted;
private Transform mTrans;
public OnStateChange onStateChange;
[SerializeField, HideInInspector]
private bool option;
public bool optionCanBeNone;
public Transform radioButtonRoot;
public bool startsChecked = true;
private void Awake()
{
this.mTrans = base.transform;
if (this.radioButtonRoot == null)
{
this.radioButtonRoot = base.transform.parent;
}
if ((this.label == null) && (base.transform.FindChild("label") != null))
{
this.label = base.transform.FindChild("label").GetComponent<UILabel>();
}
if ((this.checkSprite == null) && (base.transform.FindChild("light") != null))
{
this.checkSprite = base.transform.FindChild("light").GetComponent<UISprite>();
}
if (this.checkSprite != null)
{
this.checkSprite.alpha = !this.startsChecked ? 0f : 1f;
}
if (this.option)
{
this.option = false;
if (this.radioButtonRoot == null)
{
this.radioButtonRoot = this.mTrans.parent;
}
}
}
private void OnClick()
{
if (base.enabled)
{
this.isChecked = !this.isChecked;
}
}
private void Set(bool state)
{
if (!this.mStarted)
{
this.mChecked = state;
this.startsChecked = state;
if (this.checkSprite != null)
{
this.checkSprite.alpha = !state ? 0f : 1f;
}
}
else if (this.mChecked != state)
{
if ((this.radioButtonRoot != null) && state)
{
UICheckboxX[] componentsInChildren = this.radioButtonRoot.GetComponentsInChildren<UICheckboxX>(true);
int index = 0;
int length = componentsInChildren.Length;
while (index < length)
{
UICheckboxX xx = componentsInChildren[index];
if ((xx != this) && (xx.radioButtonRoot == this.radioButtonRoot))
{
xx.Set(false);
}
index++;
}
}
this.mChecked = state;
if (this.checkSprite != null)
{
if (this.instantTween)
{
this.checkSprite.alpha = !this.mChecked ? 0f : 1f;
}
else
{
TweenAlpha.Begin(this.checkSprite.gameObject, 0.15f, !this.mChecked ? 0f : 1f);
}
}
if (this.label != null)
{
this.label.color = !state ? NGUITools.ParseColor("EAAE8F", 0) : Color.white;
}
current = this;
if (this.onStateChange != null)
{
this.onStateChange(this.mChecked);
}
if ((this.eventReceiver != null) && !string.IsNullOrEmpty(this.functionName))
{
this.eventReceiver.SendMessage(this.functionName, this.mChecked, SendMessageOptions.DontRequireReceiver);
}
current = null;
if (this.checkAnimation != null)
{
ActiveAnimation.Play(this.checkAnimation, !state ? AnimationOrTween.Direction.Reverse : AnimationOrTween.Direction.Forward);
}
}
}
private void Start()
{
if (this.eventReceiver == null)
{
this.eventReceiver = base.gameObject;
}
this.mChecked = !this.startsChecked;
this.mStarted = true;
this.Set(this.startsChecked);
}
public bool isChecked
{
get
{
return this.mChecked;
}
set
{
if (((this.radioButtonRoot == null) || value) || (this.optionCanBeNone || !this.mStarted))
{
this.Set(value);
}
}
}
public delegate void OnStateChange(bool state);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wayfarer/rongYaoDaLuCode.git
git@gitee.com:wayfarer/rongYaoDaLuCode.git
wayfarer
rongYaoDaLuCode
rongYaoDaLuCode
master

搜索帮助