protected override void OnEvent(bool paramBool) { if (paramBool) { if (spawnTemplate != null) { return; } if (m_spawnRef != null) { ResourceSystem.Load <GameObject>(m_spawnRef, OnLoadComplete); } else if (string.IsNullOrEmpty(m_spawnResource)) { ResourceSystem.Load <GameObject>(m_spawnResource, OnLoadComplete); } else if (m_spawnObj != null) { OnLoadComplete(m_spawnObj); } } else { if (spawnedObj) { Destroy(spawnedObj); } } }
public bool PlayAnimation(string path, AnimPlayType type, float speed = 1.0f, bool loop = false, bool reverse = false, float fadeLength = 0.15f, float time = 0.0f, bool async = true) { if (type == AnimPlayType.Priority) { Debug.LogError("高优先级动画请用PlayPriorityAnimation播放!"); return(false); } if (string.IsNullOrEmpty(path)) { return(false); } if (async) { // 未来Lambda改成Request ResourceSystem.LoadAsync <AnimationClip>(path, (o) => { AnimationClip c = o as AnimationClip; if (c == null) { return; } PlayClipAnimation(c, c.name, type, speed * mAnimSpeed, loop, reverse, fadeLength, time); }); } else { AnimationClip c = ResourceSystem.Load <AnimationClip>(path); if (c == null) { return(false); } PlayClipAnimation(c, c.name, type, speed * mAnimSpeed, loop, reverse, fadeLength, time); } return(true); }
public static ChildObject CreateChildObject(int id, Character owner, Transform parentObj, Vector3 targetPos, Character target = null) { excel_child_object data = excel_child_object.Find(id); if (data == null) { Debug.LogError("未找到ID为" + id + "的子物体"); return(null); } GameObject go = ResourceSystem.Load <GameObject>("Particles/Prefabs/" + data.path); if (go == null) { return(null); } go = GameObject.Instantiate(go); ChildObject childObject = go.GetComponent <ChildObject>(); if (childObject == null) { childObject = go.AddComponent <ChildObject>(); } if (!childObject.gameObject.activeSelf) { childObject.gameObject.SetActive(true); } childObject.Reset(); childObject.mVanish = false; childObject.mContext.Reset(); childObject.mContext.mOwner = owner; childObject.mContext.mChildObject = childObject; childObject.mContext.SkillTargetID = target == null ? 0 : target.gid; childObject.mContext.TargetPos = targetPos; childObject.mData = data; childObject.mParentObj = null; childObject.Init(parentObj); return(childObject); }
private void Awake() { MessageSystem.Instance.MsgRegister(MessageType.InitHeadBar, OnInitHeadBar); GameObject spawnPoolGO = new GameObject("HeadTextPool"); spawnPoolGO.transform.position = Vector3.zero; spawnPoolGO.transform.rotation = Quaternion.identity; spawnPoolGO.transform.localScale = Vector3.one; mHeadTextPool = spawnPoolGO.AddComponent <SpawnPool>(); mHeadTextPool.poolName = "HeadTextPool"; mHeadTextPool.dontDestroyOnLoad = true; headTextTransform = ResourceSystem.Load <Transform>("GUI/UI_HeadText"); PrefabPool refabPool = new PrefabPool(headTextTransform); //默认初始化两个Prefab refabPool.preloadAmount = 0; //开启限制 refabPool.limitInstances = true; //关闭无限取Prefab refabPool.limitFIFO = false; //限制池子里最大的Prefab数量 refabPool.limitAmount = 20; //开启自动清理池子 refabPool.cullDespawned = true; //最终保留 refabPool.cullAbove = 5; //多久清理一次 refabPool.cullDelay = 20; //每次清理几个 refabPool.cullMaxPerPass = 10; //初始化内存池 mHeadTextPool._perPrefabPoolOptions.Add(refabPool); mHeadTextPool.CreatePrefabPool(mHeadTextPool._perPrefabPoolOptions[mHeadTextPool.Count]); }
void OnInitPlayers(byte[] data) { NotifyStartGame startGame = ProtoBufUtils.Deserialize <NotifyStartGame>(data); excel_scn_list scnList = SceneSystem.Instance.mCurrentScene.mScnLists; GameController.mServerStartTime = startGame.ServerStartTime; GameController.mClientStartTime = Time.realtimeSinceStartup; for (int i = 0; i < startGame.Players.Count; ++i) { ScnPlayerInfo playerInfo = startGame.Players[i]; excel_cha_class chaClass = excel_cha_class.Find(mScnLists.temp); if (chaClass == null) { continue; } excel_cha_list chaList = excel_cha_list.Find(chaClass.chaListID); GameObject o = ResourceSystem.Load <GameObject>(chaList.path); if (o != null) { GameObject mainPlayer = GameObject.Instantiate(o); Player player = mainPlayer.GetComponent <Player>(); player.gid = playerInfo.GID; player.UserID = playerInfo.UserID; player.mChaList = chaList; mainPlayer.transform.position = new Vector3(82.51f, 7.25f, 34.82f); mainPlayer.transform.localScale = new Vector3(chaList.scale[0], chaList.scale[1], chaList.scale[2]); mPlayersList.Add(player); mCharacterList.Add(player); mPlayers.Add(player.gid, player); mCharacters.Add(player.gid, player); if (GameController.mUserInfo.uid == playerInfo.UserID) { player.mEvent += TargetChgEvent; MessageSystem.Instance.MsgDispatch(MessageType.OnSetChaClass, chaClass); GameController.OnPlayerInit(player); } } //ResourceSystem.LoadAsync<GameObject>(chaList.path, (obj) => //{ // GameObject o = obj as GameObject; // if (o != null) // { // GameObject mainPlayer = GameObject.Instantiate(o); // Player player = mainPlayer.GetComponent<Player>(); // player.gid = playerInfo.GID; // player.UserID = playerInfo.UserID; // player.mChaList = chaList; // mainPlayer.transform.position = new Vector3(82.51f, 7.25f, 34.82f); // mainPlayer.transform.localScale = new Vector3(chaList.scale[0], chaList.scale[1], chaList.scale[2]); // mPlayersList.Add(player); // mCharacterList.Add(player); // mPlayers.Add(player.gid, player); // mCharacters.Add(player.gid, player); // if (GameController.mUserInfo.uid == playerInfo.UserID) // { // player.mEvent += TargetChgEvent; // MessageSystem.Instance.MsgDispatch(MessageType.OnSetChaClass, chaClass); // GameController.OnPlayerInit(player); // } // } //}); } }
public bool PlayPriorityAnimation(string name, AnimPriority priority, float speed = 1.0f, bool loop = false, bool reverse = false, float fadeLength = 0.15f, float time = 0.0f, bool async = true) { float curTime = Time.realtimeSinceStartup; for (int i = 0; i < (int)priority; ++i) { float length = mPriorityLength[i]; if (length < 0) { return(false); } float startTime = mPriorityStartTimes[i]; if (length >= curTime - startTime) { return(false); } } if (async) { // 未来Lambda改成Request ResourceSystem.LoadAsync <AnimationClip>(name, (o) => { AnimationClip c = o as AnimationClip; if (c == null) { return; } if (loop) { mPriorityLength[(int)priority] = -1.0f; } else { mPriorityLength[(int)priority] = c.length; } mPriorityStartTimes[(int)priority] = Time.realtimeSinceStartup; var state = PlayClipAnimation(c, c.name, AnimPlayType.Priority, speed, loop, reverse, fadeLength, time); if (state != null) { float sign = 1.0f; if (state.speed < 0.0f) { sign = -1.0f; } state.speed = mAnimSpeed * sign; } }); } else { AnimationClip c = ResourceSystem.Load <AnimationClip>(name); if (c == null) { return(false); } if (loop) { mPriorityLength[(int)priority] = -1.0f; } else { mPriorityLength[(int)priority] = c.length; } mPriorityStartTimes[(int)priority] = Time.realtimeSinceStartup; var state = PlayClipAnimation(c, c.name, AnimPlayType.Priority, speed, loop, reverse, fadeLength, time); if (state != null) { float sign = 1.0f; if (state.speed < 0.0f) { sign = -1.0f; } state.speed = mAnimSpeed * sign; } } return(true); }