Beispiel #1
0
    /// <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);
    }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 /// <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);
 }
Beispiel #4
0
    /// <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);
    }