修改调整
This commit is contained in:
8
Assets/Plugins/FairyGUI.meta
Normal file
8
Assets/Plugins/FairyGUI.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5af0671c5d1d6af44aa29e82ab32d444
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Plugins/FairyGUI/Editor.meta
Normal file
8
Assets/Plugins/FairyGUI/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8d62b02f274ce4253af1ef45831279e3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fd0c51d2146977c4aa7ab34e712a863d
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446193142
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Bag.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Bag.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 458c4ffa8748140419a56ce3d93de74a
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446625368
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
36
Assets/Plugins/FairyGUI/Examples/Bag/BagMain.cs
Normal file
36
Assets/Plugins/FairyGUI/Examples/Bag/BagMain.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A game bag demo, demonstrated how to customize loader to load icons not in the UI package.
|
||||||
|
/// </summary>
|
||||||
|
public class BagMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
BagWindow _bagWindow;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
//Register custom loader class
|
||||||
|
UIObjectFactory.SetLoaderExtension(typeof(MyGLoader));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
GRoot.inst.SetContentScaleFactor(1136, 640);
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_bagWindow = new BagWindow();
|
||||||
|
_mainView.GetChild("bagBtn").onClick.Add(() => { _bagWindow.Show(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Bag/BagMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Bag/BagMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 72adad54c37cc25499988e9b785d5b90
|
||||||
|
timeCreated: 1446194671
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
49
Assets/Plugins/FairyGUI/Examples/Bag/BagWindow.cs
Normal file
49
Assets/Plugins/FairyGUI/Examples/Bag/BagWindow.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using FairyGUI;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class BagWindow : Window
|
||||||
|
{
|
||||||
|
GList _list;
|
||||||
|
|
||||||
|
public BagWindow()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnInit()
|
||||||
|
{
|
||||||
|
this.contentPane = UIPackage.CreateObject("Bag", "BagWin").asCom;
|
||||||
|
this.Center();
|
||||||
|
this.modal = true;
|
||||||
|
|
||||||
|
_list = this.contentPane.GetChild("list").asList;
|
||||||
|
_list.onClickItem.Add(__clickItem);
|
||||||
|
_list.itemRenderer = RenderListItem;
|
||||||
|
_list.numItems = 45;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderListItem(int index, GObject obj)
|
||||||
|
{
|
||||||
|
GButton button = (GButton)obj;
|
||||||
|
button.icon = "i" + UnityEngine.Random.Range(0, 10);
|
||||||
|
button.title = "" + UnityEngine.Random.Range(0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected void DoShowAnimation()
|
||||||
|
{
|
||||||
|
this.SetScale(0.1f, 0.1f);
|
||||||
|
this.SetPivot(0.5f, 0.5f);
|
||||||
|
this.TweenScale(new Vector2(1, 1), 0.3f).OnComplete(this.OnShown);
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected void DoHideAnimation()
|
||||||
|
{
|
||||||
|
this.TweenScale(new Vector2(0.1f, 0.1f), 0.3f).OnComplete(this.HideImmediately);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __clickItem(EventContext context)
|
||||||
|
{
|
||||||
|
GButton item = (GButton)context.data;
|
||||||
|
this.contentPane.GetChild("n11").asLoader.url = item.icon;
|
||||||
|
this.contentPane.GetChild("n13").text = item.icon;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Bag/BagWindow.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Bag/BagWindow.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 418d0818f0209ee42938610bc6cb82be
|
||||||
|
timeCreated: 1446193148
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
188
Assets/Plugins/FairyGUI/Examples/Bag/IconManager.cs
Normal file
188
Assets/Plugins/FairyGUI/Examples/Bag/IconManager.cs
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using FairyGUI;
|
||||||
|
#if UNITY_5_4_OR_NEWER
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public delegate void LoadCompleteCallback(NTexture texture);
|
||||||
|
public delegate void LoadErrorCallback(string error);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use to load icons from asset bundle, and pool them
|
||||||
|
/// </summary>
|
||||||
|
public class IconManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
static IconManager _instance;
|
||||||
|
public static IconManager inst
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
GameObject go = new GameObject("IconManager");
|
||||||
|
DontDestroyOnLoad(go);
|
||||||
|
_instance = go.AddComponent<IconManager>();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public const int POOL_CHECK_TIME = 30;
|
||||||
|
public const int MAX_POOL_SIZE = 10;
|
||||||
|
|
||||||
|
List<LoadItem> _items;
|
||||||
|
bool _started;
|
||||||
|
Hashtable _pool;
|
||||||
|
string _basePath;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
_items = new List<LoadItem>();
|
||||||
|
_pool = new Hashtable();
|
||||||
|
_basePath = Application.streamingAssetsPath.Replace("\\", "/") + "/fairygui-examples/";
|
||||||
|
if (Application.platform != RuntimePlatform.Android)
|
||||||
|
_basePath = "file:///" + _basePath;
|
||||||
|
|
||||||
|
StartCoroutine(FreeIdleIcons());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadIcon(string url,
|
||||||
|
LoadCompleteCallback onSuccess,
|
||||||
|
LoadErrorCallback onFail)
|
||||||
|
{
|
||||||
|
LoadItem item = new LoadItem();
|
||||||
|
item.url = url;
|
||||||
|
item.onSuccess = onSuccess;
|
||||||
|
item.onFail = onFail;
|
||||||
|
_items.Add(item);
|
||||||
|
if (!_started)
|
||||||
|
StartCoroutine(Run());
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator Run()
|
||||||
|
{
|
||||||
|
_started = true;
|
||||||
|
|
||||||
|
LoadItem item = null;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (_items.Count > 0)
|
||||||
|
{
|
||||||
|
item = _items[0];
|
||||||
|
_items.RemoveAt(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (_pool.ContainsKey(item.url))
|
||||||
|
{
|
||||||
|
//Debug.Log("hit " + item.url);
|
||||||
|
|
||||||
|
NTexture texture = (NTexture)_pool[item.url];
|
||||||
|
texture.refCount++;
|
||||||
|
|
||||||
|
if (item.onSuccess != null)
|
||||||
|
item.onSuccess(texture);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string url = _basePath + item.url + ".ab";
|
||||||
|
#if UNITY_2017_2_OR_NEWER
|
||||||
|
#if UNITY_2018_1_OR_NEWER
|
||||||
|
UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url);
|
||||||
|
#else
|
||||||
|
UnityWebRequest www = UnityWebRequest.GetAssetBundle(url);
|
||||||
|
#endif
|
||||||
|
yield return www.SendWebRequest();
|
||||||
|
|
||||||
|
#if UNITY_2020_2_OR_NEWER
|
||||||
|
if (www.result == UnityWebRequest.Result.Success)
|
||||||
|
#else
|
||||||
|
if (!www.isNetworkError && !www.isHttpError)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
|
||||||
|
#else
|
||||||
|
WWW www = new WWW(url);
|
||||||
|
yield return www;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(www.error))
|
||||||
|
{
|
||||||
|
AssetBundle bundle = www.assetBundle;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (bundle == null)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("Run Window->Build FairyGUI example Bundles first.");
|
||||||
|
if (item.onFail != null)
|
||||||
|
item.onFail(www.error);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#if (UNITY_5 || UNITY_5_3_OR_NEWER)
|
||||||
|
NTexture texture = new NTexture(bundle.LoadAllAssets<Texture2D>()[0]);
|
||||||
|
#else
|
||||||
|
NTexture texture = new NTexture((Texture2D)bundle.mainAsset);
|
||||||
|
#endif
|
||||||
|
texture.refCount++;
|
||||||
|
bundle.Unload(false);
|
||||||
|
|
||||||
|
_pool[item.url] = texture;
|
||||||
|
|
||||||
|
if (item.onSuccess != null)
|
||||||
|
item.onSuccess(texture);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (item.onFail != null)
|
||||||
|
item.onFail(www.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_started = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator FreeIdleIcons()
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(POOL_CHECK_TIME); //check the pool every 30 seconds
|
||||||
|
|
||||||
|
int cnt = _pool.Count;
|
||||||
|
if (cnt > MAX_POOL_SIZE)
|
||||||
|
{
|
||||||
|
ArrayList toRemove = null;
|
||||||
|
foreach (DictionaryEntry de in _pool)
|
||||||
|
{
|
||||||
|
string key = (string)de.Key;
|
||||||
|
NTexture texture = (NTexture)de.Value;
|
||||||
|
if (texture.refCount == 0)
|
||||||
|
{
|
||||||
|
if (toRemove == null)
|
||||||
|
toRemove = new ArrayList();
|
||||||
|
toRemove.Add(key);
|
||||||
|
texture.Dispose();
|
||||||
|
|
||||||
|
//Debug.Log("free icon " + de.Key);
|
||||||
|
|
||||||
|
cnt--;
|
||||||
|
if (cnt <= 8)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toRemove != null)
|
||||||
|
{
|
||||||
|
foreach (string key in toRemove)
|
||||||
|
_pool.Remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadItem
|
||||||
|
{
|
||||||
|
public string url;
|
||||||
|
public LoadCompleteCallback onSuccess;
|
||||||
|
public LoadErrorCallback onFail;
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Bag/IconManager.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Bag/IconManager.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b5725e4855896724d9bdeb29c68c6c92
|
||||||
|
timeCreated: 1446193148
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
33
Assets/Plugins/FairyGUI/Examples/Bag/MyGLoader.cs
Normal file
33
Assets/Plugins/FairyGUI/Examples/Bag/MyGLoader.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extend the ability of GLoader
|
||||||
|
/// </summary>
|
||||||
|
public class MyGLoader : GLoader
|
||||||
|
{
|
||||||
|
protected override void LoadExternal()
|
||||||
|
{
|
||||||
|
IconManager.inst.LoadIcon(this.url, OnLoadSuccess, OnLoadFail);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void FreeExternal(NTexture texture)
|
||||||
|
{
|
||||||
|
texture.refCount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnLoadSuccess(NTexture texture)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(this.url))
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.onExternalLoadSuccess(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnLoadFail(string error)
|
||||||
|
{
|
||||||
|
Debug.Log("load " + this.url + " failed: " + error);
|
||||||
|
this.onExternalLoadFailed();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Bag/MyGLoader.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Bag/MyGLoader.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ca2c5718cae50694a8291cc372ad458d
|
||||||
|
timeCreated: 1446193148
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Basics.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Basics.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7afac4ff0289dac479c37c0cbf60f745
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446194671
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
441
Assets/Plugins/FairyGUI/Examples/Basics/BasicsMain.cs
Normal file
441
Assets/Plugins/FairyGUI/Examples/Basics/BasicsMain.cs
Normal file
@@ -0,0 +1,441 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class BasicsMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
private GComponent _mainView;
|
||||||
|
private GObject _backBtn;
|
||||||
|
private GComponent _demoContainer;
|
||||||
|
private Controller _viewController;
|
||||||
|
private Dictionary<string, GComponent> _demoObjects;
|
||||||
|
|
||||||
|
public Gradient lineGradient;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
#if (UNITY_5 || UNITY_5_3_OR_NEWER)
|
||||||
|
//Use the font names directly
|
||||||
|
UIConfig.defaultFont = "Microsoft YaHei";
|
||||||
|
#else
|
||||||
|
//Need to put a ttf file into Resources folder. Here is the file name of the ttf file.
|
||||||
|
UIConfig.defaultFont = "afont";
|
||||||
|
#endif
|
||||||
|
UIPackage.AddPackage("UI/Basics");
|
||||||
|
|
||||||
|
UIConfig.verticalScrollBar = "ui://Basics/ScrollBar_VT";
|
||||||
|
UIConfig.horizontalScrollBar = "ui://Basics/ScrollBar_HZ";
|
||||||
|
UIConfig.popupMenu = "ui://Basics/PopupMenu";
|
||||||
|
UIConfig.buttonSound = (NAudioClip)UIPackage.GetItemAsset("Basics", "click");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_backBtn = _mainView.GetChild("btn_Back");
|
||||||
|
_backBtn.visible = false;
|
||||||
|
_backBtn.onClick.Add(onClickBack);
|
||||||
|
|
||||||
|
_demoContainer = _mainView.GetChild("container").asCom;
|
||||||
|
_viewController = _mainView.GetController("c1");
|
||||||
|
|
||||||
|
_demoObjects = new Dictionary<string, GComponent>();
|
||||||
|
|
||||||
|
int cnt = _mainView.numChildren;
|
||||||
|
for (int i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
GObject obj = _mainView.GetChildAt(i);
|
||||||
|
if (obj.group != null && obj.group.name == "btns")
|
||||||
|
obj.onClick.Add(runDemo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runDemo(EventContext context)
|
||||||
|
{
|
||||||
|
string type = ((GObject)(context.sender)).name.Substring(4);
|
||||||
|
GComponent obj;
|
||||||
|
if (!_demoObjects.TryGetValue(type, out obj))
|
||||||
|
{
|
||||||
|
obj = UIPackage.CreateObject("Basics", "Demo_" + type).asCom;
|
||||||
|
_demoObjects[type] = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
_demoContainer.RemoveChildren();
|
||||||
|
_demoContainer.AddChild(obj);
|
||||||
|
_viewController.selectedIndex = 1;
|
||||||
|
_backBtn.visible = true;
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case "Graph":
|
||||||
|
PlayGraph();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Button":
|
||||||
|
PlayButton();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Text":
|
||||||
|
PlayText();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Grid":
|
||||||
|
PlayGrid();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Transition":
|
||||||
|
PlayTransition();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Window":
|
||||||
|
PlayWindow();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Popup":
|
||||||
|
PlayPopup();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Drag&Drop":
|
||||||
|
PlayDragDrop();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Depth":
|
||||||
|
PlayDepth();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "ProgressBar":
|
||||||
|
PlayProgressBar();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onClickBack()
|
||||||
|
{
|
||||||
|
_viewController.selectedIndex = 0;
|
||||||
|
_backBtn.visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------
|
||||||
|
private void PlayGraph()
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["Graph"];
|
||||||
|
|
||||||
|
Shape shape;
|
||||||
|
|
||||||
|
shape = obj.GetChild("pie").asGraph.shape;
|
||||||
|
EllipseMesh ellipse = shape.graphics.GetMeshFactory<EllipseMesh>();
|
||||||
|
ellipse.startDegree = 30;
|
||||||
|
ellipse.endDegreee = 300;
|
||||||
|
shape.graphics.SetMeshDirty();
|
||||||
|
|
||||||
|
shape = obj.GetChild("trapezoid").asGraph.shape;
|
||||||
|
PolygonMesh trapezoid = shape.graphics.GetMeshFactory<PolygonMesh>();
|
||||||
|
trapezoid.usePercentPositions = true;
|
||||||
|
trapezoid.points.Clear();
|
||||||
|
trapezoid.points.Add(new Vector2(0f, 1f));
|
||||||
|
trapezoid.points.Add(new Vector2(0.3f, 0));
|
||||||
|
trapezoid.points.Add(new Vector2(0.7f, 0));
|
||||||
|
trapezoid.points.Add(new Vector2(1f, 1f));
|
||||||
|
trapezoid.texcoords.Clear();
|
||||||
|
trapezoid.texcoords.AddRange(VertexBuffer.NormalizedUV);
|
||||||
|
shape.graphics.SetMeshDirty();
|
||||||
|
shape.graphics.texture = (NTexture)UIPackage.GetItemAsset("Basics", "change");
|
||||||
|
|
||||||
|
shape = obj.GetChild("line").asGraph.shape;
|
||||||
|
LineMesh line = shape.graphics.GetMeshFactory<LineMesh>();
|
||||||
|
line.lineWidthCurve = AnimationCurve.Linear(0, 25, 1, 10);
|
||||||
|
line.roundEdge = true;
|
||||||
|
line.gradient = lineGradient;
|
||||||
|
line.path.Create(new GPathPoint[] {
|
||||||
|
new GPathPoint(new Vector3(0, 120, 0)),
|
||||||
|
new GPathPoint(new Vector3(20, 120, 0)),
|
||||||
|
new GPathPoint(new Vector3(100, 100, 0)),
|
||||||
|
new GPathPoint(new Vector3(180, 30, 0)),
|
||||||
|
new GPathPoint(new Vector3(100, 0, 0)),
|
||||||
|
new GPathPoint(new Vector3(20, 30, 0)),
|
||||||
|
new GPathPoint(new Vector3(100, 100, 0)),
|
||||||
|
new GPathPoint(new Vector3(180, 120, 0)),
|
||||||
|
new GPathPoint(new Vector3(200, 120, 0)),
|
||||||
|
});
|
||||||
|
shape.graphics.SetMeshDirty();
|
||||||
|
GTween.To(0, 1, 5).SetEase(EaseType.Linear).SetTarget(shape.graphics).OnUpdate((GTweener t) =>
|
||||||
|
{
|
||||||
|
((NGraphics)t.target).GetMeshFactory<LineMesh>().fillEnd = t.value.x;
|
||||||
|
((NGraphics)t.target).SetMeshDirty();
|
||||||
|
});
|
||||||
|
|
||||||
|
shape = obj.GetChild("line2").asGraph.shape;
|
||||||
|
LineMesh line2 = shape.graphics.GetMeshFactory<LineMesh>();
|
||||||
|
line2.lineWidth = 3;
|
||||||
|
line2.roundEdge = true;
|
||||||
|
line2.path.Create(new GPathPoint[] {
|
||||||
|
new GPathPoint(new Vector3(0, 120, 0), GPathPoint.CurveType.Straight),
|
||||||
|
new GPathPoint(new Vector3(60, 30, 0), GPathPoint.CurveType.Straight),
|
||||||
|
new GPathPoint(new Vector3(80, 90, 0), GPathPoint.CurveType.Straight),
|
||||||
|
new GPathPoint(new Vector3(140, 30, 0), GPathPoint.CurveType.Straight),
|
||||||
|
new GPathPoint(new Vector3(160, 90, 0), GPathPoint.CurveType.Straight),
|
||||||
|
new GPathPoint(new Vector3(220, 30, 0), GPathPoint.CurveType.Straight)
|
||||||
|
});
|
||||||
|
shape.graphics.SetMeshDirty();
|
||||||
|
|
||||||
|
GObject image = obj.GetChild("line3");
|
||||||
|
LineMesh line3 = image.displayObject.graphics.GetMeshFactory<LineMesh>();
|
||||||
|
line3.lineWidth = 30;
|
||||||
|
line3.roundEdge = false;
|
||||||
|
line3.path.Create(new GPathPoint[] {
|
||||||
|
new GPathPoint(new Vector3(0, 30, 0), new Vector3(50, -30), new Vector3(150, -50)),
|
||||||
|
new GPathPoint(new Vector3(200, 30, 0), new Vector3(300, 130)),
|
||||||
|
new GPathPoint(new Vector3(400, 30, 0))
|
||||||
|
});
|
||||||
|
image.displayObject.graphics.SetMeshDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------
|
||||||
|
private void PlayButton()
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["Button"];
|
||||||
|
obj.GetChild("n34").onClick.Add(() => { UnityEngine.Debug.Log("click button"); });
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
private void PlayText()
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["Text"];
|
||||||
|
obj.GetChild("n12").asRichTextField.onClickLink.Add((EventContext context) =>
|
||||||
|
{
|
||||||
|
GRichTextField t = context.sender as GRichTextField;
|
||||||
|
t.text = "[img]ui://Basics/pet[/img][color=#FF0000]You click the link[/color]:" + context.data;
|
||||||
|
});
|
||||||
|
obj.GetChild("n25").onClick.Add(() =>
|
||||||
|
{
|
||||||
|
obj.GetChild("n24").text = obj.GetChild("n22").text;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
private void PlayGrid()
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["Grid"];
|
||||||
|
GList list1 = obj.GetChild("list1").asList;
|
||||||
|
list1.RemoveChildrenToPool();
|
||||||
|
string[] testNames = System.Enum.GetNames(typeof(RuntimePlatform));
|
||||||
|
Color[] testColor = new Color[] { Color.yellow, Color.red, Color.white, Color.cyan };
|
||||||
|
int cnt = testNames.Length;
|
||||||
|
for (int i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
GButton item = list1.AddItemFromPool().asButton;
|
||||||
|
item.GetChild("t0").text = "" + (i + 1);
|
||||||
|
item.GetChild("t1").text = testNames[i];
|
||||||
|
item.GetChild("t2").asTextField.color = testColor[UnityEngine.Random.Range(0, 4)];
|
||||||
|
item.GetChild("star").asProgress.value = (int)((float)UnityEngine.Random.Range(1, 4) / 3f * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
GList list2 = obj.GetChild("list2").asList;
|
||||||
|
list2.RemoveChildrenToPool();
|
||||||
|
for (int i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
GButton item = list2.AddItemFromPool().asButton;
|
||||||
|
item.GetChild("cb").asButton.selected = false;
|
||||||
|
item.GetChild("t1").text = testNames[i];
|
||||||
|
item.GetChild("mc").asMovieClip.playing = i % 2 == 0;
|
||||||
|
item.GetChild("t3").text = "" + UnityEngine.Random.Range(0, 10000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
private void PlayTransition()
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["Transition"];
|
||||||
|
obj.GetChild("n2").asCom.GetTransition("t0").Play(int.MaxValue, 0, null);
|
||||||
|
obj.GetChild("n3").asCom.GetTransition("peng").Play(int.MaxValue, 0, null);
|
||||||
|
|
||||||
|
obj.onAddedToStage.Add(() =>
|
||||||
|
{
|
||||||
|
obj.GetChild("n2").asCom.GetTransition("t0").Stop();
|
||||||
|
obj.GetChild("n3").asCom.GetTransition("peng").Stop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
private Window _winA;
|
||||||
|
private Window _winB;
|
||||||
|
private void PlayWindow()
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["Window"];
|
||||||
|
obj.GetChild("n0").onClick.Add(() =>
|
||||||
|
{
|
||||||
|
if (_winA == null)
|
||||||
|
_winA = new Window1();
|
||||||
|
_winA.Show();
|
||||||
|
});
|
||||||
|
|
||||||
|
obj.GetChild("n1").onClick.Add(() =>
|
||||||
|
{
|
||||||
|
if (_winB == null)
|
||||||
|
_winB = new Window2();
|
||||||
|
_winB.Show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
private PopupMenu _pm;
|
||||||
|
private GComponent _popupCom;
|
||||||
|
private void PlayPopup()
|
||||||
|
{
|
||||||
|
if (_pm == null)
|
||||||
|
{
|
||||||
|
_pm = new PopupMenu();
|
||||||
|
_pm.AddItem("Item 1", __clickMenu);
|
||||||
|
_pm.AddItem("Item 2", __clickMenu);
|
||||||
|
_pm.AddItem("Item 3", __clickMenu);
|
||||||
|
_pm.AddItem("Item 4", __clickMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_popupCom == null)
|
||||||
|
{
|
||||||
|
_popupCom = UIPackage.CreateObject("Basics", "Component12").asCom;
|
||||||
|
_popupCom.Center();
|
||||||
|
}
|
||||||
|
GComponent obj = _demoObjects["Popup"];
|
||||||
|
obj.GetChild("n0").onClick.Add((EventContext context) =>
|
||||||
|
{
|
||||||
|
_pm.Show((GObject)context.sender, PopupDirection.Down);
|
||||||
|
});
|
||||||
|
|
||||||
|
obj.GetChild("n1").onClick.Add(() =>
|
||||||
|
{
|
||||||
|
GRoot.inst.ShowPopup(_popupCom);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
obj.onRightClick.Add(() =>
|
||||||
|
{
|
||||||
|
_pm.Show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void __clickMenu(EventContext context)
|
||||||
|
{
|
||||||
|
GObject itemObject = (GObject)context.data;
|
||||||
|
UnityEngine.Debug.Log("click " + itemObject.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
Vector2 startPos;
|
||||||
|
private void PlayDepth()
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["Depth"];
|
||||||
|
GComponent testContainer = obj.GetChild("n22").asCom;
|
||||||
|
GObject fixedObj = testContainer.GetChild("n0");
|
||||||
|
fixedObj.sortingOrder = 100;
|
||||||
|
fixedObj.draggable = true;
|
||||||
|
|
||||||
|
int numChildren = testContainer.numChildren;
|
||||||
|
int i = 0;
|
||||||
|
while (i < numChildren)
|
||||||
|
{
|
||||||
|
GObject child = testContainer.GetChildAt(i);
|
||||||
|
if (child != fixedObj)
|
||||||
|
{
|
||||||
|
testContainer.RemoveChildAt(i);
|
||||||
|
numChildren--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
startPos = new Vector2(fixedObj.x, fixedObj.y);
|
||||||
|
|
||||||
|
obj.GetChild("btn0").onClick.Add(() =>
|
||||||
|
{
|
||||||
|
GGraph graph = new GGraph();
|
||||||
|
startPos.x += 10;
|
||||||
|
startPos.y += 10;
|
||||||
|
graph.xy = startPos;
|
||||||
|
graph.DrawRect(150, 150, 1, Color.black, Color.red);
|
||||||
|
obj.GetChild("n22").asCom.AddChild(graph);
|
||||||
|
});
|
||||||
|
|
||||||
|
obj.GetChild("btn1").onClick.Add(() =>
|
||||||
|
{
|
||||||
|
GGraph graph = new GGraph();
|
||||||
|
startPos.x += 10;
|
||||||
|
startPos.y += 10;
|
||||||
|
graph.xy = startPos;
|
||||||
|
graph.DrawRect(150, 150, 1, Color.black, Color.green);
|
||||||
|
graph.sortingOrder = 200;
|
||||||
|
obj.GetChild("n22").asCom.AddChild(graph);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
private void PlayDragDrop()
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["Drag&Drop"];
|
||||||
|
obj.GetChild("a").draggable = true;
|
||||||
|
|
||||||
|
GButton b = obj.GetChild("b").asButton;
|
||||||
|
b.draggable = true;
|
||||||
|
b.onDragStart.Add((EventContext context) =>
|
||||||
|
{
|
||||||
|
//Cancel the original dragging, and start a new one with a agent.
|
||||||
|
context.PreventDefault();
|
||||||
|
|
||||||
|
DragDropManager.inst.StartDrag(b, b.icon, b.icon, (int)context.data);
|
||||||
|
});
|
||||||
|
|
||||||
|
GButton c = obj.GetChild("c").asButton;
|
||||||
|
c.icon = null;
|
||||||
|
c.onDrop.Add((EventContext context) =>
|
||||||
|
{
|
||||||
|
c.icon = (string)context.data;
|
||||||
|
});
|
||||||
|
|
||||||
|
GObject bounds = obj.GetChild("n7");
|
||||||
|
Rect rect = bounds.TransformRect(new Rect(0, 0, bounds.width, bounds.height), GRoot.inst);
|
||||||
|
|
||||||
|
//---!!Because at this time the container is on the right side of the stage and beginning to move to left(transition), so we need to caculate the final position
|
||||||
|
rect.x -= obj.parent.x;
|
||||||
|
//----
|
||||||
|
|
||||||
|
GButton d = obj.GetChild("d").asButton;
|
||||||
|
d.draggable = true;
|
||||||
|
d.dragBounds = rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
private void PlayProgressBar()
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["ProgressBar"];
|
||||||
|
Timers.inst.Add(0.001f, 0, __playProgress);
|
||||||
|
obj.onRemovedFromStage.Add(() => { Timers.inst.Remove(__playProgress); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void __playProgress(object param)
|
||||||
|
{
|
||||||
|
GComponent obj = _demoObjects["ProgressBar"];
|
||||||
|
int cnt = obj.numChildren;
|
||||||
|
for (int i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
GProgressBar child = obj.GetChildAt(i) as GProgressBar;
|
||||||
|
if (child != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
child.value += 1;
|
||||||
|
if (child.value > child.max)
|
||||||
|
child.value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Basics/BasicsMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Basics/BasicsMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a7c649dfadf79df4a963190eded74b30
|
||||||
|
timeCreated: 1446194671
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
29
Assets/Plugins/FairyGUI/Examples/Basics/Window1.cs
Normal file
29
Assets/Plugins/FairyGUI/Examples/Basics/Window1.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class Window1 : Window
|
||||||
|
{
|
||||||
|
public Window1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnInit()
|
||||||
|
{
|
||||||
|
this.contentPane = UIPackage.CreateObject("Basics", "WindowA").asCom;
|
||||||
|
this.Center();
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected void OnShown()
|
||||||
|
{
|
||||||
|
GList list = this.contentPane.GetChild("n6").asList;
|
||||||
|
list.RemoveChildrenToPool();
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
GButton item = list.AddItemFromPool().asButton;
|
||||||
|
item.title = "" + i;
|
||||||
|
item.icon = UIPackage.GetItemURL("Basics", "r4");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Basics/Window1.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Basics/Window1.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f9e33dc08a51fd04883526e4f5129e42
|
||||||
|
timeCreated: 1447054717
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
39
Assets/Plugins/FairyGUI/Examples/Basics/Window2.cs
Normal file
39
Assets/Plugins/FairyGUI/Examples/Basics/Window2.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using FairyGUI;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Window2 : Window
|
||||||
|
{
|
||||||
|
public Window2()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnInit()
|
||||||
|
{
|
||||||
|
this.contentPane = UIPackage.CreateObject("Basics", "WindowB").asCom;
|
||||||
|
this.Center();
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected void DoShowAnimation()
|
||||||
|
{
|
||||||
|
this.SetScale(0.1f, 0.1f);
|
||||||
|
this.SetPivot(0.5f, 0.5f);
|
||||||
|
this.TweenScale(new Vector2(1, 1), 0.3f).OnComplete(this.OnShown);
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected void DoHideAnimation()
|
||||||
|
{
|
||||||
|
this.TweenScale(new Vector2(0.1f, 0.1f), 0.3f).OnComplete(this.HideImmediately);
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected void OnShown()
|
||||||
|
{
|
||||||
|
contentPane.GetTransition("t1").Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected void OnHide()
|
||||||
|
{
|
||||||
|
contentPane.GetTransition("t1").Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Basics/Window2.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Basics/Window2.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f922289dfda2b1d4689eabfcdf6a5b91
|
||||||
|
timeCreated: 1447054712
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/BundleUsage.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/BundleUsage.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ae0ad495a670df246b212607e661ec96
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446643487
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
using System.Net;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Demonstrated how to load UI package from assetbundle. The bundle can be build from the Window Menu->Build FairyGUI example bundles.
|
||||||
|
/// </summary>
|
||||||
|
class BundleUsageMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
StartCoroutine(LoadUIPackage());
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator LoadUIPackage()
|
||||||
|
{
|
||||||
|
string url = Application.streamingAssetsPath.Replace("\\", "/") + "/fairygui-examples/bundleusage.ab";
|
||||||
|
if (Application.isEditor)
|
||||||
|
{
|
||||||
|
UriBuilder uri = new UriBuilder(url);
|
||||||
|
uri.Scheme = "file";
|
||||||
|
url = uri.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_2017_2_OR_NEWER
|
||||||
|
|
||||||
|
#if UNITY_2018_1_OR_NEWER
|
||||||
|
UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url);
|
||||||
|
#else
|
||||||
|
UnityWebRequest www = UnityWebRequest.GetAssetBundle(url);
|
||||||
|
#endif
|
||||||
|
yield return www.SendWebRequest();
|
||||||
|
|
||||||
|
#if UNITY_2020_2_OR_NEWER
|
||||||
|
if (www.result == UnityWebRequest.Result.Success)
|
||||||
|
#else
|
||||||
|
if (!www.isNetworkError && !www.isHttpError)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
|
||||||
|
#else
|
||||||
|
WWW www = new WWW(url);
|
||||||
|
yield return www;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(www.error))
|
||||||
|
{
|
||||||
|
AssetBundle bundle = www.assetBundle;
|
||||||
|
#endif
|
||||||
|
if (bundle == null)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("Run Window->Build FairyGUI example Bundles first.");
|
||||||
|
yield return 0;
|
||||||
|
}
|
||||||
|
UIPackage.AddPackage(bundle);
|
||||||
|
|
||||||
|
_mainView = UIPackage.CreateObject("BundleUsage", "Main").asCom;
|
||||||
|
_mainView.fairyBatching = true;
|
||||||
|
_mainView.MakeFullScreen();
|
||||||
|
_mainView.AddRelation(GRoot.inst, RelationType.Size);
|
||||||
|
|
||||||
|
GRoot.inst.AddChild(_mainView);
|
||||||
|
_mainView.GetTransition("t0").Play();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogWarning("Run Window->Build FairyGUI example Bundles first.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c34dde491ef252c49af798031b5a37de
|
||||||
|
timeCreated: 1446643490
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Cooldown.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Cooldown.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ee28fce39e275054fad5911e3f98c5e2
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1447173764
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
57
Assets/Plugins/FairyGUI/Examples/Cooldown/CooldownMain.cs
Normal file
57
Assets/Plugins/FairyGUI/Examples/Cooldown/CooldownMain.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
public class CooldownMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
|
||||||
|
GButton _btn0;
|
||||||
|
GImage _mask0;
|
||||||
|
float _time1;
|
||||||
|
|
||||||
|
GButton _btn1;
|
||||||
|
GImage _mask1;
|
||||||
|
float _time2;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_mainView = this.gameObject.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_btn0 = _mainView.GetChild("b0").asButton;
|
||||||
|
_btn0.icon = "Cooldown/k0";
|
||||||
|
_time1 = 5;
|
||||||
|
_mask0 = _btn0.GetChild("mask").asImage;
|
||||||
|
|
||||||
|
_btn1 = _mainView.GetChild("b1").asButton;
|
||||||
|
_btn1.icon = "Cooldown/k1";
|
||||||
|
_time2 = 10;
|
||||||
|
_mask1 = _btn1.GetChild("mask").asImage;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
_time1 -= Time.deltaTime;
|
||||||
|
if (_time1 < 0)
|
||||||
|
_time1 = 5;
|
||||||
|
_mask0.fillAmount = 1 - (5 - _time1) / 5f;
|
||||||
|
|
||||||
|
_time2 -= Time.deltaTime;
|
||||||
|
if (_time2 < 0)
|
||||||
|
_time2 = 10;
|
||||||
|
_btn1.text = string.Empty + Mathf.RoundToInt(_time2);
|
||||||
|
_mask1.fillAmount = 1 - (10 - _time2) / 10f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c59a131f345dd4e4895409b111e0c434
|
||||||
|
timeCreated: 1447174165
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Curve.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Curve.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9255b3554fc92214b98dc85f52b3ebb2
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1461431337
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
58
Assets/Plugins/FairyGUI/Examples/Curve/CurveMain.cs
Normal file
58
Assets/Plugins/FairyGUI/Examples/Curve/CurveMain.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class CurveMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
GList _list;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPainter>().ui;
|
||||||
|
|
||||||
|
_list = _mainView.GetChild("list").asList;
|
||||||
|
_list.SetVirtualAndLoop();
|
||||||
|
_list.itemRenderer = RenderListItem;
|
||||||
|
_list.numItems = 5;
|
||||||
|
_list.scrollPane.onScroll.Add(DoSpecialEffect);
|
||||||
|
|
||||||
|
DoSpecialEffect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoSpecialEffect()
|
||||||
|
{
|
||||||
|
//change the scale according to the distance to middle
|
||||||
|
float midX = _list.scrollPane.posX + _list.viewWidth / 2;
|
||||||
|
int cnt = _list.numChildren;
|
||||||
|
for (int i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
GObject obj = _list.GetChildAt(i);
|
||||||
|
float dist = Mathf.Abs(midX - obj.x - obj.width / 2);
|
||||||
|
if (dist > obj.width) //no intersection
|
||||||
|
obj.SetScale(1, 1);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float ss = 1 + (1 - dist / obj.width) * 0.24f;
|
||||||
|
obj.SetScale(ss, ss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderListItem(int index, GObject obj)
|
||||||
|
{
|
||||||
|
GButton item = (GButton)obj;
|
||||||
|
item.SetPivot(0.5f, 0.5f);
|
||||||
|
item.icon = UIPackage.GetItemURL("Curve", "n" + (index + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Curve/CurveMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Curve/CurveMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d30b14c0ce756e2428ef9db93b692b69
|
||||||
|
timeCreated: 1461431341
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/CutScene.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/CutScene.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0b781546cb2bc024a9f388f515ff11e4
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446628629
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
28
Assets/Plugins/FairyGUI/Examples/CutScene/CutSceneMain.cs
Normal file
28
Assets/Plugins/FairyGUI/Examples/CutScene/CutSceneMain.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Demonstrated the simple flow of a game.
|
||||||
|
/// </summary>
|
||||||
|
public class CutSceneMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
UIPackage.AddPackage("UI/CutScene");
|
||||||
|
|
||||||
|
LevelManager.inst.Init();
|
||||||
|
LevelManager.inst.LoadLevel("scene1");
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f0c05fcb4b735cf4587717a360b2a231
|
||||||
|
timeCreated: 1446628633
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
82
Assets/Plugins/FairyGUI/Examples/CutScene/LevelManager.cs
Normal file
82
Assets/Plugins/FairyGUI/Examples/CutScene/LevelManager.cs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
#if UNITY_5_3_OR_NEWER
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
#endif
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class LevelManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
static LevelManager _instance;
|
||||||
|
public static LevelManager inst
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
GameObject go = new GameObject("LevelManager");
|
||||||
|
DontDestroyOnLoad(go);
|
||||||
|
_instance = go.AddComponent<LevelManager>();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GComponent _cutSceneView;
|
||||||
|
GComponent _mainView;
|
||||||
|
|
||||||
|
public LevelManager()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
_cutSceneView = UIPackage.CreateObject("CutScene", "CutScene").asCom;
|
||||||
|
_cutSceneView.SetSize(GRoot.inst.width, GRoot.inst.height);
|
||||||
|
_cutSceneView.AddRelation(GRoot.inst, RelationType.Size);
|
||||||
|
|
||||||
|
_mainView = UIPackage.CreateObject("CutScene", "Main").asCom;
|
||||||
|
_mainView.SetSize(GRoot.inst.width, GRoot.inst.height);
|
||||||
|
_mainView.AddRelation(GRoot.inst, RelationType.Size);
|
||||||
|
|
||||||
|
_mainView.GetChild("n0").onClick.Add(() =>
|
||||||
|
{
|
||||||
|
LoadLevel("scene1");
|
||||||
|
});
|
||||||
|
|
||||||
|
_mainView.GetChild("n1").onClick.Add(() =>
|
||||||
|
{
|
||||||
|
LoadLevel("scene2");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadLevel(string levelName)
|
||||||
|
{
|
||||||
|
StartCoroutine(DoLoad(levelName));
|
||||||
|
GRoot.inst.AddChild(_cutSceneView);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator DoLoad(string sceneName)
|
||||||
|
{
|
||||||
|
GRoot.inst.AddChild(_cutSceneView);
|
||||||
|
GProgressBar pb = _cutSceneView.GetChild("pb").asProgress;
|
||||||
|
pb.value = 0;
|
||||||
|
#if UNITY_5_3_OR_NEWER
|
||||||
|
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
|
||||||
|
#else
|
||||||
|
AsyncOperation op = Application.LoadLevelAsync(sceneName);
|
||||||
|
#endif
|
||||||
|
float startTime = Time.time;
|
||||||
|
while (!op.isDone || pb.value != 100)
|
||||||
|
{
|
||||||
|
int value = (int)((Time.time - startTime) * 100f / 3f);
|
||||||
|
if (value > 100)
|
||||||
|
value = 100;
|
||||||
|
pb.value = value;
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
GRoot.inst.RemoveChild(_cutSceneView);
|
||||||
|
GRoot.inst.AddChild(_mainView);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cfefd808bb86e4f4cb34eaf9da5d1a36
|
||||||
|
timeCreated: 1446630965
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Editor.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Editor.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b79c211a7d63ecf4796b13556fd29826
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446620759
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
33
Assets/Plugins/FairyGUI/Examples/Editor/BuildAssetBundles.cs
Normal file
33
Assets/Plugins/FairyGUI/Examples/Editor/BuildAssetBundles.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
public class BuildAssetBundles
|
||||||
|
{
|
||||||
|
[MenuItem("Window/Build FairyGUI Example Bundles")]
|
||||||
|
public static void Build()
|
||||||
|
{
|
||||||
|
string testPath = "UI/BundleUsage_fui";
|
||||||
|
Object obj = Resources.Load(testPath);
|
||||||
|
string path = AssetDatabase.GetAssetPath(obj);
|
||||||
|
if(string.IsNullOrEmpty(path))
|
||||||
|
{
|
||||||
|
Debug.LogWarning("sample not found: " + testPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string basePath = path.Substring(0, path.Length - testPath.Length - 6);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
AssetImporter.GetAtPath(basePath + "Icons/i" + i + ".png").assetBundleName = "fairygui-examples/i" + i + ".ab";
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetImporter.GetAtPath(basePath + "UI/BundleUsage_fui.bytes").assetBundleName = "fairygui-examples/bundleusage.ab";
|
||||||
|
AssetImporter.GetAtPath(basePath + "UI/BundleUsage_atlas0.png").assetBundleName = "fairygui-examples/bundleusage.ab";
|
||||||
|
|
||||||
|
if (!Directory.Exists(Application.streamingAssetsPath))
|
||||||
|
Directory.CreateDirectory(Application.streamingAssetsPath);
|
||||||
|
|
||||||
|
BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bb6ce699bc9e31440b4f01462aacc612
|
||||||
|
timeCreated: 1446625466
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/EmitNumbers.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/EmitNumbers.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 91fdebf77175d934ab3d4689ca57f396
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446569240
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class EmitComponent : GComponent
|
||||||
|
{
|
||||||
|
GLoader _symbolLoader;
|
||||||
|
GTextField _numberText;
|
||||||
|
Transform _owner;
|
||||||
|
|
||||||
|
const float OFFSET_ADDITION = 2.2f;
|
||||||
|
static Vector2 JITTER_FACTOR = new Vector2(80, 80);
|
||||||
|
|
||||||
|
public EmitComponent()
|
||||||
|
{
|
||||||
|
this.touchable = false;
|
||||||
|
|
||||||
|
_symbolLoader = new GLoader();
|
||||||
|
_symbolLoader.autoSize = true;
|
||||||
|
AddChild(_symbolLoader);
|
||||||
|
|
||||||
|
_numberText = new GTextField();
|
||||||
|
_numberText.autoSize = AutoSizeType.Both;
|
||||||
|
|
||||||
|
AddChild(_numberText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetHurt(Transform owner, int type, long hurt, bool critical)
|
||||||
|
{
|
||||||
|
_owner = owner;
|
||||||
|
|
||||||
|
TextFormat tf = _numberText.textFormat;
|
||||||
|
if (type == 0)
|
||||||
|
tf.font = EmitManager.inst.hurtFont1;
|
||||||
|
else
|
||||||
|
tf.font = EmitManager.inst.hurtFont2;
|
||||||
|
_numberText.textFormat = tf;
|
||||||
|
_numberText.text = "-" + hurt;
|
||||||
|
|
||||||
|
if (critical)
|
||||||
|
_symbolLoader.url = EmitManager.inst.criticalSign;
|
||||||
|
else
|
||||||
|
_symbolLoader.url = "";
|
||||||
|
|
||||||
|
UpdateLayout();
|
||||||
|
|
||||||
|
this.alpha = 1;
|
||||||
|
UpdatePosition(Vector2.zero);
|
||||||
|
Vector2 rnd = Vector2.Scale(UnityEngine.Random.insideUnitCircle, JITTER_FACTOR);
|
||||||
|
int toX = (int)rnd.x * 2;
|
||||||
|
int toY = (int)rnd.y * 2;
|
||||||
|
|
||||||
|
EmitManager.inst.view.AddChild(this);
|
||||||
|
GTween.To(Vector2.zero, new Vector2(toX, toY), 1f).SetTarget(this)
|
||||||
|
.OnUpdate((GTweener tweener) => { this.UpdatePosition(tweener.value.vec2); }).OnComplete(this.OnCompleted);
|
||||||
|
this.TweenFade(0, 0.5f).SetDelay(0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateLayout()
|
||||||
|
{
|
||||||
|
this.SetSize(_symbolLoader.width + _numberText.width, Mathf.Max(_symbolLoader.height, _numberText.height));
|
||||||
|
_numberText.SetXY(_symbolLoader.width > 0 ? (_symbolLoader.width + 2) : 0,
|
||||||
|
(this.height - _numberText.height) / 2);
|
||||||
|
_symbolLoader.y = (this.height - _symbolLoader.height) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdatePosition(Vector2 pos)
|
||||||
|
{
|
||||||
|
Vector3 ownerPos = _owner.position;
|
||||||
|
ownerPos.y += OFFSET_ADDITION;
|
||||||
|
Vector3 screenPos = Camera.main.WorldToScreenPoint(ownerPos);
|
||||||
|
screenPos.y = Screen.height - screenPos.y; //convert to Stage coordinates system
|
||||||
|
|
||||||
|
Vector3 pt = GRoot.inst.GlobalToLocal(screenPos);
|
||||||
|
this.SetXY(Mathf.RoundToInt(pt.x + pos.x - this.actualWidth / 2), Mathf.RoundToInt(pt.y + pos.y - this.height));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnCompleted()
|
||||||
|
{
|
||||||
|
_owner = null;
|
||||||
|
EmitManager.inst.view.RemoveChild(this);
|
||||||
|
EmitManager.inst.ReturnComponent(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Cancel()
|
||||||
|
{
|
||||||
|
_owner = null;
|
||||||
|
if (this.parent != null)
|
||||||
|
{
|
||||||
|
GTween.Kill(this);
|
||||||
|
EmitManager.inst.view.RemoveChild(this);
|
||||||
|
}
|
||||||
|
EmitManager.inst.ReturnComponent(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d8535a403e7324c49890b1de70edc2a0
|
||||||
|
timeCreated: 1446570746
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
50
Assets/Plugins/FairyGUI/Examples/EmitNumbers/EmitManager.cs
Normal file
50
Assets/Plugins/FairyGUI/Examples/EmitNumbers/EmitManager.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class EmitManager
|
||||||
|
{
|
||||||
|
static EmitManager _instance;
|
||||||
|
public static EmitManager inst
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
_instance = new EmitManager();
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string hurtFont1;
|
||||||
|
public string hurtFont2;
|
||||||
|
public string criticalSign;
|
||||||
|
|
||||||
|
public GComponent view { get; private set; }
|
||||||
|
|
||||||
|
private readonly Stack<EmitComponent> _componentPool = new Stack<EmitComponent>();
|
||||||
|
|
||||||
|
public EmitManager()
|
||||||
|
{
|
||||||
|
hurtFont1 = "ui://EmitNumbers/number1";
|
||||||
|
hurtFont2 = "ui://EmitNumbers/number2";
|
||||||
|
criticalSign = "ui://EmitNumbers/critical";
|
||||||
|
|
||||||
|
view = new GComponent();
|
||||||
|
GRoot.inst.AddChild(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Emit(Transform owner, int type, long hurt, bool critical)
|
||||||
|
{
|
||||||
|
EmitComponent ec;
|
||||||
|
if (_componentPool.Count > 0)
|
||||||
|
ec = _componentPool.Pop();
|
||||||
|
else
|
||||||
|
ec = new EmitComponent();
|
||||||
|
ec.SetHurt(owner, type, hurt, critical);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReturnComponent(EmitComponent com)
|
||||||
|
{
|
||||||
|
_componentPool.Push(com);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 335d4e8607937704285d9e0aec495020
|
||||||
|
timeCreated: 1446570745
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class EmitNumbersMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
Transform _npc1;
|
||||||
|
Transform _npc2;
|
||||||
|
bool _finished;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_npc1 = GameObject.Find("npc1").transform;
|
||||||
|
_npc2 = GameObject.Find("npc2").transform;
|
||||||
|
|
||||||
|
StartCoroutine(RunTest());
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnDisable()
|
||||||
|
{
|
||||||
|
_finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator RunTest()
|
||||||
|
{
|
||||||
|
while (!_finished)
|
||||||
|
{
|
||||||
|
EmitManager.inst.Emit(_npc1, 0, UnityEngine.Random.Range(100, 100000), UnityEngine.Random.Range(0, 10) == 5);
|
||||||
|
EmitManager.inst.Emit(_npc2, 1, UnityEngine.Random.Range(100, 100000), UnityEngine.Random.Range(0, 10) == 5);
|
||||||
|
yield return new WaitForSeconds(0.3f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3ee84d8c960d2404893a09cb4009bee8
|
||||||
|
timeCreated: 1446569244
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Emoji.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Emoji.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fbba022553e7d1d438d20305716af90e
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446193142
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
196
Assets/Plugins/FairyGUI/Examples/Emoji/EmojiMain.cs
Normal file
196
Assets/Plugins/FairyGUI/Examples/Emoji/EmojiMain.cs
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class EmojiMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
GList _list;
|
||||||
|
GTextInput _input1;
|
||||||
|
GTextInput _input2;
|
||||||
|
GComponent _emojiSelectUI1;
|
||||||
|
GComponent _emojiSelectUI2;
|
||||||
|
|
||||||
|
class Message
|
||||||
|
{
|
||||||
|
public string sender;
|
||||||
|
public string senderIcon;
|
||||||
|
public string msg;
|
||||||
|
public bool fromMe;
|
||||||
|
}
|
||||||
|
List<Message> _messages;
|
||||||
|
|
||||||
|
Dictionary<uint, Emoji> _emojies;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
UIPackage.AddPackage("UI/Emoji");
|
||||||
|
|
||||||
|
UIConfig.verticalScrollBar = "ui://Emoji/ScrollBar_VT";
|
||||||
|
UIConfig.defaultScrollBarDisplay = ScrollBarDisplayType.Auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_messages = new List<Message>();
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_list = _mainView.GetChild("list").asList;
|
||||||
|
_list.SetVirtual();
|
||||||
|
_list.itemProvider = GetListItemResource;
|
||||||
|
_list.itemRenderer = RenderListItem;
|
||||||
|
|
||||||
|
_input1 = _mainView.GetChild("input1").asTextInput;
|
||||||
|
_input1.onKeyDown.Add(__inputKeyDown1);
|
||||||
|
|
||||||
|
_input2 = _mainView.GetChild("input2").asTextInput;
|
||||||
|
_input2.onKeyDown.Add(__inputKeyDown2);
|
||||||
|
|
||||||
|
//作为demo,这里只添加了部分表情素材
|
||||||
|
_emojies = new Dictionary<uint, Emoji>();
|
||||||
|
for (uint i = 0x1f600; i < 0x1f637; i++)
|
||||||
|
{
|
||||||
|
string url = UIPackage.GetItemURL("Emoji", Convert.ToString(i, 16));
|
||||||
|
if (url != null)
|
||||||
|
_emojies.Add(i, new Emoji(url));
|
||||||
|
}
|
||||||
|
_input2.emojies = _emojies;
|
||||||
|
|
||||||
|
_mainView.GetChild("btnSend1").onClick.Add(__clickSendBtn1);
|
||||||
|
_mainView.GetChild("btnSend2").onClick.Add(__clickSendBtn2);
|
||||||
|
|
||||||
|
_mainView.GetChild("btnEmoji1").onClick.Add(__clickEmojiBtn1);
|
||||||
|
_mainView.GetChild("btnEmoji2").onClick.Add(__clickEmojiBtn2);
|
||||||
|
|
||||||
|
_emojiSelectUI1 = UIPackage.CreateObject("Emoji", "EmojiSelectUI").asCom;
|
||||||
|
_emojiSelectUI1.fairyBatching = true;
|
||||||
|
_emojiSelectUI1.GetChild("list").asList.onClickItem.Add(__clickEmoji1);
|
||||||
|
|
||||||
|
_emojiSelectUI2 = UIPackage.CreateObject("Emoji", "EmojiSelectUI_ios").asCom;
|
||||||
|
_emojiSelectUI2.fairyBatching = true;
|
||||||
|
_emojiSelectUI2.GetChild("list").asList.onClickItem.Add(__clickEmoji2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddMsg(string sender, string senderIcon, string msg, bool fromMe)
|
||||||
|
{
|
||||||
|
bool isScrollBottom = _list.scrollPane.isBottomMost;
|
||||||
|
|
||||||
|
Message newMessage = new Message();
|
||||||
|
newMessage.sender = sender;
|
||||||
|
newMessage.senderIcon = senderIcon;
|
||||||
|
newMessage.msg = msg;
|
||||||
|
newMessage.fromMe = fromMe;
|
||||||
|
_messages.Add(newMessage);
|
||||||
|
|
||||||
|
if (newMessage.fromMe)
|
||||||
|
{
|
||||||
|
if (_messages.Count == 1 || UnityEngine.Random.Range(0f, 1f) < 0.5f)
|
||||||
|
{
|
||||||
|
Message replyMessage = new Message();
|
||||||
|
replyMessage.sender = "FairyGUI";
|
||||||
|
replyMessage.senderIcon = "r1";
|
||||||
|
replyMessage.msg = "Today is a good day. \U0001f600";
|
||||||
|
replyMessage.fromMe = false;
|
||||||
|
_messages.Add(replyMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_messages.Count > 100)
|
||||||
|
_messages.RemoveRange(0, _messages.Count - 100);
|
||||||
|
|
||||||
|
_list.numItems = _messages.Count;
|
||||||
|
|
||||||
|
if (isScrollBottom)
|
||||||
|
_list.scrollPane.ScrollBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
string GetListItemResource(int index)
|
||||||
|
{
|
||||||
|
Message msg = _messages[index];
|
||||||
|
if (msg.fromMe)
|
||||||
|
return "ui://Emoji/chatRight";
|
||||||
|
else
|
||||||
|
return "ui://Emoji/chatLeft";
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderListItem(int index, GObject obj)
|
||||||
|
{
|
||||||
|
GButton item = (GButton)obj;
|
||||||
|
Message msg = _messages[index];
|
||||||
|
if (!msg.fromMe)
|
||||||
|
item.GetChild("name").text = msg.sender;
|
||||||
|
item.icon = UIPackage.GetItemURL("Emoji", msg.senderIcon);
|
||||||
|
|
||||||
|
//Recaculate the text width
|
||||||
|
GRichTextField tf = item.GetChild("msg").asRichTextField;
|
||||||
|
tf.emojies = _emojies;
|
||||||
|
tf.text = EmojiParser.inst.Parse(msg.msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __clickSendBtn1(EventContext context)
|
||||||
|
{
|
||||||
|
string msg = _input1.text;
|
||||||
|
if (msg.Length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AddMsg("Unity", "r0", msg, true);
|
||||||
|
_input1.text = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void __clickSendBtn2(EventContext context)
|
||||||
|
{
|
||||||
|
string msg = _input2.text;
|
||||||
|
if (msg.Length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AddMsg("Unity", "r0", msg, true);
|
||||||
|
_input2.text = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void __clickEmojiBtn1(EventContext context)
|
||||||
|
{
|
||||||
|
GRoot.inst.ShowPopup(_emojiSelectUI1, (GObject)context.sender, PopupDirection.Up);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __clickEmojiBtn2(EventContext context)
|
||||||
|
{
|
||||||
|
GRoot.inst.ShowPopup(_emojiSelectUI2, (GObject)context.sender, PopupDirection.Up);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __clickEmoji1(EventContext context)
|
||||||
|
{
|
||||||
|
GButton item = (GButton)context.data;
|
||||||
|
_input1.ReplaceSelection("[:" + item.text + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __clickEmoji2(EventContext context)
|
||||||
|
{
|
||||||
|
GButton item = (GButton)context.data;
|
||||||
|
_input2.ReplaceSelection(Char.ConvertFromUtf32(Convert.ToInt32(UIPackage.GetItemByURL(item.icon).name, 16)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void __inputKeyDown1(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Return)
|
||||||
|
_mainView.GetChild("btnSend1").onClick.Call();
|
||||||
|
}
|
||||||
|
|
||||||
|
void __inputKeyDown2(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Return)
|
||||||
|
_mainView.GetChild("btnSend2").onClick.Call();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Emoji/EmojiMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Emoji/EmojiMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4953851686ef2ed4d90f67c5fe144849
|
||||||
|
timeCreated: 1446193148
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
31
Assets/Plugins/FairyGUI/Examples/Emoji/EmojiParser.cs
Normal file
31
Assets/Plugins/FairyGUI/Examples/Emoji/EmojiParser.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using FairyGUI;
|
||||||
|
using FairyGUI.Utils;
|
||||||
|
|
||||||
|
public class EmojiParser : UBBParser
|
||||||
|
{
|
||||||
|
static EmojiParser _instance;
|
||||||
|
public new static EmojiParser inst
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
_instance = new EmojiParser();
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string[] TAGS = new string[]
|
||||||
|
{ "88","am","bs","bz","ch","cool","dhq","dn","fd","gz","han","hx","hxiao","hxiu" };
|
||||||
|
public EmojiParser ()
|
||||||
|
{
|
||||||
|
foreach (string ss in TAGS)
|
||||||
|
{
|
||||||
|
this.handlers[":"+ss] = OnTag_Emoji;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string OnTag_Emoji(string tagName, bool end, string attr)
|
||||||
|
{
|
||||||
|
return "<img src='" + UIPackage.GetItemURL("Emoji", tagName.Substring(1).ToLower()) + "'/>";
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Emoji/EmojiParser.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Emoji/EmojiParser.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ebe7b2fb6b5fe8c488fac00b1b177326
|
||||||
|
timeCreated: 1446193148
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Extension.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Extension.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dc519b1dfb870064ea786640d8a0a8d1
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446648215
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
55
Assets/Plugins/FairyGUI/Examples/Extension/ExtensionMain.cs
Normal file
55
Assets/Plugins/FairyGUI/Examples/Extension/ExtensionMain.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class ExtensionMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
GList _list;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
UIPackage.AddPackage("UI/Extension");
|
||||||
|
UIObjectFactory.SetPackageItemExtension("ui://Extension/mailItem", typeof(MailItem));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_list = _mainView.GetChild("mailList").asList;
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
MailItem item = (MailItem)_list.AddItemFromPool();
|
||||||
|
item.setFetched(i % 3 == 0);
|
||||||
|
item.setRead(i % 2 == 0);
|
||||||
|
item.setTime("5 Nov 2015 16:24:33");
|
||||||
|
item.title = "Mail title here";
|
||||||
|
}
|
||||||
|
|
||||||
|
_list.EnsureBoundsCorrect();
|
||||||
|
float delay = 0f;
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
MailItem item = (MailItem)_list.GetChildAt(i);
|
||||||
|
if (_list.IsChildInView(item))
|
||||||
|
{
|
||||||
|
item.PlayEffect(delay);
|
||||||
|
delay += 0.2f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1b0647927cbff65449b89590caf97481
|
||||||
|
timeCreated: 1446648215
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
41
Assets/Plugins/FairyGUI/Examples/Extension/MailItem.cs
Normal file
41
Assets/Plugins/FairyGUI/Examples/Extension/MailItem.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class MailItem : GButton
|
||||||
|
{
|
||||||
|
GTextField _timeText;
|
||||||
|
Controller _readController;
|
||||||
|
Controller _fetchController;
|
||||||
|
Transition _trans;
|
||||||
|
|
||||||
|
public override void ConstructFromXML(FairyGUI.Utils.XML cxml)
|
||||||
|
{
|
||||||
|
base.ConstructFromXML(cxml);
|
||||||
|
|
||||||
|
_timeText = this.GetChild("timeText").asTextField;
|
||||||
|
_readController = this.GetController("IsRead");
|
||||||
|
_fetchController = this.GetController("c1");
|
||||||
|
_trans = this.GetTransition("t0");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(string value)
|
||||||
|
{
|
||||||
|
_timeText.text = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRead(bool value)
|
||||||
|
{
|
||||||
|
_readController.selectedIndex = value ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFetched(bool value)
|
||||||
|
{
|
||||||
|
_fetchController.selectedIndex = value ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PlayEffect(float delay)
|
||||||
|
{
|
||||||
|
this.visible = false;
|
||||||
|
_trans.Play(1, delay, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Extension/MailItem.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Extension/MailItem.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 26140e87934f8754689c7bf2ac147fbe
|
||||||
|
timeCreated: 1446648219
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Filter.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Filter.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 029ae1bcb2ae7f2448723a7be724a31d
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1465913233
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
78
Assets/Plugins/FairyGUI/Examples/Filter/FilterMain.cs
Normal file
78
Assets/Plugins/FairyGUI/Examples/Filter/FilterMain.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class FilterMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
GSlider _s0;
|
||||||
|
GSlider _s1;
|
||||||
|
GSlider _s2;
|
||||||
|
GSlider _s3;
|
||||||
|
GSlider _s4;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
UIPackage.AddPackage("UI/Filter");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
BlurFilter blurFilter = new BlurFilter();
|
||||||
|
blurFilter.blurSize = 2;
|
||||||
|
_mainView.GetChild("n21").filter = blurFilter;
|
||||||
|
|
||||||
|
_s0 = _mainView.GetChild("s0").asSlider;
|
||||||
|
_s1 = _mainView.GetChild("s1").asSlider;
|
||||||
|
_s2 = _mainView.GetChild("s2").asSlider;
|
||||||
|
_s3 = _mainView.GetChild("s3").asSlider;
|
||||||
|
_s4 = _mainView.GetChild("s4").asSlider;
|
||||||
|
|
||||||
|
_s0.value = 100;
|
||||||
|
_s1.value = 100;
|
||||||
|
_s2.value = 100;
|
||||||
|
_s3.value = 200;
|
||||||
|
_s4.value = 20;
|
||||||
|
|
||||||
|
_s0.onChanged.Add(__sliderChanged);
|
||||||
|
_s1.onChanged.Add(__sliderChanged);
|
||||||
|
_s2.onChanged.Add(__sliderChanged);
|
||||||
|
_s3.onChanged.Add(__sliderChanged);
|
||||||
|
_s4.onChanged.Add(__sliderChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __sliderChanged(EventContext context)
|
||||||
|
{
|
||||||
|
int cnt = _mainView.numChildren;
|
||||||
|
for (int i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
GObject obj = _mainView.GetChildAt(i);
|
||||||
|
if (obj.filter is ColorFilter)
|
||||||
|
{
|
||||||
|
ColorFilter filter = (ColorFilter)obj.filter;
|
||||||
|
filter.Reset();
|
||||||
|
filter.AdjustBrightness((float)(_s0.value - 100) / 100f);
|
||||||
|
filter.AdjustContrast((float)(_s1.value - 100) / 100f);
|
||||||
|
filter.AdjustSaturation((float)(_s2.value - 100) / 100f);
|
||||||
|
filter.AdjustHue((float)(_s3.value - 100) / 100f);
|
||||||
|
}
|
||||||
|
else if (obj.filter is BlurFilter)
|
||||||
|
{
|
||||||
|
BlurFilter filter = (BlurFilter)obj.filter;
|
||||||
|
filter.blurSize = (float)_s4.value / 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Filter/FilterMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Filter/FilterMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 78878c40447242843aa913ef50cce606
|
||||||
|
timeCreated: 1465402161
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Gesture.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Gesture.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c2c523738da07e8498b13cb58f69289e
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1464248161
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
115
Assets/Plugins/FairyGUI/Examples/Gesture/GestureMain.cs
Normal file
115
Assets/Plugins/FairyGUI/Examples/Gesture/GestureMain.cs
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class GestureMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
Transform _ball;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
UIPackage.AddPackage("UI/Gesture");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
GObject holder = _mainView.GetChild("holder");
|
||||||
|
|
||||||
|
_ball = GameObject.Find("Globe").transform;
|
||||||
|
|
||||||
|
SwipeGesture gesture1 = new SwipeGesture(holder);
|
||||||
|
gesture1.onMove.Add(OnSwipeMove);
|
||||||
|
gesture1.onEnd.Add(OnSwipeEnd);
|
||||||
|
|
||||||
|
LongPressGesture gesture2 = new LongPressGesture(holder);
|
||||||
|
gesture2.once = false;
|
||||||
|
gesture2.onAction.Add(OnHold);
|
||||||
|
|
||||||
|
PinchGesture gesture3 = new PinchGesture(holder);
|
||||||
|
gesture3.onAction.Add(OnPinch);
|
||||||
|
|
||||||
|
RotationGesture gesture4 = new RotationGesture(holder);
|
||||||
|
gesture4.onAction.Add(OnRotate);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSwipeMove(EventContext context)
|
||||||
|
{
|
||||||
|
SwipeGesture gesture = (SwipeGesture)context.sender;
|
||||||
|
Vector3 v = new Vector3();
|
||||||
|
if (Mathf.Abs(gesture.delta.x) > Mathf.Abs(gesture.delta.y))
|
||||||
|
{
|
||||||
|
v.y = -Mathf.Round(gesture.delta.x);
|
||||||
|
if (Mathf.Abs(v.y) < 2) //消除手抖的影响
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v.x = -Mathf.Round(gesture.delta.y);
|
||||||
|
if (Mathf.Abs(v.x) < 2)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ball.Rotate(v, Space.World);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSwipeEnd(EventContext context)
|
||||||
|
{
|
||||||
|
SwipeGesture gesture = (SwipeGesture)context.sender;
|
||||||
|
Vector3 v = new Vector3();
|
||||||
|
if (Mathf.Abs(gesture.velocity.x) > Mathf.Abs(gesture.velocity.y))
|
||||||
|
{
|
||||||
|
v.y = -Mathf.Round(Mathf.Sign(gesture.velocity.x) * Mathf.Sqrt(Mathf.Abs(gesture.velocity.x)));
|
||||||
|
if (Mathf.Abs(v.y) < 2)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v.x = -Mathf.Round(Mathf.Sign(gesture.velocity.y) * Mathf.Sqrt(Mathf.Abs(gesture.velocity.y)));
|
||||||
|
if (Mathf.Abs(v.x) < 2)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GTween.To(v, Vector3.zero, 0.3f).SetTarget(_ball).OnUpdate(
|
||||||
|
(GTweener tweener) =>
|
||||||
|
{
|
||||||
|
_ball.Rotate(tweener.deltaValue.vec3, Space.World);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnHold(EventContext context)
|
||||||
|
{
|
||||||
|
GTween.Shake(_ball.transform.localPosition, 0.05f, 0.5f).SetTarget(_ball).OnUpdate(
|
||||||
|
(GTweener tweener) =>
|
||||||
|
{
|
||||||
|
_ball.transform.localPosition = new Vector3(tweener.value.x, tweener.value.y, _ball.transform.localPosition.z);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnPinch(EventContext context)
|
||||||
|
{
|
||||||
|
GTween.Kill(_ball);
|
||||||
|
|
||||||
|
PinchGesture gesture = (PinchGesture)context.sender;
|
||||||
|
float newValue = Mathf.Clamp(_ball.localScale.x + gesture.delta, 0.3f, 2);
|
||||||
|
_ball.localScale = new Vector3(newValue, newValue, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnRotate(EventContext context)
|
||||||
|
{
|
||||||
|
GTween.Kill(_ball);
|
||||||
|
|
||||||
|
RotationGesture gesture = (RotationGesture)context.sender;
|
||||||
|
_ball.Rotate(Vector3.forward, -gesture.delta, Space.World);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Gesture/GestureMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Gesture/GestureMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dffc58029aa66074287bfe11db08a102
|
||||||
|
timeCreated: 1464248165
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Guide.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Guide.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bf04af674d0fada4d93df62ec9e22a95
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1456392097
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
44
Assets/Plugins/FairyGUI/Examples/Guide/GuideMain.cs
Normal file
44
Assets/Plugins/FairyGUI/Examples/Guide/GuideMain.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class GuideMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
GComponent _guideLayer;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_guideLayer = UIPackage.CreateObject("Guide", "GuideLayer").asCom;
|
||||||
|
_guideLayer.SetSize(GRoot.inst.width, GRoot.inst.height);
|
||||||
|
_guideLayer.AddRelation(GRoot.inst, RelationType.Size);
|
||||||
|
|
||||||
|
GObject bagBtn = _mainView.GetChild("bagBtn");
|
||||||
|
bagBtn.onClick.Add(() =>
|
||||||
|
{
|
||||||
|
_guideLayer.RemoveFromParent();
|
||||||
|
});
|
||||||
|
|
||||||
|
_mainView.GetChild("n2").onClick.Add(() =>
|
||||||
|
{
|
||||||
|
GRoot.inst.AddChild(_guideLayer); //!!Before using TransformRect(or GlobalToLocal), the object must be added first
|
||||||
|
Rect rect = bagBtn.TransformRect(new Rect(0, 0, bagBtn.width, bagBtn.height), _guideLayer);
|
||||||
|
|
||||||
|
GObject window = _guideLayer.GetChild("window");
|
||||||
|
window.size = new Vector2((int)rect.size.x, (int)rect.size.y);
|
||||||
|
window.TweenMove(new Vector2((int)rect.position.x, (int)rect.position.y), 0.5f);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Guide/GuideMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Guide/GuideMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 917e86e515017db488b38e836ed52634
|
||||||
|
timeCreated: 1456392101
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/HeadBar.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/HeadBar.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8294eab8d3a942c43aed8054200d3119
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446540831
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
34
Assets/Plugins/FairyGUI/Examples/HeadBar/HeadBarMain.cs
Normal file
34
Assets/Plugins/FairyGUI/Examples/HeadBar/HeadBarMain.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class HeadBarMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
Transform npc = GameObject.Find("npc1").transform;
|
||||||
|
UIPanel panel = npc.Find("HeadBar").GetComponent<UIPanel>();
|
||||||
|
panel.ui.GetChild("name").text = "Long [color=#FFFFFF]Long[/color][img]ui://HeadBar/cool[/img] Name";
|
||||||
|
panel.ui.GetChild("blood").asProgress.value = 75;
|
||||||
|
panel.ui.GetChild("sign").asLoader.url = "ui://HeadBar/task";
|
||||||
|
|
||||||
|
npc = GameObject.Find("npc2").transform;
|
||||||
|
panel = npc.Find("HeadBar").GetComponent<UIPanel>();
|
||||||
|
panel.ui.GetChild("name").text = "Man2";
|
||||||
|
panel.ui.GetChild("blood").asProgress.value = 25;
|
||||||
|
panel.ui.GetChild("sign").asLoader.url = "ui://HeadBar/fighting";
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/HeadBar/HeadBarMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/HeadBar/HeadBarMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3f24b49a96743734c8d2ef9ba2c9b32d
|
||||||
|
timeCreated: 1446540834
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/HitTest.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/HitTest.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 108d5a390778d664cb644fadf56d6faf
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1456474673
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
40
Assets/Plugins/FairyGUI/Examples/HitTest/HitTestMain.cs
Normal file
40
Assets/Plugins/FairyGUI/Examples/HitTest/HitTestMain.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class HitTestMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
Transform cube;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
|
||||||
|
cube = GameObject.Find("Cube").transform;
|
||||||
|
|
||||||
|
Stage.inst.onTouchBegin.Add(OnTouchBegin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTouchBegin()
|
||||||
|
{
|
||||||
|
if (!Stage.isTouchOnUI)
|
||||||
|
{
|
||||||
|
RaycastHit hit;
|
||||||
|
Ray ray = Camera.main.ScreenPointToRay(new Vector2(Stage.inst.touchPosition.x, Screen.height - Stage.inst.touchPosition.y));
|
||||||
|
if (Physics.Raycast(ray, out hit))
|
||||||
|
{
|
||||||
|
if (hit.transform == cube)
|
||||||
|
{
|
||||||
|
Debug.Log("Hit the cube");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/HitTest/HitTestMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/HitTest/HitTestMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 12542fe68a883624ea477c953ae0cf52
|
||||||
|
timeCreated: 1456474677
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Joystick.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Joystick.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c90dbc7e654112a4dbaa796e7e3cc987
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446193142
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
42
Assets/Plugins/FairyGUI/Examples/Joystick/JoystickMain.cs
Normal file
42
Assets/Plugins/FairyGUI/Examples/Joystick/JoystickMain.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class JoystickMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
GTextField _text;
|
||||||
|
JoystickModule _joystick;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_text = _mainView.GetChild("n9").asTextField;
|
||||||
|
|
||||||
|
_joystick = new JoystickModule(_mainView);
|
||||||
|
_joystick.onMove.Add(__joystickMove);
|
||||||
|
_joystick.onEnd.Add(__joystickEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __joystickMove(EventContext context)
|
||||||
|
{
|
||||||
|
float degree = (float)context.data;
|
||||||
|
_text.text = "" + degree;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __joystickEnd()
|
||||||
|
{
|
||||||
|
_text.text = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 09cf2c20abdf7ea428bd3f1c68941949
|
||||||
|
timeCreated: 1446193147
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
159
Assets/Plugins/FairyGUI/Examples/Joystick/JoystickModule.cs
Normal file
159
Assets/Plugins/FairyGUI/Examples/Joystick/JoystickModule.cs
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
using FairyGUI;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class JoystickModule : EventDispatcher
|
||||||
|
{
|
||||||
|
float _InitX;
|
||||||
|
float _InitY;
|
||||||
|
float _startStageX;
|
||||||
|
float _startStageY;
|
||||||
|
float _lastStageX;
|
||||||
|
float _lastStageY;
|
||||||
|
GButton _button;
|
||||||
|
GObject _touchArea;
|
||||||
|
GObject _thumb;
|
||||||
|
GObject _center;
|
||||||
|
int touchId;
|
||||||
|
GTweener _tweener;
|
||||||
|
|
||||||
|
public EventListener onMove { get; private set; }
|
||||||
|
public EventListener onEnd { get; private set; }
|
||||||
|
|
||||||
|
public int radius { get; set; }
|
||||||
|
|
||||||
|
public JoystickModule(GComponent mainView)
|
||||||
|
{
|
||||||
|
onMove = new EventListener(this, "onMove");
|
||||||
|
onEnd = new EventListener(this, "onEnd");
|
||||||
|
|
||||||
|
_button = mainView.GetChild("joystick").asButton;
|
||||||
|
_button.changeStateOnClick = false;
|
||||||
|
_thumb = _button.GetChild("thumb");
|
||||||
|
_touchArea = mainView.GetChild("joystick_touch");
|
||||||
|
_center = mainView.GetChild("joystick_center");
|
||||||
|
|
||||||
|
_InitX = _center.x + _center.width / 2;
|
||||||
|
_InitY = _center.y + _center.height / 2;
|
||||||
|
touchId = -1;
|
||||||
|
radius = 150;
|
||||||
|
|
||||||
|
_touchArea.onTouchBegin.Add(this.OnTouchBegin);
|
||||||
|
_touchArea.onTouchMove.Add(this.OnTouchMove);
|
||||||
|
_touchArea.onTouchEnd.Add(this.OnTouchEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Trigger(EventContext context)
|
||||||
|
{
|
||||||
|
OnTouchBegin(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTouchBegin(EventContext context)
|
||||||
|
{
|
||||||
|
if (touchId == -1)//First touch
|
||||||
|
{
|
||||||
|
InputEvent evt = (InputEvent)context.data;
|
||||||
|
touchId = evt.touchId;
|
||||||
|
|
||||||
|
if (_tweener != null)
|
||||||
|
{
|
||||||
|
_tweener.Kill();
|
||||||
|
_tweener = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 pt = GRoot.inst.GlobalToLocal(new Vector2(evt.x, evt.y));
|
||||||
|
float bx = pt.x;
|
||||||
|
float by = pt.y;
|
||||||
|
_button.selected = true;
|
||||||
|
|
||||||
|
if (bx < 0)
|
||||||
|
bx = 0;
|
||||||
|
else if (bx > _touchArea.width)
|
||||||
|
bx = _touchArea.width;
|
||||||
|
|
||||||
|
if (by > GRoot.inst.height)
|
||||||
|
by = GRoot.inst.height;
|
||||||
|
else if (by < _touchArea.y)
|
||||||
|
by = _touchArea.y;
|
||||||
|
|
||||||
|
_lastStageX = bx;
|
||||||
|
_lastStageY = by;
|
||||||
|
_startStageX = bx;
|
||||||
|
_startStageY = by;
|
||||||
|
|
||||||
|
_center.visible = true;
|
||||||
|
_center.SetXY(bx - _center.width / 2, by - _center.height / 2);
|
||||||
|
_button.SetXY(bx - _button.width / 2, by - _button.height / 2);
|
||||||
|
|
||||||
|
float deltaX = bx - _InitX;
|
||||||
|
float deltaY = by - _InitY;
|
||||||
|
float degrees = Mathf.Atan2(deltaY, deltaX) * 180 / Mathf.PI;
|
||||||
|
_thumb.rotation = degrees + 90;
|
||||||
|
|
||||||
|
context.CaptureTouch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTouchEnd(EventContext context)
|
||||||
|
{
|
||||||
|
InputEvent inputEvt = (InputEvent)context.data;
|
||||||
|
if (touchId != -1 && inputEvt.touchId == touchId)
|
||||||
|
{
|
||||||
|
touchId = -1;
|
||||||
|
_thumb.rotation = _thumb.rotation + 180;
|
||||||
|
_center.visible = false;
|
||||||
|
_tweener = _button.TweenMove(new Vector2(_InitX - _button.width / 2, _InitY - _button.height / 2), 0.3f).OnComplete(() =>
|
||||||
|
{
|
||||||
|
_tweener = null;
|
||||||
|
_button.selected = false;
|
||||||
|
_thumb.rotation = 0;
|
||||||
|
_center.visible = true;
|
||||||
|
_center.SetXY(_InitX - _center.width / 2, _InitY - _center.height / 2);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.onEnd.Call();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTouchMove(EventContext context)
|
||||||
|
{
|
||||||
|
InputEvent evt = (InputEvent)context.data;
|
||||||
|
if (touchId != -1 && evt.touchId == touchId)
|
||||||
|
{
|
||||||
|
Vector2 pt = GRoot.inst.GlobalToLocal(new Vector2(evt.x, evt.y));
|
||||||
|
float bx = pt.x;
|
||||||
|
float by = pt.y;
|
||||||
|
float moveX = bx - _lastStageX;
|
||||||
|
float moveY = by - _lastStageY;
|
||||||
|
_lastStageX = bx;
|
||||||
|
_lastStageY = by;
|
||||||
|
float buttonX = _button.x + moveX;
|
||||||
|
float buttonY = _button.y + moveY;
|
||||||
|
|
||||||
|
float offsetX = buttonX + _button.width / 2 - _startStageX;
|
||||||
|
float offsetY = buttonY + _button.height / 2 - _startStageY;
|
||||||
|
|
||||||
|
float rad = Mathf.Atan2(offsetY, offsetX);
|
||||||
|
float degree = rad * 180 / Mathf.PI;
|
||||||
|
_thumb.rotation = degree + 90;
|
||||||
|
|
||||||
|
float maxX = radius * Mathf.Cos(rad);
|
||||||
|
float maxY = radius * Mathf.Sin(rad);
|
||||||
|
if (Mathf.Abs(offsetX) > Mathf.Abs(maxX))
|
||||||
|
offsetX = maxX;
|
||||||
|
if (Mathf.Abs(offsetY) > Mathf.Abs(maxY))
|
||||||
|
offsetY = maxY;
|
||||||
|
|
||||||
|
buttonX = _startStageX + offsetX;
|
||||||
|
buttonY = _startStageY + offsetY;
|
||||||
|
if (buttonX < 0)
|
||||||
|
buttonX = 0;
|
||||||
|
if (buttonY > GRoot.inst.height)
|
||||||
|
buttonY = GRoot.inst.height;
|
||||||
|
|
||||||
|
_button.SetXY(buttonX - _button.width / 2, buttonY - _button.height / 2);
|
||||||
|
|
||||||
|
this.onMove.Call(degree);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c3af309cbf1dcb94f88c9484271c4c9d
|
||||||
|
timeCreated: 1446193148
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/LoopList.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/LoopList.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7b7ffb771e0a22b4ebf0a7c2bed7d802
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1456388404
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
63
Assets/Plugins/FairyGUI/Examples/LoopList/LoopListMain.cs
Normal file
63
Assets/Plugins/FairyGUI/Examples/LoopList/LoopListMain.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class LoopListMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
GList _list;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
UIPackage.AddPackage("UI/LoopList");
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_list = _mainView.GetChild("list").asList;
|
||||||
|
_list.SetVirtualAndLoop();
|
||||||
|
|
||||||
|
_list.itemRenderer = RenderListItem;
|
||||||
|
_list.numItems = 5;
|
||||||
|
_list.scrollPane.onScroll.Add(DoSpecialEffect);
|
||||||
|
|
||||||
|
DoSpecialEffect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoSpecialEffect()
|
||||||
|
{
|
||||||
|
//change the scale according to the distance to middle
|
||||||
|
float midX = _list.scrollPane.posX + _list.viewWidth / 2;
|
||||||
|
int cnt = _list.numChildren;
|
||||||
|
for (int i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
GObject obj = _list.GetChildAt(i);
|
||||||
|
float dist = Mathf.Abs(midX - obj.x - obj.width / 2);
|
||||||
|
if (dist > obj.width) //no intersection
|
||||||
|
obj.SetScale(1, 1);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float ss = 1 + (1 - dist / obj.width) * 0.24f;
|
||||||
|
obj.SetScale(ss, ss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_mainView.GetChild("n3").text = "" + ((_list.GetFirstChildInView() + 1) % _list.numItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderListItem(int index, GObject obj)
|
||||||
|
{
|
||||||
|
GButton item = (GButton)obj;
|
||||||
|
item.SetPivot(0.5f, 0.5f);
|
||||||
|
item.icon = UIPackage.GetItemURL("LoopList", "n" + (index + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bab7cb69f587250498d0079f0e323fb0
|
||||||
|
timeCreated: 1456388407
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/ModalWaiting.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/ModalWaiting.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7d56bcf9c2887a841b07c14e421e98d5
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1447054712
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class ModalWaitingMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
Window4 _testWin;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
UIPackage.AddPackage("UI/ModalWaiting");
|
||||||
|
UIConfig.globalModalWaiting = "ui://ModalWaiting/GlobalModalWaiting";
|
||||||
|
UIConfig.windowModalWaiting = "ui://ModalWaiting/WindowModalWaiting";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_testWin = new Window4();
|
||||||
|
|
||||||
|
_mainView.GetChild("n0").onClick.Add(() => { _testWin.Show(); });
|
||||||
|
|
||||||
|
StartCoroutine(WaitSomeTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator WaitSomeTime()
|
||||||
|
{
|
||||||
|
GRoot.inst.ShowModalWait();
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(3);
|
||||||
|
|
||||||
|
GRoot.inst.CloseModalWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 81df70f0eca40f24eb4d6448b5e3ed22
|
||||||
|
timeCreated: 1447054712
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
20
Assets/Plugins/FairyGUI/Examples/ModalWaiting/Window4.cs
Normal file
20
Assets/Plugins/FairyGUI/Examples/ModalWaiting/Window4.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class Window4 : Window
|
||||||
|
{
|
||||||
|
public Window4()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnInit()
|
||||||
|
{
|
||||||
|
this.contentPane = UIPackage.CreateObject("ModalWaiting", "TestWin").asCom;
|
||||||
|
this.contentPane.GetChild("n1").onClick.Add(OnClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnClick()
|
||||||
|
{
|
||||||
|
this.ShowModalWait();
|
||||||
|
Timers.inst.Add(3, 1, (object param) => { this.CloseModalWait(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ac9ab786f60351340a5de178d7d19c0d
|
||||||
|
timeCreated: 1447054712
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Model.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Model.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0b78b9866af43744b820fe19b605d80a
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1456389889
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
30
Assets/Plugins/FairyGUI/Examples/Model/ModelMain.cs
Normal file
30
Assets/Plugins/FairyGUI/Examples/Model/ModelMain.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class ModelMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
Object prefab = Resources.Load("Role/npc");
|
||||||
|
GameObject go = (GameObject)Object.Instantiate(prefab);
|
||||||
|
go.transform.localPosition = new Vector3(61, -89, 1000); //set z to far from UICamera is important!
|
||||||
|
go.transform.localScale = new Vector3(180, 180, 180);
|
||||||
|
go.transform.localEulerAngles = new Vector3(0, 100, 0);
|
||||||
|
_mainView.GetChild("holder").asGraph.SetNativeObject(new GoWrapper(go));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Plugins/FairyGUI/Examples/Model/ModelMain.cs.meta
Normal file
12
Assets/Plugins/FairyGUI/Examples/Model/ModelMain.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: eabf5f06c048be84cbc8226659385e1f
|
||||||
|
timeCreated: 1456390000
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Particles.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Particles.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: df311ae819dccf7428102e1700e12ae1
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446730751
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
16
Assets/Plugins/FairyGUI/Examples/Particles/CoolComponent.cs
Normal file
16
Assets/Plugins/FairyGUI/Examples/Particles/CoolComponent.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class CoolComponent : GComponent
|
||||||
|
{
|
||||||
|
public override void ConstructFromXML(FairyGUI.Utils.XML cxml)
|
||||||
|
{
|
||||||
|
base.ConstructFromXML(cxml);
|
||||||
|
|
||||||
|
GGraph graph = this.GetChild("effect").asGraph;
|
||||||
|
|
||||||
|
Object prefab = Resources.Load("Flame");
|
||||||
|
GameObject go = (GameObject)Object.Instantiate(prefab);
|
||||||
|
graph.SetNativeObject(new GoWrapper(go));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b5abdea97f302e7438821d427b458651
|
||||||
|
timeCreated: 1446781797
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
37
Assets/Plugins/FairyGUI/Examples/Particles/ParticlesMain.cs
Normal file
37
Assets/Plugins/FairyGUI/Examples/Particles/ParticlesMain.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class ParticlesMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
UIPackage.AddPackage("UI/Particles");
|
||||||
|
|
||||||
|
UIObjectFactory.SetPackageItemExtension("ui://Particles/CoolComponent", typeof(CoolComponent));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
Object prefab = Resources.Load("Flame");
|
||||||
|
GameObject go = (GameObject)Object.Instantiate(prefab);
|
||||||
|
_mainView.GetChild("holder").asGraph.SetNativeObject(new GoWrapper(go));
|
||||||
|
|
||||||
|
_mainView.GetChild("c0").draggable = true;
|
||||||
|
_mainView.GetChild("c1").draggable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1be113d23714dfb49819b314ffb3ffdc
|
||||||
|
timeCreated: 1446731503
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/Perspetive.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/Perspetive.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 75bbf0b6726dd1c4685b6a5f8970b045
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1456393929
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class PerspectiveMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GList _list;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
//GComponent g1 = GameObject.Find("UIPanel1").GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
GComponent g2 = GameObject.Find("UIPanel2").GetComponent<UIPanel>().ui;
|
||||||
|
_list = g2.GetChild("mailList").asList;
|
||||||
|
_list.SetVirtual();
|
||||||
|
_list.itemRenderer = (int index, GObject obj) => { obj.text = index + " Mail title here"; };
|
||||||
|
_list.numItems = 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ccbee12c33459e546bf698dc4ca46bea
|
||||||
|
timeCreated: 1456393933
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/PullToRefresh.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/PullToRefresh.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4cd02b3a50ee7314290496197a8ad749
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1497251849
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using FairyGUI;
|
||||||
|
|
||||||
|
public class PullToRefreshMain : MonoBehaviour
|
||||||
|
{
|
||||||
|
GComponent _mainView;
|
||||||
|
GList _list1;
|
||||||
|
GList _list2;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
Application.targetFrameRate = 60;
|
||||||
|
Stage.inst.onKeyDown.Add(OnKeyDown);
|
||||||
|
|
||||||
|
UIObjectFactory.SetPackageItemExtension("ui://PullToRefresh/Header", typeof(ScrollPaneHeader));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
_mainView = this.GetComponent<UIPanel>().ui;
|
||||||
|
|
||||||
|
_list1 = _mainView.GetChild("list1").asList;
|
||||||
|
_list1.itemRenderer = RenderListItem1;
|
||||||
|
_list1.SetVirtual();
|
||||||
|
_list1.numItems = 1;
|
||||||
|
_list1.scrollPane.onPullDownRelease.Add(OnPullDownToRefresh);
|
||||||
|
|
||||||
|
_list2 = _mainView.GetChild("list2").asList;
|
||||||
|
_list2.itemRenderer = RenderListItem2;
|
||||||
|
_list2.SetVirtual();
|
||||||
|
_list2.numItems = 1;
|
||||||
|
_list2.scrollPane.onPullUpRelease.Add(OnPullUpToRefresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderListItem1(int index, GObject obj)
|
||||||
|
{
|
||||||
|
GButton item = obj.asButton;
|
||||||
|
item.title = "Item " + (_list1.numItems - index - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderListItem2(int index, GObject obj)
|
||||||
|
{
|
||||||
|
GButton item = obj.asButton;
|
||||||
|
item.title = "Item " + index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnPullDownToRefresh()
|
||||||
|
{
|
||||||
|
ScrollPaneHeader header = (ScrollPaneHeader)_list1.scrollPane.header;
|
||||||
|
if (header.ReadyToRefresh)
|
||||||
|
{
|
||||||
|
header.SetRefreshStatus(2);
|
||||||
|
_list1.scrollPane.LockHeader(header.sourceHeight);
|
||||||
|
|
||||||
|
//Simulate a async resquest
|
||||||
|
Timers.inst.Add(2, 1, (object param) =>
|
||||||
|
{
|
||||||
|
_list1.numItems += 5;
|
||||||
|
|
||||||
|
//Refresh completed
|
||||||
|
header.SetRefreshStatus(3);
|
||||||
|
_list1.scrollPane.LockHeader(35);
|
||||||
|
|
||||||
|
Timers.inst.Add(2, 1, (object param2) =>
|
||||||
|
{
|
||||||
|
header.SetRefreshStatus(0);
|
||||||
|
_list1.scrollPane.LockHeader(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnPullUpToRefresh()
|
||||||
|
{
|
||||||
|
GComponent footer = (GComponent)_list2.scrollPane.footer;
|
||||||
|
|
||||||
|
footer.GetController("c1").selectedIndex = 1;
|
||||||
|
_list2.scrollPane.LockFooter(footer.sourceHeight);
|
||||||
|
|
||||||
|
//Simulate a async resquest
|
||||||
|
Timers.inst.Add(2, 1, (object param) =>
|
||||||
|
{
|
||||||
|
_list2.numItems += 5;
|
||||||
|
|
||||||
|
//Refresh completed
|
||||||
|
footer.GetController("c1").selectedIndex = 0;
|
||||||
|
_list2.scrollPane.LockFooter(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(EventContext context)
|
||||||
|
{
|
||||||
|
if (context.inputEvent.keyCode == KeyCode.Escape)
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cc11ef8b3e553814d83688351418d0cf
|
||||||
|
timeCreated: 1497251849
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using FairyGUI;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class ScrollPaneHeader : GComponent
|
||||||
|
{
|
||||||
|
Controller _c1;
|
||||||
|
|
||||||
|
public override void ConstructFromXML(FairyGUI.Utils.XML xml)
|
||||||
|
{
|
||||||
|
base.ConstructFromXML(xml);
|
||||||
|
|
||||||
|
_c1 = this.GetController("c1");
|
||||||
|
|
||||||
|
this.onSizeChanged.Add(OnSizeChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSizeChanged()
|
||||||
|
{
|
||||||
|
if (_c1.selectedIndex == 2 || _c1.selectedIndex == 3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this.height > this.sourceHeight)
|
||||||
|
_c1.selectedIndex = 1;
|
||||||
|
else
|
||||||
|
_c1.selectedIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ReadyToRefresh
|
||||||
|
{
|
||||||
|
get { return _c1.selectedIndex == 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetRefreshStatus(int value)
|
||||||
|
{
|
||||||
|
_c1.selectedIndex = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 30c3bcfb5d9414e4d8f75eedcfddea9c
|
||||||
|
timeCreated: 1497253470
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/Plugins/FairyGUI/Examples/RenderTexture.meta
Normal file
9
Assets/Plugins/FairyGUI/Examples/RenderTexture.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f22327fed912f5d43a01c26c059c39ac
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446193142
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
292
Assets/Plugins/FairyGUI/Examples/RenderTexture/RenderImage.cs
Normal file
292
Assets/Plugins/FairyGUI/Examples/RenderTexture/RenderImage.cs
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
using FairyGUI;
|
||||||
|
using FairyGUI.Utils;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class RenderImage
|
||||||
|
{
|
||||||
|
public Transform modelRoot { get; private set; }
|
||||||
|
|
||||||
|
Camera _camera;
|
||||||
|
Image _image;
|
||||||
|
Transform _root;
|
||||||
|
Transform _background;
|
||||||
|
Transform _model;
|
||||||
|
RenderTexture _renderTexture;
|
||||||
|
int _width;
|
||||||
|
int _height;
|
||||||
|
bool _cacheTexture;
|
||||||
|
float _rotating;
|
||||||
|
|
||||||
|
const int RENDER_LAYER = 0;
|
||||||
|
const int HIDDEN_LAYER = 10;
|
||||||
|
|
||||||
|
public RenderImage(GGraph holder)
|
||||||
|
{
|
||||||
|
_width = (int)holder.width;
|
||||||
|
_height = (int)holder.height;
|
||||||
|
_cacheTexture = true;
|
||||||
|
|
||||||
|
this._image = new Image();
|
||||||
|
holder.SetNativeObject(this._image);
|
||||||
|
|
||||||
|
Object prefab = Resources.Load("RenderTexture/RenderImageCamera");
|
||||||
|
GameObject go = (GameObject)Object.Instantiate(prefab);
|
||||||
|
_camera = go.GetComponent<Camera>();
|
||||||
|
_camera.transform.position = new Vector3(0, 1000, 0);
|
||||||
|
_camera.cullingMask = 1 << RENDER_LAYER;
|
||||||
|
_camera.enabled = false;
|
||||||
|
Object.DontDestroyOnLoad(_camera.gameObject);
|
||||||
|
|
||||||
|
this._root = new GameObject("RenderImage").transform;
|
||||||
|
this._root.SetParent(_camera.transform, false);
|
||||||
|
SetLayer(this._root.gameObject, HIDDEN_LAYER);
|
||||||
|
|
||||||
|
this.modelRoot = new GameObject("model_root").transform;
|
||||||
|
this.modelRoot.SetParent(this._root, false);
|
||||||
|
|
||||||
|
this._background = new GameObject("background").transform;
|
||||||
|
this._background.SetParent(this._root, false);
|
||||||
|
|
||||||
|
this._image.onAddedToStage.Add(OnAddedToStage);
|
||||||
|
this._image.onRemovedFromStage.Add(OnRemoveFromStage);
|
||||||
|
|
||||||
|
if (this._image.stage != null)
|
||||||
|
OnAddedToStage();
|
||||||
|
else
|
||||||
|
_camera.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Object.Destroy(_camera.gameObject);
|
||||||
|
DestroyTexture();
|
||||||
|
|
||||||
|
this._image.Dispose();
|
||||||
|
this._image = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The rendertexture is not transparent. So if you want to the UI elements can be seen in the back of the models/particles in rendertexture,
|
||||||
|
/// you can set a maximunm two images for background.
|
||||||
|
/// Be careful if your image is 9 grid scaling, you must make sure the place holder is inside the middle box(dont cover from border to middle).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image"></param>
|
||||||
|
public void SetBackground(GObject image)
|
||||||
|
{
|
||||||
|
SetBackground(image, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The rendertexture is not transparent. So if you want to the UI elements can be seen in the back of the models/particles in rendertexture,
|
||||||
|
/// you can set a maximunm two images for background.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image1"></param>
|
||||||
|
/// <param name="image2"></param>
|
||||||
|
public void SetBackground(GObject image1, GObject image2)
|
||||||
|
{
|
||||||
|
Image source1 = (Image)image1.displayObject;
|
||||||
|
Image source2 = image2 != null ? (Image)image2.displayObject : null;
|
||||||
|
|
||||||
|
Vector3 pos = _background.position;
|
||||||
|
pos.z = _camera.farClipPlane;
|
||||||
|
_background.position = pos;
|
||||||
|
|
||||||
|
Vector2[] uv = new Vector2[4];
|
||||||
|
Vector2[] uv2 = null;
|
||||||
|
|
||||||
|
Rect rect = _image.TransformRect(new Rect(0, 0, this._width, this._height), source1);
|
||||||
|
Rect uvRect = GetImageUVRect(source1, rect, uv);
|
||||||
|
|
||||||
|
if (source2 != null)
|
||||||
|
{
|
||||||
|
rect = _image.TransformRect(new Rect(0, 0, this._width, this._height), source2);
|
||||||
|
uv2 = new Vector2[4];
|
||||||
|
GetImageUVRect(source2, rect, uv2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3[] vertices = new Vector3[4];
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
Vector2 v = uv[i];
|
||||||
|
vertices[i] = new Vector3((v.x - uvRect.x) / uvRect.width * 2 - 1,
|
||||||
|
(v.y - uvRect.y) / uvRect.height * 2 - 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mesh mesh = new Mesh();
|
||||||
|
mesh.vertices = vertices;
|
||||||
|
mesh.uv = uv;
|
||||||
|
if (uv2 != null)
|
||||||
|
mesh.uv2 = uv2;
|
||||||
|
mesh.colors32 = new Color32[] { Color.white, Color.white, Color.white, Color.white };
|
||||||
|
mesh.triangles = new int[] { 0, 1, 2, 2, 3, 0 };
|
||||||
|
|
||||||
|
MeshFilter meshFilter = this._background.gameObject.GetComponent<MeshFilter>();
|
||||||
|
if (meshFilter == null)
|
||||||
|
meshFilter = this._background.gameObject.AddComponent<MeshFilter>();
|
||||||
|
meshFilter.mesh = mesh;
|
||||||
|
MeshRenderer meshRenderer = this._background.gameObject.GetComponent<MeshRenderer>();
|
||||||
|
if (meshRenderer == null)
|
||||||
|
meshRenderer = this._background.gameObject.AddComponent<MeshRenderer>();
|
||||||
|
#if (UNITY_5 || UNITY_5_3_OR_NEWER)
|
||||||
|
meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||||
|
#else
|
||||||
|
meshRenderer.castShadows = false;
|
||||||
|
#endif
|
||||||
|
meshRenderer.receiveShadows = false;
|
||||||
|
Shader shader = Shader.Find("Game/FullScreen");
|
||||||
|
Material mat = new Material(shader);
|
||||||
|
mat.mainTexture = source1.texture.nativeTexture;
|
||||||
|
if (source2 != null)
|
||||||
|
mat.SetTexture("_Tex2", source2.texture.nativeTexture);
|
||||||
|
meshRenderer.material = mat;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect GetImageUVRect(Image image, Rect localRect, Vector2[] uv)
|
||||||
|
{
|
||||||
|
Rect imageRect = new Rect(0, 0, image.size.x, image.size.y);
|
||||||
|
Rect bound = ToolSet.Intersection(ref imageRect, ref localRect);
|
||||||
|
Rect uvRect = image.texture.uvRect;
|
||||||
|
|
||||||
|
if (image.scale9Grid != null)
|
||||||
|
{
|
||||||
|
Rect gridRect = (Rect)image.scale9Grid;
|
||||||
|
float sourceW = image.texture.width;
|
||||||
|
float sourceH = image.texture.height;
|
||||||
|
uvRect = Rect.MinMaxRect(Mathf.Lerp(uvRect.xMin, uvRect.xMax, gridRect.xMin / sourceW),
|
||||||
|
Mathf.Lerp(uvRect.yMin, uvRect.yMax, (sourceH - gridRect.yMax) / sourceH),
|
||||||
|
Mathf.Lerp(uvRect.xMin, uvRect.xMax, gridRect.xMax / sourceW),
|
||||||
|
Mathf.Lerp(uvRect.yMin, uvRect.yMax, (sourceH - gridRect.yMin) / sourceH));
|
||||||
|
|
||||||
|
float vw = imageRect.width - (sourceW - gridRect.width);
|
||||||
|
float vh = imageRect.height - (sourceH - gridRect.height);
|
||||||
|
uvRect = Rect.MinMaxRect(Mathf.Lerp(uvRect.xMin, uvRect.xMax, (bound.x - gridRect.x) / vw),
|
||||||
|
Mathf.Lerp(uvRect.yMin, uvRect.yMax, (imageRect.height - bound.yMax - (sourceH - gridRect.yMax)) / vh),
|
||||||
|
Mathf.Lerp(uvRect.xMin, uvRect.xMax, (bound.xMax - gridRect.x) / vw),
|
||||||
|
Mathf.Lerp(uvRect.yMin, uvRect.yMax, (imageRect.height - bound.yMin - gridRect.y) / vh));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uvRect = Rect.MinMaxRect(Mathf.Lerp(uvRect.xMin, uvRect.xMax, bound.xMin / imageRect.width),
|
||||||
|
Mathf.Lerp(uvRect.yMin, uvRect.yMax, (imageRect.height - bound.yMax) / imageRect.height),
|
||||||
|
Mathf.Lerp(uvRect.xMin, uvRect.xMax, bound.xMax / imageRect.width),
|
||||||
|
Mathf.Lerp(uvRect.yMin, uvRect.yMax, (imageRect.height - bound.yMin) / imageRect.height));
|
||||||
|
}
|
||||||
|
|
||||||
|
uv[0] = uvRect.position;
|
||||||
|
uv[1] = new Vector2(uvRect.xMin, uvRect.yMax);
|
||||||
|
uv[2] = new Vector2(uvRect.xMax, uvRect.yMax);
|
||||||
|
uv[3] = new Vector2(uvRect.xMax, uvRect.yMin);
|
||||||
|
|
||||||
|
if (image.texture.rotated)
|
||||||
|
ToolSet.RotateUV(uv, ref image.texture.uvRect);
|
||||||
|
|
||||||
|
return uvRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadModel(string model)
|
||||||
|
{
|
||||||
|
this.UnloadModel();
|
||||||
|
|
||||||
|
Object prefab = Resources.Load(model);
|
||||||
|
GameObject go = ((GameObject)Object.Instantiate(prefab));
|
||||||
|
_model = go.transform;
|
||||||
|
_model.SetParent(this.modelRoot, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnloadModel()
|
||||||
|
{
|
||||||
|
if (_model != null)
|
||||||
|
{
|
||||||
|
Object.Destroy(_model.gameObject);
|
||||||
|
_model = null;
|
||||||
|
}
|
||||||
|
_rotating = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartRotate(float delta)
|
||||||
|
{
|
||||||
|
_rotating = delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopRotate()
|
||||||
|
{
|
||||||
|
_rotating = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateTexture()
|
||||||
|
{
|
||||||
|
if (_renderTexture != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_renderTexture = new RenderTexture(_width, _height, 24, RenderTextureFormat.ARGB32)
|
||||||
|
{
|
||||||
|
antiAliasing = 1,
|
||||||
|
filterMode = FilterMode.Bilinear,
|
||||||
|
anisoLevel = 0,
|
||||||
|
useMipMap = false
|
||||||
|
};
|
||||||
|
this._image.texture = new NTexture(_renderTexture);
|
||||||
|
this._image.blendMode = BlendMode.Off;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DestroyTexture()
|
||||||
|
{
|
||||||
|
if (_renderTexture != null)
|
||||||
|
{
|
||||||
|
Object.Destroy(_renderTexture);
|
||||||
|
_renderTexture = null;
|
||||||
|
this._image.texture = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnAddedToStage()
|
||||||
|
{
|
||||||
|
if (_renderTexture == null)
|
||||||
|
CreateTexture();
|
||||||
|
|
||||||
|
Timers.inst.AddUpdate(this.Render);
|
||||||
|
_camera.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
Render();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnRemoveFromStage()
|
||||||
|
{
|
||||||
|
if (!_cacheTexture)
|
||||||
|
DestroyTexture();
|
||||||
|
|
||||||
|
Timers.inst.Remove(this.Render);
|
||||||
|
_camera.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Render(object param = null)
|
||||||
|
{
|
||||||
|
if (_rotating != 0 && this.modelRoot != null)
|
||||||
|
{
|
||||||
|
Vector3 localRotation = this.modelRoot.localRotation.eulerAngles;
|
||||||
|
localRotation.y += _rotating;
|
||||||
|
this.modelRoot.localRotation = Quaternion.Euler(localRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetLayer(this._root.gameObject, RENDER_LAYER);
|
||||||
|
|
||||||
|
_camera.targetTexture = this._renderTexture;
|
||||||
|
RenderTexture old = RenderTexture.active;
|
||||||
|
RenderTexture.active = this._renderTexture;
|
||||||
|
GL.Clear(true, true, Color.clear);
|
||||||
|
_camera.Render();
|
||||||
|
RenderTexture.active = old;
|
||||||
|
|
||||||
|
SetLayer(this._root.gameObject, HIDDEN_LAYER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetLayer(GameObject go, int layer)
|
||||||
|
{
|
||||||
|
Transform[] transforms = go.GetComponentsInChildren<Transform>(true);
|
||||||
|
foreach (Transform t in transforms)
|
||||||
|
{
|
||||||
|
t.gameObject.layer = layer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aeda19930ca9fac4a84f365bf998d0cf
|
||||||
|
timeCreated: 1446193148
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
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
Reference in New Issue
Block a user