public virtual void Tick(float elapse) { if (this.next != null) { if (this.current != null) { this.current.Quit(); } this.current = this.next; this.next = null; XCSharp.InvokeAction(this.onChangeState, this.last, this.current); if (this.current != null) { this.current.Init(this); } } else { if (this.current != null) { this.current.Update(elapse); } } }
public void LoadPrefabAsync(string bundleName, string prefabName, System.Action <GameObject> handler) { if (string.IsNullOrEmpty(bundleName) || string.IsNullOrEmpty(prefabName)) { XCSharp.InvokeAction(handler, null); return; } this.LoadAssetAsync <GameObject>(bundleName, "Prefabs/" + prefabName, handler); }
public static void WriteTextFile(string filePath, string data) { XCSharp.MakeDir(Path.GetDirectoryName(filePath)); TextWriter writer = new StreamWriter(filePath, false, Encoding.UTF8); writer.Write(data); writer.Flush(); writer.Close(); }
public static void WriteBytesFile(string filePath, byte[] data, int offset, int count) { XCSharp.MakeDir(Path.GetDirectoryName(filePath)); FileStream stream = File.OpenWrite(filePath); stream.Write(data, offset, count); stream.Flush(); stream.Close(); }
public static float Decode(byte[] data) { byte[] temp = new byte[data.Length]; Array.Copy(data, temp, data.Length); XCSharp.Decipher(temp, 0, 3, temp[3]); float value = BitConverter.ToSingle(temp, 0); return(value); }
public void LoadAssetAsync <T>(string bundleName, string location, System.Action <T> handler) where T : Object { if (string.IsNullOrEmpty(bundleName) || string.IsNullOrEmpty(location)) { Debug.LogError("LoadAssetAsync: bundle name or location is null or empty. bundle=" + bundleName + "\n location=" + location); XCSharp.InvokeAction(handler, null); return; } this.StartCoroutine(this.CreateAssetAsync <T>(bundleName, location, handler)); }
public bool Load(string filePath) { this.mFilePath = filePath; string content = XFile.ReadTextFile(this.mFilePath); this.mContents = XTableExchange.lua.StringToTable(XCSharp.EncodeUTF8(content)); if (this.mContents == null) { this.mContents = new XTable(); } return(true); }
public static string LocalBundleURI(string package) { string path = AssetPath.LocalBundlePath(package); path = XCSharp.FileURI(path); if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { path = path.Replace("file://", "file:///"); } return(path); }
public virtual void Close() { if (this.destroyOnClose) { Object.Destroy(this.gameObject); } else { this.gameObject.SetActive(false); } XCSharp.InvokeAction(this.onClose); }
private IEnumerator CreateSceneAsync(string sceneName, System.Action <string> handler = null) { this.mIsLoadingScene = true; this.mLoadingSceneName = sceneName; string bundleName = this.GetBundleNameFromLevelName(sceneName); if (string.IsNullOrEmpty(bundleName)) { var oper = SceneManager.LoadSceneAsync(sceneName); yield return(oper); } else { AssetBundle bundle = mBundleCache.Get(bundleName); if (bundle == null) { BundleLoading loading = new BundleLoading(); yield return(this.StartCoroutine(loading.LoadAsync(bundleName))); if (!string.IsNullOrEmpty(loading.error)) { Debug.LogError(loading.error); this.mIsLoadingScene = false; XCSharp.InvokeAction(handler, ""); yield break; } bundle = loading.bundle; } if (bundle == null) { this.mIsLoadingScene = false; XCSharp.InvokeAction(handler, ""); yield break; } var oper = SceneManager.LoadSceneAsync(sceneName); yield return(oper); if (bundle != null) { bundle.Unload(false); } } this.mIsLoadingScene = false; XCSharp.InvokeAction(handler, sceneName); }
public void LoadAssetAsync <T>(string path, System.Action <T> handler) where T : Object { int index = path.IndexOf('/'); if (index <= 0 || index >= path.Length - 1) { XCSharp.InvokeAction(handler, null); return; } string bundleName = path.Substring(0, index); string location = path.Substring(index + 1); this.LoadAssetAsync <T>(bundleName, location, handler); }
void Awake() { // register messages XCSharp.InvokeAction(this.onRegisterMessages, this); // register recv-callback this.mClient.OnConnSuccess += this.OnConnSuccess; this.mClient.OnConnFailure += this.OnConnFailure; this.mClient.OnSendSuccess += this.OnSendSuccess; this.mClient.OnSendFailure += this.OnSendFailure; this.mClient.OnSendRawdata += this.OnSendRawdata; this.mClient.OnSendMessage += this.OnSendMessage; this.mClient.OnRecvSuccess += this.OnRecvSuccess; this.mClient.OnRecvFailure += this.OnRecvFailure; this.mClient.OnRecvRawdata += this.OnRecvRawdata; this.mClient.OnRecvMessage += this.OnRecvMessage; }
public static string StreamBundleURI(string package) { string path = AssetPath.StreamBundlePath(package); if (Application.platform != RuntimePlatform.Android) { path = XCSharp.FileURI(path); if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { path = path.Replace("file://", "file:///"); } } else { path = XCSharp.JarFileURI(path); } return(path); }
public object GetValue(int index) { string type = mLuaState.L_TypeName(index); switch (type) { case "number": return(mLuaState.ToNumber(index)); case "boolean": return(mLuaState.ToBoolean(index)); case "string": string utf8 = mLuaState.ToString(index); return(XCSharp.DecodeUTF8(utf8)); case "function": return(mLuaState.L_Ref(UniLua.LuaDef.LUA_REGISTRYINDEX)); case "table": XTable table = new XTable(); { mLuaState.PushValue(index); int t = mLuaState.GetTop(); mLuaState.PushNil(); while (mLuaState.Next(t)) { object key = this.GetValue(-2); object val = this.GetValue(-1); table[key] = val; mLuaState.Pop(1); } mLuaState.Pop(1); } return(table); default: return(mLuaState.ToUserData(index)); } }
public void AcquireGameObjectAsync(string bundleName, string prefabName, System.Action <GameObject> handler) { GameObject go = mGameObjectPool.Pop(bundleName, prefabName); if (go != null) { go.SetActive(true); XCSharp.InvokeAction(handler, go); return; } this.LoadPrefabAsync(bundleName, prefabName, prefab => { if (prefab == null) { XCSharp.InvokeAction(handler, null); return; } GameObject result = Object.Instantiate(prefab) as GameObject; XCSharp.InvokeAction(handler, result); }); }
public static string JarFileURI(string path) { return(XCSharp.PathToURI("jar:file://", path)); }
public int PushValue(object o) { if (o == null) { mLuaState.PushNil(); return(1); } Type t = o.GetType(); switch (t.FullName) { case "System.Boolean": { mLuaState.PushBoolean((bool)o); return(1); } case "System.Char": { mLuaState.PushString(((char)o).ToString()); return(1); } case "System.Byte": { mLuaState.PushNumber((byte)o); return(1); } case "System.SByte": { mLuaState.PushNumber((sbyte)o); return(1); } case "System.Int16": { mLuaState.PushNumber((short)o); return(1); } case "System.UInt16": { mLuaState.PushNumber((ushort)o); return(1); } case "System.Int32": { mLuaState.PushNumber((int)o); return(1); } case "System.UInt32": { mLuaState.PushNumber((uint)o); return(1); } case "System.Int64": { mLuaState.PushUInt64((ulong)o); return(1); } case "System.UInt64": { mLuaState.PushUInt64((ulong)o); return(1); } case "System.Single": { mLuaState.PushNumber((float)o); return(1); } case "System.Double": { mLuaState.PushNumber((double)o); return(1); } case "System.Decimal": { mLuaState.PushLightUserData((decimal)o); return(1); } case "System.String": { string utf8 = XCSharp.EncodeUTF8(o as string); mLuaState.PushString(utf8); return(1); } case "System.Object": { mLuaState.PushLightUserData((object)o); return(1); } case "XTable": { mLuaState.NewTable(); XTable table = o as XTable; foreach (string key in table.Nodes.Keys) { object val = table.Nodes[key]; this.PushValue(key); this.PushValue(val); mLuaState.RawSet(-3); } mLuaState.RawSet(-3); return(1); } default: { mLuaState.PushLightUserData((object)o); return(1); } } }
void OnPressItem(InputTouch touch, DragListItem item) { this.mPressItem = item; XCSharp.InvokeAction(this.onPressItem, this, item); }
public virtual void Open() { XCSharp.InvokeAction(this.onOpen); this.gameObject.SetActive(true); }
void OnClick(InputTouch touch) { XCSharp.InvokeAction(this.onClick, touch, this); }
void OnPress(InputTouch touch) { XCSharp.InvokeAction(this.onPress, touch, this); }
void OnClickItem(InputTouch touch, DragListItem item) { XCSharp.InvokeAction(this.onClickItem, this, item); }
public static byte[] Encode(float value) { byte[] data = BitConverter.GetBytes(value); XCSharp.Encrypt(data, 0, 3, data[3]); return(data); }
public static object Deserialize(MemoryStream stream, Type type) { BinaryReader reader = new BinaryReader(stream); object o = Activator.CreateInstance(type); FieldInfo[] fields = o.GetType().GetFields(); foreach (FieldInfo f in fields) { Type t = f.FieldType; object v = null; switch (t.FullName) { case "System.Boolean": v = reader.ReadBoolean(); break; case "System.Char": v = reader.ReadChar(); break; case "System.Byte": v = reader.ReadByte(); break; case "System.SByte": v = reader.ReadSByte(); break; case "System.Int16": v = reader.ReadInt16(); break; case "System.UInt16": v = reader.ReadUInt16(); break; case "System.Int32": v = reader.ReadInt32(); break; case "System.UInt32": v = reader.ReadUInt32(); break; case "System.Int64": v = reader.ReadInt64(); break; case "System.UInt64": v = reader.ReadUInt64(); break; case "System.Single": v = reader.ReadSingle(); break; case "System.Double": v = reader.ReadDouble(); break; case "System.Decimal": v = reader.ReadDecimal(); break; case "System.String": v = reader.ReadString(); break; default: v = XCSharp.Deserialize(stream, t); break; } f.SetValue(o, v); } return(o); }
public static void Serialize(Stream stream, object value) { BinaryWriter writer = new BinaryWriter(stream); FieldInfo[] fields = value.GetType().GetFields(); foreach (FieldInfo f in fields) { Type t = f.FieldType; object v = f.GetValue(value); switch (t.FullName) { case "System.Boolean": writer.Write((bool)v); break; case "System.Char": writer.Write((char)v); break; case "System.Byte": writer.Write((byte)v); break; case "System.SByte": writer.Write((sbyte)v); break; case "System.Int16": writer.Write((short)v); break; case "System.UInt16": writer.Write((ushort)v); break; case "System.Int32": writer.Write((int)v); break; case "System.UInt32": writer.Write((uint)v); break; case "System.Int64": writer.Write((long)v); break; case "System.UInt64": writer.Write((ulong)v); break; case "System.Single": writer.Write((float)v); break; case "System.Double": writer.Write((double)v); break; case "System.Decimal": writer.Write((decimal)v); break; case "System.String": writer.Write((string)v); break; default: XCSharp.Serialize(stream, v); break; } } }
void OnMoveAnyWhere(InputTouch touch) { if (this.mPressTouch == null || touch.fingerId != this.mPressTouch.fingerId) { return; } RaycastHit hit; if (this.TouchOnColliders(this.mPressTouch, touch, out hit)) { Vector3 point = this.transform.InverseTransformPoint(hit.point); Vector3 delta = point - this.mLastPoint; if (this.Approximately(delta, Vector3.zero)) { return; } this.mPressDelta += delta; if (this.mPressItem != null && this.mPressItem.canBeDragOut && touch.target != null && touch.target == this.mPressItem.inputTarget) { float sqrd = this.mPressDelta.sqrMagnitude; float angle = Vector3.Angle(this.mPressDelta, this.mDirection); if (sqrd > this.dragOut * this.dragOut && angle > 45 && angle < 135) { XCSharp.InvokeAction(this.onDragOut, this, this.mPressItem); if (this.mPressItem.removeWhenDragOut) { this.Remove(this.mPressItem); } this.mPressTouch = null; this.mPressItem = null; return; } } delta = this.ShadowOnNomalized(delta, this.mDirection); delta = this.AdjustDeltaInRange(delta); this.mLastPoint = point; this.mLastDelta = delta; this.mDestination += delta; this.mNeedUpdate = true; } else { if (this.mPressItem != null && this.mPressItem.canBeDragOut) { XCSharp.InvokeAction(this.onDragOut, this, this.mPressItem); if (this.mPressItem.removeWhenDragOut) { this.Remove(this.mPressItem); } this.mPressTouch = null; this.mPressItem = null; } } }
void Awake() { XCSharp.InvokeAction(this.onAwake); }
private IEnumerator CreateAssetAsync <T>(string bundleName, string location, System.Action <T> handler) where T : Object { // get from cache { T asset = mAssetCache.Get <T>(bundleName, location); if (asset != null) { XCSharp.InvokeAction(handler, asset); yield break; } } // async begins if (mAssetWaitings.Wait(bundleName, location, handler)) { yield break; } string assetPath = bundleName + "/" + location; var req = Resources.LoadAsync <T>(assetPath); yield return(req); if (req.asset != null) { mAssetCache.Put(bundleName, location, req.asset); mAssetWaitings.Notify(location, req.asset as T); yield break; } AssetBundle bundle = mBundleCache.Get(bundleName); if (bundle == null) { BundleLoading loading = mBundleLoader.GetBundleAsyncLoading(bundleName); if (loading != null) { while (!loading.done) { yield return(null); } bundle = loading.bundle; } else { loading = mBundleLoader.NewBundleAsyncLoading(bundleName); yield return(this.StartCoroutine(loading.LoadAsync(bundleName))); if (!string.IsNullOrEmpty(loading.error)) { mAssetWaitings.Notify(location, null as T); yield break; } bundle = loading.bundle; if (bundle != null) { mBundleCache.Put(bundleName, bundle); } } mBundleLoader.RemoveBundleAsyncLoading(bundleName); } if (bundle == null) { mAssetWaitings.Notify(location, null as T); yield break; } { string assetName = System.IO.Path.GetFileName(location); var request = bundle.LoadAssetAsync <T>(assetName); yield return(request); // check if the bundle is destroyed by extern code. if (bundle == null) { mAssetWaitings.Notify(location, null as T); yield break; } // get asset now. if (request.asset != null) { mAssetCache.Put(bundleName, location, request.asset); } mAssetWaitings.Notify(location, request.asset as T); } }
void OnParticleCollision(GameObject other) { XCSharp.InvokeAction(this.onParticleCollision, other); }
public static string HttpURI(string path) { return(XCSharp.PathToURI("http://", path)); }