提交FairyGUI

This commit is contained in:
PC-20230316NUNE\Administrator
2024-10-15 20:37:54 +08:00
parent ef1d3dfb2f
commit 9cd469b811
409 changed files with 66228 additions and 4076 deletions

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 76c9ac9d39933da4e833eddb1a96581a
folderAsset: yes
timeCreated: 1500559678
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,52 @@
using FairyGUI.Utils;
namespace FairyGUI
{
public class ChangePageAction : ControllerAction
{
public string objectId;
public string controllerName;
public string targetPage;
public ChangePageAction()
{
}
override protected void Enter(Controller controller)
{
if (string.IsNullOrEmpty(controllerName))
return;
GComponent gcom;
if (!string.IsNullOrEmpty(objectId))
gcom = controller.parent.GetChildById(objectId) as GComponent;
else
gcom = controller.parent;
if (gcom != null)
{
Controller cc = gcom.GetController(controllerName);
if (cc != null && cc != controller && !cc.changing)
{
if (this.targetPage == "~1")
{
if (controller.selectedIndex < cc.pageCount)
cc.selectedIndex = controller.selectedIndex;
}
else if (this.targetPage == "~2")
cc.selectedPage = controller.selectedPage;
else
cc.selectedPageId = this.targetPage;
}
}
}
override public void Setup(ByteBuffer buffer)
{
base.Setup(buffer);
objectId = buffer.ReadS();
controllerName = buffer.ReadS();
targetPage = buffer.ReadS();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 625a0a9a670984b47a4b170a801c850e
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
using System;
using FairyGUI.Utils;
namespace FairyGUI
{
public class ControllerAction
{
public enum ActionType
{
PlayTransition,
ChangePage
}
public string[] fromPage;
public string[] toPage;
public static ControllerAction CreateAction(ActionType type)
{
switch (type)
{
case ActionType.PlayTransition:
return new PlayTransitionAction();
case ActionType.ChangePage:
return new ChangePageAction();
}
return null;
}
public ControllerAction()
{
}
public void Run(Controller controller, string prevPage, string curPage)
{
if ((fromPage == null || fromPage.Length == 0 || Array.IndexOf(fromPage, prevPage) != -1)
&& (toPage == null || toPage.Length == 0 || Array.IndexOf(toPage, curPage) != -1))
Enter(controller);
else
Leave(controller);
}
virtual protected void Enter(Controller controller)
{
}
virtual protected void Leave(Controller controller)
{
}
virtual public void Setup(ByteBuffer buffer)
{
int cnt;
cnt = buffer.ReadShort();
fromPage = new string[cnt];
for (int i = 0; i < cnt; i++)
fromPage[i] = buffer.ReadS();
cnt = buffer.ReadShort();
toPage = new string[cnt];
for (int i = 0; i < cnt; i++)
toPage[i] = buffer.ReadS();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d6fb1eb3d57827b4bb09eddfa5c76137
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,52 @@
using FairyGUI.Utils;
namespace FairyGUI
{
public class PlayTransitionAction : ControllerAction
{
public string transitionName;
public int playTimes;
public float delay;
public bool stopOnExit;
private Transition _currentTransition;
public PlayTransitionAction()
{
playTimes = 1;
delay = 0;
}
override protected void Enter(Controller controller)
{
Transition trans = controller.parent.GetTransition(transitionName);
if (trans != null)
{
if (_currentTransition != null && _currentTransition.playing)
trans.ChangePlayTimes(playTimes);
else
trans.Play(playTimes, delay, null);
_currentTransition = trans;
}
}
override protected void Leave(Controller controller)
{
if (stopOnExit && _currentTransition != null)
{
_currentTransition.Stop();
_currentTransition = null;
}
}
override public void Setup(ByteBuffer buffer)
{
base.Setup(buffer);
transitionName = buffer.ReadS();
playTimes = buffer.ReadInt();
delay = buffer.ReadFloat();
stopOnExit = buffer.ReadBool();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: eac7f8de0d09f17439fb3c8e4a06090e
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,189 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
public class AsyncCreationHelper
{
public static void CreateObject(PackageItem item, UIPackage.CreateObjectCallback callback)
{
Timers.inst.StartCoroutine(_CreateObject(item, callback));
}
static IEnumerator _CreateObject(PackageItem item, UIPackage.CreateObjectCallback callback)
{
Stats.LatestObjectCreation = 0;
Stats.LatestGraphicsCreation = 0;
float frameTime = UIConfig.frameTimeForAsyncUIConstruction;
List<DisplayListItem> itemList = new List<DisplayListItem>();
DisplayListItem di = new DisplayListItem(item, ObjectType.Component);
di.childCount = CollectComponentChildren(item, itemList);
itemList.Add(di);
int cnt = itemList.Count;
List<GObject> objectPool = new List<GObject>(cnt);
GObject obj;
float t = Time.realtimeSinceStartup;
bool alreadyNextFrame = false;
for (int i = 0; i < cnt; i++)
{
di = itemList[i];
if (di.packageItem != null)
{
obj = UIObjectFactory.NewObject(di.packageItem);
objectPool.Add(obj);
UIPackage._constructing++;
if (di.packageItem.type == PackageItemType.Component)
{
int poolStart = objectPool.Count - di.childCount - 1;
((GComponent)obj).ConstructFromResource(objectPool, poolStart);
objectPool.RemoveRange(poolStart, di.childCount);
}
else
{
obj.ConstructFromResource();
}
UIPackage._constructing--;
}
else
{
obj = UIObjectFactory.NewObject(di.type);
objectPool.Add(obj);
if (di.type == ObjectType.List && di.listItemCount > 0)
{
int poolStart = objectPool.Count - di.listItemCount - 1;
for (int k = 0; k < di.listItemCount; k++) //把他们都放到pool里这样GList在创建时就不需要创建对象了
((GList)obj).itemPool.ReturnObject(objectPool[k + poolStart]);
objectPool.RemoveRange(poolStart, di.listItemCount);
}
}
if ((i % 5 == 0) && Time.realtimeSinceStartup - t >= frameTime)
{
yield return null;
t = Time.realtimeSinceStartup;
alreadyNextFrame = true;
}
}
if (!alreadyNextFrame) //强制至至少下一帧才调用callback避免调用者逻辑出错
yield return null;
callback(objectPool[0]);
}
/// <summary>
/// 收集创建目标对象所需的所有类型信息
/// </summary>
/// <param name="item"></param>
/// <param name="list"></param>
static int CollectComponentChildren(PackageItem item, List<DisplayListItem> list)
{
ByteBuffer buffer = item.rawData;
buffer.Seek(0, 2);
int dcnt = buffer.ReadShort();
DisplayListItem di;
PackageItem pi;
for (int i = 0; i < dcnt; i++)
{
int dataLen = buffer.ReadShort();
int curPos = buffer.position;
buffer.Seek(curPos, 0);
ObjectType type = (ObjectType)buffer.ReadByte();
string src = buffer.ReadS();
string pkgId = buffer.ReadS();
buffer.position = curPos;
if (src != null)
{
UIPackage pkg;
if (pkgId != null)
pkg = UIPackage.GetById(pkgId);
else
pkg = item.owner;
pi = pkg != null ? pkg.GetItem(src) : null;
di = new DisplayListItem(pi, type);
if (pi != null && pi.type == PackageItemType.Component)
di.childCount = CollectComponentChildren(pi, list);
}
else
{
di = new DisplayListItem(null, type);
if (type == ObjectType.List) //list
di.listItemCount = CollectListChildren(buffer, list);
}
list.Add(di);
buffer.position = curPos + dataLen;
}
return dcnt;
}
static int CollectListChildren(ByteBuffer buffer, List<DisplayListItem> list)
{
buffer.Seek(buffer.position, 8);
string defaultItem = buffer.ReadS();
int listItemCount = 0;
int itemCount = buffer.ReadShort();
for (int i = 0; i < itemCount; i++)
{
int nextPos = buffer.ReadShort();
nextPos += buffer.position;
string url = buffer.ReadS();
if (url == null)
url = defaultItem;
if (!string.IsNullOrEmpty(url))
{
PackageItem pi = UIPackage.GetItemByURL(url);
if (pi != null)
{
DisplayListItem di = new DisplayListItem(pi, pi.objectType);
if (pi.type == PackageItemType.Component)
di.childCount = CollectComponentChildren(pi, list);
list.Add(di);
listItemCount++;
}
}
buffer.position = nextPos;
}
return listItemCount;
}
/// <summary>
///
/// </summary>
class DisplayListItem
{
public PackageItem packageItem;
public ObjectType type;
public int childCount;
public int listItemCount;
public DisplayListItem(PackageItem pi, ObjectType type)
{
this.packageItem = pi;
this.type = type;
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 99d38995f0d185d4eb694a7728219c01
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,434 @@
using System.Collections.Generic;
using FairyGUI.Utils;
using System;
namespace FairyGUI
{
/// <summary>
/// Controller class.
/// 控制器类。控制器的创建和设计需通过编辑器完成,不建议使用代码创建。
/// 最常用的方法是通过selectedIndex获得或改变控制器的活动页面。如果要获得控制器页面改变的通知使用onChanged事件。
/// </summary>
public class Controller : EventDispatcher
{
/// <summary>
/// Name of the controller
/// 控制器名称。
/// </summary>
public string name;
internal GComponent parent;
internal bool autoRadioGroupDepth;
internal bool changing;
int _selectedIndex;
int _previousIndex;
List<string> _pageIds;
List<string> _pageNames;
List<ControllerAction> _actions;
EventListener _onChanged;
static uint _nextPageId;
public Controller()
{
_pageIds = new List<string>();
_pageNames = new List<string>();
_selectedIndex = -1;
_previousIndex = -1;
}
public void Dispose()
{
RemoveEventListeners();
}
/// <summary>
/// When controller page changed.
/// 当控制器活动页面改变时,此事件被触发。
/// </summary>
public EventListener onChanged
{
get { return _onChanged ?? (_onChanged = new EventListener(this, "onChanged")); }
}
/// <summary>
/// Current page index.
/// 获得或设置当前活动页面索引。
/// </summary>
public int selectedIndex
{
get
{
return _selectedIndex;
}
set
{
if (_selectedIndex != value)
{
if (value > _pageIds.Count - 1)
throw new IndexOutOfRangeException("" + value);
changing = true;
_previousIndex = _selectedIndex;
_selectedIndex = value;
parent.ApplyController(this);
DispatchEvent("onChanged", null);
changing = false;
}
}
}
/// <summary>
/// Set current page index, no onChanged event.
/// 通过索引设置当前活动页面和selectedIndex的区别在于这个方法不会触发onChanged事件。
/// </summary>
/// <param name="value">Page index</param>
public void SetSelectedIndex(int value)
{
if (_selectedIndex != value)
{
if (value > _pageIds.Count - 1)
throw new IndexOutOfRangeException("" + value);
changing = true;
_previousIndex = _selectedIndex;
_selectedIndex = value;
parent.ApplyController(this);
changing = false;
}
}
/// <summary>
/// Set current page by name, no onChanged event.
/// 通过页面名称设置当前活动页面和selectedPage的区别在于这个方法不会触发onChanged事件。
/// </summary>
/// <param name="value">Page name</param>
public void SetSelectedPage(string value)
{
int i = _pageNames.IndexOf(value);
if (i == -1)
i = 0;
this.SetSelectedIndex(i);
}
/// <summary>
/// Current page name.
/// 获得当前活动页面名称
/// </summary>
public string selectedPage
{
get
{
if (_selectedIndex == -1)
return null;
else
return _pageNames[_selectedIndex];
}
set
{
int i = _pageNames.IndexOf(value);
if (i == -1)
i = 0;
this.selectedIndex = i;
}
}
/// <summary>
/// Previouse page index.
/// 获得上次活动页面索引
/// </summary>
public int previsousIndex
{
get { return _previousIndex; }
}
/// <summary>
/// Previous page name.
/// 获得上次活动页面名称。
/// </summary>
public string previousPage
{
get
{
if (_previousIndex == -1)
return null;
else
return _pageNames[_previousIndex];
}
}
/// <summary>
/// Page count of this controller.
/// 获得页面数量。
/// </summary>
public int pageCount
{
get { return _pageIds.Count; }
}
/// <summary>
/// Get page name by an index.
/// 通过页面索引获得页面名称。
/// </summary>
/// <param name="index">Page index</param>
/// <returns>Page Name</returns>
public string GetPageName(int index)
{
return _pageNames[index];
}
/// <summary>
/// Get page id by an index.
/// 通过页面索引获得页面id。
/// </summary>
/// <param name="index">Page index</param>
/// <returns>Page Id</returns>
public string GetPageId(int index)
{
return _pageIds[index];
}
/// <summary>
/// Get page id by name
/// </summary>
/// <param name="aName"></param>
/// <returns></returns>
public string GetPageIdByName(string aName)
{
int i = _pageNames.IndexOf(aName);
if (i != -1)
return _pageIds[i];
else
return null;
}
/// <summary>
/// Add a new page to this controller.
/// </summary>
/// <param name="name">Page name</param>
public void AddPage(string name)
{
if (name == null)
name = string.Empty;
AddPageAt(name, _pageIds.Count);
}
/// <summary>
/// Add a new page to this controller at a certain index.
/// </summary>
/// <param name="name">Page name</param>
/// <param name="index">Insert position</param>
public void AddPageAt(string name, int index)
{
string nid = "_" + (_nextPageId++);
if (index == _pageIds.Count)
{
_pageIds.Add(nid);
_pageNames.Add(name);
}
else
{
_pageIds.Insert(index, nid);
_pageNames.Insert(index, name);
}
}
/// <summary>
/// Remove a page.
/// </summary>
/// <param name="name">Page name</param>
public void RemovePage(string name)
{
int i = _pageNames.IndexOf(name);
if (i != -1)
{
_pageIds.RemoveAt(i);
_pageNames.RemoveAt(i);
if (_selectedIndex >= _pageIds.Count)
this.selectedIndex = _selectedIndex - 1;
else
parent.ApplyController(this);
}
}
/// <summary>
/// Removes a page at a certain index.
/// </summary>
/// <param name="index"></param>
public void RemovePageAt(int index)
{
_pageIds.RemoveAt(index);
_pageNames.RemoveAt(index);
if (_selectedIndex >= _pageIds.Count)
this.selectedIndex = _selectedIndex - 1;
else
parent.ApplyController(this);
}
/// <summary>
/// Remove all pages.
/// </summary>
public void ClearPages()
{
_pageIds.Clear();
_pageNames.Clear();
if (_selectedIndex != -1)
this.selectedIndex = -1;
else
parent.ApplyController(this);
}
/// <summary>
/// Check if the controller has a page.
/// </summary>
/// <param name="aName">Page name.</param>
/// <returns></returns>
public bool HasPage(string aName)
{
return _pageNames.IndexOf(aName) != -1;
}
internal int GetPageIndexById(string aId)
{
return _pageIds.IndexOf(aId);
}
internal string GetPageNameById(string aId)
{
int i = _pageIds.IndexOf(aId);
if (i != -1)
return _pageNames[i];
else
return null;
}
internal string selectedPageId
{
get
{
if (_selectedIndex == -1)
return string.Empty;
else
return _pageIds[_selectedIndex];
}
set
{
int i = _pageIds.IndexOf(value);
if (i != -1)
this.selectedIndex = i;
}
}
internal string oppositePageId
{
set
{
int i = _pageIds.IndexOf(value);
if (i > 0)
this.selectedIndex = 0;
else if (_pageIds.Count > 1)
this.selectedIndex = 1;
}
}
internal string previousPageId
{
get
{
if (_previousIndex == -1)
return null;
else
return _pageIds[_previousIndex];
}
}
public void RunActions()
{
if (_actions != null)
{
int cnt = _actions.Count;
for (int i = 0; i < cnt; i++)
{
_actions[i].Run(this, previousPageId, selectedPageId);
}
}
}
public void Setup(ByteBuffer buffer)
{
int beginPos = buffer.position;
buffer.Seek(beginPos, 0);
name = buffer.ReadS();
autoRadioGroupDepth = buffer.ReadBool();
buffer.Seek(beginPos, 1);
int cnt = buffer.ReadShort();
_pageIds.Capacity = cnt;
_pageNames.Capacity = cnt;
for (int i = 0; i < cnt; i++)
{
_pageIds.Add(buffer.ReadS());
_pageNames.Add(buffer.ReadS());
}
int homePageIndex = 0;
if (buffer.version >= 2)
{
int homePageType = buffer.ReadByte();
switch (homePageType)
{
case 1:
homePageIndex = buffer.ReadShort();
break;
case 2:
homePageIndex = _pageNames.IndexOf(UIPackage.branch);
if (homePageIndex == -1)
homePageIndex = 0;
break;
case 3:
homePageIndex = _pageNames.IndexOf(UIPackage.GetVar(buffer.ReadS()));
if (homePageIndex == -1)
homePageIndex = 0;
break;
}
}
buffer.Seek(beginPos, 2);
cnt = buffer.ReadShort();
if (cnt > 0)
{
if (_actions == null)
_actions = new List<ControllerAction>(cnt);
for (int i = 0; i < cnt; i++)
{
int nextPos = buffer.ReadUshort();
nextPos += buffer.position;
ControllerAction action = ControllerAction.CreateAction((ControllerAction.ActionType)buffer.ReadByte());
action.Setup(buffer);
_actions.Add(action);
buffer.position = nextPos;
}
}
if (parent != null && _pageIds.Count > 0)
_selectedIndex = homePageIndex;
else
_selectedIndex = -1;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7a032426f9564db4a95c1c5a513bcd12
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace FairyGUI
{
/// <summary>
/// Helper for drag and drop.
/// 这是一个提供特殊拖放功能的功能类。与GObject.draggable不同拖动开始后他使用一个替代的图标作为拖动对象。
/// 当玩家释放鼠标/手指目标组件会发出一个onDrop事件。
/// </summary>
public class DragDropManager
{
private GLoader _agent;
private object _sourceData;
private GObject _source;
private static DragDropManager _inst;
public static DragDropManager inst
{
get
{
if (_inst == null)
_inst = new DragDropManager();
return _inst;
}
}
public DragDropManager()
{
_agent = (GLoader)UIObjectFactory.NewObject(ObjectType.Loader);
_agent.gameObjectName = "DragDropAgent";
_agent.SetHome(GRoot.inst);
_agent.touchable = false;//important
_agent.draggable = true;
_agent.SetSize(100, 100);
_agent.SetPivot(0.5f, 0.5f, true);
_agent.align = AlignType.Center;
_agent.verticalAlign = VertAlignType.Middle;
_agent.sortingOrder = int.MaxValue;
_agent.onDragEnd.Add(__dragEnd);
}
/// <summary>
/// Loader object for real dragging.
/// 用于实际拖动的Loader对象。你可以根据实际情况设置loader的大小对齐等。
/// </summary>
public GLoader dragAgent
{
get { return _agent; }
}
/// <summary>
/// Is dragging?
/// 返回当前是否正在拖动。
/// </summary>
public bool dragging
{
get { return _agent.parent != null; }
}
/// <summary>
/// Start dragging.
/// 开始拖动。
/// </summary>
/// <param name="source">Source object. This is the object which initiated the dragging.</param>
/// <param name="icon">Icon to be used as the dragging sign.</param>
/// <param name="sourceData">Custom data. You can get it in the onDrop event data.</param>
/// <param name="touchPointID">Copy the touchId from InputEvent to here, if has one.</param>
public void StartDrag(GObject source, string icon, object sourceData, int touchPointID = -1)
{
if (_agent.parent != null)
return;
_sourceData = sourceData;
_source = source;
_agent.url = icon;
GRoot.inst.AddChild(_agent);
_agent.xy = GRoot.inst.GlobalToLocal(Stage.inst.GetTouchPosition(touchPointID));
_agent.StartDrag(touchPointID);
}
/// <summary>
/// Cancel dragging.
/// 取消拖动。
/// </summary>
public void Cancel()
{
if (_agent.parent != null)
{
_agent.StopDrag();
GRoot.inst.RemoveChild(_agent);
_sourceData = null;
}
}
private void __dragEnd(EventContext evt)
{
if (_agent.parent == null) //cancelled
return;
GRoot.inst.RemoveChild(_agent);
object sourceData = _sourceData;
GObject source = _source;
_sourceData = null;
_source = null;
GObject obj = GRoot.inst.touchTarget;
while (obj != null)
{
if (obj.hasEventListeners("onDrop"))
{
obj.RequestFocus();
obj.DispatchEvent("onDrop", sourceData, source);
return;
}
obj = obj.parent;
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: fb013a6e64663c34694529d92a620777
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,129 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public interface EMRenderTarget
{
int EM_sortingOrder { get; }
void EM_BeforeUpdate();
void EM_Update(UpdateContext context);
void EM_Reload();
}
/// <summary>
/// 这是一个在编辑状态下渲染UI的功能类。EM=Edit Mode
/// </summary>
public class EMRenderSupport
{
/// <summary>
///
/// </summary>
public static bool orderChanged;
static UpdateContext _updateContext;
static List<EMRenderTarget> _targets = new List<EMRenderTarget>();
/// <summary>
///
/// </summary>
public static bool packageListReady { get; private set; }
/// <summary>
///
/// </summary>
public static bool hasTarget
{
get { return _targets.Count > 0; }
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
public static void Add(EMRenderTarget value)
{
if (!_targets.Contains(value))
_targets.Add(value);
orderChanged = true;
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
public static void Remove(EMRenderTarget value)
{
_targets.Remove(value);
}
/// <summary>
/// 由StageCamera调用
/// </summary>
public static void Update()
{
if (Application.isPlaying)
return;
if (_updateContext == null)
_updateContext = new UpdateContext();
if (orderChanged)
{
_targets.Sort(CompareDepth);
orderChanged = false;
}
int cnt = _targets.Count;
for (int i = 0; i < cnt; i++)
{
EMRenderTarget panel = _targets[i];
panel.EM_BeforeUpdate();
}
if (packageListReady)
{
_updateContext.Begin();
for (int i = 0; i < cnt; i++)
{
EMRenderTarget panel = _targets[i];
panel.EM_Update(_updateContext);
}
_updateContext.End();
}
}
/// <summary>
/// 当发生二进制重载时,或用户点击刷新菜单
/// </summary>
public static void Reload()
{
if (Application.isPlaying)
return;
UIConfig.ClearResourceRefs();
UIConfig[] configs = GameObject.FindObjectsOfType<UIConfig>();
foreach (UIConfig config in configs)
config.Load();
packageListReady = true;
int cnt = _targets.Count;
for (int i = 0; i < cnt; i++)
{
EMRenderTarget panel = _targets[i];
panel.EM_Reload();
}
}
static int CompareDepth(EMRenderTarget c1, EMRenderTarget c2)
{
return c1.EM_sortingOrder - c2.EM_sortingOrder;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 0ea7d5d9d5c232d4f9a312870329cbd2
timeCreated: 1464535178
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,304 @@
namespace FairyGUI
{
public enum PackageItemType
{
Image,
MovieClip,
Sound,
Component,
Atlas,
Font,
Swf,
Misc,
Unknown,
Spine,
DragoneBones
}
public enum ObjectType
{
Image,
MovieClip,
Swf,
Graph,
Loader,
Group,
Text,
RichText,
InputText,
Component,
List,
Label,
Button,
ComboBox,
ProgressBar,
Slider,
ScrollBar,
Tree,
Loader3D
}
public enum AlignType
{
Left,
Center,
Right
}
public enum VertAlignType
{
Top,
Middle,
Bottom
}
public enum OverflowType
{
Visible,
Hidden,
Scroll
}
public enum FillType
{
None,
Scale,
ScaleMatchHeight,
ScaleMatchWidth,
ScaleFree,
ScaleNoBorder
}
public enum AutoSizeType
{
None,
Both,
Height,
Shrink,
Ellipsis
}
public enum ScrollType
{
Horizontal,
Vertical,
Both
}
public enum ScrollBarDisplayType
{
Default,
Visible,
Auto,
Hidden
}
public enum RelationType
{
Left_Left,
Left_Center,
Left_Right,
Center_Center,
Right_Left,
Right_Center,
Right_Right,
Top_Top,
Top_Middle,
Top_Bottom,
Middle_Middle,
Bottom_Top,
Bottom_Middle,
Bottom_Bottom,
Width,
Height,
LeftExt_Left,
LeftExt_Right,
RightExt_Left,
RightExt_Right,
TopExt_Top,
TopExt_Bottom,
BottomExt_Top,
BottomExt_Bottom,
Size
}
public enum ListLayoutType
{
SingleColumn,
SingleRow,
FlowHorizontal,
FlowVertical,
Pagination
}
public enum ListSelectionMode
{
Single,
Multiple,
Multiple_SingleClick,
None
}
public enum ProgressTitleType
{
Percent,
ValueAndMax,
Value,
Max
}
public enum ButtonMode
{
Common,
Check,
Radio
}
public enum TransitionActionType
{
XY,
Size,
Scale,
Pivot,
Alpha,
Rotation,
Color,
Animation,
Visible,
Sound,
Transition,
Shake,
ColorFilter,
Skew,
Text,
Icon,
Unknown
}
public enum GroupLayoutType
{
None,
Horizontal,
Vertical
}
public enum ChildrenRenderOrder
{
Ascent,
Descent,
Arch,
}
public enum PopupDirection
{
Auto,
Up,
Down
}
/// <summary>
///
/// </summary>
public enum FlipType
{
None,
Horizontal,
Vertical,
Both
}
/// <summary>
///
/// </summary>
public enum FillMethod
{
None = 0,
/// <summary>
/// The Image will be filled Horizontally
/// </summary>
Horizontal = 1,
/// <summary>
/// The Image will be filled Vertically.
/// </summary>
Vertical = 2,
/// <summary>
/// The Image will be filled Radially with the radial center in one of the corners.
/// </summary>
Radial90 = 3,
/// <summary>
/// The Image will be filled Radially with the radial center in one of the edges.
/// </summary>
Radial180 = 4,
/// <summary>
/// The Image will be filled Radially with the radial center at the center.
/// </summary>
Radial360 = 5,
}
/// <summary>
///
/// </summary>
public enum OriginHorizontal
{
Left,
Right,
}
/// <summary>
///
/// </summary>
public enum OriginVertical
{
Top,
Bottom
}
/// <summary>
///
/// </summary>
public enum Origin90
{
TopLeft,
TopRight,
BottomLeft,
BottomRight
}
/// <summary>
///
/// </summary>
public enum Origin180
{
Top,
Bottom,
Left,
Right
}
/// <summary>
///
/// </summary>
public enum Origin360
{
Top,
Bottom,
Left,
Right
}
public enum FocusRule
{
NotFocusable,
Focusable,
NavigationBase
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 1d03a824e0fdd8a48a0ad6173b4593e0
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,657 @@
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GButton class.
/// </summary>
public class GButton : GComponent, IColorGear
{
/// <summary>
/// Play sound when button is clicked.
/// </summary>
public NAudioClip sound;
/// <summary>
/// Volume of the click sound. (0-1)
/// </summary>
public float soundVolumeScale;
/// <summary>
/// For radio or checkbox. if false, the button will not change selected status on click. Default is true.
/// 如果为true对于单选和多选按钮当玩家点击时按钮会自动切换状态。设置为false则不会。默认为true。
/// </summary>
public bool changeStateOnClick;
/// <summary>
/// Show a popup on click.
/// 可以为按钮设置一个关联的组件,当按钮被点击时,此组件被自动弹出。
/// </summary>
public GObject linkedPopup;
protected GObject _titleObject;
protected GObject _iconObject;
protected Controller _relatedController;
protected string _relatedPageId;
ButtonMode _mode;
bool _selected;
string _title;
string _icon;
string _selectedTitle;
string _selectedIcon;
Controller _buttonController;
int _downEffect;
float _downEffectValue;
bool _downScaled;
bool _down;
bool _over;
EventListener _onChanged;
public const string UP = "up";
public const string DOWN = "down";
public const string OVER = "over";
public const string SELECTED_OVER = "selectedOver";
public const string DISABLED = "disabled";
public const string SELECTED_DISABLED = "selectedDisabled";
public GButton()
{
sound = UIConfig.buttonSound;
soundVolumeScale = UIConfig.buttonSoundVolumeScale;
changeStateOnClick = true;
_downEffectValue = 0.8f;
_title = string.Empty;
}
/// <summary>
/// Dispatched when the button status was changed.
/// 如果为单选或多选按钮,当按钮的选中状态发生改变时,此事件触发。
/// </summary>
public EventListener onChanged
{
get { return _onChanged ?? (_onChanged = new EventListener(this, "onChanged")); }
}
/// <summary>
/// Icon of the button.
/// </summary>
override public string icon
{
get
{
return _icon;
}
set
{
_icon = value;
value = (_selected && _selectedIcon != null) ? _selectedIcon : _icon;
if (_iconObject != null)
_iconObject.icon = value;
UpdateGear(7);
}
}
/// <summary>
/// Title of the button
/// </summary>
public string title
{
get
{
return _title;
}
set
{
_title = value;
if (_titleObject != null)
_titleObject.text = (_selected && _selectedTitle != null) ? _selectedTitle : _title;
UpdateGear(6);
}
}
/// <summary>
/// Same of the title.
/// </summary>
override public string text
{
get { return this.title; }
set { this.title = value; }
}
/// <summary>
/// Icon value on selected status.
/// </summary>
public string selectedIcon
{
get
{
return _selectedIcon;
}
set
{
_selectedIcon = value;
value = (_selected && _selectedIcon != null) ? _selectedIcon : _icon;
if (_iconObject != null)
_iconObject.icon = value;
}
}
/// <summary>
/// Title value on selected status.
/// </summary>
public string selectedTitle
{
get
{
return _selectedTitle;
}
set
{
_selectedTitle = value;
if (_titleObject != null)
_titleObject.text = (_selected && _selectedTitle != null) ? _selectedTitle : _title;
}
}
/// <summary>
/// Title color.
/// </summary>
public Color titleColor
{
get
{
GTextField tf = GetTextField();
if (tf != null)
return tf.color;
else
return Color.black;
}
set
{
GTextField tf = GetTextField();
if (tf != null)
{
tf.color = value;
UpdateGear(4);
}
}
}
/// <summary>
///
/// </summary>
public Color color
{
get { return this.titleColor; }
set { this.titleColor = value; }
}
/// <summary>
///
/// </summary>
public int titleFontSize
{
get
{
GTextField tf = GetTextField();
if (tf != null)
return tf.textFormat.size;
else
return 0;
}
set
{
GTextField tf = GetTextField();
if (tf != null)
{
TextFormat format = tf.textFormat;
format.size = value;
tf.textFormat = format;
}
}
}
/// <summary>
/// If the button is in selected status.
/// </summary>
public bool selected
{
get
{
return _selected;
}
set
{
if (_mode == ButtonMode.Common)
return;
if (_selected != value)
{
_selected = value;
SetCurrentState();
if (_selectedTitle != null && _titleObject != null)
_titleObject.text = _selected ? _selectedTitle : _title;
if (_selectedIcon != null)
{
string str = _selected ? _selectedIcon : _icon;
if (_iconObject != null)
_iconObject.icon = str;
}
if (_relatedController != null
&& parent != null
&& !parent._buildingDisplayList)
{
if (_selected)
{
_relatedController.selectedPageId = _relatedPageId;
if (_relatedController.autoRadioGroupDepth)
parent.AdjustRadioGroupDepth(this, _relatedController);
}
else if (_mode == ButtonMode.Check && _relatedController.selectedPageId == _relatedPageId)
_relatedController.oppositePageId = _relatedPageId;
}
}
}
}
/// <summary>
/// Button mode.
/// </summary>
/// <seealso cref="ButtonMode"/>
public ButtonMode mode
{
get
{
return _mode;
}
set
{
if (_mode != value)
{
if (value == ButtonMode.Common)
this.selected = false;
_mode = value;
}
}
}
/// <summary>
/// A controller is connected to this button, the activate page of this controller will change while the button status changed.
/// 对应编辑器中的单选控制器。
/// </summary>
public Controller relatedController
{
get
{
return _relatedController;
}
set
{
if (value != _relatedController)
{
_relatedController = value;
_relatedPageId = null;
}
}
}
/// <summary>
///
/// </summary>
public string relatedPageId
{
get
{
return _relatedPageId;
}
set
{
_relatedPageId = value;
}
}
/// <summary>
/// Simulates a click on this button.
/// 模拟点击这个按钮。
/// </summary>
/// <param name="downEffect">If the down effect will simulate too.</param>
public void FireClick(bool downEffect, bool clickCall = false)
{
if (downEffect && _mode == ButtonMode.Common)
{
SetState(OVER);
Timers.inst.Add(0.1f, 1, (object param) => { SetState(DOWN); });
Timers.inst.Add(0.2f, 1,
(object param) =>
{
SetState(UP);
if (clickCall)
{
onClick.Call();
}
}
);
}
else
{
if (clickCall)
{
onClick.Call();
}
}
__click();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public GTextField GetTextField()
{
if (_titleObject is GTextField)
return (GTextField)_titleObject;
else if (_titleObject is GLabel)
return ((GLabel)_titleObject).GetTextField();
else if (_titleObject is GButton)
return ((GButton)_titleObject).GetTextField();
else
return null;
}
protected void SetState(string val)
{
if (_buttonController != null)
_buttonController.selectedPage = val;
if (_downEffect == 1)
{
int cnt = this.numChildren;
if (val == DOWN || val == SELECTED_OVER || val == SELECTED_DISABLED)
{
Color color = new Color(_downEffectValue, _downEffectValue, _downEffectValue);
for (int i = 0; i < cnt; i++)
{
GObject obj = this.GetChildAt(i);
if ((obj is IColorGear) && !(obj is GTextField))
((IColorGear)obj).color = color;
}
}
else
{
for (int i = 0; i < cnt; i++)
{
GObject obj = this.GetChildAt(i);
if ((obj is IColorGear) && !(obj is GTextField))
((IColorGear)obj).color = Color.white;
}
}
}
else if (_downEffect == 2)
{
if (val == DOWN || val == SELECTED_OVER || val == SELECTED_DISABLED)
{
if (!_downScaled)
{
_downScaled = true;
SetScale(this.scaleX * _downEffectValue, this.scaleY * _downEffectValue);
}
}
else
{
if (_downScaled)
{
_downScaled = false;
SetScale(this.scaleX / _downEffectValue, this.scaleY / _downEffectValue);
}
}
}
}
protected void SetCurrentState()
{
if (this.grayed && _buttonController != null && _buttonController.HasPage(DISABLED))
{
if (_selected)
SetState(SELECTED_DISABLED);
else
SetState(DISABLED);
}
else
{
if (_selected)
SetState(_over ? SELECTED_OVER : DOWN);
else
SetState(_over ? OVER : UP);
}
}
override public void HandleControllerChanged(Controller c)
{
base.HandleControllerChanged(c);
if (_relatedController == c)
this.selected = _relatedPageId == c.selectedPageId;
}
override protected void HandleGrayedChanged()
{
if (_buttonController != null && _buttonController.HasPage(DISABLED))
{
if (this.grayed)
{
if (_selected)
SetState(SELECTED_DISABLED);
else
SetState(DISABLED);
}
else
{
if (_selected)
SetState(DOWN);
else
SetState(UP);
}
}
else
base.HandleGrayedChanged();
}
override protected void ConstructExtension(ByteBuffer buffer)
{
buffer.Seek(0, 6);
_mode = (ButtonMode)buffer.ReadByte();
string str = buffer.ReadS();
if (str != null)
sound = UIPackage.GetItemAssetByURL(str) as NAudioClip;
soundVolumeScale = buffer.ReadFloat();
_downEffect = buffer.ReadByte();
_downEffectValue = buffer.ReadFloat();
if (_downEffect == 2)
SetPivot(0.5f, 0.5f, this.pivotAsAnchor);
_buttonController = GetController("button");
_titleObject = GetChild("title");
_iconObject = GetChild("icon");
if (_titleObject != null)
_title = _titleObject.text;
if (_iconObject != null)
_icon = _iconObject.icon;
if (_mode == ButtonMode.Common)
SetState(UP);
displayObject.onRollOver.Add(__rollover);
displayObject.onRollOut.Add(__rollout);
displayObject.onTouchBegin.Add(__touchBegin);
displayObject.onTouchEnd.Add(__touchEnd);
displayObject.onRemovedFromStage.Add(__removedFromStage);
displayObject.onClick.Add(__click);
}
override public void Setup_AfterAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_AfterAdd(buffer, beginPos);
if (!buffer.Seek(beginPos, 6))
return;
if ((ObjectType)buffer.ReadByte() != packageItem.objectType)
return;
string str;
str = buffer.ReadS();
if (str != null)
this.title = str;
str = buffer.ReadS();
if (str != null)
this.selectedTitle = str;
str = buffer.ReadS();
if (str != null)
this.icon = str;
str = buffer.ReadS();
if (str != null)
this.selectedIcon = str;
if (buffer.ReadBool())
this.titleColor = buffer.ReadColor();
int iv = buffer.ReadInt();
if (iv != 0)
this.titleFontSize = iv;
iv = buffer.ReadShort();
if (iv >= 0)
_relatedController = parent.GetControllerAt(iv);
_relatedPageId = buffer.ReadS();
str = buffer.ReadS();
if (str != null)
sound = UIPackage.GetItemAssetByURL(str) as NAudioClip;
if (buffer.ReadBool())
soundVolumeScale = buffer.ReadFloat();
this.selected = buffer.ReadBool();
}
private void __rollover()
{
if (_buttonController == null || !_buttonController.HasPage(OVER))
return;
_over = true;
if (_down)
return;
if (this.grayed && _buttonController.HasPage(DISABLED))
return;
SetState(_selected ? SELECTED_OVER : OVER);
}
private void __rollout()
{
if (_buttonController == null || !_buttonController.HasPage(OVER))
return;
_over = false;
if (_down)
return;
if (this.grayed && _buttonController.HasPage(DISABLED))
return;
SetState(_selected ? DOWN : UP);
}
private void __touchBegin(EventContext context)
{
if (context.inputEvent.button != 0)
return;
_down = true;
context.CaptureTouch();
if (_mode == ButtonMode.Common)
{
if (this.grayed && _buttonController != null && _buttonController.HasPage(DISABLED))
SetState(SELECTED_DISABLED);
else
SetState(DOWN);
}
if (linkedPopup != null)
{
if (linkedPopup is Window)
((Window)linkedPopup).ToggleStatus();
else
this.root.TogglePopup(linkedPopup, this);
}
}
private void __touchEnd()
{
if (_down)
{
_down = false;
if (_mode == ButtonMode.Common)
{
if (this.grayed && _buttonController != null && _buttonController.HasPage(DISABLED))
SetState(DISABLED);
else if (_over)
SetState(OVER);
else
SetState(UP);
}
else
{
if (!_over
&& _buttonController != null
&& (_buttonController.selectedPage == OVER || _buttonController.selectedPage == SELECTED_OVER))
{
SetCurrentState();
}
}
}
}
private void __removedFromStage()
{
if (_over)
__rollout();
}
private void __click()
{
if (sound != null && sound.nativeClip != null)
Stage.inst.PlayOneShotSound(sound.nativeClip, soundVolumeScale);
if (_mode == ButtonMode.Check)
{
if (changeStateOnClick)
{
this.selected = !_selected;
DispatchEvent("onChanged", null);
}
}
else if (_mode == ButtonMode.Radio)
{
if (changeStateOnClick && !_selected)
{
this.selected = true;
DispatchEvent("onChanged", null);
}
}
else
{
if (_relatedController != null)
_relatedController.selectedPageId = _relatedPageId;
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 4e5e996dd06bc77458af09a2465efb6d
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,629 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GComboBox class.
/// </summary>
public class GComboBox : GComponent
{
/// <summary>
/// Visible item count of the drop down list.
/// </summary>
public int visibleItemCount;
/// <summary>
///
/// </summary>
public GComponent dropdown;
/// <summary>
/// Play sound when button is clicked.
/// </summary>
public NAudioClip sound;
/// <summary>
/// Volume of the click sound. (0-1)
/// </summary>
public float soundVolumeScale;
protected GObject _titleObject;
protected GObject _iconObject;
protected GList _list;
protected List<string> _items;
protected List<string> _icons;
protected List<string> _values;
protected PopupDirection _popupDirection;
protected Controller _selectionController;
bool _itemsUpdated;
int _selectedIndex;
Controller _buttonController;
bool _down;
bool _over;
EventListener _onChanged;
public GComboBox()
{
visibleItemCount = UIConfig.defaultComboBoxVisibleItemCount;
_itemsUpdated = true;
_selectedIndex = -1;
_items = new List<string>();
_values = new List<string>();
_popupDirection = PopupDirection.Auto;
soundVolumeScale = 1;
}
/// <summary>
/// Dispatched when selection was changed.
/// </summary>
public EventListener onChanged
{
get { return _onChanged ?? (_onChanged = new EventListener(this, "onChanged")); }
}
/// <summary>
/// Icon of the combobox.
/// </summary>
override public string icon
{
get
{
if (_iconObject != null)
return _iconObject.icon;
else
return null;
}
set
{
if (_iconObject != null)
_iconObject.icon = value;
UpdateGear(7);
}
}
/// <summary>
/// Title of the combobox.
/// </summary>
public string title
{
get
{
if (_titleObject != null)
return _titleObject.text;
else
return null;
}
set
{
if (_titleObject != null)
_titleObject.text = value;
UpdateGear(6);
}
}
/// <summary>
/// Same of the title.
/// </summary>
override public string text
{
get { return this.title; }
set { this.title = value; }
}
/// <summary>
/// Text color
/// </summary>
public Color titleColor
{
get
{
GTextField tf = GetTextField();
if (tf != null)
return tf.color;
else
return Color.black;
}
set
{
GTextField tf = GetTextField();
if (tf != null)
tf.color = value;
}
}
/// <summary>
///
/// </summary>
public int titleFontSize
{
get
{
GTextField tf = GetTextField();
if (tf != null)
return tf.textFormat.size;
else
return 0;
}
set
{
GTextField tf = GetTextField();
if (tf != null)
{
TextFormat format = tf.textFormat;
format.size = value;
tf.textFormat = format;
}
}
}
/// <summary>
/// Items to build up drop down list.
/// </summary>
public string[] items
{
get
{
return _items.ToArray();
}
set
{
_items.Clear();
if (value != null)
_items.AddRange(value);
ApplyListChange();
}
}
/// <summary>
///
/// </summary>
public string[] icons
{
get { return _icons != null ? _icons.ToArray() : null; }
set
{
this.iconList.Clear();
if (value != null)
_icons.AddRange(value);
ApplyListChange();
}
}
/// <summary>
/// Values, should be same size of the items.
/// </summary>
public string[] values
{
get { return _values.ToArray(); }
set
{
_values.Clear();
if (value != null)
_values.AddRange(value);
}
}
/// <summary>
///
/// </summary>
public List<string> itemList
{
get { return _items; }
}
/// <summary>
///
/// </summary>
public List<string> valueList
{
get { return _values; }
}
/// <summary>
///
/// </summary>
public List<string> iconList
{
get { return _icons ?? (_icons = new List<string>()); }
}
/// <summary>
/// Call this method after you made changes on itemList or iconList
/// </summary>
public void ApplyListChange()
{
if (_items.Count > 0)
{
if (_selectedIndex >= _items.Count)
_selectedIndex = _items.Count - 1;
else if (_selectedIndex == -1)
_selectedIndex = 0;
this.text = _items[_selectedIndex];
if (_icons != null && _selectedIndex < _icons.Count)
this.icon = _icons[_selectedIndex];
}
else
{
this.text = string.Empty;
if (_icons != null)
this.icon = null;
_selectedIndex = -1;
}
_itemsUpdated = true;
}
/// <summary>
/// Selected index.
/// </summary>
public int selectedIndex
{
get
{
return _selectedIndex;
}
set
{
if (_selectedIndex == value)
return;
_selectedIndex = value;
if (_selectedIndex >= 0 && _selectedIndex < _items.Count)
{
this.text = (string)_items[_selectedIndex];
if (_icons != null && _selectedIndex < _icons.Count)
this.icon = _icons[_selectedIndex];
}
else
{
this.text = string.Empty;
if (_icons != null)
this.icon = null;
}
UpdateSelectionController();
}
}
/// <summary>
///
/// </summary>
public Controller selectionController
{
get { return _selectionController; }
set { _selectionController = value; }
}
/// <summary>
/// Selected value.
/// </summary>
public string value
{
get
{
if (_selectedIndex >= 0 && _selectedIndex < _values.Count)
return _values[_selectedIndex];
else
return null;
}
set
{
int index = _values.IndexOf(value);
if (index == -1 && value == null)
index = _values.IndexOf(string.Empty);
if (index == -1)
index = 0;
this.selectedIndex = index;
}
}
/// <summary>
///
/// </summary>
public PopupDirection popupDirection
{
get { return _popupDirection; }
set { _popupDirection = value; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public GTextField GetTextField()
{
if (_titleObject is GTextField)
return (GTextField)_titleObject;
else if (_titleObject is GLabel)
return ((GLabel)_titleObject).GetTextField();
else if (_titleObject is GButton)
return ((GButton)_titleObject).GetTextField();
else
return null;
}
protected void SetState(string value)
{
if (_buttonController != null)
_buttonController.selectedPage = value;
}
protected void SetCurrentState()
{
if (this.grayed && _buttonController != null && _buttonController.HasPage(GButton.DISABLED))
SetState(GButton.DISABLED);
else if (dropdown != null && dropdown.parent != null)
SetState(GButton.DOWN);
else
SetState(_over ? GButton.OVER : GButton.UP);
}
override protected void HandleGrayedChanged()
{
if (_buttonController != null && _buttonController.HasPage(GButton.DISABLED))
{
if (this.grayed)
SetState(GButton.DISABLED);
else
SetState(GButton.UP);
}
else
base.HandleGrayedChanged();
}
override public void HandleControllerChanged(Controller c)
{
base.HandleControllerChanged(c);
if (_selectionController == c)
this.selectedIndex = c.selectedIndex;
}
void UpdateSelectionController()
{
if (_selectionController != null && !_selectionController.changing
&& _selectedIndex < _selectionController.pageCount)
{
Controller c = _selectionController;
_selectionController = null;
c.selectedIndex = _selectedIndex;
_selectionController = c;
}
}
public override void Dispose()
{
if (dropdown != null)
{
dropdown.Dispose();
dropdown = null;
}
_selectionController = null;
base.Dispose();
}
override protected void ConstructExtension(ByteBuffer buffer)
{
buffer.Seek(0, 6);
_buttonController = GetController("button");
_titleObject = GetChild("title");
_iconObject = GetChild("icon");
string str = buffer.ReadS();
if (str != null)
{
dropdown = UIPackage.CreateObjectFromURL(str) as GComponent;
if (dropdown == null)
{
Debug.LogWarning("FairyGUI: " + this.resourceURL + " should be a component.");
return;
}
_list = dropdown.GetChild("list") as GList;
if (_list == null)
{
Debug.LogWarning("FairyGUI: " + this.resourceURL + ": should container a list component named list.");
return;
}
_list.onClickItem.Add(__clickItem);
_list.AddRelation(dropdown, RelationType.Width);
_list.RemoveRelation(dropdown, RelationType.Height);
dropdown.AddRelation(_list, RelationType.Height);
dropdown.RemoveRelation(_list, RelationType.Width);
dropdown.SetHome(this);
}
displayObject.onRollOver.Add(__rollover);
displayObject.onRollOut.Add(__rollout);
displayObject.onTouchBegin.Add(__touchBegin);
displayObject.onTouchEnd.Add(__touchEnd);
displayObject.onClick.Add(__click);
}
override public void Setup_AfterAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_AfterAdd(buffer, beginPos);
if (!buffer.Seek(beginPos, 6))
return;
if ((ObjectType)buffer.ReadByte() != packageItem.objectType)
return;
string str;
int itemCount = buffer.ReadShort();
for (int i = 0; i < itemCount; i++)
{
int nextPos = buffer.ReadUshort();
nextPos += buffer.position;
_items.Add(buffer.ReadS());
_values.Add(buffer.ReadS());
str = buffer.ReadS();
if (str != null)
{
if (_icons == null)
_icons = new List<string>();
_icons.Add(str);
}
buffer.position = nextPos;
}
str = buffer.ReadS();
if (str != null)
{
this.text = str;
_selectedIndex = _items.IndexOf(str);
}
else if (_items.Count > 0)
{
_selectedIndex = 0;
this.text = _items[0];
}
else
_selectedIndex = -1;
str = buffer.ReadS();
if (str != null)
this.icon = str;
if (buffer.ReadBool())
this.titleColor = buffer.ReadColor();
int iv = buffer.ReadInt();
if (iv > 0)
visibleItemCount = iv;
_popupDirection = (PopupDirection)buffer.ReadByte();
iv = buffer.ReadShort();
if (iv >= 0)
_selectionController = parent.GetControllerAt(iv);
if (buffer.version >= 5)
{
str = buffer.ReadS();
if (str != null)
sound = UIPackage.GetItemAssetByURL(str) as NAudioClip;
soundVolumeScale = buffer.ReadFloat();
}
}
public void UpdateDropdownList()
{
if (_itemsUpdated)
{
_itemsUpdated = false;
RenderDropdownList();
_list.ResizeToFit(visibleItemCount);
}
}
protected void ShowDropdown()
{
UpdateDropdownList();
if (_list.selectionMode == ListSelectionMode.Single)
_list.selectedIndex = -1;
dropdown.width = this.width;
_list.EnsureBoundsCorrect(); //avoid flicker
this.root.TogglePopup(dropdown, this, _popupDirection);
if (dropdown.parent != null)
{
dropdown.displayObject.onRemovedFromStage.Add(__popupWinClosed);
SetState(GButton.DOWN);
}
}
virtual protected void RenderDropdownList()
{
_list.RemoveChildrenToPool();
int cnt = _items.Count;
for (int i = 0; i < cnt; i++)
{
GObject item = _list.AddItemFromPool();
item.text = _items[i];
item.icon = (_icons != null && i < _icons.Count) ? _icons[i] : null;
item.name = i < _values.Count ? _values[i] : string.Empty;
}
}
private void __popupWinClosed(object obj)
{
dropdown.displayObject.onRemovedFromStage.Remove(__popupWinClosed);
SetCurrentState();
RequestFocus();
}
private void __clickItem(EventContext context)
{
if (dropdown.parent is GRoot)
((GRoot)dropdown.parent).HidePopup(dropdown);
_selectedIndex = int.MinValue;
this.selectedIndex = _list.GetChildIndex((GObject)context.data);
DispatchEvent("onChanged", null);
}
private void __rollover()
{
_over = true;
if (_down || dropdown != null && dropdown.parent != null)
return;
SetCurrentState();
}
private void __rollout()
{
_over = false;
if (_down || dropdown != null && dropdown.parent != null)
return;
SetCurrentState();
}
private void __touchBegin(EventContext context)
{
if (context.initiator is InputTextField)
return;
_down = true;
if (dropdown != null)
ShowDropdown();
context.CaptureTouch();
}
private void __touchEnd(EventContext context)
{
if (_down)
{
_down = false;
if (dropdown != null && dropdown.parent != null)
SetCurrentState();
}
}
private void __click()
{
if (sound != null && sound.nativeClip != null)
Stage.inst.PlayOneShotSound(sound.nativeClip, soundVolumeScale);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 65b819211c4a7ec4eb1cf17cda579377
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
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,13 @@
fileFormatVersion: 2
guid: a21ec486dca945f459590f80e1e6f699
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,274 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GGraph class.
/// 对应编辑器里的图形对象。图形有两个用途,一是用来显示简单的图形,例如矩形等;二是作为一个占位的用途,
/// 可以将本对象替换为其他对象,或者在它的前后添加其他对象,相当于一个位置和深度的占位;还可以直接将内容设置
/// 为原生对象。
/// </summary>
public class GGraph : GObject, IColorGear
{
Shape _shape;
public GGraph()
{
}
override protected void CreateDisplayObject()
{
_shape = new Shape();
_shape.gOwner = this;
displayObject = _shape;
}
/// <summary>
/// Replace this object to another object in the display list.
/// 在显示列表中,将指定对象取代这个图形对象。这个图形对象相当于一个占位的用途。
/// </summary>
/// <param name="target">Target object.</param>
public void ReplaceMe(GObject target)
{
if (parent == null)
throw new Exception("parent not set");
target.name = this.name;
target.alpha = this.alpha;
target.rotation = this.rotation;
target.visible = this.visible;
target.touchable = this.touchable;
target.grayed = this.grayed;
target.SetXY(this.x, this.y);
target.SetSize(this.width, this.height);
int index = parent.GetChildIndex(this);
parent.AddChildAt(target, index);
target.relations.CopyFrom(this.relations);
parent.RemoveChild(this, true);
}
/// <summary>
/// Add another object before this object.
/// 在显示列表中,将另一个对象插入到这个对象的前面。
/// </summary>
/// <param name="target">Target object.</param>
public void AddBeforeMe(GObject target)
{
if (parent == null)
throw new Exception("parent not set");
int index = parent.GetChildIndex(this);
parent.AddChildAt(target, index);
}
/// <summary>
/// Add another object after this object.
/// 在显示列表中,将另一个对象插入到这个对象的后面。
/// </summary>
/// <param name="target">Target object.</param>
public void AddAfterMe(GObject target)
{
if (parent == null)
throw new Exception("parent not set");
int index = parent.GetChildIndex(this);
index++;
parent.AddChildAt(target, index);
}
/// <summary>
/// 设置内容为一个原生对象。这个图形对象相当于一个占位的用途。
/// </summary>
/// <param name="obj">原生对象</param>
public void SetNativeObject(DisplayObject obj)
{
if (displayObject == obj)
return;
if (_shape != null)
{
if (_shape.parent != null)
_shape.parent.RemoveChild(displayObject, true);
else
_shape.Dispose();
_shape.gOwner = null;
_shape = null;
}
displayObject = obj;
if (displayObject != null)
{
displayObject.alpha = this.alpha;
displayObject.rotation = this.rotation;
displayObject.visible = this.visible;
displayObject.touchable = this.touchable;
displayObject.gOwner = this;
}
if (parent != null)
parent.ChildStateChanged(this);
HandlePositionChanged();
}
/// <summary>
///
/// </summary>
public Color color
{
get
{
if (_shape != null)
return _shape.color;
else
return Color.clear;
}
set
{
if (_shape != null && _shape.color != value)
{
_shape.color = value;
UpdateGear(4);
}
}
}
/// <summary>
/// Get the shape object. It can be used for drawing.
/// 获取图形的原生对象,可用于绘制图形。
/// </summary>
public Shape shape
{
get { return _shape; }
}
/// <summary>
/// Draw a rectangle.
/// 画矩形。
/// </summary>
/// <param name="aWidth">Width</param>
/// <param name="aHeight">Height</param>
/// <param name="lineSize">Line size</param>
/// <param name="lineColor">Line color</param>
/// <param name="fillColor">Fill color</param>
public void DrawRect(float aWidth, float aHeight, int lineSize, Color lineColor, Color fillColor)
{
this.SetSize(aWidth, aHeight);
_shape.DrawRect(lineSize, lineColor, fillColor);
}
/// <summary>
///
/// </summary>
/// <param name="aWidth"></param>
/// <param name="aHeight"></param>
/// <param name="fillColor"></param>
/// <param name="corner"></param>
public void DrawRoundRect(float aWidth, float aHeight, Color fillColor, float[] corner)
{
this.SetSize(aWidth, aHeight);
this.shape.DrawRoundRect(0, Color.white, fillColor, corner[0], corner[1], corner[2], corner[3]);
}
/// <summary>
///
/// </summary>
/// <param name="aWidth"></param>
/// <param name="aHeight"></param>
/// <param name="fillColor"></param>
public void DrawEllipse(float aWidth, float aHeight, Color fillColor)
{
this.SetSize(aWidth, aHeight);
_shape.DrawEllipse(fillColor);
}
/// <summary>
///
/// </summary>
/// <param name="aWidth"></param>
/// <param name="aHeight"></param>
/// <param name="points"></param>
/// <param name="fillColor"></param>
public void DrawPolygon(float aWidth, float aHeight, IList<Vector2> points, Color fillColor)
{
this.SetSize(aWidth, aHeight);
_shape.DrawPolygon(points, fillColor);
}
/// <summary>
///
/// </summary>
/// <param name="aWidth"></param>
/// <param name="aHeight"></param>
/// <param name="points"></param>
/// <param name="fillColor"></param>
/// <param name="lineSize"></param>
/// <param name="lineColor"></param>
public void DrawPolygon(float aWidth, float aHeight, IList<Vector2> points, Color fillColor, float lineSize, Color lineColor)
{
this.SetSize(aWidth, aHeight);
_shape.DrawPolygon(points, fillColor, lineSize, lineColor);
}
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_BeforeAdd(buffer, beginPos);
buffer.Seek(beginPos, 5);
int type = buffer.ReadByte();
if (type != 0)
{
int lineSize = buffer.ReadInt();
Color lineColor = buffer.ReadColor();
Color fillColor = buffer.ReadColor();
bool roundedRect = buffer.ReadBool();
Vector4 cornerRadius = new Vector4();
if (roundedRect)
{
for (int i = 0; i < 4; i++)
cornerRadius[i] = buffer.ReadFloat();
}
if (type == 1)
{
if (roundedRect)
_shape.DrawRoundRect(lineSize, lineColor, fillColor, cornerRadius.x, cornerRadius.y, cornerRadius.z, cornerRadius.w);
else
_shape.DrawRect(lineSize, lineColor, fillColor);
}
else if (type == 2)
_shape.DrawEllipse(lineSize, fillColor, lineColor, fillColor, 0, 360);
else if (type == 3)
{
int cnt = buffer.ReadShort() / 2;
Vector2[] points = new Vector2[cnt];
for (int i = 0; i < cnt; i++)
points[i].Set(buffer.ReadFloat(), buffer.ReadFloat());
_shape.DrawPolygon(points, fillColor, lineSize, lineColor);
}
else if (type == 4)
{
int sides = buffer.ReadShort();
float startAngle = buffer.ReadFloat();
int cnt = buffer.ReadShort();
float[] distances = null;
if (cnt > 0)
{
distances = new float[cnt];
for (int i = 0; i < cnt; i++)
distances[i] = buffer.ReadFloat();
}
_shape.DrawRegularPolygon(sides, lineSize, fillColor, lineColor, fillColor, startAngle, distances);
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 913b7964e87194d4182c1ad388d94f19
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,538 @@
using System;
using FairyGUI.Utils;
using UnityEngine;
namespace FairyGUI
{
/// <summary>
/// GGroup class.
/// 组对象,对应编辑器里的高级组。
/// </summary>
public class GGroup : GObject
{
GroupLayoutType _layout;
int _lineGap;
int _columnGap;
bool _excludeInvisibles;
bool _autoSizeDisabled;
int _mainGridIndex;
int _mainGridMinSize;
bool _percentReady;
bool _boundsChanged;
int _mainChildIndex;
float _totalSize;
int _numChildren;
internal int _updating;
Action _refreshDelegate;
public GGroup()
{
_mainGridIndex = -1;
_mainChildIndex = -1;
_mainGridMinSize = 50;
_refreshDelegate = EnsureBoundsCorrect;
}
/// <summary>
/// Group layout type.
/// </summary>
public GroupLayoutType layout
{
get { return _layout; }
set
{
if (_layout != value)
{
_layout = value;
SetBoundsChangedFlag();
}
}
}
/// <summary>
///
/// </summary>
public int lineGap
{
get { return _lineGap; }
set
{
if (_lineGap != value)
{
_lineGap = value;
SetBoundsChangedFlag(true);
}
}
}
/// <summary>
///
/// </summary>
public int columnGap
{
get { return _columnGap; }
set
{
if (_columnGap != value)
{
_columnGap = value;
SetBoundsChangedFlag(true);
}
}
}
/// <summary>
///
/// </summary>
public bool excludeInvisibles
{
get { return _excludeInvisibles; }
set
{
if (_excludeInvisibles != value)
{
_excludeInvisibles = value;
SetBoundsChangedFlag();
}
}
}
/// <summary>
///
/// </summary>
public bool autoSizeDisabled
{
get { return _autoSizeDisabled; }
set
{
if (_autoSizeDisabled != value)
{
_autoSizeDisabled = value;
SetBoundsChangedFlag();
}
}
}
/// <summary>
///
/// </summary>
public int mainGridMinSize
{
get { return _mainGridMinSize; }
set
{
if (_mainGridMinSize != value)
{
_mainGridMinSize = value;
SetBoundsChangedFlag();
}
}
}
/// <summary>
///
/// </summary>
public int mainGridIndex
{
get { return _mainGridIndex; }
set
{
if (_mainGridIndex != value)
{
_mainGridIndex = value;
SetBoundsChangedFlag();
}
}
}
/// <summary>
/// Update group bounds.
/// 更新组的包围.
/// </summary>
public void SetBoundsChangedFlag(bool positionChangedOnly = false)
{
if (_updating == 0 && parent != null)
{
if (!positionChangedOnly)
_percentReady = false;
if (!_boundsChanged)
{
_boundsChanged = true;
if (_layout != GroupLayoutType.None)
{
UpdateContext.OnBegin -= _refreshDelegate;
UpdateContext.OnBegin += _refreshDelegate;
}
}
}
}
public void EnsureBoundsCorrect()
{
if (parent == null || !_boundsChanged)
return;
UpdateContext.OnBegin -= _refreshDelegate;
_boundsChanged = false;
if (_autoSizeDisabled)
ResizeChildren(0, 0);
else
{
HandleLayout();
UpdateBounds();
}
}
void UpdateBounds()
{
int cnt = parent.numChildren;
int i;
GObject child;
float ax = int.MaxValue, ay = int.MaxValue;
float ar = int.MinValue, ab = int.MinValue;
float tmp;
bool empty = true;
bool skipInvisibles = _layout != GroupLayoutType.None && _excludeInvisibles;
for (i = 0; i < cnt; i++)
{
child = parent.GetChildAt(i);
if (child.group != this)
continue;
if (skipInvisibles && !child.internalVisible3)
continue;
tmp = child.xMin;
if (tmp < ax)
ax = tmp;
tmp = child.yMin;
if (tmp < ay)
ay = tmp;
tmp = child.xMin + child.width;
if (tmp > ar)
ar = tmp;
tmp = child.yMin + child.height;
if (tmp > ab)
ab = tmp;
empty = false;
}
float w;
float h;
if (!empty)
{
_updating |= 1;
SetXY(ax, ay);
_updating &= 2;
w = ar - ax;
h = ab - ay;
}
else
w = h = 0;
if ((_updating & 2) == 0)
{
_updating |= 2;
SetSize(w, h);
_updating &= 1;
}
else
{
_updating &= 1;
ResizeChildren(_width - w, _height - h);
}
}
void HandleLayout()
{
_updating |= 1;
if (_layout == GroupLayoutType.Horizontal)
{
float curX = this.x;
int cnt = parent.numChildren;
for (int i = 0; i < cnt; i++)
{
GObject child = parent.GetChildAt(i);
if (child.group != this)
continue;
if (_excludeInvisibles && !child.internalVisible3)
continue;
child.xMin = curX;
if (child.width != 0)
curX += child.width + _columnGap;
}
}
else if (_layout == GroupLayoutType.Vertical)
{
float curY = this.y;
int cnt = parent.numChildren;
for (int i = 0; i < cnt; i++)
{
GObject child = parent.GetChildAt(i);
if (child.group != this)
continue;
if (_excludeInvisibles && !child.internalVisible3)
continue;
child.yMin = curY;
if (child.height != 0)
curY += child.height + _lineGap;
}
}
_updating &= 2;
}
internal void MoveChildren(float dx, float dy)
{
if ((_updating & 1) != 0 || parent == null)
return;
_updating |= 1;
int cnt = parent.numChildren;
int i;
GObject child;
for (i = 0; i < cnt; i++)
{
child = parent.GetChildAt(i);
if (child.group == this)
{
child.SetXY(child.x + dx, child.y + dy);
}
}
_updating &= 2;
}
internal void ResizeChildren(float dw, float dh)
{
if (_layout == GroupLayoutType.None || (_updating & 2) != 0 || parent == null)
return;
_updating |= 2;
if (_boundsChanged)
{
_boundsChanged = false;
if (!_autoSizeDisabled)
{
UpdateBounds();
return;
}
}
int cnt = parent.numChildren;
if (!_percentReady)
{
_percentReady = true;
_numChildren = 0;
_totalSize = 0;
_mainChildIndex = -1;
int j = 0;
for (int i = 0; i < cnt; i++)
{
GObject child = parent.GetChildAt(i);
if (child.group != this)
continue;
if (!_excludeInvisibles || child.internalVisible3)
{
if (j == _mainGridIndex)
_mainChildIndex = i;
_numChildren++;
if (_layout == GroupLayoutType.Horizontal)
_totalSize += child.width;
else
_totalSize += child.height;
}
j++;
}
if (_mainChildIndex != -1)
{
if (_layout == GroupLayoutType.Horizontal)
{
GObject child = parent.GetChildAt(_mainChildIndex);
_totalSize += _mainGridMinSize - child.width;
child._sizePercentInGroup = _mainGridMinSize / _totalSize;
}
else
{
GObject child = parent.GetChildAt(_mainChildIndex);
_totalSize += _mainGridMinSize - child.height;
child._sizePercentInGroup = _mainGridMinSize / _totalSize;
}
}
for (int i = 0; i < cnt; i++)
{
GObject child = parent.GetChildAt(i);
if (child.group != this)
continue;
if (i == _mainChildIndex)
continue;
if (_totalSize > 0)
child._sizePercentInGroup = (_layout == GroupLayoutType.Horizontal ? child.width : child.height) / _totalSize;
else
child._sizePercentInGroup = 0;
}
}
float remainSize = 0;
float remainPercent = 1;
bool priorHandled = false;
if (_layout == GroupLayoutType.Horizontal)
{
remainSize = this.width - (_numChildren - 1) * _columnGap;
if (_mainChildIndex != -1 && remainSize >= _totalSize)
{
GObject child = parent.GetChildAt(_mainChildIndex);
child.SetSize(remainSize - (_totalSize - _mainGridMinSize), child._rawHeight + dh, true);
remainSize -= child.width;
remainPercent -= child._sizePercentInGroup;
priorHandled = true;
}
float curX = this.x;
for (int i = 0; i < cnt; i++)
{
GObject child = parent.GetChildAt(i);
if (child.group != this)
continue;
if (_excludeInvisibles && !child.internalVisible3)
{
child.SetSize(child._rawWidth, child._rawHeight + dh, true);
continue;
}
if (!priorHandled || i != _mainChildIndex)
{
child.SetSize(Mathf.Round(child._sizePercentInGroup / remainPercent * remainSize), child._rawHeight + dh, true);
remainPercent -= child._sizePercentInGroup;
remainSize -= child.width;
}
child.xMin = curX;
if (child.width != 0)
curX += child.width + _columnGap;
}
}
else
{
remainSize = this.height - (_numChildren - 1) * _lineGap;
if (_mainChildIndex != -1 && remainSize >= _totalSize)
{
GObject child = parent.GetChildAt(_mainChildIndex);
child.SetSize(child._rawWidth + dw, remainSize - (_totalSize - _mainGridMinSize), true);
remainSize -= child.height;
remainPercent -= child._sizePercentInGroup;
priorHandled = true;
}
float curY = this.y;
for (int i = 0; i < cnt; i++)
{
GObject child = parent.GetChildAt(i);
if (child.group != this)
continue;
if (_excludeInvisibles && !child.internalVisible3)
{
child.SetSize(child._rawWidth + dw, child._rawHeight, true);
continue;
}
if (!priorHandled || i != _mainChildIndex)
{
child.SetSize(child._rawWidth + dw, Mathf.Round(child._sizePercentInGroup / remainPercent * remainSize), true);
remainPercent -= child._sizePercentInGroup;
remainSize -= child.height;
}
child.yMin = curY;
if (child.height != 0)
curY += child.height + _lineGap;
}
}
_updating &= 1;
}
override protected void HandleAlphaChanged()
{
base.HandleAlphaChanged();
if (this.underConstruct || parent == null)
return;
int cnt = parent.numChildren;
float a = this.alpha;
for (int i = 0; i < cnt; i++)
{
GObject child = parent.GetChildAt(i);
if (child.group == this)
child.alpha = a;
}
}
override internal protected void HandleVisibleChanged()
{
if (parent == null)
return;
int cnt = parent.numChildren;
for (int i = 0; i < cnt; i++)
{
GObject child = parent.GetChildAt(i);
if (child.group == this)
child.HandleVisibleChanged();
}
}
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_BeforeAdd(buffer, beginPos);
buffer.Seek(beginPos, 5);
_layout = (GroupLayoutType)buffer.ReadByte();
_lineGap = buffer.ReadInt();
_columnGap = buffer.ReadInt();
if (buffer.version >= 2)
{
_excludeInvisibles = buffer.ReadBool();
_autoSizeDisabled = buffer.ReadBool();
_mainGridIndex = buffer.ReadShort();
}
}
override public void Setup_AfterAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_AfterAdd(buffer, beginPos);
if (!this.visible)
HandleVisibleChanged();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: b8aac7740f89ffc409bfb6cd30d58fec
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,172 @@
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GImage class.
/// </summary>
public class GImage : GObject, IColorGear
{
Image _content;
public Image Content => _content;
public GImage()
{
}
override protected void CreateDisplayObject()
{
_content = new Image();
_content.gOwner = this;
displayObject = _content;
}
/// <summary>
/// Color of the image.
/// </summary>
public Color color
{
get { return _content.color; }
set
{
_content.color = value;
UpdateGear(4);
}
}
/// <summary>
/// Flip type.
/// </summary>
/// <seealso cref="FlipType"/>
public FlipType flip
{
get { return _content.graphics.flip; }
set { _content.graphics.flip = value; }
}
/// <summary>
/// Fill method.
/// </summary>
/// <seealso cref="FillMethod"/>
public FillMethod fillMethod
{
get { return _content.fillMethod; }
set { _content.fillMethod = value; }
}
/// <summary>
/// Fill origin.
/// </summary>
/// <seealso cref="OriginHorizontal"/>
/// <seealso cref="OriginVertical"/>
/// <seealso cref="Origin90"/>
/// <seealso cref="Origin180"/>
/// <seealso cref="Origin360"/>
public int fillOrigin
{
get { return _content.fillOrigin; }
set { _content.fillOrigin = value; }
}
/// <summary>
/// Fill clockwise if true.
/// </summary>
public bool fillClockwise
{
get { return _content.fillClockwise; }
set { _content.fillClockwise = value; }
}
/// <summary>
/// Fill amount. (0~1)
/// </summary>
public float fillAmount
{
get { return _content.fillAmount; }
set { _content.fillAmount = value; }
}
/// <summary>
/// Set texture directly. The image wont own the texture.
/// </summary>
public NTexture texture
{
get { return _content.texture; }
set
{
if (value != null)
{
sourceWidth = value.width;
sourceHeight = value.height;
}
else
{
sourceWidth = 0;
sourceHeight = 0;
}
initWidth = sourceWidth;
initHeight = sourceHeight;
_content.texture = value;
}
}
/// <summary>
/// Set material.
/// </summary>
public Material material
{
get { return _content.material; }
set { _content.material = value; }
}
/// <summary>
/// Set shader.
/// </summary>
public string shader
{
get { return _content.shader; }
set { _content.shader = value; }
}
override public void ConstructFromResource()
{
this.gameObjectName = packageItem.name;
PackageItem contentItem = packageItem.getBranch();
sourceWidth = contentItem.width;
sourceHeight = contentItem.height;
initWidth = sourceWidth;
initHeight = sourceHeight;
contentItem = contentItem.getHighResolution();
contentItem.Load();
_content.scale9Grid = contentItem.scale9Grid;
_content.scaleByTile = contentItem.scaleByTile;
_content.tileGridIndice = contentItem.tileGridIndice;
_content.texture = contentItem.texture;
_content.textureScale = new Vector2(contentItem.width / (float)sourceWidth, contentItem.height / (float)sourceHeight);
SetSize(sourceWidth, sourceHeight);
}
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_BeforeAdd(buffer, beginPos);
buffer.Seek(beginPos, 5);
if (buffer.ReadBool())
_content.color = buffer.ReadColor();
_content.graphics.flip = (FlipType)buffer.ReadByte();
_content.fillMethod = (FillMethod)buffer.ReadByte();
if (_content.fillMethod != FillMethod.None)
{
_content.fillOrigin = buffer.ReadByte();
_content.fillClockwise = buffer.ReadBool();
_content.fillAmount = buffer.ReadFloat();
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 106156ac7c8773640af01f14fd396393
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,235 @@
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GLabel class.
/// </summary>
public class GLabel : GComponent, IColorGear
{
protected GObject _titleObject;
protected GObject _iconObject;
public GLabel()
{
}
/// <summary>
/// Icon of the label.
/// </summary>
override public string icon
{
get
{
if (_iconObject != null)
return _iconObject.icon;
else
return null;
}
set
{
if (_iconObject != null)
_iconObject.icon = value;
UpdateGear(7);
}
}
/// <summary>
/// Title of the label.
/// </summary>
public string title
{
get
{
if (_titleObject != null)
return _titleObject.text;
else
return null;
}
set
{
if (_titleObject != null)
_titleObject.text = value;
UpdateGear(6);
}
}
/// <summary>
/// Same of the title.
/// </summary>
override public string text
{
get { return this.title; }
set { this.title = value; }
}
/// <summary>
/// If title is input text.
/// </summary>
public bool editable
{
get
{
if (_titleObject is GTextInput)
return _titleObject.asTextInput.editable;
else
return false;
}
set
{
if (_titleObject is GTextInput)
_titleObject.asTextInput.editable = value;
}
}
/// <summary>
/// Title color of the label
/// </summary>
public Color titleColor
{
get
{
GTextField tf = GetTextField();
if (tf != null)
return tf.color;
else
return Color.black;
}
set
{
GTextField tf = GetTextField();
if (tf != null)
{
tf.color = value;
UpdateGear(4);
}
}
}
/// <summary>
///
/// </summary>
public int titleFontSize
{
get
{
GTextField tf = GetTextField();
if (tf != null)
return tf.textFormat.size;
else
return 0;
}
set
{
GTextField tf = GetTextField();
if (tf != null)
{
TextFormat format = tf.textFormat;
format.size = value;
tf.textFormat = format;
}
}
}
/// <summary>
///
/// </summary>
public Color color
{
get { return this.titleColor; }
set { this.titleColor = value; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public GTextField GetTextField()
{
if (_titleObject is GTextField)
return (GTextField)_titleObject;
else if (_titleObject is GLabel)
return ((GLabel)_titleObject).GetTextField();
else if (_titleObject is GButton)
return ((GButton)_titleObject).GetTextField();
else
return null;
}
override protected void ConstructExtension(ByteBuffer buffer)
{
_titleObject = GetChild("title");
_iconObject = GetChild("icon");
}
override public void Setup_AfterAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_AfterAdd(buffer, beginPos);
if (!buffer.Seek(beginPos, 6))
return;
if ((ObjectType)buffer.ReadByte() != packageItem.objectType)
return;
string str;
str = buffer.ReadS();
if (str != null)
this.title = str;
str = buffer.ReadS();
if (str != null)
this.icon = str;
if (buffer.ReadBool())
this.titleColor = buffer.ReadColor();
int iv = buffer.ReadInt();
if (iv != 0)
this.titleFontSize = iv;
if (buffer.ReadBool())
{
GTextInput input = GetTextField() as GTextInput;
if (input != null)
{
str = buffer.ReadS();
if (str != null)
input.promptText = str;
str = buffer.ReadS();
if (str != null)
input.restrict = str;
iv = buffer.ReadInt();
if (iv != 0)
input.maxLength = iv;
iv = buffer.ReadInt();
if (iv != 0)
input.keyboardType = iv;
if (buffer.ReadBool())
input.displayAsPassword = true;
}
else
buffer.Skip(13);
}
if (buffer.version >= 5)
{
string sound = buffer.ReadS();
if (!string.IsNullOrEmpty(sound))
{
float volumeScale = buffer.ReadFloat();
displayObject.onClick.Add(() =>
{
NAudioClip audioClip = UIPackage.GetItemAssetByURL(sound) as NAudioClip;
if (audioClip != null && audioClip.nativeClip != null)
Stage.inst.PlayOneShotSound(audioClip.nativeClip, volumeScale);
});
}
else
buffer.Skip(4);
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: bd9c62cc282bb9b4fa9e794317eedd30
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
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,13 @@
fileFormatVersion: 2
guid: f5eda689519c51b42955139d2c6caba4
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,701 @@
using System;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GLoader class
/// </summary>
public class GLoader : GObject, IAnimationGear, IColorGear
{
/// <summary>
/// Display an error sign if the loader fails to load the content.
/// UIConfig.loaderErrorSign muse be set.
/// </summary>
public bool showErrorSign;
string _url;
AlignType _align;
VertAlignType _verticalAlign;
bool _autoSize;
FillType _fill;
bool _shrinkOnly;
bool _updatingLayout;
PackageItem _contentItem;
Action<NTexture> _reloadDelegate;
MovieClip _content;
GObject _errorSign;
GComponent _content2;
#if FAIRYGUI_PUERTS
public Action __loadExternal;
public Action<NTexture> __freeExternal;
#endif
public GLoader()
{
_url = string.Empty;
_align = AlignType.Left;
_verticalAlign = VertAlignType.Top;
showErrorSign = true;
_reloadDelegate = OnExternalReload;
}
override protected void CreateDisplayObject()
{
displayObject = new Container("GLoader");
displayObject.gOwner = this;
_content = new MovieClip();
((Container)displayObject).AddChild(_content);
((Container)displayObject).opaque = true;
}
override public void Dispose()
{
if (_disposed) return;
if (_content.texture != null)
{
if (_contentItem == null)
{
_content.texture.onSizeChanged -= _reloadDelegate;
try
{
FreeExternal(_content.texture);
}
catch (Exception err)
{
Debug.LogWarning(err);
}
}
}
if (_errorSign != null)
_errorSign.Dispose();
if (_content2 != null)
_content2.Dispose();
_content.Dispose();
base.Dispose();
}
/// <summary>
///
/// </summary>
public string url
{
get { return _url; }
set
{
if (_url == value)
return;
ClearContent();
_url = value;
LoadContent();
UpdateGear(7);
}
}
override public string icon
{
get { return _url; }
set { this.url = value; }
}
/// <summary>
///
/// </summary>
public AlignType align
{
get { return _align; }
set
{
if (_align != value)
{
_align = value;
UpdateLayout();
}
}
}
/// <summary>
///
/// </summary>
public VertAlignType verticalAlign
{
get { return _verticalAlign; }
set
{
if (_verticalAlign != value)
{
_verticalAlign = value;
UpdateLayout();
}
}
}
/// <summary>
///
/// </summary>
public FillType fill
{
get { return _fill; }
set
{
if (_fill != value)
{
_fill = value;
UpdateLayout();
}
}
}
/// <summary>
///
/// </summary>
public bool shrinkOnly
{
get { return _shrinkOnly; }
set
{
if (_shrinkOnly != value)
{
_shrinkOnly = value;
UpdateLayout();
}
}
}
/// <summary>
///
/// </summary>
public bool autoSize
{
get { return _autoSize; }
set
{
if (_autoSize != value)
{
_autoSize = value;
UpdateLayout();
}
}
}
/// <summary>
///
/// </summary>
public bool playing
{
get { return _content.playing; }
set
{
_content.playing = value;
UpdateGear(5);
}
}
/// <summary>
///
/// </summary>
public int frame
{
get { return _content.frame; }
set
{
_content.frame = value;
UpdateGear(5);
}
}
/// <summary>
///
/// </summary>
public float timeScale
{
get { return _content.timeScale; }
set { _content.timeScale = value; }
}
/// <summary>
///
/// </summary>
public bool ignoreEngineTimeScale
{
get { return _content.ignoreEngineTimeScale; }
set { _content.ignoreEngineTimeScale = value; }
}
/// <summary>
///
/// </summary>
/// <param name="time"></param>
public void Advance(float time)
{
_content.Advance(time);
}
/// <summary>
///
/// </summary>
public Material material
{
get { return _content.material; }
set { _content.material = value; }
}
/// <summary>
///
/// </summary>
public string shader
{
get { return _content.shader; }
set { _content.shader = value; }
}
/// <summary>
///
/// </summary>
public Color color
{
get { return _content.color; }
set
{
if (_content.color != value)
{
_content.color = value;
UpdateGear(4);
}
}
}
/// <summary>
///
/// </summary>
public FillMethod fillMethod
{
get { return _content.fillMethod; }
set { _content.fillMethod = value; }
}
/// <summary>
///
/// </summary>
public int fillOrigin
{
get { return _content.fillOrigin; }
set { _content.fillOrigin = value; }
}
/// <summary>
///
/// </summary>
public bool fillClockwise
{
get { return _content.fillClockwise; }
set { _content.fillClockwise = value; }
}
/// <summary>
///
/// </summary>
public float fillAmount
{
get { return _content.fillAmount; }
set { _content.fillAmount = value; }
}
/// <summary>
///
/// </summary>
public Image image
{
get { return _content; }
}
/// <summary>
///
/// </summary>
public MovieClip movieClip
{
get { return _content; }
}
/// <summary>
///
/// </summary>
public GComponent component
{
get { return _content2; }
}
/// <summary>
///
/// </summary>
public NTexture texture
{
get
{
return _content.texture;
}
set
{
this.url = null;
_content.texture = value;
if (value != null)
{
sourceWidth = value.width;
sourceHeight = value.height;
}
else
{
sourceWidth = sourceHeight = 0;
}
UpdateLayout();
}
}
override public IFilter filter
{
get { return _content.filter; }
set { _content.filter = value; }
}
override public BlendMode blendMode
{
get { return _content.blendMode; }
set { _content.blendMode = value; }
}
/// <summary>
///
/// </summary>
protected void LoadContent()
{
ClearContent();
if (string.IsNullOrEmpty(_url))
return;
if (_url.StartsWith(UIPackage.URL_PREFIX))
LoadFromPackage(_url);
else
LoadExternal();
}
protected void LoadFromPackage(string itemURL)
{
_contentItem = UIPackage.GetItemByURL(itemURL);
if (_contentItem != null)
{
_contentItem = _contentItem.getBranch();
sourceWidth = _contentItem.width;
sourceHeight = _contentItem.height;
_contentItem = _contentItem.getHighResolution();
_contentItem.Load();
if (_contentItem.type == PackageItemType.Image)
{
_content.texture = _contentItem.texture;
_content.textureScale = new Vector2(_contentItem.width / (float)sourceWidth, _contentItem.height / (float)sourceHeight);
_content.scale9Grid = _contentItem.scale9Grid;
_content.scaleByTile = _contentItem.scaleByTile;
_content.tileGridIndice = _contentItem.tileGridIndice;
UpdateLayout();
}
else if (_contentItem.type == PackageItemType.MovieClip)
{
_content.interval = _contentItem.interval;
_content.swing = _contentItem.swing;
_content.repeatDelay = _contentItem.repeatDelay;
_content.frames = _contentItem.frames;
UpdateLayout();
}
else if (_contentItem.type == PackageItemType.Component)
{
GObject obj = UIPackage.CreateObjectFromURL(itemURL);
if (obj == null)
SetErrorState();
else if (!(obj is GComponent))
{
obj.Dispose();
SetErrorState();
}
else
{
_content2 = (GComponent)obj;
((Container)displayObject).AddChild(_content2.displayObject);
UpdateLayout();
}
}
else
{
if (_autoSize)
this.SetSize(_contentItem.width, _contentItem.height);
SetErrorState();
Debug.LogWarning("Unsupported type of GLoader: " + _contentItem.type);
}
}
else
SetErrorState();
}
virtual protected void LoadExternal()
{
#if FAIRYGUI_PUERTS
if (__loadExternal != null) {
__loadExternal();
return;
}
#endif
Texture2D tex = (Texture2D)Resources.Load(_url, typeof(Texture2D));
if (tex != null)
onExternalLoadSuccess(new NTexture(tex));
else
onExternalLoadFailed();
}
virtual protected void FreeExternal(NTexture texture)
{
#if FAIRYGUI_PUERTS
if (__freeExternal != null) {
__freeExternal(texture);
return;
}
#endif
}
public void onExternalLoadSuccess(NTexture texture)
{
_content.texture = texture;
sourceWidth = texture.width;
sourceHeight = texture.height;
_content.scale9Grid = null;
_content.scaleByTile = false;
texture.onSizeChanged += _reloadDelegate;
UpdateLayout();
}
public void onExternalLoadFailed()
{
SetErrorState();
}
void OnExternalReload(NTexture texture)
{
sourceWidth = texture.width;
sourceHeight = texture.height;
UpdateLayout();
}
private void SetErrorState()
{
if (!showErrorSign || !Application.isPlaying)
return;
if (_errorSign == null)
{
if (UIConfig.loaderErrorSign != null)
_errorSign = UIPackage.CreateObjectFromURL(UIConfig.loaderErrorSign);
else
return;
}
if (_errorSign != null)
{
_errorSign.SetSize(this.width, this.height);
((Container)displayObject).AddChild(_errorSign.displayObject);
}
}
protected void ClearErrorState()
{
if (_errorSign != null && _errorSign.displayObject.parent != null)
((Container)displayObject).RemoveChild(_errorSign.displayObject);
}
protected void UpdateLayout()
{
if (_content2 == null && _content.texture == null && _content.frames == null)
{
if (_autoSize)
{
_updatingLayout = true;
SetSize(50, 30);
_updatingLayout = false;
}
return;
}
float contentWidth = sourceWidth;
float contentHeight = sourceHeight;
if (_autoSize)
{
_updatingLayout = true;
if (contentWidth == 0)
contentWidth = 50;
if (contentHeight == 0)
contentHeight = 30;
SetSize(contentWidth, contentHeight);
_updatingLayout = false;
if (_width == contentWidth && _height == contentHeight)
{
if (_content2 != null)
{
_content2.SetXY(0, 0);
_content2.SetScale(1, 1);
}
else
{
_content.SetXY(0, 0);
_content.SetSize(contentWidth, contentHeight);
}
InvalidateBatchingState();
return;
}
//如果不相等,可能是由于大小限制造成的,要后续处理
}
float sx = 1, sy = 1;
if (_fill != FillType.None)
{
sx = this.width / sourceWidth;
sy = this.height / sourceHeight;
if (sx != 1 || sy != 1)
{
if (_fill == FillType.ScaleMatchHeight)
sx = sy;
else if (_fill == FillType.ScaleMatchWidth)
sy = sx;
else if (_fill == FillType.Scale)
{
if (sx > sy)
sx = sy;
else
sy = sx;
}
else if (_fill == FillType.ScaleNoBorder)
{
if (sx > sy)
sy = sx;
else
sx = sy;
}
if (_shrinkOnly)
{
if (sx > 1)
sx = 1;
if (sy > 1)
sy = 1;
}
contentWidth = sourceWidth * sx;
contentHeight = sourceHeight * sy;
}
}
if (_content2 != null)
_content2.SetScale(sx, sy);
else
_content.size = new Vector2(contentWidth, contentHeight);
float nx;
float ny;
if (_align == AlignType.Center)
nx = (this.width - contentWidth) / 2;
else if (_align == AlignType.Right)
nx = this.width - contentWidth;
else
nx = 0;
if (_verticalAlign == VertAlignType.Middle)
ny = (this.height - contentHeight) / 2;
else if (_verticalAlign == VertAlignType.Bottom)
ny = this.height - contentHeight;
else
ny = 0;
if (_content2 != null)
_content2.SetXY(nx, ny);
else
_content.SetXY(nx, ny);
InvalidateBatchingState();
}
private void ClearContent()
{
ClearErrorState();
if (_content.texture != null)
{
if (_contentItem == null)
{
_content.texture.onSizeChanged -= _reloadDelegate;
FreeExternal(_content.texture);
}
_content.texture = null;
}
_content.frames = null;
if (_content2 != null)
{
_content2.Dispose();
_content2 = null;
}
_contentItem = null;
}
override protected void HandleSizeChanged()
{
base.HandleSizeChanged();
if (!_updatingLayout)
UpdateLayout();
}
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_BeforeAdd(buffer, beginPos);
buffer.Seek(beginPos, 5);
_url = buffer.ReadS();
_align = (AlignType)buffer.ReadByte();
_verticalAlign = (VertAlignType)buffer.ReadByte();
_fill = (FillType)buffer.ReadByte();
_shrinkOnly = buffer.ReadBool();
_autoSize = buffer.ReadBool();
showErrorSign = buffer.ReadBool();
_content.playing = buffer.ReadBool();
_content.frame = buffer.ReadInt();
if (buffer.ReadBool())
_content.color = buffer.ReadColor();
_content.fillMethod = (FillMethod)buffer.ReadByte();
if (_content.fillMethod != FillMethod.None)
{
_content.fillOrigin = buffer.ReadByte();
_content.fillClockwise = buffer.ReadBool();
_content.fillAmount = buffer.ReadFloat();
}
if (!string.IsNullOrEmpty(_url))
LoadContent();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 43ce591d02b49e8419c431df4af3da0b
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,566 @@
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public partial class GLoader3D : GObject, IAnimationGear, IColorGear
{
string _url;
AlignType _align;
VertAlignType _verticalAlign;
bool _autoSize;
FillType _fill;
bool _shrinkOnly;
string _animationName;
string _skinName;
bool _playing;
int _frame;
bool _loop;
bool _updatingLayout;
Color _color;
protected PackageItem _contentItem;
protected GoWrapper _content;
public GLoader3D()
{
_url = string.Empty;
_align = AlignType.Left;
_verticalAlign = VertAlignType.Top;
_playing = true;
_color = Color.white;
}
override protected void CreateDisplayObject()
{
displayObject = new Container("GLoader3D");
displayObject.gOwner = this;
_content = new GoWrapper();
_content.onUpdate += OnUpdateContent;
((Container)displayObject).AddChild(_content);
((Container)displayObject).opaque = true;
}
override public void Dispose()
{
_content.Dispose();
base.Dispose();
}
/// <summary>
///
/// </summary>
public string url
{
get { return _url; }
set
{
if (_url == value)
return;
ClearContent();
_url = value;
LoadContent();
UpdateGear(7);
}
}
override public string icon
{
get { return _url; }
set { this.url = value; }
}
/// <summary>
///
/// </summary>
public AlignType align
{
get { return _align; }
set
{
if (_align != value)
{
_align = value;
UpdateLayout();
}
}
}
/// <summary>
///
/// </summary>
public VertAlignType verticalAlign
{
get { return _verticalAlign; }
set
{
if (_verticalAlign != value)
{
_verticalAlign = value;
UpdateLayout();
}
}
}
/// <summary>
///
/// </summary>
public FillType fill
{
get { return _fill; }
set
{
if (_fill != value)
{
_fill = value;
UpdateLayout();
}
}
}
/// <summary>
///
/// </summary>
public bool shrinkOnly
{
get { return _shrinkOnly; }
set
{
if (_shrinkOnly != value)
{
_shrinkOnly = value;
UpdateLayout();
}
}
}
/// <summary>
///
/// </summary>
public bool autoSize
{
get { return _autoSize; }
set
{
if (_autoSize != value)
{
_autoSize = value;
UpdateLayout();
}
}
}
public bool playing
{
get { return _playing; }
set
{
if (_playing != value)
{
_playing = value;
OnChange("playing");
UpdateGear(5);
}
}
}
public int frame
{
get { return _frame; }
set
{
if (_frame != value)
{
_frame = value;
OnChange("frame");
UpdateGear(5);
}
}
}
/// <summary>
/// Not implemented
/// </summary>
public float timeScale
{
get;
set;
}
/// <summary>
/// Not implemented
/// </summary>
public bool ignoreEngineTimeScale
{
get;
set;
}
/// <summary>
/// Not implemented
/// </summary>
/// <param name="time"></param>
public void Advance(float time)
{
}
/// <summary>
///
/// </summary>
public bool loop
{
get { return _loop; }
set
{
if (_loop != value)
{
_loop = value;
OnChange("loop");
}
}
}
/// <summary>
///
/// </summary>
/// <value></value>
public string animationName
{
get { return _animationName; }
set
{
_animationName = value;
OnChange("animationName");
UpdateGear(5);
}
}
/// <summary>
///
/// </summary>
/// <value></value>
public string skinName
{
get { return _skinName; }
set
{
_skinName = value;
OnChange("skinName");
UpdateGear(5);
}
}
/// <summary>
///
/// </summary>
public Material material
{
get { return _content.material; }
set { _content.material = value; }
}
/// <summary>
///
/// </summary>
public string shader
{
get { return _content.shader; }
set { _content.shader = value; }
}
/// <summary>
///
/// </summary>
public Color color
{
get { return _color; }
set
{
if (_color != value)
{
_color = value;
UpdateGear(4);
OnChange("color");
}
}
}
/// <summary>
///
/// </summary>
public GameObject wrapTarget
{
get { return _content.wrapTarget; }
}
/// <summary>
///
/// </summary>
/// <param name="gameObject"></param>
/// <param name="cloneMaterial"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public void SetWrapTarget(GameObject gameObject, bool cloneMaterial, int width, int height)
{
_content.SetWrapTarget(gameObject, cloneMaterial);
_content.SetSize(width, height);
sourceWidth = width;
sourceHeight = height;
UpdateLayout();
}
override public IFilter filter
{
get { return _content.filter; }
set { _content.filter = value; }
}
override public BlendMode blendMode
{
get { return _content.blendMode; }
set { _content.blendMode = value; }
}
/// <summary>
///
/// </summary>
protected void LoadContent()
{
ClearContent();
if (string.IsNullOrEmpty(_url))
return;
_contentItem = UIPackage.GetItemByURL(_url);
if (_contentItem != null)
{
_contentItem = _contentItem.getBranch();
_contentItem = _contentItem.getHighResolution();
_contentItem.Load();
if (_contentItem.type == PackageItemType.Spine)
{
#if FAIRYGUI_SPINE
LoadSpine();
#endif
}
else if (_contentItem.type == PackageItemType.DragoneBones)
{
#if FAIRYGUI_DRAGONBONES
LoadDragonBones();
#endif
}
}
else
LoadExternal();
}
virtual protected void OnChange(string propertyName)
{
if (_contentItem == null)
return;
if (_contentItem.type == PackageItemType.Spine)
{
#if FAIRYGUI_SPINE
OnChangeSpine(propertyName);
#endif
}
else if (_contentItem.type == PackageItemType.DragoneBones)
{
#if FAIRYGUI_DRAGONBONES
OnChangeDragonBones(propertyName);
#endif
}
}
virtual protected void LoadExternal()
{
}
virtual protected void FreeExternal()
{
GameObject.DestroyImmediate(_content.wrapTarget);
}
protected void UpdateLayout()
{
if (sourceWidth == 0 || sourceHeight == 0)
return;
float contentWidth = sourceWidth;
float contentHeight = sourceHeight;
if (_autoSize)
{
_updatingLayout = true;
if (contentWidth == 0)
contentWidth = 50;
if (contentHeight == 0)
contentHeight = 30;
SetSize(contentWidth, contentHeight);
_updatingLayout = false;
if (_width == contentWidth && _height == contentHeight)
{
_content.SetXY(0, 0);
_content.SetScale(1, 1);
InvalidateBatchingState();
return;
}
//如果不相等,可能是由于大小限制造成的,要后续处理
}
float sx = 1, sy = 1;
if (_fill != FillType.None)
{
sx = this.width / sourceWidth;
sy = this.height / sourceHeight;
if (sx != 1 || sy != 1)
{
if (_fill == FillType.ScaleMatchHeight)
sx = sy;
else if (_fill == FillType.ScaleMatchWidth)
sy = sx;
else if (_fill == FillType.Scale)
{
if (sx > sy)
sx = sy;
else
sy = sx;
}
else if (_fill == FillType.ScaleNoBorder)
{
if (sx > sy)
sy = sx;
else
sx = sy;
}
if (_shrinkOnly)
{
if (sx > 1)
sx = 1;
if (sy > 1)
sy = 1;
}
contentWidth = sourceWidth * sx;
contentHeight = sourceHeight * sy;
}
}
_content.SetScale(sx, sy);
float nx;
float ny;
if (_align == AlignType.Center)
nx = (this.width - contentWidth) / 2;
else if (_align == AlignType.Right)
nx = this.width - contentWidth;
else
nx = 0;
if (_verticalAlign == VertAlignType.Middle)
ny = (this.height - contentHeight) / 2;
else if (_verticalAlign == VertAlignType.Bottom)
ny = this.height - contentHeight;
else
ny = 0;
_content.SetXY(nx, ny);
InvalidateBatchingState();
}
protected void ClearContent()
{
if (_content.wrapTarget != null)
{
if (_contentItem != null)
{
if (_contentItem.type == PackageItemType.Spine)
{
#if FAIRYGUI_SPINE
FreeSpine();
#endif
}
else if (_contentItem.type == PackageItemType.DragoneBones)
{
#if FAIRYGUI_DRAGONBONES
FreeDragonBones();
#endif
}
}
else
FreeExternal();
}
_content.wrapTarget = null;
_contentItem = null;
}
protected void OnUpdateContent(UpdateContext context)
{
if (_contentItem == null)
return;
if (_contentItem.type == PackageItemType.Spine)
{
#if FAIRYGUI_SPINE
OnUpdateSpine(context);
#endif
}
else if (_contentItem.type == PackageItemType.DragoneBones)
{
#if FAIRYGUI_DRAGONBONES
OnUpdateDragonBones(context);
#endif
}
}
override protected void HandleSizeChanged()
{
base.HandleSizeChanged();
if (!_updatingLayout)
UpdateLayout();
}
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_BeforeAdd(buffer, beginPos);
buffer.Seek(beginPos, 5);
_url = buffer.ReadS();
_align = (AlignType)buffer.ReadByte();
_verticalAlign = (VertAlignType)buffer.ReadByte();
_fill = (FillType)buffer.ReadByte();
_shrinkOnly = buffer.ReadBool();
_autoSize = buffer.ReadBool();
_animationName = buffer.ReadS();
_skinName = buffer.ReadS();
_playing = buffer.ReadBool();
_frame = buffer.ReadInt();
_loop = buffer.ReadBool();
if (buffer.ReadBool())
this.color = buffer.ReadColor(); //color
if (!string.IsNullOrEmpty(_url))
LoadContent();
}
}
}

View File

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

View File

@@ -0,0 +1,190 @@
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GMovieClip class.
/// </summary>
public class GMovieClip : GObject, IAnimationGear, IColorGear
{
MovieClip _content;
EventListener _onPlayEnd;
public GMovieClip()
{
}
override protected void CreateDisplayObject()
{
_content = new MovieClip();
_content.gOwner = this;
_content.ignoreEngineTimeScale = true;
displayObject = _content;
}
/// <summary>
///
/// </summary>
public EventListener onPlayEnd
{
get { return _onPlayEnd ?? (_onPlayEnd = new EventListener(this, "onPlayEnd")); }
}
/// <summary>
///
/// </summary>
public bool playing
{
get { return _content.playing; }
set
{
_content.playing = value;
UpdateGear(5);
}
}
/// <summary>
///
/// </summary>
public int frame
{
get { return _content.frame; }
set
{
_content.frame = value;
UpdateGear(5);
}
}
/// <summary>
///
/// </summary>
public Color color
{
get { return _content.color; }
set
{
_content.color = value;
UpdateGear(4);
}
}
/// <summary>
///
/// </summary>
public FlipType flip
{
get { return _content.graphics.flip; }
set { _content.graphics.flip = value; }
}
/// <summary>
///
/// </summary>
public Material material
{
get { return _content.material; }
set { _content.material = value; }
}
/// <summary>
///
/// </summary>
public string shader
{
get { return _content.shader; }
set { _content.shader = value; }
}
/// <summary>
///
/// </summary>
public float timeScale
{
get { return _content.timeScale; }
set { _content.timeScale = value; }
}
/// <summary>
///
/// </summary>
public bool ignoreEngineTimeScale
{
get { return _content.ignoreEngineTimeScale; }
set { _content.ignoreEngineTimeScale = value; }
}
/// <summary>
///
/// </summary>
public void Rewind()
{
_content.Rewind();
}
/// <summary>
///
/// </summary>
/// <param name="anotherMc"></param>
public void SyncStatus(GMovieClip anotherMc)
{
_content.SyncStatus(anotherMc._content);
}
/// <summary>
///
/// </summary>
/// <param name="time"></param>
public void Advance(float time)
{
_content.Advance(time);
}
/// <summary>
/// Play from the start to end, repeat times, set to endAt on complete.
/// 从start帧开始播放到end帧-1表示结尾重复times次0表示无限循环循环结束后停止在endAt帧-1表示参数end
/// </summary>
/// <param name="start">Start frame</param>
/// <param name="end">End frame. -1 indicates the last frame.</param>
/// <param name="times">Repeat times. 0 indicates infinite loop.</param>
/// <param name="endAt">Stop frame. -1 indicates to equal to the end parameter.</param>
public void SetPlaySettings(int start, int end, int times, int endAt)
{
((MovieClip)displayObject).SetPlaySettings(start, end, times, endAt);
}
override public void ConstructFromResource()
{
this.gameObjectName = packageItem.name;
PackageItem contentItem = packageItem.getBranch();
sourceWidth = contentItem.width;
sourceHeight = contentItem.height;
initWidth = sourceWidth;
initHeight = sourceHeight;
contentItem = contentItem.getHighResolution();
contentItem.Load();
_content.interval = contentItem.interval;
_content.swing = contentItem.swing;
_content.repeatDelay = contentItem.repeatDelay;
_content.frames = contentItem.frames;
SetSize(sourceWidth, sourceHeight);
}
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_BeforeAdd(buffer, beginPos);
buffer.Seek(beginPos, 5);
if (buffer.ReadBool())
_content.color = buffer.ReadColor();
_content.graphics.flip = (FlipType)buffer.ReadByte();
_content.frame = buffer.ReadInt();
_content.playing = buffer.ReadBool();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 158e4b32fb035414091844233b2b9269
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
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,13 @@
fileFormatVersion: 2
guid: d3ab09a55620b5f40a544e775edc4b22
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,106 @@
using UnityEngine;
using System.Collections.Generic;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GObjectPool is use for GObject pooling.
/// </summary>
public class GObjectPool
{
/// <summary>
/// Callback function when a new object is creating.
/// </summary>
/// <param name="obj"></param>
public delegate void InitCallbackDelegate(GObject obj);
/// <summary>
/// Callback function when a new object is creating.
/// </summary>
public InitCallbackDelegate initCallback;
Dictionary<string, Queue<GObject>> _pool;
Transform _manager;
/// <summary>
/// 需要设置一个manager加入池里的对象都成为这个manager的孩子
/// </summary>
/// <param name="manager"></param>
public GObjectPool(Transform manager)
{
_manager = manager;
_pool = new Dictionary<string, Queue<GObject>>();
}
/// <summary>
/// Dispose all objects in the pool.
/// </summary>
public void Clear()
{
foreach (KeyValuePair<string, Queue<GObject>> kv in _pool)
{
Queue<GObject> list = kv.Value;
foreach (GObject obj in list)
obj.Dispose();
}
_pool.Clear();
}
/// <summary>
///
/// </summary>
public int count
{
get { return _pool.Count; }
}
/// <summary>
///
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public GObject GetObject(string url)
{
url = UIPackage.NormalizeURL(url);
if (url == null)
return null;
Queue<GObject> arr;
if (_pool.TryGetValue(url, out arr)
&& arr.Count > 0)
return arr.Dequeue();
GObject obj = UIPackage.CreateObjectFromURL(url);
if (obj != null)
{
if (initCallback != null)
initCallback(obj);
}
return obj;
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
public void ReturnObject(GObject obj)
{
if (obj.displayObject.isDisposed)
return;
string url = obj.resourceURL;
Queue<GObject> arr;
if (!_pool.TryGetValue(url, out arr))
{
arr = new Queue<GObject>();
_pool.Add(url, arr);
}
if (_manager != null)
obj.displayObject.cachedTransform.SetParent(_manager, false);
arr.Enqueue(obj);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: bb355b8d4ba140f469be6be6b062dfda
timeCreated: 1460480288
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,311 @@
using System;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GProgressBar class.
/// </summary>
public class GProgressBar : GComponent
{
double _min;
double _max;
double _value;
ProgressTitleType _titleType;
bool _reverse;
GObject _titleObject;
GMovieClip _aniObject;
GObject _barObjectH;
GObject _barObjectV;
float _barMaxWidth;
float _barMaxHeight;
float _barMaxWidthDelta;
float _barMaxHeightDelta;
float _barStartX;
float _barStartY;
public GProgressBar()
{
_value = 50;
_max = 100;
}
/// <summary>
///
/// </summary>
public ProgressTitleType titleType
{
get
{
return _titleType;
}
set
{
if (_titleType != value)
{
_titleType = value;
Update(_value);
}
}
}
/// <summary>
///
/// </summary>
public double min
{
get
{
return _min;
}
set
{
if (_min != value)
{
_min = value;
Update(_value);
}
}
}
/// <summary>
///
/// </summary>
public double max
{
get
{
return _max;
}
set
{
if (_max != value)
{
_max = value;
Update(_value);
}
}
}
/// <summary>
///
/// </summary>
public double value
{
get
{
return _value;
}
set
{
if (_value != value)
{
GTween.Kill(this, TweenPropType.Progress, false);
_value = value;
Update(_value);
}
}
}
public bool reverse
{
get { return _reverse; }
set { _reverse = value; }
}
/// <summary>
/// 动态改变进度值。
/// </summary>
/// <param name="value"></param>
/// <param name="duration"></param>
public GTweener TweenValue(double value, float duration)
{
double oldValule;
GTweener twener = GTween.GetTween(this, TweenPropType.Progress);
if (twener != null)
{
oldValule = twener.value.d;
twener.Kill(false);
}
else
oldValule = _value;
_value = value;
return GTween.ToDouble(oldValule, _value, duration)
.SetEase(EaseType.Linear)
.SetTarget(this, TweenPropType.Progress);
}
/// <summary>
///
/// </summary>
/// <param name="newValue"></param>
public void Update(double newValue)
{
float percent = Mathf.Clamp01((float)((newValue - _min) / (_max - _min)));
if (_titleObject != null)
{
switch (_titleType)
{
case ProgressTitleType.Percent:
if (RTLSupport.BaseDirection == RTLSupport.DirectionType.RTL)
_titleObject.text = "%" + Mathf.FloorToInt(percent * 100);
else
_titleObject.text = Mathf.FloorToInt(percent * 100) + "%";
break;
case ProgressTitleType.ValueAndMax:
if (RTLSupport.BaseDirection == RTLSupport.DirectionType.RTL)
_titleObject.text = Math.Round(max) + "/" + Math.Round(newValue);
else
_titleObject.text = Math.Round(newValue) + "/" + Math.Round(max);
break;
case ProgressTitleType.Value:
_titleObject.text = "" + Math.Round(newValue);
break;
case ProgressTitleType.Max:
_titleObject.text = "" + Math.Round(_max);
break;
}
}
float fullWidth = this.width - _barMaxWidthDelta;
float fullHeight = this.height - _barMaxHeightDelta;
if (!_reverse)
{
if (_barObjectH != null)
{
if (!SetFillAmount(_barObjectH, percent))
_barObjectH.width = Mathf.RoundToInt(fullWidth * percent);
}
if (_barObjectV != null)
{
if (!SetFillAmount(_barObjectV, percent))
_barObjectV.height = Mathf.RoundToInt(fullHeight * percent);
}
}
else
{
if (_barObjectH != null)
{
if (!SetFillAmount(_barObjectH, 1 - percent))
{
_barObjectH.width = Mathf.RoundToInt(fullWidth * percent);
_barObjectH.x = _barStartX + (fullWidth - _barObjectH.width);
}
}
if (_barObjectV != null)
{
if (!SetFillAmount(_barObjectV, 1 - percent))
{
_barObjectV.height = Mathf.RoundToInt(fullHeight * percent);
_barObjectV.y = _barStartY + (fullHeight - _barObjectV.height);
}
}
}
if (_aniObject != null)
_aniObject.frame = Mathf.RoundToInt(percent * 100);
InvalidateBatchingState(true);
}
bool SetFillAmount(GObject bar, float amount)
{
if ((bar is GImage) && ((GImage)bar).fillMethod != FillMethod.None)
((GImage)bar).fillAmount = amount;
else if ((bar is GLoader) && ((GLoader)bar).fillMethod != FillMethod.None)
((GLoader)bar).fillAmount = amount;
else
return false;
return true;
}
override protected void ConstructExtension(ByteBuffer buffer)
{
buffer.Seek(0, 6);
_titleType = (ProgressTitleType)buffer.ReadByte();
_reverse = buffer.ReadBool();
_titleObject = GetChild("title");
_barObjectH = GetChild("bar");
_barObjectV = GetChild("bar_v");
_aniObject = GetChild("ani") as GMovieClip;
if (_barObjectH != null)
{
_barMaxWidth = _barObjectH.width;
_barMaxWidthDelta = this.width - _barMaxWidth;
_barStartX = _barObjectH.x;
}
if (_barObjectV != null)
{
_barMaxHeight = _barObjectV.height;
_barMaxHeightDelta = this.height - _barMaxHeight;
_barStartY = _barObjectV.y;
}
}
override public void Setup_AfterAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_AfterAdd(buffer, beginPos);
if (!buffer.Seek(beginPos, 6))
{
Update(_value);
return;
}
if ((ObjectType)buffer.ReadByte() != packageItem.objectType)
{
Update(_value);
return;
}
_value = buffer.ReadInt();
_max = buffer.ReadInt();
if (buffer.version >= 2)
_min = buffer.ReadInt();
if (buffer.version >= 5)
{
string sound = buffer.ReadS();
if (!string.IsNullOrEmpty(sound))
{
float volumeScale = buffer.ReadFloat();
displayObject.onClick.Add(() =>
{
NAudioClip audioClip = UIPackage.GetItemAssetByURL(sound) as NAudioClip;
if (audioClip != null && audioClip.nativeClip != null)
Stage.inst.PlayOneShotSound(audioClip.nativeClip, volumeScale);
});
}
else
buffer.Skip(4);
}
Update(_value);
}
override protected void HandleSizeChanged()
{
base.HandleSizeChanged();
if (_barObjectH != null)
_barMaxWidth = this.width - _barMaxWidthDelta;
if (_barObjectV != null)
_barMaxHeight = this.height - _barMaxHeightDelta;
if (!this.underConstruct)
Update(_value);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 4f13bf1fdc7711c4aa9c5e1631138025
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,53 @@
using System.Collections.Generic;
using FairyGUI.Utils;
using UnityEngine;
namespace FairyGUI
{
/// <summary>
/// GRichTextField class.
/// </summary>
public class GRichTextField : GTextField
{
/// <summary>
///
/// </summary>
public RichTextField richTextField { get; private set; }
public GRichTextField()
: base()
{
}
override protected void CreateDisplayObject()
{
richTextField = new RichTextField();
richTextField.gOwner = this;
displayObject = richTextField;
_textField = richTextField.textField;
}
override protected void SetTextFieldText()
{
string str = _text;
if (_templateVars != null)
str = ParseTemplate(str);
_textField.maxWidth = maxWidth;
if (_ubbEnabled)
richTextField.htmlText = UBBParser.inst.Parse(str);
else
richTextField.htmlText = str;
}
/// <summary>
///
/// </summary>
public Dictionary<uint, Emoji> emojies
{
get { return richTextField.emojies; }
set { richTextField.emojies = value; }
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: c329d14f7b7d35348be7ec3e2a4b0591
timeCreated: 1460480288
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,847 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace FairyGUI
{
/// <summary>
/// GRoot is a topmost component of UI display list.You dont need to create GRoot. It is created automatically.
/// </summary>
public class GRoot : GComponent
{
/// <summary>
///
/// </summary>
public static float contentScaleFactor
{
get { return UIContentScaler.scaleFactor; }
}
/// <summary>
///
/// </summary>
public static int contentScaleLevel
{
get { return UIContentScaler.scaleLevel; }
}
GGraph _modalLayer;
GObject _modalWaitPane;
List<GObject> _popupStack;
List<GObject> _justClosedPopups;
HashSet<GObject> _specialPopups;
GObject _tooltipWin;
GObject _defaultTooltipWin;
internal static GRoot _inst;
public static GRoot inst
{
get
{
if (_inst == null)
Stage.Instantiate();
return _inst;
}
}
public GRoot()
{
this.name = this.rootContainer.name = this.rootContainer.gameObject.name = "GRoot";
this.opaque = false;
_popupStack = new List<GObject>();
_justClosedPopups = new List<GObject>();
_specialPopups = new HashSet<GObject>();
Stage.inst.onTouchBegin.AddCapture(__stageTouchBegin);
Stage.inst.onTouchEnd.AddCapture(__stageTouchEnd);
}
override public void Dispose()
{
base.Dispose();
Stage.inst.onTouchBegin.RemoveCapture(__stageTouchBegin);
Stage.inst.onTouchEnd.RemoveCapture(__stageTouchEnd);
}
/// <summary>
/// Set content scale factor.
/// </summary>
/// <param name="designResolutionX">Design resolution of x axis.</param>
/// <param name="designResolutionY">Design resolution of y axis.</param>
public void SetContentScaleFactor(int designResolutionX, int designResolutionY)
{
SetContentScaleFactor(designResolutionX, designResolutionY, UIContentScaler.ScreenMatchMode.MatchWidthOrHeight);
}
/// <summary>
/// Set content scale factor.
/// </summary>
/// <param name="designResolutionX">Design resolution of x axis.</param>
/// <param name="designResolutionY">Design resolution of y axis.</param>
/// <param name="screenMatchMode">Match mode.</param>
public void SetContentScaleFactor(int designResolutionX, int designResolutionY, UIContentScaler.ScreenMatchMode screenMatchMode)
{
UIContentScaler scaler = Stage.inst.gameObject.GetComponent<UIContentScaler>();
scaler.designResolutionX = designResolutionX;
scaler.designResolutionY = designResolutionY;
scaler.scaleMode = UIContentScaler.ScaleMode.ScaleWithScreenSize;
scaler.screenMatchMode = screenMatchMode;
scaler.ApplyChange();
ApplyContentScaleFactor();
}
/// <summary>
///
/// </summary>
/// <param name="constantScaleFactor"></param>
public void SetContentScaleFactor(float constantScaleFactor)
{
UIContentScaler scaler = Stage.inst.gameObject.GetComponent<UIContentScaler>();
scaler.scaleMode = UIContentScaler.ScaleMode.ConstantPixelSize;
scaler.constantScaleFactor = constantScaleFactor;
scaler.ApplyChange();
ApplyContentScaleFactor();
}
/// <summary>
/// This is called after screen size changed.
/// </summary>
public void ApplyContentScaleFactor()
{
this.SetSize(Mathf.CeilToInt(Stage.inst.width / UIContentScaler.scaleFactor), Mathf.CeilToInt(Stage.inst.height / UIContentScaler.scaleFactor));
this.SetScale(UIContentScaler.scaleFactor, UIContentScaler.scaleFactor);
}
/// <summary>
/// Display a window.
/// </summary>
/// <param name="win"></param>
public void ShowWindow(Window win)
{
AddChild(win);
AdjustModalLayer();
}
/// <summary>
/// Call window.Hide
/// 关闭一个窗口。将调用Window.Hide方法。
/// </summary>
/// <param name="win"></param>
public void HideWindow(Window win)
{
win.Hide();
}
/// <summary>
/// Remove a window from stage immediatelly. window.Hide/window.OnHide will never be called.
///立刻关闭一个窗口。不会调用Window.Hide方法Window.OnHide也不会被调用。
/// </summary>
/// <param name="win"></param>
public void HideWindowImmediately(Window win)
{
HideWindowImmediately(win, false);
}
/// <summary>
/// Remove a window from stage immediatelly. window.Hide/window.OnHide will never be called.
/// 立刻关闭一个窗口。不会调用Window.Hide方法Window.OnHide也不会被调用。
/// </summary>
/// <param name="win"></param>
/// <param name="dispose">True to dispose the window.</param>
public void HideWindowImmediately(Window win, bool dispose)
{
if (win.parent == this)
RemoveChild(win, dispose);
else if (dispose)
win.Dispose();
AdjustModalLayer();
}
/// <summary>
/// 将一个窗口提到所有窗口的最前面
/// </summary>
/// <param name="win"></param>
public void BringToFront(Window win)
{
int cnt = this.numChildren;
int i;
if (_modalLayer != null && _modalLayer.parent != null && !win.modal)
i = GetChildIndex(_modalLayer) - 1;
else
i = cnt - 1;
for (; i >= 0; i--)
{
GObject g = GetChildAt(i);
if (g == win)
return;
if (g is Window)
break;
}
if (i >= 0)
SetChildIndex(win, i);
}
/// <summary>
/// Display a modal layer and a waiting sign in the front.
/// 显示一个半透明层和一个等待标志在最前面。半透明层的颜色可以通过UIConfig.modalLayerColor设定。
/// 等待标志的资源可以通过UIConfig.globalModalWaiting。等待标志组件会设置为屏幕大小请内部做好关联。
/// </summary>
public void ShowModalWait()
{
if (UIConfig.globalModalWaiting != null)
{
if (_modalWaitPane == null || _modalWaitPane.isDisposed)
{
_modalWaitPane = UIPackage.CreateObjectFromURL(UIConfig.globalModalWaiting);
_modalWaitPane.SetHome(this);
}
_modalWaitPane.SetSize(this.width, this.height);
_modalWaitPane.AddRelation(this, RelationType.Size);
AddChild(_modalWaitPane);
}
}
/// <summary>
/// Hide modal layer and waiting sign.
/// </summary>
public void CloseModalWait()
{
if (_modalWaitPane != null && _modalWaitPane.parent != null)
RemoveChild(_modalWaitPane);
}
/// <summary>
/// Close all windows except modal windows.
/// </summary>
public void CloseAllExceptModals()
{
GObject[] arr = _children.ToArray();
foreach (GObject g in arr)
{
if ((g is Window) && !(g as Window).modal)
HideWindowImmediately(g as Window);
}
}
/// <summary>
/// Close all windows.
/// </summary>
public void CloseAllWindows()
{
GObject[] arr = _children.ToArray();
foreach (GObject g in arr)
{
if (g is Window)
HideWindowImmediately(g as Window);
}
}
/// <summary>
/// Get window on top.
/// </summary>
/// <returns></returns>
public Window GetTopWindow()
{
int cnt = this.numChildren;
for (int i = cnt - 1; i >= 0; i--)
{
GObject g = this.GetChildAt(i);
if (g is Window)
{
return (Window)(g);
}
}
return null;
}
/// <summary>
///
/// </summary>
public GGraph modalLayer
{
get
{
if (_modalLayer == null || _modalLayer.isDisposed)
CreateModalLayer();
return _modalLayer;
}
}
void CreateModalLayer()
{
_modalLayer = new GGraph();
_modalLayer.DrawRect(this.width, this.height, 0, Color.white, UIConfig.modalLayerColor);
_modalLayer.AddRelation(this, RelationType.Size);
_modalLayer.name = _modalLayer.gameObjectName = "ModalLayer";
_modalLayer.SetHome(this);
}
/// <summary>
/// Return true if a modal window is on stage.
/// </summary>
public bool hasModalWindow
{
get { return _modalLayer != null && _modalLayer.parent != null; }
}
/// <summary>
/// Return true if modal waiting layer is on stage.
/// </summary>
public bool modalWaiting
{
get
{
return (_modalWaitPane != null) && _modalWaitPane.onStage;
}
}
/// <summary>
/// Get current touch target. (including hover)
/// </summary>
public GObject touchTarget
{
get
{
return DisplayObjectToGObject(Stage.inst.touchTarget);
}
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public GObject DisplayObjectToGObject(DisplayObject obj)
{
while (obj != null)
{
if (obj.gOwner != null)
return obj.gOwner;
obj = obj.parent;
}
return null;
}
private void AdjustModalLayer()
{
if (_modalLayer == null || _modalLayer.isDisposed)
CreateModalLayer();
int cnt = this.numChildren;
if (_modalWaitPane != null && _modalWaitPane.parent != null)
SetChildIndex(_modalWaitPane, cnt - 1);
for (int i = cnt - 1; i >= 0; i--)
{
GObject g = this.GetChildAt(i);
if ((g is Window) && (g as Window).modal)
{
if (_modalLayer.parent == null)
AddChildAt(_modalLayer, i);
else
SetChildIndexBefore(_modalLayer, i);
return;
}
}
if (_modalLayer.parent != null)
RemoveChild(_modalLayer);
}
/// <summary>
/// Show a popup object.
/// 显示一个popup。
/// popup的特点是点击popup对象外的区域popup对象将自动消失。
/// </summary>
/// <param name="popup"></param>
public void ShowPopup(GObject popup)
{
ShowPopup(popup, null, PopupDirection.Auto, false);
}
/// <summary>
/// Show a popup object along with the specific target object.
/// 显示一个popup。将popup显示在指定对象的上边或者下边。
/// popup的特点是点击popup对象外的区域popup对象将自动消失。
/// </summary>
/// <param name="popup"></param>
/// <param name="target"></param>
public void ShowPopup(GObject popup, GObject target)
{
ShowPopup(popup, target, PopupDirection.Auto, false);
}
[Obsolete]
public void ShowPopup(GObject popup, GObject target, object downward)
{
ShowPopup(popup, target,
downward == null ? PopupDirection.Auto : ((bool)downward == true ? PopupDirection.Down : PopupDirection.Up),
false);
}
/// <summary>
/// Show a popup object along with the specific target object.
/// 显示一个popup。将popup显示在指定对象的上方或者下方。
/// popup的特点是点击popup对象外的区域popup对象将自动消失。
/// </summary>
/// <param name="popup"></param>
/// <param name="target"></param>
/// <param name="dir"></param>
public void ShowPopup(GObject popup, GObject target, PopupDirection dir)
{
ShowPopup(popup, target, dir, false);
}
/// <summary>
/// Show a popup object along with the specific target object.
/// 显示一个popup。将popup显示在指定对象的上方或者下方。
/// popup的特点是点击popup对象外的区域popup对象将自动消失。
/// 默认情况下popup在touchEnd事件中关闭特别设置closeUntilUpEvent=true则可使该popup在touchEnd中才关闭。
/// </summary>
/// <param name="popup"></param>
/// <param name="target"></param>
/// <param name="dir"></param>
/// <param name="closeUntilUpEvent"></param>
public void ShowPopup(GObject popup, GObject target, PopupDirection dir, bool closeUntilUpEvent)
{
if (_popupStack.Count > 0)
{
int k = _popupStack.IndexOf(popup);
if (k != -1)
{
for (int i = _popupStack.Count - 1; i >= k; i--)
{
int last = _popupStack.Count - 1;
GObject obj = _popupStack[last];
ClosePopup(obj);
_popupStack.RemoveAt(last);
_specialPopups.Remove(obj);
}
}
}
_popupStack.Add(popup);
if (closeUntilUpEvent)
_specialPopups.Add(popup);
if (target != null)
{
GObject p = target;
while (p != null)
{
if (p.parent == this)
{
if (popup.sortingOrder < p.sortingOrder)
{
popup.sortingOrder = p.sortingOrder;
}
break;
}
p = p.parent;
}
}
AddChild(popup);
AdjustModalLayer();
if ((popup is Window) && target == null && dir == PopupDirection.Auto)
return;
Vector2 pos = GetPoupPosition(popup, target, dir);
popup.xy = pos;
}
[Obsolete]
public Vector2 GetPoupPosition(GObject popup, GObject target, object downward)
{
return GetPoupPosition(popup, target,
downward == null ? PopupDirection.Auto : ((bool)downward == true ? PopupDirection.Down : PopupDirection.Up));
}
/// <summary>
///
/// </summary>
/// <param name="popup"></param>
/// <param name="target"></param>
/// <param name="dir"></param>
/// <returns></returns>
public Vector2 GetPoupPosition(GObject popup, GObject target, PopupDirection dir)
{
Vector2 pos;
Vector2 size = Vector2.zero;
if (target != null)
{
pos = target.LocalToRoot(Vector2.zero, this);
size = target.LocalToRoot(target.size, this) - pos;
}
else
{
pos = this.GlobalToLocal(Stage.inst.touchPosition);
}
float xx, yy;
xx = pos.x;
if (xx + popup.width > this.width)
xx = xx + size.x - popup.width;
yy = pos.y + size.y;
if ((dir == PopupDirection.Auto && yy + popup.height > this.height)
|| dir == PopupDirection.Up)
{
yy = pos.y - popup.height - 1;
if (yy < 0)
{
yy = 0;
xx += size.x / 2;
}
}
return new Vector2(Mathf.RoundToInt(xx), Mathf.RoundToInt(yy));
}
/// <summary>
/// If a popup is showing, then close it; otherwise, open it.
/// </summary>
/// <param name="popup"></param>
public void TogglePopup(GObject popup)
{
TogglePopup(popup, null, PopupDirection.Auto, false);
}
/// <summary>
///
/// </summary>
/// <param name="popup"></param>
/// <param name="target"></param>
public void TogglePopup(GObject popup, GObject target)
{
TogglePopup(popup, target, PopupDirection.Auto, false);
}
[Obsolete]
public void TogglePopup(GObject popup, GObject target, object downward)
{
TogglePopup(popup, target,
downward == null ? PopupDirection.Auto : ((bool)downward == true ? PopupDirection.Down : PopupDirection.Up),
false);
}
/// <summary>
///
/// </summary>
/// <param name="popup"></param>
/// <param name="target"></param>
/// <param name="dir"></param>
public void TogglePopup(GObject popup, GObject target, PopupDirection dir)
{
TogglePopup(popup, target, dir, false);
}
/// <summary>
///
/// </summary>
/// <param name="popup"></param>
/// <param name="target"></param>
/// <param name="dir"></param>
/// <param name="closeUntilUpEvent"></param>
public void TogglePopup(GObject popup, GObject target, PopupDirection dir, bool closeUntilUpEvent)
{
if (_justClosedPopups.IndexOf(popup) != -1)
return;
ShowPopup(popup, target, dir, closeUntilUpEvent);
}
/// <summary>
/// Close all popups.
/// </summary>
public void HidePopup()
{
HidePopup(null);
}
/// <summary>
/// Close a popup.
/// </summary>
/// <param name="popup"></param>
public void HidePopup(GObject popup)
{
if (popup != null)
{
int k = _popupStack.IndexOf(popup);
if (k != -1)
{
for (int i = _popupStack.Count - 1; i >= k; i--)
{
int last = _popupStack.Count - 1;
GObject obj = _popupStack[last];
ClosePopup(obj);
_popupStack.RemoveAt(last);
_specialPopups.Remove(obj);
}
}
}
else
{
foreach (GObject obj in _popupStack)
ClosePopup(obj);
_popupStack.Clear();
_specialPopups.Clear();
}
}
/// <summary>
///
/// </summary>
public bool hasAnyPopup
{
get { return _popupStack.Count > 0; }
}
void ClosePopup(GObject target)
{
if (target.parent != null)
{
if (target is Window)
((Window)target).Hide();
else
RemoveChild(target);
}
}
/// <summary>
///
/// </summary>
/// <param name="msg"></param>
public void ShowTooltips(string msg)
{
ShowTooltips(msg, 0.1f);
}
/// <summary>
///
/// </summary>
/// <param name="msg"></param>
/// <param name="delay"></param>
public void ShowTooltips(string msg, float delay)
{
if (_defaultTooltipWin == null || _defaultTooltipWin.isDisposed)
{
string resourceURL = UIConfig.tooltipsWin;
if (string.IsNullOrEmpty(resourceURL))
{
Debug.LogWarning("FairyGUI: UIConfig.tooltipsWin not defined");
return;
}
_defaultTooltipWin = UIPackage.CreateObjectFromURL(resourceURL);
_defaultTooltipWin.SetHome(this);
_defaultTooltipWin.touchable = false;
}
_defaultTooltipWin.text = msg;
ShowTooltipsWin(_defaultTooltipWin, delay);
}
/// <summary>
///
/// </summary>
/// <param name="tooltipWin"></param>
public void ShowTooltipsWin(GObject tooltipWin)
{
ShowTooltipsWin(tooltipWin, 0.1f);
}
/// <summary>
///
/// </summary>
/// <param name="tooltipWin"></param>
/// <param name="delay"></param>
public void ShowTooltipsWin(GObject tooltipWin, float delay)
{
HideTooltips();
_tooltipWin = tooltipWin;
Timers.inst.Add(delay, 1, __showTooltipsWin);
}
void __showTooltipsWin(object param)
{
if (_tooltipWin == null)
return;
float xx = Stage.inst.touchPosition.x + 10;
float yy = Stage.inst.touchPosition.y + 20;
Vector2 pt = this.GlobalToLocal(new Vector2(xx, yy));
xx = pt.x;
yy = pt.y;
if (xx + _tooltipWin.width > this.width)
xx = xx - _tooltipWin.width;
if (yy + _tooltipWin.height > this.height)
{
yy = yy - _tooltipWin.height - 1;
if (yy < 0)
yy = 0;
}
_tooltipWin.x = Mathf.RoundToInt(xx);
_tooltipWin.y = Mathf.RoundToInt(yy);
AddChild(_tooltipWin);
}
/// <summary>
///
/// </summary>
public void HideTooltips()
{
if (_tooltipWin != null)
{
if (_tooltipWin.parent != null)
RemoveChild(_tooltipWin);
_tooltipWin = null;
}
}
/// <summary>
///
/// </summary>
public GObject focus
{
get
{
GObject obj = DisplayObjectToGObject(Stage.inst.focus);
if (obj != null && !IsAncestorOf(obj))
return null;
else
return obj;
}
set
{
if (value == null)
Stage.inst.focus = null;
else
Stage.inst.focus = value.displayObject;
}
}
void __stageTouchBegin(EventContext context)
{
if (_tooltipWin != null)
HideTooltips();
CheckPopups(true);
}
void __stageTouchEnd(EventContext context)
{
CheckPopups(false);
}
void CheckPopups(bool touchBegin)
{
if (touchBegin)
_justClosedPopups.Clear();
if (_popupStack.Count > 0)
{
DisplayObject mc = Stage.inst.touchTarget as DisplayObject;
bool handled = false;
while (mc != Stage.inst && mc != null)
{
if (mc.gOwner != null)
{
int k = _popupStack.IndexOf(mc.gOwner);
if (k != -1)
{
for (int i = _popupStack.Count - 1; i > k; i--)
{
int last = _popupStack.Count - 1;
GObject popup = _popupStack[last];
if (touchBegin == _specialPopups.Contains(popup))
continue;
ClosePopup(popup);
_justClosedPopups.Add(popup);
_popupStack.RemoveAt(last);
_specialPopups.Remove(popup);
}
handled = true;
break;
}
}
mc = mc.parent;
}
if (!handled)
{
for (int i = _popupStack.Count - 1; i >= 0; i--)
{
GObject popup = _popupStack[i];
if (touchBegin == _specialPopups.Contains(popup))
continue;
ClosePopup(popup);
_justClosedPopups.Add(popup);
_popupStack.RemoveAt(i);
_specialPopups.Remove(popup);
}
}
}
}
/// <summary>
///
/// </summary>
public void EnableSound()
{
Stage.inst.EnableSound();
}
/// <summary>
///
/// </summary>
public void DisableSound()
{
Stage.inst.DisableSound();
}
/// <summary>
///
/// </summary>
/// <param name="clip"></param>
/// <param name="volumeScale"></param>
public void PlayOneShotSound(AudioClip clip, float volumeScale)
{
Stage.inst.PlayOneShotSound(clip, volumeScale);
}
/// <summary>
///
/// </summary>
/// <param name="clip"></param>
public void PlayOneShotSound(AudioClip clip)
{
Stage.inst.PlayOneShotSound(clip);
}
/// <summary>
///
/// </summary>
public float soundVolume
{
get { return Stage.inst.soundVolume; }
set { Stage.inst.soundVolume = value; }
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: c82e50658ca58b2459448b9c86cb4777
timeCreated: 1460480288
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,226 @@
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// GScrollBar class.
/// </summary>
public class GScrollBar : GComponent
{
GObject _grip;
GObject _arrowButton1;
GObject _arrowButton2;
GObject _bar;
ScrollPane _target;
bool _vertical;
float _scrollPerc;
bool _fixedGripSize;
bool _gripDragging;
Vector2 _dragOffset;
public GScrollBar()
{
_scrollPerc = 0;
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <param name="vertical"></param>
public void SetScrollPane(ScrollPane target, bool vertical)
{
_target = target;
_vertical = vertical;
}
/// <summary>
///
/// </summary>
public void SetDisplayPerc(float value)
{
if (_vertical)
{
if (!_fixedGripSize)
_grip.height = Mathf.FloorToInt(value * _bar.height);
_grip.y = Mathf.RoundToInt(_bar.y + (_bar.height - _grip.height) * _scrollPerc);
}
else
{
if (!_fixedGripSize)
_grip.width = Mathf.FloorToInt(value * _bar.width);
_grip.x = Mathf.RoundToInt(_bar.x + (_bar.width - _grip.width) * _scrollPerc);
}
_grip.visible = value != 0 && value != 1;
}
/// <summary>
///
/// </summary>
public void setScrollPerc(float value)
{
_scrollPerc = value;
if (_vertical)
_grip.y = Mathf.RoundToInt(_bar.y + (_bar.height - _grip.height) * _scrollPerc);
else
_grip.x = Mathf.RoundToInt(_bar.x + (_bar.width - _grip.width) * _scrollPerc);
}
/// <summary>
///
/// </summary>
public float minSize
{
get
{
if (_vertical)
return (_arrowButton1 != null ? _arrowButton1.height : 0) + (_arrowButton2 != null ? _arrowButton2.height : 0);
else
return (_arrowButton1 != null ? _arrowButton1.width : 0) + (_arrowButton2 != null ? _arrowButton2.width : 0);
}
}
/// <summary>
///
/// </summary>
public bool gripDragging
{
get
{
return _gripDragging;
}
}
override protected void ConstructExtension(ByteBuffer buffer)
{
buffer.Seek(0, 6);
_fixedGripSize = buffer.ReadBool();
_grip = GetChild("grip");
if (_grip == null)
{
Debug.LogWarning("FairyGUI: " + this.resourceURL + " should define grip");
return;
}
_bar = GetChild("bar");
if (_bar == null)
{
Debug.LogWarning("FairyGUI: " + this.resourceURL + " should define bar");
return;
}
_arrowButton1 = GetChild("arrow1");
_arrowButton2 = GetChild("arrow2");
_grip.onTouchBegin.Add(__gripTouchBegin);
_grip.onTouchMove.Add(__gripTouchMove);
_grip.onTouchEnd.Add(__gripTouchEnd);
this.onTouchBegin.Add(__touchBegin);
if (_arrowButton1 != null)
_arrowButton1.onTouchBegin.Add(__arrowButton1Click);
if (_arrowButton2 != null)
_arrowButton2.onTouchBegin.Add(__arrowButton2Click);
}
void __gripTouchBegin(EventContext context)
{
if (_bar == null)
return;
context.StopPropagation();
InputEvent evt = context.inputEvent;
if (evt.button != 0)
return;
context.CaptureTouch();
_gripDragging = true;
_target.UpdateScrollBarVisible();
_dragOffset = this.GlobalToLocal(new Vector2(evt.x, evt.y)) - _grip.xy;
}
void __gripTouchMove(EventContext context)
{
InputEvent evt = context.inputEvent;
Vector2 pt = this.GlobalToLocal(new Vector2(evt.x, evt.y));
if (float.IsNaN(pt.x))
return;
if (_vertical)
{
float curY = pt.y - _dragOffset.y;
float diff = _bar.height - _grip.height;
if (diff == 0)
_target.percY = 0;
else
_target.percY = (curY - _bar.y) / diff;
}
else
{
float curX = pt.x - _dragOffset.x;
float diff = _bar.width - _grip.width;
if (diff == 0)
_target.percX = 0;
else
_target.percX = (curX - _bar.x) / diff;
}
}
void __gripTouchEnd(EventContext context)
{
_gripDragging = false;
_target.UpdateScrollBarVisible();
}
void __arrowButton1Click(EventContext context)
{
context.StopPropagation();
if (_vertical)
_target.ScrollUp();
else
_target.ScrollLeft();
}
void __arrowButton2Click(EventContext context)
{
context.StopPropagation();
if (_vertical)
_target.ScrollDown();
else
_target.ScrollRight();
}
void __touchBegin(EventContext context)
{
context.StopPropagation();
InputEvent evt = context.inputEvent;
Vector2 pt = _grip.GlobalToLocal(new Vector2(evt.x, evt.y));
if (_vertical)
{
if (pt.y < 0)
_target.ScrollUp(4, false);
else
_target.ScrollDown(4, false);
}
else
{
if (pt.x < 0)
_target.ScrollLeft(4, false);
else
_target.ScrollRight(4, false);
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: b6b0ce43cdb60cf4e8e1ddccdf2f5082
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,405 @@
using System;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public class GSlider : GComponent
{
double _min;
double _max;
double _value;
ProgressTitleType _titleType;
bool _reverse;
bool _wholeNumbers;
GObject _titleObject;
GObject _barObjectH;
GObject _barObjectV;
float _barMaxWidth;
float _barMaxHeight;
float _barMaxWidthDelta;
float _barMaxHeightDelta;
GObject _gripObject;
Vector2 _clickPos;
float _clickPercent;
float _barStartX;
float _barStartY;
EventListener _onChanged;
EventListener _onGripTouchEnd;
public bool changeOnClick;
public bool canDrag;
public GSlider()
{
_value = 50;
_max = 100;
changeOnClick = true;
canDrag = true;
}
/// <summary>
///
/// </summary>
public EventListener onChanged
{
get { return _onChanged ?? (_onChanged = new EventListener(this, "onChanged")); }
}
/// <summary>
///
/// </summary>
public EventListener onGripTouchEnd
{
get { return _onGripTouchEnd ?? (_onGripTouchEnd = new EventListener(this, "onGripTouchEnd")); }
}
/// <summary>
///
/// </summary>
public ProgressTitleType titleType
{
get
{
return _titleType;
}
set
{
if (_titleType != value)
{
_titleType = value;
Update();
}
}
}
/// <summary>
///
/// </summary>
public double min
{
get
{
return _min;
}
set
{
if (_min != value)
{
_min = value;
Update();
}
}
}
/// <summary>
///
/// </summary>
public double max
{
get
{
return _max;
}
set
{
if (_max != value)
{
_max = value;
Update();
}
}
}
/// <summary>
///
/// </summary>
public double value
{
get
{
return _value;
}
set
{
if (_value != value)
{
_value = value;
Update();
}
}
}
/// <summary>
///
/// </summary>
public bool wholeNumbers
{
get
{
return _wholeNumbers;
}
set
{
if (_wholeNumbers != value)
{
_wholeNumbers = value;
Update();
}
}
}
private void Update()
{
UpdateWithPercent((float)((_value - _min) / (_max - _min)), false);
}
private void UpdateWithPercent(float percent, bool manual)
{
percent = Mathf.Clamp01(percent);
if (manual)
{
double newValue = _min + (_max - _min) * percent;
if (newValue < _min)
newValue = _min;
if (newValue > _max)
newValue = _max;
if (_wholeNumbers)
{
newValue = Math.Round(newValue);
percent = Mathf.Clamp01((float)((newValue - _min) / (_max - _min)));
}
if (newValue != _value)
{
_value = newValue;
if (DispatchEvent("onChanged", null))
return;
}
}
if (_titleObject != null)
{
switch (_titleType)
{
case ProgressTitleType.Percent:
_titleObject.text = Mathf.FloorToInt(percent * 100) + "%";
break;
case ProgressTitleType.ValueAndMax:
_titleObject.text = Math.Round(_value) + "/" + Math.Round(max);
break;
case ProgressTitleType.Value:
_titleObject.text = "" + Math.Round(_value);
break;
case ProgressTitleType.Max:
_titleObject.text = "" + Math.Round(_max);
break;
}
}
float fullWidth = this.width - _barMaxWidthDelta;
float fullHeight = this.height - _barMaxHeightDelta;
if (!_reverse)
{
if (_barObjectH != null)
{
if (!SetFillAmount(_barObjectH, percent))
_barObjectH.width = Mathf.RoundToInt(fullWidth * percent);
}
if (_barObjectV != null)
{
if (!SetFillAmount(_barObjectV, percent))
_barObjectV.height = Mathf.RoundToInt(fullHeight * percent);
}
}
else
{
if (_barObjectH != null)
{
if (!SetFillAmount(_barObjectH, 1 - percent))
{
_barObjectH.width = Mathf.RoundToInt(fullWidth * percent);
_barObjectH.x = _barStartX + (fullWidth - _barObjectH.width);
}
}
if (_barObjectV != null)
{
if (!SetFillAmount(_barObjectV, 1 - percent))
{
_barObjectV.height = Mathf.RoundToInt(fullHeight * percent);
_barObjectV.y = _barStartY + (fullHeight - _barObjectV.height);
}
}
}
InvalidateBatchingState(true);
}
bool SetFillAmount(GObject bar, float amount)
{
if ((bar is GImage) && ((GImage)bar).fillMethod != FillMethod.None)
((GImage)bar).fillAmount = amount;
else if ((bar is GLoader) && ((GLoader)bar).fillMethod != FillMethod.None)
((GLoader)bar).fillAmount = amount;
else
return false;
return true;
}
override protected void ConstructExtension(ByteBuffer buffer)
{
buffer.Seek(0, 6);
_titleType = (ProgressTitleType)buffer.ReadByte();
_reverse = buffer.ReadBool();
if (buffer.version >= 2)
{
_wholeNumbers = buffer.ReadBool();
this.changeOnClick = buffer.ReadBool();
}
_titleObject = GetChild("title");
_barObjectH = GetChild("bar");
_barObjectV = GetChild("bar_v");
_gripObject = GetChild("grip");
if (_barObjectH != null)
{
_barMaxWidth = _barObjectH.width;
_barMaxWidthDelta = this.width - _barMaxWidth;
_barStartX = _barObjectH.x;
}
if (_barObjectV != null)
{
_barMaxHeight = _barObjectV.height;
_barMaxHeightDelta = this.height - _barMaxHeight;
_barStartY = _barObjectV.y;
}
if (_gripObject != null)
{
_gripObject.onTouchBegin.Add(__gripTouchBegin);
_gripObject.onTouchMove.Add(__gripTouchMove);
_gripObject.onTouchEnd.Add(__gripTouchEnd);
}
onTouchBegin.Add(__barTouchBegin);
}
override public void Setup_AfterAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_AfterAdd(buffer, beginPos);
if (!buffer.Seek(beginPos, 6))
{
Update();
return;
}
if ((ObjectType)buffer.ReadByte() != packageItem.objectType)
{
Update();
return;
}
_value = buffer.ReadInt();
_max = buffer.ReadInt();
if (buffer.version >= 2)
_min = buffer.ReadInt();
Update();
}
override protected void HandleSizeChanged()
{
base.HandleSizeChanged();
if (_barObjectH != null)
_barMaxWidth = this.width - _barMaxWidthDelta;
if (_barObjectV != null)
_barMaxHeight = this.height - _barMaxHeightDelta;
if (!this.underConstruct)
Update();
}
private void __gripTouchBegin(EventContext context)
{
this.canDrag = true;
context.StopPropagation();
InputEvent evt = context.inputEvent;
if (evt.button != 0)
return;
context.CaptureTouch();
_clickPos = this.GlobalToLocal(new Vector2(evt.x, evt.y));
_clickPercent = Mathf.Clamp01((float)((_value - _min) / (_max - _min)));
}
private void __gripTouchMove(EventContext context)
{
if (!this.canDrag)
return;
InputEvent evt = context.inputEvent;
Vector2 pt = this.GlobalToLocal(new Vector2(evt.x, evt.y));
if (float.IsNaN(pt.x))
return;
float deltaX = pt.x - _clickPos.x;
float deltaY = pt.y - _clickPos.y;
if (_reverse)
{
deltaX = -deltaX;
deltaY = -deltaY;
}
float percent;
if (_barObjectH != null)
percent = _clickPercent + deltaX / _barMaxWidth;
else
percent = _clickPercent + deltaY / _barMaxHeight;
UpdateWithPercent(percent, true);
}
private void __gripTouchEnd(EventContext context)
{
DispatchEvent("onGripTouchEnd", null);
}
private void __barTouchBegin(EventContext context)
{
if (!changeOnClick)
return;
InputEvent evt = context.inputEvent;
Vector2 pt = _gripObject.GlobalToLocal(new Vector2(evt.x, evt.y));
float percent = Mathf.Clamp01((float)((_value - _min) / (_max - _min)));
float delta = 0;
if (_barObjectH != null)
delta = (pt.x - _gripObject.width / 2) / _barMaxWidth;
if (_barObjectV != null)
delta = (pt.y - _gripObject.height / 2) / _barMaxHeight;
if (_reverse)
percent -= delta;
else
percent += delta;
UpdateWithPercent(percent, true);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a2a1a4a3ec0a296489e15eb1ae1214ee
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,438 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public class GTextField : GObject, ITextColorGear
{
protected TextField _textField;
protected string _text;
protected bool _ubbEnabled;
protected bool _updatingSize;
protected Dictionary<string, string> _templateVars;
public GTextField()
: base()
{
TextFormat tf = _textField.textFormat;
tf.font = UIConfig.defaultFont;
tf.size = 12;
tf.color = Color.black;
tf.lineSpacing = 3;
tf.letterSpacing = 0;
_textField.textFormat = tf;
_text = string.Empty;
_textField.autoSize = AutoSizeType.Both;
_textField.wordWrap = false;
}
override protected void CreateDisplayObject()
{
_textField = new TextField();
_textField.gOwner = this;
displayObject = _textField;
}
/// <summary>
///
/// </summary>
override public string text
{
get
{
if (this is GTextInput)
_text = ((GTextInput)this).inputTextField.text;
return _text;
}
set
{
if (value == null)
value = string.Empty;
_text = value;
SetTextFieldText();
UpdateSize();
UpdateGear(6);
}
}
virtual protected void SetTextFieldText()
{
string str = _text;
if (_templateVars != null)
str = ParseTemplate(str);
_textField.maxWidth = maxWidth;
if (_ubbEnabled)
_textField.htmlText = UBBParser.inst.Parse(XMLUtils.EncodeString(str));
else
_textField.text = str;
}
/// <summary>
///
/// </summary>
public Dictionary<string, string> templateVars
{
get { return _templateVars; }
set
{
if (_templateVars == null && value == null)
return;
_templateVars = value;
FlushVars();
}
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
/// <returns></returns>
public GTextField SetVar(string name, string value)
{
if (_templateVars == null)
_templateVars = new Dictionary<string, string>();
_templateVars[name] = value;
return this;
}
/// <summary>
///
/// </summary>
public void FlushVars()
{
SetTextFieldText();
UpdateSize();
}
/// <summary>
///
/// </summary>
public bool HasCharacter(char ch)
{
return _textField.HasCharacter(ch);
}
protected string ParseTemplate(string template)
{
int pos1 = 0, pos2 = 0;
int pos3;
string tag;
string value;
StringBuilder buffer = new StringBuilder();
while ((pos2 = template.IndexOf('{', pos1)) != -1)
{
if (pos2 > 0 && template[pos2 - 1] == '\\')
{
buffer.Append(template, pos1, pos2 - pos1 - 1);
buffer.Append('{');
pos1 = pos2 + 1;
continue;
}
buffer.Append(template, pos1, pos2 - pos1);
pos1 = pos2;
pos2 = template.IndexOf('}', pos1);
if (pos2 == -1)
break;
if (pos2 == pos1 + 1)
{
buffer.Append(template, pos1, 2);
pos1 = pos2 + 1;
continue;
}
tag = template.Substring(pos1 + 1, pos2 - pos1 - 1);
pos3 = tag.IndexOf('=');
if (pos3 != -1)
{
if (!_templateVars.TryGetValue(tag.Substring(0, pos3), out value))
value = tag.Substring(pos3 + 1);
}
else
{
if (!_templateVars.TryGetValue(tag, out value))
value = "";
}
buffer.Append(value);
pos1 = pos2 + 1;
}
if (pos1 < template.Length)
buffer.Append(template, pos1, template.Length - pos1);
return buffer.ToString();
}
/// <summary>
///
/// </summary>
public TextFormat textFormat
{
get
{
return _textField.textFormat;
}
set
{
_textField.textFormat = value;
if (!underConstruct)
UpdateSize();
}
}
/// <summary>
///
/// </summary>
public Color color
{
get
{
return _textField.textFormat.color;
}
set
{
if (_textField.textFormat.color != value)
{
TextFormat tf = _textField.textFormat;
tf.color = value;
_textField.textFormat = tf;
UpdateGear(4);
}
}
}
/// <summary>
///
/// </summary>
public AlignType align
{
get { return _textField.align; }
set { _textField.align = value; }
}
/// <summary>
///
/// </summary>
public VertAlignType verticalAlign
{
get { return _textField.verticalAlign; }
set { _textField.verticalAlign = value; }
}
/// <summary>
///
/// </summary>
public bool singleLine
{
get { return _textField.singleLine; }
set { _textField.singleLine = value; }
}
/// <summary>
///
/// </summary>
public float stroke
{
get { return _textField.stroke; }
set { _textField.stroke = value; }
}
/// <summary>
///
/// </summary>
public Color strokeColor
{
get { return _textField.strokeColor; }
set
{
_textField.strokeColor = value;
UpdateGear(4);
}
}
/// <summary>
///
/// </summary>
public Vector2 shadowOffset
{
get { return _textField.shadowOffset; }
set { _textField.shadowOffset = value; }
}
/// <summary>
///
/// </summary>
public bool UBBEnabled
{
get { return _ubbEnabled; }
set { _ubbEnabled = value; }
}
/// <summary>
///
/// </summary>
public AutoSizeType autoSize
{
get { return _textField.autoSize; }
set
{
_textField.autoSize = value;
if (value == AutoSizeType.Both)
{
_textField.wordWrap = false;
if (!underConstruct)
this.SetSize(_textField.textWidth, _textField.textHeight);
}
else
{
_textField.wordWrap = true;
if (value == AutoSizeType.Height)
{
if (!underConstruct)
{
displayObject.width = this.width;
this.height = _textField.textHeight;
}
}
else
displayObject.SetSize(this.width, this.height);
}
}
}
/// <summary>
///
/// </summary>
public float textWidth
{
get { return _textField.textWidth; }
}
/// <summary>
///
/// </summary>
public float textHeight
{
get { return _textField.textHeight; }
}
protected void UpdateSize()
{
if (_updatingSize)
return;
_updatingSize = true;
if (_textField.autoSize == AutoSizeType.Both)
{
this.size = displayObject.size;
InvalidateBatchingState();
}
else if (_textField.autoSize == AutoSizeType.Height)
{
this.height = displayObject.height;
InvalidateBatchingState();
}
_updatingSize = false;
}
override protected void HandleSizeChanged()
{
if (_updatingSize)
return;
if (underConstruct)
displayObject.SetSize(this.width, this.height);
else if (_textField.autoSize != AutoSizeType.Both)
{
if (_textField.autoSize == AutoSizeType.Height)
{
displayObject.width = this.width;//先调整宽度,让文本重排
if (_text != string.Empty) //文本为空时1是本来就不需要调整 2是为了防止改掉文本为空时的默认高度造成关联错误
SetSizeDirectly(this.width, displayObject.height);
}
else
displayObject.SetSize(this.width, this.height);
}
}
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_BeforeAdd(buffer, beginPos);
buffer.Seek(beginPos, 5);
TextFormat tf = _textField.textFormat;
tf.font = buffer.ReadS();
tf.size = buffer.ReadShort();
tf.color = buffer.ReadColor();
this.align = (AlignType)buffer.ReadByte();
this.verticalAlign = (VertAlignType)buffer.ReadByte();
tf.lineSpacing = buffer.ReadShort();
tf.letterSpacing = buffer.ReadShort();
_ubbEnabled = buffer.ReadBool();
this.autoSize = (AutoSizeType)buffer.ReadByte();
tf.underline = buffer.ReadBool();
tf.italic = buffer.ReadBool();
tf.bold = buffer.ReadBool();
this.singleLine = buffer.ReadBool();
if (buffer.ReadBool())
{
tf.outlineColor = buffer.ReadColor();
tf.outline = buffer.ReadFloat();
}
if (buffer.ReadBool())
{
tf.shadowColor = buffer.ReadColor();
float f1 = buffer.ReadFloat();
float f2 = buffer.ReadFloat();
tf.shadowOffset = new Vector2(f1, f2);
}
if (buffer.ReadBool())
_templateVars = new Dictionary<string, string>();
if (buffer.version >= 3)
{
tf.strikethrough = buffer.ReadBool();
#if FAIRYGUI_TMPRO
tf.faceDilate = buffer.ReadFloat();
tf.outlineSoftness = buffer.ReadFloat();
tf.underlaySoftness = buffer.ReadFloat();
#else
buffer.Skip(12);
#endif
}
_textField.textFormat = tf;
}
override public void Setup_AfterAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_AfterAdd(buffer, beginPos);
buffer.Seek(beginPos, 6);
string str = buffer.ReadS();
if (str != null)
this.text = str;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d64856957bd90d24aa05d134fb14e01d
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,243 @@
using System.Collections.Generic;
using FairyGUI.Utils;
using UnityEngine;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public class GTextInput : GTextField
{
/// <summary>
///
/// </summary>
public InputTextField inputTextField { get; private set; }
EventListener _onChanged;
EventListener _onSubmit;
public GTextInput()
{
_textField.autoSize = AutoSizeType.None;
_textField.wordWrap = false;
}
/// <summary>
///
/// </summary>
public EventListener onChanged
{
get { return _onChanged ?? (_onChanged = new EventListener(this, "onChanged")); }
}
/// <summary>
///
/// </summary>
public EventListener onSubmit
{
get { return _onSubmit ?? (_onSubmit = new EventListener(this, "onSubmit")); }
}
/// <summary>
///
/// </summary>
public bool editable
{
get { return inputTextField.editable; }
set { inputTextField.editable = value; }
}
/// <summary>
///
/// </summary>
public bool hideInput
{
get { return inputTextField.hideInput; }
set { inputTextField.hideInput = value; }
}
/// <summary>
///
/// </summary>
public int maxLength
{
get { return inputTextField.maxLength; }
set { inputTextField.maxLength = value; }
}
/// <summary>
///
/// </summary>
public string restrict
{
get { return inputTextField.restrict; }
set { inputTextField.restrict = value; }
}
/// <summary>
///
/// </summary>
public bool displayAsPassword
{
get { return inputTextField.displayAsPassword; }
set { inputTextField.displayAsPassword = value; }
}
/// <summary>
///
/// </summary>
public int caretPosition
{
get { return inputTextField.caretPosition; }
set { inputTextField.caretPosition = value; }
}
/// <summary>
///
/// </summary>
public string promptText
{
get { return inputTextField.promptText; }
set { inputTextField.promptText = value; }
}
/// <summary>
/// 在移动设备上是否使用键盘输入。如果false则文本在获得焦点后不会弹出键盘。
/// </summary>
public bool keyboardInput
{
get { return inputTextField.keyboardInput; }
set { inputTextField.keyboardInput = value; }
}
/// <summary>
/// <see cref="UnityEngine.TouchScreenKeyboardType"/>
/// </summary>
public int keyboardType
{
get { return inputTextField.keyboardType; }
set { inputTextField.keyboardType = value; }
}
/// <summary>
///
/// </summary>
public bool disableIME
{
get { return inputTextField.disableIME; }
set { inputTextField.disableIME = value; }
}
/// <summary>
///
/// </summary>
public Dictionary<uint, Emoji> emojies
{
get { return inputTextField.emojies; }
set { inputTextField.emojies = value; }
}
/// <summary>
///
/// </summary>
public int border
{
get { return inputTextField.border; }
set { inputTextField.border = value; }
}
/// <summary>
///
/// </summary>
public int corner
{
get { return inputTextField.corner; }
set { inputTextField.corner = value; }
}
/// <summary>
///
/// </summary>
public Color borderColor
{
get { return inputTextField.borderColor; }
set { inputTextField.borderColor = value; }
}
/// <summary>
///
/// </summary>
public Color backgroundColor
{
get { return inputTextField.backgroundColor; }
set { inputTextField.backgroundColor = value; }
}
/// <summary>
///
/// </summary>
public bool mouseWheelEnabled
{
get { return inputTextField.mouseWheelEnabled; }
set { inputTextField.mouseWheelEnabled = value; }
}
/// <summary>
///
/// </summary>
/// <param name="start"></param>
/// <param name="length"></param>
public void SetSelection(int start, int length)
{
inputTextField.SetSelection(start, length);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
public void ReplaceSelection(string value)
{
inputTextField.ReplaceSelection(value);
}
override protected void SetTextFieldText()
{
inputTextField.text = _text;
}
override protected void CreateDisplayObject()
{
inputTextField = new InputTextField();
inputTextField.gOwner = this;
displayObject = inputTextField;
_textField = inputTextField.textField;
}
public override void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_BeforeAdd(buffer, beginPos);
buffer.Seek(beginPos, 4);
string str = buffer.ReadS();
if (str != null)
inputTextField.promptText = str;
str = buffer.ReadS();
if (str != null)
inputTextField.restrict = str;
int iv = buffer.ReadInt();
if (iv != 0)
inputTextField.maxLength = iv;
iv = buffer.ReadInt();
if (iv != 0)
inputTextField.keyboardType = iv;
if (buffer.ReadBool())
inputTextField.displayAsPassword = true;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 0e6f98107e4db9142b9de3358cf95378
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,557 @@
using System;
using System.Collections.Generic;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public class GTree : GList
{
public delegate void TreeNodeRenderDelegate(GTreeNode node, GComponent obj);
public delegate void TreeNodeWillExpandDelegate(GTreeNode node, bool expand);
/// <summary>
/// 当TreeNode需要更新时回调
/// </summary>
public TreeNodeRenderDelegate treeNodeRender;
/// <summary>
/// 当TreeNode即将展开或者收缩时回调。可以在回调中动态增加子节点。
/// </summary>
public TreeNodeWillExpandDelegate treeNodeWillExpand;
int _indent;
GTreeNode _rootNode;
int _clickToExpand;
bool _expandedStatusInEvt;
private static List<int> helperIntList = new List<int>();
/// <summary>
///
/// </summary>
public GTree()
{
_indent = 30;
_rootNode = new GTreeNode(true);
_rootNode._SetTree(this);
_rootNode.expanded = true;
}
/// <summary>
/// TreeView的顶层节点这是个虚拟节点也就是他不会显示出来。
/// </summary>
public GTreeNode rootNode
{
get { return _rootNode; }
}
/// <summary>
/// TreeView每级的缩进单位像素。
/// </summary>
public int indent
{
get { return _indent; }
set { _indent = value; }
}
/// <summary>
///
/// </summary>
public int clickToExpand
{
get { return _clickToExpand; }
set { _clickToExpand = value; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public GTreeNode GetSelectedNode()
{
int i = this.selectedIndex;
if (i != -1)
return (GTreeNode)this.GetChildAt(i)._treeNode;
else
return null;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public List<GTreeNode> GetSelectedNodes()
{
return GetSelectedNodes(null);
}
/// <summary>
///
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
public List<GTreeNode> GetSelectedNodes(List<GTreeNode> result)
{
if (result == null)
result = new List<GTreeNode>();
helperIntList.Clear();
List<int> sels = GetSelection(helperIntList);
int cnt = sels.Count;
for (int i = 0; i < cnt; i++)
{
GTreeNode node = GetChildAt(sels[i])._treeNode;
result.Add(node);
}
return result;
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
public void SelectNode(GTreeNode node)
{
SelectNode(node, false);
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
/// <param name="scrollItToView"></param>
public void SelectNode(GTreeNode node, bool scrollItToView)
{
GTreeNode parentNode = node.parent;
while (parentNode != null && parentNode != _rootNode)
{
parentNode.expanded = true;
parentNode = parentNode.parent;
}
AddSelection(GetChildIndex(node.cell), scrollItToView);
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
public void UnselectNode(GTreeNode node)
{
RemoveSelection(GetChildIndex(node.cell));
}
/// <summary>
///
/// </summary>
public void ExpandAll()
{
ExpandAll(_rootNode);
}
/// <summary>
///
/// </summary>
/// <param name="folderNode"></param>
public void ExpandAll(GTreeNode folderNode)
{
folderNode.expanded = true;
int cnt = folderNode.numChildren;
for (int i = 0; i < cnt; i++)
{
GTreeNode node = folderNode.GetChildAt(i);
if (node.isFolder)
ExpandAll(node);
}
}
/// <summary>
///
/// </summary>
/// <param name="folderNode"></param>
public void CollapseAll()
{
CollapseAll(_rootNode);
}
/// <summary>
///
/// </summary>
/// <param name="folderNode"></param>
public void CollapseAll(GTreeNode folderNode)
{
if (folderNode != _rootNode)
folderNode.expanded = false;
int cnt = folderNode.numChildren;
for (int i = 0; i < cnt; i++)
{
GTreeNode node = folderNode.GetChildAt(i);
if (node.isFolder)
CollapseAll(node);
}
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
void CreateCell(GTreeNode node)
{
GComponent child = itemPool.GetObject(string.IsNullOrEmpty(node._resURL) ? this.defaultItem : node._resURL) as GComponent;
if (child == null)
throw new Exception("FairyGUI: cannot create tree node object.");
child.displayObject.home = this.displayObject.cachedTransform;
child._treeNode = node;
node._cell = child;
GObject indentObj = node.cell.GetChild("indent");
if (indentObj != null)
indentObj.width = (node.level - 1) * indent;
Controller cc;
cc = child.GetController("expanded");
if (cc != null)
{
cc.onChanged.Add(__expandedStateChanged);
cc.selectedIndex = node.expanded ? 1 : 0;
}
cc = child.GetController("leaf");
if (cc != null)
cc.selectedIndex = node.isFolder ? 0 : 1;
if (node.isFolder)
child.onTouchBegin.Add(__cellTouchBegin);
if (treeNodeRender != null)
treeNodeRender(node, node._cell);
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
internal void _AfterInserted(GTreeNode node)
{
if (node._cell == null)
CreateCell(node);
int index = GetInsertIndexForNode(node);
AddChildAt(node.cell, index);
if (treeNodeRender != null)
treeNodeRender(node, node._cell);
if (node.isFolder && node.expanded)
CheckChildren(node, index);
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
int GetInsertIndexForNode(GTreeNode node)
{
GTreeNode prevNode = node.GetPrevSibling();
if (prevNode == null)
prevNode = node.parent;
int insertIndex = GetChildIndex(prevNode.cell) + 1;
int myLevel = node.level;
int cnt = this.numChildren;
for (int i = insertIndex; i < cnt; i++)
{
GTreeNode testNode = GetChildAt(i)._treeNode;
if (testNode.level <= myLevel)
break;
insertIndex++;
}
return insertIndex;
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
internal void _AfterRemoved(GTreeNode node)
{
RemoveNode(node);
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
internal void _AfterExpanded(GTreeNode node)
{
if (node == _rootNode)
{
CheckChildren(_rootNode, 0);
return;
}
if (this.treeNodeWillExpand != null)
this.treeNodeWillExpand(node, true);
if (node._cell == null)
return;
if (this.treeNodeRender != null)
this.treeNodeRender(node, node._cell);
Controller cc = node._cell.GetController("expanded");
if (cc != null)
cc.selectedIndex = 1;
if (node._cell.parent != null)
CheckChildren(node, GetChildIndex(node._cell));
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
internal void _AfterCollapsed(GTreeNode node)
{
if (node == _rootNode)
{
CheckChildren(_rootNode, 0);
return;
}
if (this.treeNodeWillExpand != null)
this.treeNodeWillExpand(node, false);
if (node._cell == null)
return;
if (this.treeNodeRender != null)
this.treeNodeRender(node, node._cell);
Controller cc = node._cell.GetController("expanded");
if (cc != null)
cc.selectedIndex = 0;
if (node._cell.parent != null)
HideFolderNode(node);
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
internal void _AfterMoved(GTreeNode node)
{
int startIndex = GetChildIndex(node._cell);
int endIndex;
if (node.isFolder)
endIndex = GetFolderEndIndex(startIndex, node.level);
else
endIndex = startIndex + 1;
int insertIndex = GetInsertIndexForNode(node);
int cnt = endIndex - startIndex;
if (insertIndex < startIndex)
{
for (int i = 0; i < cnt; i++)
{
GObject obj = GetChildAt(startIndex + i);
SetChildIndex(obj, insertIndex + i);
}
}
else
{
for (int i = 0; i < cnt; i++)
{
GObject obj = GetChildAt(startIndex);
SetChildIndex(obj, insertIndex);
}
}
}
private int GetFolderEndIndex(int startIndex, int level)
{
int cnt = this.numChildren;
for (int i = startIndex + 1; i < cnt; i++)
{
GTreeNode node = GetChildAt(i)._treeNode;
if (node.level <= level)
return i;
}
return cnt;
}
/// <summary>
///
/// </summary>
/// <param name="folderNode"></param>
/// <param name="index"></param>
/// <returns></returns>
int CheckChildren(GTreeNode folderNode, int index)
{
int cnt = folderNode.numChildren;
for (int i = 0; i < cnt; i++)
{
index++;
GTreeNode node = folderNode.GetChildAt(i);
if (node.cell == null)
CreateCell(node);
if (node.cell.parent == null)
AddChildAt(node.cell, index);
if (node.isFolder && node.expanded)
index = CheckChildren(node, index);
}
return index;
}
/// <summary>
///
/// </summary>
/// <param name="folderNode"></param>
void HideFolderNode(GTreeNode folderNode)
{
int cnt = folderNode.numChildren;
for (int i = 0; i < cnt; i++)
{
GTreeNode node = folderNode.GetChildAt(i);
if (node.cell != null && node.cell.parent != null)
RemoveChild(node.cell);
if (node.isFolder && node.expanded)
HideFolderNode(node);
}
}
/// <summary>
///
/// </summary>
/// <param name="node"></param>
void RemoveNode(GTreeNode node)
{
if (node.cell != null)
{
if (node.cell.parent != null)
RemoveChild(node.cell);
itemPool.ReturnObject(node.cell);
node._cell._treeNode = null;
node._cell = null;
}
if (node.isFolder)
{
int cnt = node.numChildren;
for (int i = 0; i < cnt; i++)
{
GTreeNode node2 = node.GetChildAt(i);
RemoveNode(node2);
}
}
}
void __cellTouchBegin(EventContext context)
{
GTreeNode node = ((GObject)context.sender)._treeNode;
_expandedStatusInEvt = node.expanded;
}
void __expandedStateChanged(EventContext context)
{
Controller cc = (Controller)context.sender;
GTreeNode node = cc.parent._treeNode;
node.expanded = cc.selectedIndex == 1;
}
override protected void DispatchItemEvent(GObject item, EventContext context)
{
if (_clickToExpand != 0)
{
GTreeNode node = item._treeNode;
if (node != null && _expandedStatusInEvt == node.expanded)
{
if (_clickToExpand == 2)
{
if (context.inputEvent.isDoubleClick)
node.expanded = !node.expanded;
}
else
node.expanded = !node.expanded;
}
}
base.DispatchItemEvent(item, context);
}
override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
{
base.Setup_BeforeAdd(buffer, beginPos);
buffer.Seek(beginPos, 9);
_indent = buffer.ReadInt();
_clickToExpand = buffer.ReadByte();
}
override protected void ReadItems(ByteBuffer buffer)
{
int nextPos;
string str;
bool isFolder;
GTreeNode lastNode = null;
int level;
int prevLevel = 0;
int cnt = buffer.ReadShort();
for (int i = 0; i < cnt; i++)
{
nextPos = buffer.ReadUshort();
nextPos += buffer.position;
str = buffer.ReadS();
if (str == null)
{
str = this.defaultItem;
if (str == null)
{
buffer.position = nextPos;
continue;
}
}
isFolder = buffer.ReadBool();
level = buffer.ReadByte();
GTreeNode node = new GTreeNode(isFolder, str);
node.expanded = true;
if (i == 0)
_rootNode.AddChild(node);
else
{
if (level > prevLevel)
lastNode.AddChild(node);
else if (level < prevLevel)
{
for (int j = level; j <= prevLevel; j++)
lastNode = lastNode.parent;
lastNode.AddChild(node);
}
else
lastNode.parent.AddChild(node);
}
lastNode = node;
prevLevel = level;
SetupItem(buffer, node.cell);
buffer.position = nextPos;
}
}
}
}

View File

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

View File

@@ -0,0 +1,406 @@
using System;
using System.Collections.Generic;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public class GTreeNode
{
/// <summary>
///
/// </summary>
public object data;
/// <summary>
///
/// </summary>
public GTreeNode parent { get; private set; }
/// <summary>
///
/// </summary>
public GTree tree { get; private set; }
List<GTreeNode> _children;
bool _expanded;
int _level;
internal GComponent _cell;
internal string _resURL;
/// <summary>
///
/// </summary>
/// <param name="hasChild"></param>
public GTreeNode(bool hasChild) : this(hasChild, null)
{
}
/// <summary>
///
/// </summary>
/// <param name="hasChild"></param>
/// <param name="resURL"></param>
public GTreeNode(bool hasChild, string resURL)
{
if (hasChild)
_children = new List<GTreeNode>();
_resURL = resURL;
}
/// <summary>
///
/// </summary>
public GComponent cell
{
get { return _cell; }
}
/// <summary>
///
/// </summary>
public int level
{
get { return _level; }
}
/// <summary>
///
/// </summary>
public bool expanded
{
get
{
return _expanded;
}
set
{
if (_children == null)
return;
if (_expanded != value)
{
_expanded = value;
if (tree != null)
{
if (_expanded)
tree._AfterExpanded(this);
else
tree._AfterCollapsed(this);
}
}
}
}
/// <summary>
///
/// </summary>
public void ExpandToRoot()
{
GTreeNode p = this;
while (p != null)
{
p.expanded = true;
p = p.parent;
}
}
/// <summary>
///
/// </summary>
public bool isFolder
{
get { return _children != null; }
}
/// <summary>
///
/// </summary>
public string text
{
get
{
if (_cell != null)
return _cell.text;
else
return null;
}
set
{
if (_cell != null)
_cell.text = value;
}
}
/// <summary>
///
/// </summary>
public string icon
{
get
{
if (_cell != null)
return _cell.icon;
else
return null;
}
set
{
if (_cell != null)
_cell.icon = value;
}
}
/// <summary>
///
/// </summary>
/// <param name="child"></param>
/// <returns></returns>
public GTreeNode AddChild(GTreeNode child)
{
AddChildAt(child, _children.Count);
return child;
}
/// <summary>
///
/// </summary>
/// <param name="child"></param>
/// <param name="index"></param>
/// <returns></returns>
public GTreeNode AddChildAt(GTreeNode child, int index)
{
if (child == null)
throw new Exception("child is null");
int numChildren = _children.Count;
if (index >= 0 && index <= numChildren)
{
if (child.parent == this)
{
SetChildIndex(child, index);
}
else
{
if (child.parent != null)
child.parent.RemoveChild(child);
int cnt = _children.Count;
if (index == cnt)
_children.Add(child);
else
_children.Insert(index, child);
child.parent = this;
child._level = _level + 1;
child._SetTree(this.tree);
if (tree != null && this == tree.rootNode || _cell != null && _cell.parent != null && _expanded)
tree._AfterInserted(child);
}
return child;
}
else
{
throw new Exception("Invalid child index");
}
}
/// <summary>
///
/// </summary>
/// <param name="child"></param>
/// <returns></returns>
public GTreeNode RemoveChild(GTreeNode child)
{
int childIndex = _children.IndexOf(child);
if (childIndex != -1)
{
RemoveChildAt(childIndex);
}
return child;
}
/// <summary>
///
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public GTreeNode RemoveChildAt(int index)
{
if (index >= 0 && index < numChildren)
{
GTreeNode child = _children[index];
_children.RemoveAt(index);
child.parent = null;
if (tree != null)
{
child._SetTree(null);
tree._AfterRemoved(child);
}
return child;
}
else
{
throw new Exception("Invalid child index");
}
}
/// <summary>
///
/// </summary>
/// <param name="beginIndex"></param>
/// <param name="endIndex"></param>
public void RemoveChildren(int beginIndex = 0, int endIndex = -1)
{
if (endIndex < 0 || endIndex >= numChildren)
endIndex = numChildren - 1;
for (int i = beginIndex; i <= endIndex; ++i)
RemoveChildAt(beginIndex);
}
/// <summary>
///
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public GTreeNode GetChildAt(int index)
{
if (index >= 0 && index < numChildren)
return _children[index];
else
throw new Exception("Invalid child index");
}
/// <summary>
///
/// </summary>
/// <param name="child"></param>
/// <returns></returns>
public int GetChildIndex(GTreeNode child)
{
return _children.IndexOf(child);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public GTreeNode GetPrevSibling()
{
if (parent == null)
return null;
int i = parent._children.IndexOf(this);
if (i <= 0)
return null;
return parent._children[i - 1];
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public GTreeNode GetNextSibling()
{
if (parent == null)
return null;
int i = parent._children.IndexOf(this);
if (i < 0 || i >= parent._children.Count - 1)
return null;
return parent._children[i + 1];
}
/// <summary>
///
/// </summary>
/// <param name="child"></param>
/// <param name="index"></param>
public void SetChildIndex(GTreeNode child, int index)
{
int oldIndex = _children.IndexOf(child);
if (oldIndex == -1)
throw new Exception("Not a child of this container");
int cnt = _children.Count;
if (index < 0)
index = 0;
else if (index > cnt)
index = cnt;
if (oldIndex == index)
return;
_children.RemoveAt(oldIndex);
_children.Insert(index, child);
if (tree != null && this == tree.rootNode || _cell != null && _cell.parent != null && _expanded)
tree._AfterMoved(child);
}
/// <summary>
///
/// </summary>
/// <param name="child1"></param>
/// <param name="child2"></param>
public void SwapChildren(GTreeNode child1, GTreeNode child2)
{
int index1 = _children.IndexOf(child1);
int index2 = _children.IndexOf(child2);
if (index1 == -1 || index2 == -1)
throw new Exception("Not a child of this container");
SwapChildrenAt(index1, index2);
}
/// <summary>
///
/// </summary>
/// <param name="index1"></param>
/// <param name="index2"></param>
public void SwapChildrenAt(int index1, int index2)
{
GTreeNode child1 = _children[index1];
GTreeNode child2 = _children[index2];
SetChildIndex(child1, index2);
SetChildIndex(child2, index1);
}
/// <summary>
///
/// </summary>
public int numChildren
{
get { return (null == _children) ? 0 : _children.Count; }
}
internal void _SetTree(GTree value)
{
tree = value;
if (tree != null && tree.treeNodeWillExpand != null && _expanded)
tree.treeNodeWillExpand(this, true);
if (_children != null)
{
int cnt = _children.Count;
for (int i = 0; i < cnt; i++)
{
GTreeNode node = _children[i];
node._level = _level + 1;
node._SetTree(value);
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b22c996c870881c438177e27f3450ac7
folderAsset: yes
timeCreated: 1476166202
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,109 @@
using System.Collections.Generic;
using FairyGUI.Utils;
namespace FairyGUI
{
class GearAnimationValue
{
public bool playing;
public int frame;
public string animationName;
public string skinName;
public GearAnimationValue(bool playing, int frame)
{
this.playing = playing;
this.frame = frame;
}
}
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearAnimation : GearBase
{
Dictionary<string, GearAnimationValue> _storage;
GearAnimationValue _default;
public GearAnimation(GObject owner)
: base(owner)
{
}
protected override void Init()
{
_default = new GearAnimationValue(((IAnimationGear)_owner).playing, ((IAnimationGear)_owner).frame);
if (_owner is GLoader3D)
{
_default.animationName = ((GLoader3D)_owner).animationName;
_default.skinName = ((GLoader3D)_owner).skinName;
}
_storage = new Dictionary<string, GearAnimationValue>();
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
GearAnimationValue gv;
if (pageId == null)
gv = _default;
else
{
gv = new GearAnimationValue(false, 0);
_storage[pageId] = gv;
}
gv.playing = buffer.ReadBool();
gv.frame = buffer.ReadInt();
}
public void AddExtStatus(string pageId, ByteBuffer buffer)
{
GearAnimationValue gv;
if (pageId == null)
gv = _default;
else
gv = _storage[pageId];
gv.animationName = buffer.ReadS();
gv.skinName = buffer.ReadS();
}
override public void Apply()
{
_owner._gearLocked = true;
GearAnimationValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
gv = _default;
IAnimationGear mc = (IAnimationGear)_owner;
mc.frame = gv.frame;
mc.playing = gv.playing;
if (_owner is GLoader3D)
{
((GLoader3D)_owner).animationName = gv.animationName;
((GLoader3D)_owner).skinName = gv.skinName;
}
_owner._gearLocked = false;
}
override public void UpdateState()
{
IAnimationGear mc = (IAnimationGear)_owner;
GearAnimationValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
_storage[_controller.selectedPageId] = gv = new GearAnimationValue(mc.playing, mc.frame);
else
{
gv.playing = mc.playing;
gv.frame = mc.frame;
}
if (_owner is GLoader3D)
{
gv.animationName = ((GLoader3D)_owner).animationName;
gv.skinName = ((GLoader3D)_owner).skinName;
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 87e99c1910ca9684d8719dae7bdb7658
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,203 @@
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
abstract public class GearBase
{
public static bool disableAllTweenEffect = false;
protected GObject _owner;
protected Controller _controller;
protected GearTweenConfig _tweenConfig;
public GearBase(GObject owner)
{
_owner = owner;
}
public void Dispose()
{
if (_tweenConfig != null && _tweenConfig._tweener != null)
{
_tweenConfig._tweener.Kill();
_tweenConfig._tweener = null;
}
}
/// <summary>
/// Controller object.
/// </summary>
public Controller controller
{
get
{
return _controller;
}
set
{
if (value != _controller)
{
_controller = value;
if (_controller != null)
Init();
}
}
}
public GearTweenConfig tweenConfig
{
get
{
if (_tweenConfig == null)
_tweenConfig = new GearTweenConfig();
return _tweenConfig;
}
}
public void Setup(ByteBuffer buffer)
{
_controller = _owner.parent.GetControllerAt(buffer.ReadShort());
Init();
int cnt = buffer.ReadShort();
if (this is GearDisplay)
{
((GearDisplay)this).pages = buffer.ReadSArray(cnt);
}
else if (this is GearDisplay2)
{
((GearDisplay2)this).pages = buffer.ReadSArray(cnt);
}
else
{
for (int i = 0; i < cnt; i++)
{
string page = buffer.ReadS();
if (page == null)
continue;
AddStatus(page, buffer);
}
if (buffer.ReadBool())
AddStatus(null, buffer);
}
if (buffer.ReadBool())
{
_tweenConfig = new GearTweenConfig();
_tweenConfig.easeType = (EaseType)buffer.ReadByte();
_tweenConfig.duration = buffer.ReadFloat();
_tweenConfig.delay = buffer.ReadFloat();
}
if (buffer.version >= 2)
{
if (this is GearXY)
{
if (buffer.ReadBool())
{
((GearXY)this).positionsInPercent = true;
for (int i = 0; i < cnt; i++)
{
string page = buffer.ReadS();
if (page == null)
continue;
((GearXY)this).AddExtStatus(page, buffer);
}
if (buffer.ReadBool())
((GearXY)this).AddExtStatus(null, buffer);
}
}
else if (this is GearDisplay2)
((GearDisplay2)this).condition = buffer.ReadByte();
}
if (buffer.version >= 4 && _tweenConfig != null && _tweenConfig.easeType == EaseType.Custom)
{
_tweenConfig.customEase = new CustomEase();
_tweenConfig.customEase.Create(buffer.ReadPath());
}
if (buffer.version >= 6)
{
if (this is GearAnimation)
{
for (int i = 0; i < cnt; i++)
{
string page = buffer.ReadS();
if (page == null)
continue;
((GearAnimation)this).AddExtStatus(page, buffer);
}
if (buffer.ReadBool())
((GearAnimation)this).AddExtStatus(null, buffer);
}
}
}
virtual public void UpdateFromRelations(float dx, float dy)
{
}
abstract protected void AddStatus(string pageId, ByteBuffer buffer);
abstract protected void Init();
/// <summary>
/// Call when controller active page changed.
/// </summary>
abstract public void Apply();
/// <summary>
/// Call when object's properties changed.
/// </summary>
abstract public void UpdateState();
}
public class GearTweenConfig
{
/// <summary>
/// Use tween to apply change.
/// </summary>
public bool tween;
/// <summary>
/// Ease type.
/// </summary>
public EaseType easeType;
/// <summary>
///
/// </summary>
public CustomEase customEase;
/// <summary>
/// Tween duration in seconds.
/// </summary>
public float duration;
/// <summary>
/// Tween delay in seconds.
/// </summary>
public float delay;
internal uint _displayLockToken;
internal GTweener _tweener;
public GearTweenConfig()
{
tween = true;
easeType = EaseType.QuadOut;
duration = 0.3f;
delay = 0;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 2050e67af29d06a44834f7ffbfe14e83
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,142 @@
using System.Collections.Generic;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
class GearColorValue
{
public Color color;
public Color strokeColor;
public GearColorValue()
{
}
public GearColorValue(Color color, Color strokeColor)
{
this.color = color;
this.strokeColor = strokeColor;
}
}
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearColor : GearBase, ITweenListener
{
Dictionary<string, GearColorValue> _storage;
GearColorValue _default;
public GearColor(GObject owner)
: base(owner)
{
}
protected override void Init()
{
_default = new GearColorValue();
_default.color = ((IColorGear)_owner).color;
if (_owner is ITextColorGear)
_default.strokeColor = ((ITextColorGear)_owner).strokeColor;
_storage = new Dictionary<string, GearColorValue>();
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
GearColorValue gv;
if (pageId == null)
gv = _default;
else
{
gv = new GearColorValue(Color.black, Color.black);
_storage[pageId] = gv;
}
gv.color = buffer.ReadColor();
gv.strokeColor = buffer.ReadColor();
}
override public void Apply()
{
GearColorValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
gv = _default;
if (_tweenConfig != null && _tweenConfig.tween && UIPackage._constructing == 0 && !disableAllTweenEffect)
{
if ((_owner is ITextColorGear) && gv.strokeColor.a > 0)
{
_owner._gearLocked = true;
((ITextColorGear)_owner).strokeColor = gv.strokeColor;
_owner._gearLocked = false;
}
if (_tweenConfig._tweener != null)
{
if (_tweenConfig._tweener.endValue.color != gv.color)
{
_tweenConfig._tweener.Kill(true);
_tweenConfig._tweener = null;
}
else
return;
}
if (((IColorGear)_owner).color != gv.color)
{
if (_owner.CheckGearController(0, _controller))
_tweenConfig._displayLockToken = _owner.AddDisplayLock();
_tweenConfig._tweener = GTween.To(((IColorGear)_owner).color, gv.color, _tweenConfig.duration)
.SetDelay(_tweenConfig.delay)
.SetEase(_tweenConfig.easeType, _tweenConfig.customEase)
.SetTarget(this)
.SetListener(this);
}
}
else
{
_owner._gearLocked = true;
((IColorGear)_owner).color = gv.color;
if ((_owner is ITextColorGear) && gv.strokeColor.a > 0)
((ITextColorGear)_owner).strokeColor = gv.strokeColor;
_owner._gearLocked = false;
}
}
public void OnTweenStart(GTweener tweener)
{
}
public void OnTweenUpdate(GTweener tweener)
{
_owner._gearLocked = true;
((IColorGear)_owner).color = tweener.value.color;
_owner._gearLocked = false;
_owner.InvalidateBatchingState();
}
public void OnTweenComplete(GTweener tweener)
{
_tweenConfig._tweener = null;
if (_tweenConfig._displayLockToken != 0)
{
_owner.ReleaseDisplayLock(_tweenConfig._displayLockToken);
_tweenConfig._displayLockToken = 0;
}
_owner.DispatchEvent("onGearStop", this);
}
override public void UpdateState()
{
GearColorValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
_storage[_controller.selectedPageId] = gv = new GearColorValue();
gv.color = ((IColorGear)_owner).color;
if (_owner is ITextColorGear)
gv.strokeColor = ((ITextColorGear)_owner).strokeColor;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a4878a5e9a94c1d429c827f93ca3072b
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
using System;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearDisplay : GearBase
{
/// <summary>
/// Pages involed in this gear.
/// </summary>
public string[] pages { get; set; }
int _visible;
uint _displayLockToken;
public GearDisplay(GObject owner)
: base(owner)
{
_displayLockToken = 1;
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
}
override protected void Init()
{
pages = null;
}
override public void Apply()
{
_displayLockToken++;
if (_displayLockToken == 0)
_displayLockToken = 1;
if (pages == null || pages.Length == 0
|| Array.IndexOf(pages, _controller.selectedPageId) != -1)
_visible = 1;
else
_visible = 0;
}
override public void UpdateState()
{
}
public uint AddLock()
{
_visible++;
return _displayLockToken;
}
public void ReleaseLock(uint token)
{
if (token == _displayLockToken)
_visible--;
}
public bool connected
{
get { return _controller == null || _visible > 0; }
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: f88c3ac62122e7141a5d6c41eb11da27
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
using System;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearDisplay2 : GearBase
{
/// <summary>
/// Pages involed in this gear.
/// </summary>
public string[] pages { get; set; }
public int condition;
int _visible;
public GearDisplay2(GObject owner)
: base(owner)
{
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
}
override protected void Init()
{
pages = null;
}
override public void Apply()
{
if (pages == null || pages.Length == 0
|| Array.IndexOf(pages, _controller.selectedPageId) != -1)
_visible = 1;
else
_visible = 0;
}
override public void UpdateState()
{
}
public bool Evaluate(bool connected)
{
bool v = _controller == null || _visible > 0;
if (this.condition == 0)
v = v && connected;
else
v = v || connected;
return v;
}
}
}

View File

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

View File

@@ -0,0 +1,53 @@
using System.Collections.Generic;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearFontSize : GearBase
{
Dictionary<string, int> _storage;
int _default;
public GearFontSize(GObject owner)
: base(owner)
{
}
protected override void Init()
{
_default = ((GTextField)_owner).textFormat.size;
_storage = new Dictionary<string, int>();
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
if (pageId == null)
_default = buffer.ReadInt();
else
_storage[pageId] = buffer.ReadInt();
}
override public void Apply()
{
_owner._gearLocked = true;
int cv;
if (!_storage.TryGetValue(_controller.selectedPageId, out cv))
cv = _default;
TextFormat tf = ((GTextField)_owner).textFormat;
tf.size = cv;
((GTextField)_owner).textFormat = tf;
_owner._gearLocked = false;
}
override public void UpdateState()
{
_storage[_controller.selectedPageId] = ((GTextField)_owner).textFormat.size;
}
}
}

View File

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

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearIcon : GearBase
{
Dictionary<string, string> _storage;
string _default;
public GearIcon(GObject owner)
: base(owner)
{
}
protected override void Init()
{
_default = _owner.icon;
_storage = new Dictionary<string, string>();
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
if (pageId == null)
_default = buffer.ReadS();
else
_storage[pageId] = buffer.ReadS();
}
override public void Apply()
{
_owner._gearLocked = true;
string cv;
if (!_storage.TryGetValue(_controller.selectedPageId, out cv))
cv = _default;
_owner.icon = cv;
_owner._gearLocked = false;
}
override public void UpdateState()
{
_storage[_controller.selectedPageId] = _owner.icon;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 27b2a638ddb815f40994e0477c3ea4c0
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,152 @@
using System.Collections.Generic;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
class GearLookValue
{
public float alpha;
public float rotation;
public bool grayed;
public bool touchable;
public GearLookValue(float alpha, float rotation, bool grayed, bool touchable)
{
this.alpha = alpha;
this.rotation = rotation;
this.grayed = grayed;
this.touchable = touchable;
}
}
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearLook : GearBase, ITweenListener
{
Dictionary<string, GearLookValue> _storage;
GearLookValue _default;
public GearLook(GObject owner)
: base(owner)
{
}
protected override void Init()
{
_default = new GearLookValue(_owner.alpha, _owner.rotation, _owner.grayed, _owner.touchable);
_storage = new Dictionary<string, GearLookValue>();
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
GearLookValue gv;
if (pageId == null)
gv = _default;
else
{
gv = new GearLookValue(0, 0, false, false);
_storage[pageId] = gv;
}
gv.alpha = buffer.ReadFloat();
gv.rotation = buffer.ReadFloat();
gv.grayed = buffer.ReadBool();
gv.touchable = buffer.ReadBool();
}
override public void Apply()
{
GearLookValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
gv = _default;
if (_tweenConfig != null && _tweenConfig.tween && UIPackage._constructing == 0 && !disableAllTweenEffect)
{
_owner._gearLocked = true;
_owner.grayed = gv.grayed;
_owner.touchable = gv.touchable;
_owner._gearLocked = false;
if (_tweenConfig._tweener != null)
{
if (_tweenConfig._tweener.endValue.x != gv.alpha || _tweenConfig._tweener.endValue.y != gv.rotation)
{
_tweenConfig._tweener.Kill(true);
_tweenConfig._tweener = null;
}
else
return;
}
bool a = gv.alpha != _owner.alpha;
bool b = gv.rotation != _owner.rotation;
if (a || b)
{
if (_owner.CheckGearController(0, _controller))
_tweenConfig._displayLockToken = _owner.AddDisplayLock();
_tweenConfig._tweener = GTween.To(new Vector2(_owner.alpha, _owner.rotation), new Vector2(gv.alpha, gv.rotation), _tweenConfig.duration)
.SetDelay(_tweenConfig.delay)
.SetEase(_tweenConfig.easeType, _tweenConfig.customEase)
.SetUserData((a ? 1 : 0) + (b ? 2 : 0))
.SetTarget(this)
.SetListener(this);
}
}
else
{
_owner._gearLocked = true;
_owner.alpha = gv.alpha;
_owner.rotation = gv.rotation;
_owner.grayed = gv.grayed;
_owner.touchable = gv.touchable;
_owner._gearLocked = false;
}
}
public void OnTweenStart(GTweener tweener)
{
}
public void OnTweenUpdate(GTweener tweener)
{
int flag = (int)tweener.userData;
_owner._gearLocked = true;
if ((flag & 1) != 0)
_owner.alpha = tweener.value.x;
if ((flag & 2) != 0)
{
_owner.rotation = tweener.value.y;
_owner.InvalidateBatchingState();
}
_owner._gearLocked = false;
}
public void OnTweenComplete(GTweener tweener)
{
_tweenConfig._tweener = null;
if (_tweenConfig._displayLockToken != 0)
{
_owner.ReleaseDisplayLock(_tweenConfig._displayLockToken);
_tweenConfig._displayLockToken = 0;
}
_owner.DispatchEvent("onGearStop", this);
}
override public void UpdateState()
{
GearLookValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
_storage[_controller.selectedPageId] = new GearLookValue(_owner.alpha, _owner.rotation, _owner.grayed, _owner.touchable);
else
{
gv.alpha = _owner.alpha;
gv.rotation = _owner.rotation;
gv.grayed = _owner.grayed;
gv.touchable = _owner.touchable;
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 77704143cdb38714196c9ff520a079f8
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,163 @@
using System.Collections.Generic;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
class GearSizeValue
{
public float width;
public float height;
public float scaleX;
public float scaleY;
public GearSizeValue(float width, float height, float scaleX, float scaleY)
{
this.width = width;
this.height = height;
this.scaleX = scaleX;
this.scaleY = scaleY;
}
}
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearSize : GearBase, ITweenListener
{
Dictionary<string, GearSizeValue> _storage;
GearSizeValue _default;
public GearSize(GObject owner)
: base(owner)
{
}
protected override void Init()
{
_default = new GearSizeValue(_owner.width, _owner.height, _owner.scaleX, _owner.scaleY);
_storage = new Dictionary<string, GearSizeValue>();
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
GearSizeValue gv;
if (pageId == null)
gv = _default;
else
{
gv = new GearSizeValue(0, 0, 1, 1);
_storage[pageId] = gv;
}
gv.width = buffer.ReadInt();
gv.height = buffer.ReadInt();
gv.scaleX = buffer.ReadFloat();
gv.scaleY = buffer.ReadFloat();
}
override public void Apply()
{
GearSizeValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
gv = _default;
if (_tweenConfig != null && _tweenConfig.tween && UIPackage._constructing == 0 && !disableAllTweenEffect)
{
if (_tweenConfig._tweener != null)
{
if (_tweenConfig._tweener.endValue.x != gv.width || _tweenConfig._tweener.endValue.y != gv.height
|| _tweenConfig._tweener.endValue.z != gv.scaleX || _tweenConfig._tweener.endValue.w != gv.scaleY)
{
_tweenConfig._tweener.Kill(true);
_tweenConfig._tweener = null;
}
else
return;
}
bool a = gv.width != _owner.width || gv.height != _owner.height;
bool b = gv.scaleX != _owner.scaleX || gv.scaleY != _owner.scaleY;
if (a || b)
{
if (_owner.CheckGearController(0, _controller))
_tweenConfig._displayLockToken = _owner.AddDisplayLock();
_tweenConfig._tweener = GTween.To(new Vector4(_owner.width, _owner.height, _owner.scaleX, _owner.scaleY),
new Vector4(gv.width, gv.height, gv.scaleX, gv.scaleY), _tweenConfig.duration)
.SetDelay(_tweenConfig.delay)
.SetEase(_tweenConfig.easeType, _tweenConfig.customEase)
.SetUserData((a ? 1 : 0) + (b ? 2 : 0))
.SetTarget(this)
.SetListener(this);
}
}
else
{
_owner._gearLocked = true;
_owner.SetSize(gv.width, gv.height, _owner.CheckGearController(1, _controller));
_owner.SetScale(gv.scaleX, gv.scaleY);
_owner._gearLocked = false;
}
}
public void OnTweenStart(GTweener tweener)
{
}
public void OnTweenUpdate(GTweener tweener)
{
_owner._gearLocked = true;
int flag = (int)tweener.userData;
if ((flag & 1) != 0)
_owner.SetSize(tweener.value.x, tweener.value.y, _owner.CheckGearController(1, _controller));
if ((flag & 2) != 0)
_owner.SetScale(tweener.value.z, tweener.value.w);
_owner._gearLocked = false;
_owner.InvalidateBatchingState();
}
public void OnTweenComplete(GTweener tweener)
{
_tweenConfig._tweener = null;
if (_tweenConfig._displayLockToken != 0)
{
_owner.ReleaseDisplayLock(_tweenConfig._displayLockToken);
_tweenConfig._displayLockToken = 0;
}
_owner.DispatchEvent("onGearStop", this);
}
override public void UpdateState()
{
GearSizeValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
_storage[_controller.selectedPageId] = new GearSizeValue(_owner.width, _owner.height, _owner.scaleX, _owner.scaleY);
else
{
gv.width = _owner.width;
gv.height = _owner.height;
gv.scaleX = _owner.scaleX;
gv.scaleY = _owner.scaleY;
}
}
override public void UpdateFromRelations(float dx, float dy)
{
if (_controller != null && _storage != null)
{
foreach (GearSizeValue gv in _storage.Values)
{
gv.width += dx;
gv.height += dy;
}
_default.width += dx;
_default.height += dy;
UpdateState();
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 254f71ab913968a4e853a99ce79f0266
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearText : GearBase
{
Dictionary<string, string> _storage;
string _default;
public GearText(GObject owner)
: base(owner)
{
}
protected override void Init()
{
_default = _owner.text;
_storage = new Dictionary<string, string>();
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
if (pageId == null)
_default = buffer.ReadS();
else
_storage[pageId] = buffer.ReadS();
}
override public void Apply()
{
_owner._gearLocked = true;
string cv;
if (!_storage.TryGetValue(_controller.selectedPageId, out cv))
cv = _default;
_owner.text = cv;
_owner._gearLocked = false;
}
override public void UpdateState()
{
_storage[_controller.selectedPageId] = _owner.text;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d8b20f3a5dd39ec42bed3456334916fc
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,177 @@
using System.Collections.Generic;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
class GearXYValue
{
public float x;
public float y;
public float px;
public float py;
public GearXYValue(float x = 0, float y = 0, float px = 0, float py = 0)
{
this.x = x;
this.y = y;
this.px = px;
this.py = py;
}
}
/// <summary>
/// Gear is a connection between object and controller.
/// </summary>
public class GearXY : GearBase, ITweenListener
{
public bool positionsInPercent;
Dictionary<string, GearXYValue> _storage;
GearXYValue _default;
public GearXY(GObject owner)
: base(owner)
{
}
protected override void Init()
{
_default = new GearXYValue(_owner.x, _owner.y, _owner.x / _owner.parent.width, _owner.y / _owner.parent.height);
_storage = new Dictionary<string, GearXYValue>();
}
override protected void AddStatus(string pageId, ByteBuffer buffer)
{
GearXYValue gv;
if (pageId == null)
gv = _default;
else
{
gv = new GearXYValue();
_storage[pageId] = gv;
}
gv.x = buffer.ReadInt();
gv.y = buffer.ReadInt();
}
public void AddExtStatus(string pageId, ByteBuffer buffer)
{
GearXYValue gv;
if (pageId == null)
gv = _default;
else
gv = _storage[pageId];
gv.px = buffer.ReadFloat();
gv.py = buffer.ReadFloat();
}
override public void Apply()
{
GearXYValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
gv = _default;
Vector2 endPos = new Vector2();
if (positionsInPercent && _owner.parent != null)
{
endPos.x = gv.px * _owner.parent.width;
endPos.y = gv.py * _owner.parent.height;
}
else
{
endPos.x = gv.x;
endPos.y = gv.y;
}
if (_tweenConfig != null && _tweenConfig.tween && UIPackage._constructing == 0 && !disableAllTweenEffect)
{
if (_tweenConfig._tweener != null)
{
if (_tweenConfig._tweener.endValue.x != endPos.x || _tweenConfig._tweener.endValue.y != endPos.y)
{
_tweenConfig._tweener.Kill(true);
_tweenConfig._tweener = null;
}
else
return;
}
Vector2 origin = _owner.xy;
if (endPos != origin)
{
if (_owner.CheckGearController(0, _controller))
_tweenConfig._displayLockToken = _owner.AddDisplayLock();
_tweenConfig._tweener = GTween.To(origin, endPos, _tweenConfig.duration)
.SetDelay(_tweenConfig.delay)
.SetEase(_tweenConfig.easeType, _tweenConfig.customEase)
.SetTarget(this)
.SetListener(this);
}
}
else
{
_owner._gearLocked = true;
_owner.SetXY(endPos.x, endPos.y);
_owner._gearLocked = false;
}
}
public void OnTweenStart(GTweener tweener)
{//nothing
}
public void OnTweenUpdate(GTweener tweener)
{
_owner._gearLocked = true;
_owner.SetXY(tweener.value.x, tweener.value.y);
_owner._gearLocked = false;
_owner.InvalidateBatchingState();
}
public void OnTweenComplete(GTweener tweener)
{
_tweenConfig._tweener = null;
if (_tweenConfig._displayLockToken != 0)
{
_owner.ReleaseDisplayLock(_tweenConfig._displayLockToken);
_tweenConfig._displayLockToken = 0;
}
_owner.DispatchEvent("onGearStop", this);
}
override public void UpdateState()
{
GearXYValue gv;
if (!_storage.TryGetValue(_controller.selectedPageId, out gv))
_storage[_controller.selectedPageId] = gv = new GearXYValue();
gv.x = _owner.x;
gv.y = _owner.y;
gv.px = _owner.x / _owner.parent.width;
gv.py = _owner.y / _owner.parent.height;
}
override public void UpdateFromRelations(float dx, float dy)
{
if (_controller != null && _storage != null && !positionsInPercent)
{
foreach (GearXYValue gv in _storage.Values)
{
gv.x += dx;
gv.y += dy;
}
_default.x += dx;
_default.y += dy;
UpdateState();
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 082a852494dc8b94485733188788d58c
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@

namespace FairyGUI
{
/// <summary>
///
/// </summary>
public interface IAnimationGear
{
/// <summary>
///
/// </summary>
bool playing { get; set; }
/// <summary>
///
/// </summary>
int frame { get; set; }
/// <summary>
///
/// </summary>
float timeScale { get; set; }
/// <summary>
///
/// </summary>
bool ignoreEngineTimeScale { get; set; }
/// <summary>
///
/// </summary>
/// <param name="time"></param>
void Advance(float time);
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d68e5b2a3af5c444689f459a8b265df7
timeCreated: 1476166204
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using UnityEngine;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public interface IColorGear
{
/// <summary>
///
/// </summary>
Color color { get; set; }
}
/// <summary>
///
/// </summary>
public interface ITextColorGear : IColorGear
{
/// <summary>
///
/// </summary>
Color strokeColor { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: e872cd17b52152a4fa250c830b9bb8cd
timeCreated: 1476166204
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@

namespace FairyGUI
{
/// <summary>
///
/// </summary>
public delegate void UILoadCallback();
/// <summary>
///
/// </summary>
public interface IUISource
{
/// <summary>
///
/// </summary>
string fileName { get; set; }
/// <summary>
///
/// </summary>
bool loaded { get; }
/// <summary>
///
/// </summary>
/// <param name="callback"></param>
void Load(UILoadCallback callback);
/// <summary>
/// 取消加载
/// </summary>
void Cancel();
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: c742c10608d6ac84bb210a9d6abcb05d
timeCreated: 1460480288
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@

namespace FairyGUI
{
/// <summary>
///
/// </summary>
public struct Margin
{
/// <summary>
///
/// </summary>
public int left;
/// <summary>
///
/// </summary>
public int right;
/// <summary>
///
/// </summary>
public int top;
/// <summary>
///
/// </summary>
public int bottom;
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7f31f9a61b0590943ac37f1c16ff0dc9
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,85 @@
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public class PackageItem
{
public UIPackage owner;
public PackageItemType type;
public ObjectType objectType;
public string id;
public string name;
public int width;
public int height;
public string file;
public bool exported;
public NTexture texture;
public ByteBuffer rawData;
public string[] branches;
public string[] highResolution;
//image
public Rect? scale9Grid;
public bool scaleByTile;
public int tileGridIndice;
public PixelHitTestData pixelHitTestData;
//movieclip
public float interval;
public float repeatDelay;
public bool swing;
public MovieClip.Frame[] frames;
//component
public bool translated;
public UIObjectFactory.GComponentCreator extensionCreator;
//font
public BitmapFont bitmapFont;
//sound
public NAudioClip audioClip;
//spine/dragonbones
public Vector2 skeletonAnchor;
public object skeletonAsset;
public object Load()
{
return owner.GetItemAsset(this);
}
public PackageItem getBranch()
{
if (branches != null && owner._branchIndex != -1)
{
string itemId = branches[owner._branchIndex];
if (itemId != null)
return owner.GetItem(itemId);
}
return this;
}
public PackageItem getHighResolution()
{
if (highResolution != null && GRoot.contentScaleLevel > 0)
{
int i = GRoot.contentScaleLevel - 1;
if (i >= highResolution.Length)
i = highResolution.Length - 1;
string itemId = highResolution[i];
if (itemId != null)
return owner.GetItem(itemId);
}
return this;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: acb6fb5c63e3f49409db871a5a97261b
timeCreated: 1535374215
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,565 @@
using System;
using UnityEngine;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public class PopupMenu : EventDispatcher
{
protected GComponent _contentPane;
protected GList _list;
protected GObject _expandingItem;
PopupMenu _parentMenu;
TimerCallback _showSubMenu;
TimerCallback _closeSubMenu;
EventListener _onPopup;
EventListener _onClose;
public int visibleItemCount;
public bool hideOnClickItem;
public bool autoSize;
const string EVENT_TYPE = "PopupMenuItemClick";
public PopupMenu()
{
Create(null);
}
/// <summary>
///
/// </summary>
/// <param name="resourceURL"></param>
public PopupMenu(string resourceURL)
{
Create(resourceURL);
}
public EventListener onPopup
{
get { return _onPopup ?? (_onPopup = new EventListener(this, "onPopup")); }
}
public EventListener onClose
{
get { return _onClose ?? (_onClose = new EventListener(this, "onClose")); }
}
void Create(string resourceURL)
{
if (resourceURL == null)
{
resourceURL = UIConfig.popupMenu;
if (resourceURL == null)
{
Debug.LogError("FairyGUI: UIConfig.popupMenu not defined");
return;
}
}
_contentPane = UIPackage.CreateObjectFromURL(resourceURL).asCom;
_contentPane.onAddedToStage.Add(__addedToStage);
_contentPane.onRemovedFromStage.Add(__removeFromStage);
_contentPane.focusable = false;
_list = _contentPane.GetChild("list").asList;
_list.RemoveChildrenToPool();
_list.AddRelation(_contentPane, RelationType.Width);
_list.RemoveRelation(_contentPane, RelationType.Height);
_contentPane.AddRelation(_list, RelationType.Height);
_list.onClickItem.Add(__clickItem);
hideOnClickItem = true;
_showSubMenu = __showSubMenu;
_closeSubMenu = CloseSubMenu;
}
/// <summary>
///
/// </summary>
/// <param name="caption"></param>
/// <param name="callback"></param>
/// <returns></returns>
public GButton AddItem(string caption, EventCallback0 callback)
{
GButton item = CreateItem(caption, callback);
_list.AddChild(item);
return item;
}
/// <summary>
///
/// </summary>
/// <param name="caption"></param>
/// <param name="callback"></param>
/// <returns></returns>
public GButton AddItem(string caption, EventCallback1 callback)
{
GButton item = CreateItem(caption, callback);
_list.AddChild(item);
return item;
}
/// <summary>
///
/// </summary>
/// <param name="caption"></param>
/// <param name="index"></param>
/// <param name="callback"></param>
/// <returns></returns>
public GButton AddItemAt(string caption, int index, EventCallback1 callback)
{
GButton item = CreateItem(caption, callback);
_list.AddChildAt(item, index);
return item;
}
/// <summary>
///
/// </summary>
/// <param name="caption"></param>
/// <param name="index"></param>
/// <param name="callback"></param>
/// <returns></returns>
public GButton AddItemAt(string caption, int index, EventCallback0 callback)
{
GButton item = CreateItem(caption, callback);
_list.AddChildAt(item, index);
return item;
}
GButton CreateItem(string caption, Delegate callback)
{
GButton item = _list.GetFromPool(_list.defaultItem).asButton;
item.title = caption;
item.grayed = false;
Controller c = item.GetController("checked");
if (c != null)
c.selectedIndex = 0;
item.RemoveEventListeners(EVENT_TYPE);
if (callback is EventCallback0)
item.AddEventListener(EVENT_TYPE, (EventCallback0)callback);
else
item.AddEventListener(EVENT_TYPE, (EventCallback1)callback);
item.onRollOver.Add(__rollOver);
item.onRollOut.Add(__rollOut);
return item;
}
/// <summary>
///
/// </summary>
public void AddSeperator()
{
AddSeperator(-1);
}
/// <summary>
///
/// </summary>
public void AddSeperator(int index)
{
if (UIConfig.popupMenu_seperator == null)
{
Debug.LogError("FairyGUI: UIConfig.popupMenu_seperator not defined");
return;
}
if (index == -1)
_list.AddItemFromPool(UIConfig.popupMenu_seperator);
else
{
GObject item = _list.GetFromPool(UIConfig.popupMenu_seperator);
_list.AddChildAt(item, index);
}
}
/// <summary>
///
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public string GetItemName(int index)
{
GButton item = _list.GetChildAt(index).asButton;
return item.name;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="caption"></param>
public void SetItemText(string name, string caption)
{
GButton item = _list.GetChild(name).asButton;
item.title = caption;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="visible"></param>
public void SetItemVisible(string name, bool visible)
{
GButton item = _list.GetChild(name).asButton;
if (item.visible != visible)
{
item.visible = visible;
_list.SetBoundsChangedFlag();
}
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="grayed"></param>
public void SetItemGrayed(string name, bool grayed)
{
GButton item = _list.GetChild(name).asButton;
item.grayed = grayed;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="checkable"></param>
public void SetItemCheckable(string name, bool checkable)
{
GButton item = _list.GetChild(name).asButton;
Controller c = item.GetController("checked");
if (c != null)
{
if (checkable)
{
if (c.selectedIndex == 0)
c.selectedIndex = 1;
}
else
c.selectedIndex = 0;
}
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="check"></param>
public void SetItemChecked(string name, bool check)
{
GButton item = _list.GetChild(name).asButton;
Controller c = item.GetController("checked");
if (c != null)
c.selectedIndex = check ? 2 : 1;
}
[Obsolete("Use IsItemChecked instead")]
public bool isItemChecked(string name)
{
return IsItemChecked(name);
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public bool IsItemChecked(string name)
{
GButton item = _list.GetChild(name).asButton;
Controller c = item.GetController("checked");
if (c != null)
return c.selectedIndex == 2;
else
return false;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
public void RemoveItem(string name)
{
GComponent item = _list.GetChild(name).asCom;
if (item != null)
{
item.RemoveEventListeners(EVENT_TYPE);
if (item.data is PopupMenu)
{
((PopupMenu)item.data).Dispose();
item.data = null;
}
int index = _list.GetChildIndex(item);
_list.RemoveChildToPoolAt(index);
}
}
/// <summary>
///
/// </summary>
public void ClearItems()
{
_list.RemoveChildrenToPool();
}
/// <summary>
///
/// </summary>
public int itemCount
{
get { return _list.numChildren; }
}
/// <summary>
///
/// </summary>
public GComponent contentPane
{
get { return _contentPane; }
}
/// <summary>
///
/// </summary>
public GList list
{
get { return _list; }
}
public void Dispose()
{
int cnt = _list.numChildren;
for (int i = 0; i < cnt; i++)
{
GObject obj = _list.GetChildAt(i);
if (obj.data is PopupMenu)
((PopupMenu)obj.data).Dispose();
}
_contentPane.Dispose();
}
/// <summary>
///
/// </summary>
public void Show()
{
Show(null, PopupDirection.Auto);
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
public void Show(GObject target)
{
Show(target, PopupDirection.Auto, null);
}
[Obsolete]
public void Show(GObject target, object downward)
{
Show(target, downward == null ? PopupDirection.Auto : ((bool)downward == true ? PopupDirection.Down : PopupDirection.Up), null);
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <param name="dir"></param>
public void Show(GObject target, PopupDirection dir)
{
Show(target, PopupDirection.Auto, null);
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <param name="dir"></param>
/// <param name="parentMenu"></param>
public void Show(GObject target, PopupDirection dir, PopupMenu parentMenu)
{
GRoot r = target != null ? target.root : GRoot.inst;
r.ShowPopup(this.contentPane, (target is GRoot) ? null : target, dir);
_parentMenu = parentMenu;
}
public void Hide()
{
if (contentPane.parent != null)
((GRoot)contentPane.parent).HidePopup(contentPane);
}
void ShowSubMenu(GObject item)
{
_expandingItem = item;
PopupMenu popup = item.data as PopupMenu;
if (item is GButton)
((GButton)item).selected = true;
popup.Show(item, PopupDirection.Auto, this);
Vector2 pt = contentPane.LocalToRoot(new Vector2(item.x + item.width - 5, item.y - 5), item.root);
popup.contentPane.position = pt;
}
void CloseSubMenu(object param)
{
if (contentPane.isDisposed)
return;
if (_expandingItem == null)
return;
if (_expandingItem is GButton)
((GButton)_expandingItem).selected = false;
PopupMenu popup = (PopupMenu)_expandingItem.data;
if (popup == null)
return;
_expandingItem = null;
popup.Hide();
}
private void __clickItem(EventContext context)
{
GButton item = ((GObject)context.data).asButton;
if (item == null)
return;
if (item.grayed)
{
_list.selectedIndex = -1;
return;
}
Controller c = item.GetController("checked");
if (c != null && c.selectedIndex != 0)
{
if (c.selectedIndex == 1)
c.selectedIndex = 2;
else
c.selectedIndex = 1;
}
if (hideOnClickItem)
{
if (_parentMenu != null)
_parentMenu.Hide();
Hide();
}
item.DispatchEvent(EVENT_TYPE, item); //event data is for backward compatibility
}
void __addedToStage()
{
DispatchEvent("onPopup", null);
if (autoSize)
{
_list.EnsureBoundsCorrect();
int cnt = _list.numChildren;
float maxDelta = -1000;
for (int i = 0; i < cnt; i++)
{
GButton obj = _list.GetChildAt(i).asButton;
if (obj == null)
continue;
GTextField tf = obj.GetTextField();
if (tf != null)
{
float v = tf.textWidth - tf.width;
if (v > maxDelta)
maxDelta = v;
}
}
if (contentPane.width + maxDelta > contentPane.initWidth)
contentPane.width += maxDelta;
else
contentPane.width = contentPane.initWidth;
}
_list.selectedIndex = -1;
_list.ResizeToFit(visibleItemCount > 0 ? visibleItemCount : int.MaxValue, 10);
}
void __removeFromStage()
{
_parentMenu = null;
if (_expandingItem != null)
Timers.inst.Add(0, 1, _closeSubMenu);
DispatchEvent("onClose", null);
}
void __rollOver(EventContext context)
{
GObject item = (GObject)context.sender;
if ((item.data is PopupMenu) || _expandingItem != null)
{
Timers.inst.Add(0.1f, 1, _showSubMenu, item);
}
}
void __showSubMenu(object param)
{
if (contentPane.isDisposed)
return;
GObject item = (GObject)param;
GRoot r = contentPane.root;
if (r == null)
return;
if (_expandingItem != null)
{
if (_expandingItem == item)
return;
CloseSubMenu(null);
}
PopupMenu popup = item.data as PopupMenu;
if (popup == null)
return;
ShowSubMenu(item);
}
void __rollOut(EventContext context)
{
if (_expandingItem == null)
return;
Timers.inst.Remove(_showSubMenu);
GRoot r = contentPane.root;
if (r != null)
{
PopupMenu popup = (PopupMenu)_expandingItem.data;
Vector2 pt = popup.contentPane.GlobalToLocal(context.inputEvent.position);
if (pt.x >= 0 && pt.y >= 0 && pt.x < popup.contentPane.width && pt.y < popup.contentPane.height)
return;
}
CloseSubMenu(null);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: f15a5c9ba9a949d468aeb92e75f70dbd
timeCreated: 1460480288
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,672 @@
using System.Collections.Generic;
using UnityEngine;
using FairyGUI.Utils;
namespace FairyGUI
{
class RelationDef
{
public bool percent;
public RelationType type;
public int axis;
public void copyFrom(RelationDef source)
{
this.percent = source.percent;
this.type = source.type;
this.axis = source.axis;
}
}
class RelationItem
{
GObject _owner;
GObject _target;
List<RelationDef> _defs;
Vector4 _targetData;
public RelationItem(GObject owner)
{
_owner = owner;
_defs = new List<RelationDef>();
}
public GObject target
{
get { return _target; }
set
{
if (_target != value)
{
if (_target != null)
ReleaseRefTarget(_target);
_target = value;
if (_target != null)
AddRefTarget(_target);
}
}
}
public void Add(RelationType relationType, bool usePercent)
{
if (relationType == RelationType.Size)
{
Add(RelationType.Width, usePercent);
Add(RelationType.Height, usePercent);
return;
}
int dc = _defs.Count;
for (int k = 0; k < dc; k++)
{
if (_defs[k].type == relationType)
return;
}
InternalAdd(relationType, usePercent);
}
public void InternalAdd(RelationType relationType, bool usePercent)
{
if (relationType == RelationType.Size)
{
InternalAdd(RelationType.Width, usePercent);
InternalAdd(RelationType.Height, usePercent);
return;
}
RelationDef info = new RelationDef();
info.percent = usePercent;
info.type = relationType;
info.axis = (relationType <= RelationType.Right_Right || relationType == RelationType.Width || relationType >= RelationType.LeftExt_Left && relationType <= RelationType.RightExt_Right) ? 0 : 1;
_defs.Add(info);
}
public void Remove(RelationType relationType)
{
if (relationType == RelationType.Size)
{
Remove(RelationType.Width);
Remove(RelationType.Height);
return;
}
int dc = _defs.Count;
for (int k = 0; k < dc; k++)
{
if (_defs[k].type == relationType)
{
_defs.RemoveAt(k);
break;
}
}
}
public void CopyFrom(RelationItem source)
{
this.target = source.target;
_defs.Clear();
foreach (RelationDef info in source._defs)
{
RelationDef info2 = new RelationDef();
info2.copyFrom(info);
_defs.Add(info2);
}
}
public void Dispose()
{
if (_target != null)
{
ReleaseRefTarget(_target);
_target = null;
}
}
public bool isEmpty
{
get { return _defs.Count == 0; }
}
public void ApplyOnSelfSizeChanged(float dWidth, float dHeight, bool applyPivot)
{
int cnt = _defs.Count;
if (cnt == 0)
return;
float ox = _owner.x;
float oy = _owner.y;
for (int i = 0; i < cnt; i++)
{
RelationDef info = _defs[i];
switch (info.type)
{
case RelationType.Center_Center:
_owner.x -= (0.5f - (applyPivot ? _owner.pivotX : 0)) * dWidth;
break;
case RelationType.Right_Center:
case RelationType.Right_Left:
case RelationType.Right_Right:
_owner.x -= (1 - (applyPivot ? _owner.pivotX : 0)) * dWidth;
break;
case RelationType.Middle_Middle:
_owner.y -= (0.5f - (applyPivot ? _owner.pivotY : 0)) * dHeight;
break;
case RelationType.Bottom_Middle:
case RelationType.Bottom_Top:
case RelationType.Bottom_Bottom:
_owner.y -= (1 - (applyPivot ? _owner.pivotY : 0)) * dHeight;
break;
}
}
if (!Mathf.Approximately(ox, _owner.x) || !Mathf.Approximately(oy, _owner.y))
{
ox = _owner.x - ox;
oy = _owner.y - oy;
_owner.UpdateGearFromRelations(1, ox, oy);
if (_owner.parent != null)
{
int transCount = _owner.parent._transitions.Count;
for (int i = 0; i < transCount; i++)
_owner.parent._transitions[i].UpdateFromRelations(_owner.id, ox, oy);
}
}
}
void ApplyOnXYChanged(RelationDef info, float dx, float dy)
{
float tmp;
switch (info.type)
{
case RelationType.Left_Left:
case RelationType.Left_Center:
case RelationType.Left_Right:
case RelationType.Center_Center:
case RelationType.Right_Left:
case RelationType.Right_Center:
case RelationType.Right_Right:
_owner.x += dx;
break;
case RelationType.Top_Top:
case RelationType.Top_Middle:
case RelationType.Top_Bottom:
case RelationType.Middle_Middle:
case RelationType.Bottom_Top:
case RelationType.Bottom_Middle:
case RelationType.Bottom_Bottom:
_owner.y += dy;
break;
case RelationType.Width:
case RelationType.Height:
break;
case RelationType.LeftExt_Left:
case RelationType.LeftExt_Right:
if (_owner != _target.parent)
{
tmp = _owner.xMin;
_owner.width = _owner._rawWidth - dx;
_owner.xMin = tmp + dx;
}
else
_owner.width = _owner._rawWidth - dx;
break;
case RelationType.RightExt_Left:
case RelationType.RightExt_Right:
if (_owner != _target.parent)
{
tmp = _owner.xMin;
_owner.width = _owner._rawWidth + dx;
_owner.xMin = tmp;
}
else
_owner.width = _owner._rawWidth + dx;
break;
case RelationType.TopExt_Top:
case RelationType.TopExt_Bottom:
if (_owner != _target.parent)
{
tmp = _owner.yMin;
_owner.height = _owner._rawHeight - dy;
_owner.yMin = tmp + dy;
}
else
_owner.height = _owner._rawHeight - dy;
break;
case RelationType.BottomExt_Top:
case RelationType.BottomExt_Bottom:
if (_owner != _target.parent)
{
tmp = _owner.yMin;
_owner.height = _owner._rawHeight + dy;
_owner.yMin = tmp;
}
else
_owner.height = _owner._rawHeight + dy;
break;
}
}
void ApplyOnSizeChanged(RelationDef info)
{
float pos = 0, pivot = 0, delta = 0;
if (info.axis == 0)
{
if (_target != _owner.parent)
{
pos = _target.x;
if (_target.pivotAsAnchor)
pivot = _target.pivotX;
}
if (info.percent)
{
if (_targetData.z != 0)
delta = _target._width / _targetData.z;
}
else
delta = _target._width - _targetData.z;
}
else
{
if (_target != _owner.parent)
{
pos = _target.y;
if (_target.pivotAsAnchor)
pivot = _target.pivotY;
}
if (info.percent)
{
if (_targetData.w != 0)
delta = _target._height / _targetData.w;
}
else
delta = _target._height - _targetData.w;
}
float v, tmp;
switch (info.type)
{
case RelationType.Left_Left:
if (info.percent)
_owner.xMin = pos + (_owner.xMin - pos) * delta;
else if (pivot != 0)
_owner.x += delta * (-pivot);
break;
case RelationType.Left_Center:
if (info.percent)
_owner.xMin = pos + (_owner.xMin - pos) * delta;
else
_owner.x += delta * (0.5f - pivot);
break;
case RelationType.Left_Right:
if (info.percent)
_owner.xMin = pos + (_owner.xMin - pos) * delta;
else
_owner.x += delta * (1 - pivot);
break;
case RelationType.Center_Center:
if (info.percent)
_owner.xMin = pos + (_owner.xMin + _owner._rawWidth * 0.5f - pos) * delta - _owner._rawWidth * 0.5f;
else
_owner.x += delta * (0.5f - pivot);
break;
case RelationType.Right_Left:
if (info.percent)
_owner.xMin = pos + (_owner.xMin + _owner._rawWidth - pos) * delta - _owner._rawWidth;
else if (pivot != 0)
_owner.x += delta * (-pivot);
break;
case RelationType.Right_Center:
if (info.percent)
_owner.xMin = pos + (_owner.xMin + _owner._rawWidth - pos) * delta - _owner._rawWidth;
else
_owner.x += delta * (0.5f - pivot);
break;
case RelationType.Right_Right:
if (info.percent)
_owner.xMin = pos + (_owner.xMin + _owner._rawWidth - pos) * delta - _owner._rawWidth;
else
_owner.x += delta * (1 - pivot);
break;
case RelationType.Top_Top:
if (info.percent)
_owner.yMin = pos + (_owner.yMin - pos) * delta;
else if (pivot != 0)
_owner.y += delta * (-pivot);
break;
case RelationType.Top_Middle:
if (info.percent)
_owner.yMin = pos + (_owner.yMin - pos) * delta;
else
_owner.y += delta * (0.5f - pivot);
break;
case RelationType.Top_Bottom:
if (info.percent)
_owner.yMin = pos + (_owner.yMin - pos) * delta;
else
_owner.y += delta * (1 - pivot);
break;
case RelationType.Middle_Middle:
if (info.percent)
_owner.yMin = pos + (_owner.yMin + _owner._rawHeight * 0.5f - pos) * delta - _owner._rawHeight * 0.5f;
else
_owner.y += delta * (0.5f - pivot);
break;
case RelationType.Bottom_Top:
if (info.percent)
_owner.yMin = pos + (_owner.yMin + _owner._rawHeight - pos) * delta - _owner._rawHeight;
else if (pivot != 0)
_owner.y += delta * (-pivot);
break;
case RelationType.Bottom_Middle:
if (info.percent)
_owner.yMin = pos + (_owner.yMin + _owner._rawHeight - pos) * delta - _owner._rawHeight;
else
_owner.y += delta * (0.5f - pivot);
break;
case RelationType.Bottom_Bottom:
if (info.percent)
_owner.yMin = pos + (_owner.yMin + _owner._rawHeight - pos) * delta - _owner._rawHeight;
else
_owner.y += delta * (1 - pivot);
break;
case RelationType.Width:
if (_owner.underConstruct && _owner == _target.parent)
v = _owner.sourceWidth - _target.initWidth;
else
v = _owner._rawWidth - _targetData.z;
if (info.percent)
v = v * delta;
if (_target == _owner.parent)
{
if (_owner.pivotAsAnchor)
{
tmp = _owner.xMin;
_owner.SetSize(_target._width + v, _owner._rawHeight, true);
_owner.xMin = tmp;
}
else
_owner.SetSize(_target._width + v, _owner._rawHeight, true);
}
else
_owner.width = _target._width + v;
break;
case RelationType.Height:
if (_owner.underConstruct && _owner == _target.parent)
v = _owner.sourceHeight - _target.initHeight;
else
v = _owner._rawHeight - _targetData.w;
if (info.percent)
v = v * delta;
if (_target == _owner.parent)
{
if (_owner.pivotAsAnchor)
{
tmp = _owner.yMin;
_owner.SetSize(_owner._rawWidth, _target._height + v, true);
_owner.yMin = tmp;
}
else
_owner.SetSize(_owner._rawWidth, _target._height + v, true);
}
else
_owner.height = _target._height + v;
break;
case RelationType.LeftExt_Left:
tmp = _owner.xMin;
if (info.percent)
v = pos + (tmp - pos) * delta - tmp;
else
v = delta * (-pivot);
_owner.width = _owner._rawWidth - v;
_owner.xMin = tmp + v;
break;
case RelationType.LeftExt_Right:
tmp = _owner.xMin;
if (info.percent)
v = pos + (tmp - pos) * delta - tmp;
else
v = delta * (1 - pivot);
_owner.width = _owner._rawWidth - v;
_owner.xMin = tmp + v;
break;
case RelationType.RightExt_Left:
tmp = _owner.xMin;
if (info.percent)
v = pos + (tmp + _owner._rawWidth - pos) * delta - (tmp + _owner._rawWidth);
else
v = delta * (-pivot);
_owner.width = _owner._rawWidth + v;
_owner.xMin = tmp;
break;
case RelationType.RightExt_Right:
tmp = _owner.xMin;
if (info.percent)
{
if (_owner == _target.parent)
{
if (_owner.underConstruct)
_owner.width = pos + _target._width - _target._width * pivot +
(_owner.sourceWidth - pos - _target.initWidth + _target.initWidth * pivot) * delta;
else
_owner.width = pos + (_owner._rawWidth - pos) * delta;
}
else
{
v = pos + (tmp + _owner._rawWidth - pos) * delta - (tmp + _owner._rawWidth);
_owner.width = _owner._rawWidth + v;
_owner.xMin = tmp;
}
}
else
{
if (_owner == _target.parent)
{
if (_owner.underConstruct)
_owner.width = _owner.sourceWidth + (_target._width - _target.initWidth) * (1 - pivot);
else
_owner.width = _owner._rawWidth + delta * (1 - pivot);
}
else
{
v = delta * (1 - pivot);
_owner.width = _owner._rawWidth + v;
_owner.xMin = tmp;
}
}
break;
case RelationType.TopExt_Top:
tmp = _owner.yMin;
if (info.percent)
v = pos + (tmp - pos) * delta - tmp;
else
v = delta * (-pivot);
_owner.height = _owner._rawHeight - v;
_owner.yMin = tmp + v;
break;
case RelationType.TopExt_Bottom:
tmp = _owner.yMin;
if (info.percent)
v = pos + (tmp - pos) * delta - tmp;
else
v = delta * (1 - pivot);
_owner.height = _owner._rawHeight - v;
_owner.yMin = tmp + v;
break;
case RelationType.BottomExt_Top:
tmp = _owner.yMin;
if (info.percent)
v = pos + (tmp + _owner._rawHeight - pos) * delta - (tmp + _owner._rawHeight);
else
v = delta * (-pivot);
_owner.height = _owner._rawHeight + v;
_owner.yMin = tmp;
break;
case RelationType.BottomExt_Bottom:
tmp = _owner.yMin;
if (info.percent)
{
if (_owner == _target.parent)
{
if (_owner.underConstruct)
_owner.height = pos + _target._height - _target._height * pivot +
(_owner.sourceHeight - pos - _target.initHeight + _target.initHeight * pivot) * delta;
else
_owner.height = pos + (_owner._rawHeight - pos) * delta;
}
else
{
v = pos + (tmp + _owner._rawHeight - pos) * delta - (tmp + _owner._rawHeight);
_owner.height = _owner._rawHeight + v;
_owner.yMin = tmp;
}
}
else
{
if (_owner == _target.parent)
{
if (_owner.underConstruct)
_owner.height = _owner.sourceHeight + (_target._height - _target.initHeight) * (1 - pivot);
else
_owner.height = _owner._rawHeight + delta * (1 - pivot);
}
else
{
v = delta * (1 - pivot);
_owner.height = _owner._rawHeight + v;
_owner.yMin = tmp;
}
}
break;
}
}
void AddRefTarget(GObject target)
{
if (target != _owner.parent)
target.onPositionChanged.Add(__targetXYChanged);
target.onSizeChanged.Add(__targetSizeChanged);
_targetData.x = _target.x;
_targetData.y = _target.y;
_targetData.z = _target._width;
_targetData.w = _target._height;
}
void ReleaseRefTarget(GObject target)
{
target.onPositionChanged.Remove(__targetXYChanged);
target.onSizeChanged.Remove(__targetSizeChanged);
}
void __targetXYChanged(EventContext context)
{
if (_owner.relations.handling != null
|| _owner.group != null && _owner.group._updating != 0)
{
_targetData.x = _target.x;
_targetData.y = _target.y;
return;
}
_owner.relations.handling = (GObject)context.sender;
float ox = _owner.x;
float oy = _owner.y;
float dx = _target.x - _targetData.x;
float dy = _target.y - _targetData.y;
int cnt = _defs.Count;
for (int i = 0; i < cnt; i++)
ApplyOnXYChanged(_defs[i], dx, dy);
_targetData.x = _target.x;
_targetData.y = _target.y;
if (!Mathf.Approximately(ox, _owner.x) || !Mathf.Approximately(oy, _owner.y))
{
ox = _owner.x - ox;
oy = _owner.y - oy;
_owner.UpdateGearFromRelations(1, ox, oy);
if (_owner.parent != null)
{
int transCount = _owner.parent._transitions.Count;
for (int i = 0; i < transCount; i++)
_owner.parent._transitions[i].UpdateFromRelations(_owner.id, ox, oy);
}
}
_owner.relations.handling = null;
}
void __targetSizeChanged(EventContext context)
{
if (_owner.relations.handling != null
|| _owner.group != null && _owner.group._updating != 0)
{
_targetData.z = _target._width;
_targetData.w = _target._height;
return;
}
_owner.relations.handling = (GObject)context.sender;
float ox = _owner.x;
float oy = _owner.y;
float ow = _owner._rawWidth;
float oh = _owner._rawHeight;
int cnt = _defs.Count;
for (int i = 0; i < cnt; i++)
ApplyOnSizeChanged(_defs[i]);
_targetData.z = _target._width;
_targetData.w = _target._height;
if (!Mathf.Approximately(ox, _owner.x) || !Mathf.Approximately(oy, _owner.y))
{
ox = _owner.x - ox;
oy = _owner.y - oy;
_owner.UpdateGearFromRelations(1, ox, oy);
if (_owner.parent != null)
{
int transCount = _owner.parent._transitions.Count;
for (int i = 0; i < transCount; i++)
_owner.parent._transitions[i].UpdateFromRelations(_owner.id, ox, oy);
}
}
if (!Mathf.Approximately(ow, _owner._rawWidth) || !Mathf.Approximately(oh, _owner._rawHeight))
{
ow = _owner._rawWidth - ow;
oh = _owner._rawHeight - oh;
_owner.UpdateGearFromRelations(2, ow, oh);
}
_owner.relations.handling = null;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 859441fdd74333a498ff048e6b48798b
timeCreated: 1460480288
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,220 @@
using System;
using System.Collections.Generic;
using FairyGUI.Utils;
namespace FairyGUI
{
/// <summary>
///
/// </summary>
public class Relations
{
GObject _owner;
List<RelationItem> _items;
public GObject handling;
public Relations(GObject owner)
{
_owner = owner;
_items = new List<RelationItem>();
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <param name="relationType"></param>
public void Add(GObject target, RelationType relationType)
{
Add(target, relationType, false);
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <param name="relationType"></param>
/// <param name="usePercent"></param>
public void Add(GObject target, RelationType relationType, bool usePercent)
{
int cnt = _items.Count;
for (int i = 0; i < cnt; i++)
{
RelationItem item = _items[i];
if (item.target == target)
{
item.Add(relationType, usePercent);
return;
}
}
RelationItem newItem = new RelationItem(_owner);
newItem.target = target;
newItem.Add(relationType, usePercent);
_items.Add(newItem);
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <param name="relationType"></param>
public void Remove(GObject target, RelationType relationType)
{
int cnt = _items.Count;
int i = 0;
while (i < cnt)
{
RelationItem item = _items[i];
if (item.target == target)
{
item.Remove(relationType);
if (item.isEmpty)
{
item.Dispose();
_items.RemoveAt(i);
cnt--;
continue;
}
else
i++;
}
i++;
}
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public bool Contains(GObject target)
{
int cnt = _items.Count;
for (int i = 0; i < cnt; i++)
{
RelationItem item = _items[i];
if (item.target == target)
return true;
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
public void ClearFor(GObject target)
{
int cnt = _items.Count;
int i = 0;
while (i < cnt)
{
RelationItem item = _items[i];
if (item.target == target)
{
item.Dispose();
_items.RemoveAt(i);
cnt--;
}
else
i++;
}
}
/// <summary>
///
/// </summary>
public void ClearAll()
{
int cnt = _items.Count;
for (int i = 0; i < cnt; i++)
{
RelationItem item = _items[i];
item.Dispose();
}
_items.Clear();
}
/// <summary>
///
/// </summary>
/// <param name="source"></param>
public void CopyFrom(Relations source)
{
ClearAll();
List<RelationItem> arr = source._items;
foreach (RelationItem ri in arr)
{
RelationItem item = new RelationItem(_owner);
item.CopyFrom(ri);
_items.Add(item);
}
}
/// <summary>
///
/// </summary>
public void Dispose()
{
ClearAll();
handling = null;
}
/// <summary>
///
/// </summary>
/// <param name="dWidth"></param>
/// <param name="dHeight"></param>
/// <param name="applyPivot"></param>
public void OnOwnerSizeChanged(float dWidth, float dHeight, bool applyPivot)
{
int cnt = _items.Count;
if (cnt == 0)
return;
for (int i = 0; i < cnt; i++)
_items[i].ApplyOnSelfSizeChanged(dWidth, dHeight, applyPivot);
}
/// <summary>
///
/// </summary>
public bool isEmpty
{
get
{
return _items.Count == 0;
}
}
public void Setup(ByteBuffer buffer, bool parentToChild)
{
int cnt = buffer.ReadByte();
GObject target;
for (int i = 0; i < cnt; i++)
{
int targetIndex = buffer.ReadShort();
if (targetIndex == -1)
target = _owner.parent;
else if (parentToChild)
target = ((GComponent)_owner).GetChildAt(targetIndex);
else
target = _owner.parent.GetChildAt(targetIndex);
RelationItem newItem = new RelationItem(_owner);
newItem.target = target;
_items.Add(newItem);
int cnt2 = buffer.ReadByte();
for (int j = 0; j < cnt2; j++)
{
RelationType rt = (RelationType)buffer.ReadByte();
bool usePercent = buffer.ReadBool();
newItem.InternalAdd(rt, usePercent);
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 4376a9406aa478a4b82816818842d737
timeCreated: 1535374214
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More