/// <summary> /// 创建actor /// </summary> public Actor CreateActor(int itemId, ActorType type, int campId, long actorId = 0) { Actor actor = null; actorId = actorId == 0 ? (int)IdAssginer.getId(IdAssginer.IdType.ActorId) : actorId; //test switch (type) { case ActorType.Monster: case ActorType.Fly: case ActorType.Ship: actor = new Actor(itemId, type, actorId, campId); break; case ActorType.Player: case ActorType.OtherPlayer: actor = new Actor(itemId, type, actorId, campId); break; } if (actor != null) { if (actors.ContainsKey(actorId)) { Debug.LogError("重复添加actor:" + actorId); } else { actors[actorId] = actor; Debug.LogError("添加actor:" + actorId); } actor.Initalize(); } return(actor); }
public MyWWW(string url, float outTime, UnityAction <WWW> cmpCallBack = null, UnityAction timeOutCallBack = null, UnityAction failCallback = null, string postfix = "") { mWWW = new UnityEngine.WWW(url); mFailCallBack = failCallback; mCmpCallBack = cmpCallBack; mTimeOutCallBack = timeOutCallBack; mTimeOut = outTime; mPassedTime = 0; ID = IdAssginer.getId(IdAssginer.IdType.WWW).ToString() + postfix; }
/// <summary> /// 启动一个协程 /// </summary> /// <param name="co"></param> /// <returns></returns> public Int64 AddCoroutine(IEnumerator co) { if (this.gameObject.activeSelf) { CoroutineTask task = new CoroutineTask(IdAssginer.getId(IdAssginer.IdType.CoroutineId)); mCoroutines.add(task.Id.ToString(), task); StartCoroutine(task.CoroutineWrapper(co)); return(task.Id); } return(-1); }
/// <summary> /// Set timer /// </summary> /// <param name="Owner">The object that contains the timer. Required in order to remove the timer if the object is destroyed.</param> /// <param name="timer">Timer to add</param> public static long SetTimer(object Owner, Timer timer, string nickName = "") { long id = 0; if (timer.Delegate() != null && timer.Interval() > 0f && Owner != null && timer.LoopsCount() > 0) { id = IdAssginer.GetID(IdAssginer.IdType.Times); ClearTimer(timer.Delegate()); m_Timers.Add(new TimersEntity(id, nickName, new WeakReference(Owner)), timer); } return(id); }
/// <summary> /// Set an infinitely loopable timer /// </summary> /// <param name="Owner">The object that contains the timer. Required in order to remove the timer if the object is destroyed.</param> /// <param name="interval">Interval(in seconds)</param> /// <param name="unityAction">Delegate</param> public static long SetLoopableTimer(object Owner, float interval, UnityAction unityAction, string nickName = "") { long id = 0; if (unityAction != null && interval > 0f && Owner != null) { id = IdAssginer.GetID(IdAssginer.IdType.Times); ClearTimer(unityAction); m_Timers.Add(new TimersEntity(id, nickName, new WeakReference(Owner)), new Timer(interval, Timer.INFINITE, unityAction)); } return(id); }
/// <summary> /// Set a timer that loops LoopCount times /// </summary> /// <param name="Owner">The object that contains the timer. Required in order to remove the timer if the object is destroyed.</param> /// <param name="interval">Interval(in seconds) between loops</param> /// <param name="LoopsCount">How many times to loop</param> /// <param name="UnityAction">Delegate</param> public static long SetTimer(object Owner, float interval, uint LoopsCount, UnityAction unityAction, string nickName = "") { long id = 0; LoopsCount = System.Math.Max(LoopsCount, 1); if (unityAction != null && interval > 0f && Owner != null && LoopsCount > 0) { id = IdAssginer.GetID(IdAssginer.IdType.Times); ClearTimer(unityAction); m_Timers.Add(new TimersEntity(id, nickName, new WeakReference(Owner)), new Timer(interval, LoopsCount, unityAction)); } return(id); }
/// <summary> /// 播放音效 /// </summary> /// <param name="name"></param> /// <param name="loop"></param> /// <returns></returns> public long PlaySound(string name, bool loop = false) { if (!SoundFlag) { return(-1); } if (string.IsNullOrEmpty(name)) { Debug.LogWarning("某处的音效播放参数为空!"); return(-1); } var asset = Load(name) as AudioAsset; if (asset == null) { return(-1); } GameObject audioObj = getFromPool(); var clip = asset.GetAsset(); var aSrc = audioObj.GetComponent <AudioSource>(); audioObj.SetActive(true); aSrc.loop = loop; aSrc.clip = clip; aSrc.enabled = true; aSrc.Play(); var id = IdAssginer.getId(IdAssginer.IdType.Audio); mPlayingIds.Add(id, new AudioGObjAssetPair { audioObj = audioObj, asset = asset }); asset.AddRef(); if (!loop) { CoroutineManager.Singleton.delayedCall(clip.length, () => autoRemove(id)); } return(id); }
/// <summary> /// Add a list of timers. Works great with List<Timer> in inspector. See 'TimersList.cs' for an example. /// </summary> /// <param name="Owner">Owner of timers. This should be the object that have these timers. Required in order to remove the timers if the object is destroyed.</param> /// <param name="Timers">Timers list</param> public static long[] AddTimers(object Owner, List <Timer> Timers) { List <long> ids = new List <long>(); if (Owner == null) { #if UNITY_EDITOR Debug.LogWarning("Owner is null. Aborted."); #endif return(null); } foreach (Timer timer in Timers) { if (timer.Interval() > 0f && Owner != null && timer.LoopsCount() > 0) { timer.UpdateActionFromEvent(); long id = IdAssginer.GetID(IdAssginer.IdType.Times); m_Timers.Add(new TimersEntity(id, "", new WeakReference(Owner)), timer); ids.Add(id); } } return(ids.ToArray()); }