This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,179 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 管理assetsBundle的加载释放
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class CLAssetsManager : MonoBehaviour
{
public static CLAssetsManager self;
public bool isPuase = false;
// 暂停释放资源(比如战斗中,先不释放)
#if UNITY_EDITOR
public string debugKey = "";
#endif
public CLAssetsManager ()
{
self = this;
}
//未使用超过x时间就释放该资源(秒)
public int timeOutSec4Realse = 300;
public static int realseTime {
get {
return self.timeOutSec4Realse;
}
set {
self.timeOutSec4Realse = value;
}
}
public Hashtable assetsMap = System.Collections.Hashtable.Synchronized (new Hashtable ());
public class AssetsInfor
{
public string key;
public string name;
public long lastUsedTime;
public int usedCount;
public AssetBundle asset;
public Callback doRealse;
}
public void pause ()
{
isPuase = true;
}
public void regain ()
{
isPuase = false;
}
public void addAsset (string key, string name, AssetBundle asset, Callback onRealse)
{
AssetsInfor ai = new AssetsInfor ();
ai.name = name;
ai.lastUsedTime = System.DateTime.Now.ToFileTime ();
ai.usedCount = 0;
ai.asset = asset;
ai.doRealse = onRealse;
ai.key = key;
assetsMap [key] = ai;
}
public void useAsset (string key)
{
AssetsInfor ai = (AssetsInfor)(assetsMap [key]);
if (ai != null) {
ai.usedCount++;
ai.lastUsedTime = System.DateTime.Now.ToFileTime ();
assetsMap [key] = ai;
#if UNITY_EDITOR
if (!string.IsNullOrEmpty(debugKey) && key.Contains(debugKey))
Debug.LogWarning (ai.usedCount + "====useAsset===" + key);
#endif
}
}
public void unUseAsset (string key)
{
AssetsInfor ai = (AssetsInfor)(assetsMap [key]);
if (ai != null) {
ai.usedCount--;
if (ai.usedCount < 0) {
Debug.LogError ("["+ai.key+"] is use time less then zero!!");
ai.usedCount = 0;
}
ai.lastUsedTime = System.DateTime.Now.ToFileTime ();
assetsMap [key] = ai;
#if UNITY_EDITOR
if (!string.IsNullOrEmpty(debugKey) && key.Contains(debugKey))
Debug.LogWarning (ai.usedCount + "===unUseAsset====" + key);
#endif
}
}
public object getAsset (string key)
{
AssetsInfor ai = (AssetsInfor)(assetsMap [key]);
if (ai != null) {
return ai.asset;
}
return null;
}
void Start ()
{
InvokeRepeating ("releaseAsset", 10, 6);
}
void OnDestroy ()
{
CancelInvoke ();
}
public void releaseAsset ()
{
releaseAsset (false);
}
public void releaseAsset (bool isForceRelease)
{
try {
if (isPuase && !isForceRelease) {
return;
}
AssetsInfor ai = null;
ArrayList list = new ArrayList ();
list.AddRange (assetsMap.Values);
bool isHadRealseAssets = false;
for (int i = 0; i < list.Count; i++) {
ai = (AssetsInfor)(list [i]);
if (ai == null) {
continue;
}
if (ai.usedCount <= 0 &&
((System.DateTime.Now.ToFileTime () - ai.lastUsedTime) / 10000000 > realseTime || isForceRelease)) {
if (ai.doRealse != null) {
ai.doRealse (ai.name);
}
assetsMap.Remove (ai.key);
if (ai.asset != null) {
ai.asset.Unload (true);
ai.asset = null;
}
ai = null;
isHadRealseAssets = true;
}
}
// UnityEngine.Resources.UnloadUnusedAssets();
list.Clear ();
list = null;
if (isHadRealseAssets) {
//这种情况是处理当图片已经destory了材质球却未来得及destory的情况
releaseAsset(isForceRelease);
}
} catch (System.Exception e) {
Debug.LogError (e);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 80e0d7974184e42c0af4e2f27f993e49
timeCreated: 1484042021
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,488 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 资源对象池基类
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using XLua;
namespace Coolape
{
[LuaCallCSharp]
public abstract class CLAssetsPoolBase<T> where T: UnityEngine.Object
{
public CLDelegate OnSetPrefabCallbacks4Borrow = new CLDelegate ();
public CLDelegate OnSetPrefabCallbacks = new CLDelegate ();
// public static ListPool listPool = new ListPool ();
public bool isFinishInitPool = false;
public Hashtable poolMap = new Hashtable ();
public Hashtable prefabMap = new Hashtable ();
public Hashtable isSettingPrefabMap = new Hashtable ();
public void _clean ()
{
isFinishInitPool = false;
poolMap.Clear ();
prefabMap.Clear ();
}
public virtual void initPool ()
{
if (isFinishInitPool)
return;
isFinishInitPool = true;
//TODO:
}
/// <summary>
/// Wraps the path. 包装路径,以便支持 dir1/dir2/test.unity3d
/// </summary>
/// <returns>The path.</returns>
/// <param name="basePath">Base path.</param>
/// <param name="thingName">Thing name.</param>
public static string wrapPath (string basePath, string thingName)
{
string tmpStr = thingName.Replace (".", "/");
string[] strs = tmpStr.Split ('/');
string path = basePath;
int len = strs.Length;
for (int i = 0; i < len - 1; i++) {
path = PStr.begin (path).a ("/").a (strs [i]).end ();
}
path = PStr.begin (path).a ("/").a (CLPathCfg.self.platform).a ("/").a (strs [len - 1]).a (".unity3d").end ();
return path;
}
#region
//设置预设===========
public bool _havePrefab (string name)
{
return prefabMap.Contains (name);
}
public virtual bool isAutoReleaseAssetBundle
{
get {
return true;
}
}
/// <summary>
/// Gets the asset path.需要在扩展类中实在该方法调用时会用到doSetPrefab
/// </summary>
/// <returns>The asset path.</returns>
/// <param name="name">Name.</param>
public abstract string getAssetPath (string name);
public virtual void _setPrefab (string name, object finishCallback, object orgs, object progressCB)
{
string path = getAssetPath (name);
OnSetPrefabCallbacks.add (name, finishCallback, orgs);
doSetPrefab (path, name, (Callback)onFinishSetPrefab, name, progressCB);
}
public virtual void onFinishSetPrefab (object[] paras)
{
if (paras != null && paras.Length > 1) {
T unit = paras [0] as T;
string name = paras [1].ToString ();
ArrayList list = OnSetPrefabCallbacks.getDelegates (name);
int count = list.Count;
ArrayList cell = null;
object cb = null;
object orgs = null;
for (int i = 0; i < count; i++) {
cell = list [i] as ArrayList;
if (cell != null && cell.Count > 1) {
cb = cell [0];
orgs = cell [1];
if (cb != null) {
Utl.doCallback (cb, unit, orgs);
}
}
}
list.Clear ();
OnSetPrefabCallbacks.removeDelegates (name);
}
}
public void doSetPrefab (string path, string name, object finishCallback, object args, object progressCB)
{
if (name == null)
return;
if (MapEx.getBool (isSettingPrefabMap, name)) {
return;
}
if (_havePrefab (name)) {
if (finishCallback != null) {
Utl.doCallback (finishCallback, prefabMap [name], args);
}
} else {
isSettingPrefabMap [name] = true;
Callback cb = onGetAssetsBundle;
CLVerManager.self.getNewestRes (path,
CLAssetType.assetBundle,
cb, isAutoReleaseAssetBundle, finishCallback, name, args, progressCB);
}
}
public void finishSetPrefab (T unit)
{
if (unit != null)
{
prefabMap[unit.name] = unit;
}
isSettingPrefabMap.Remove (unit.name);
}
public virtual void onGetAssetsBundle (params object[] paras)
{
string name = "";
string path = "";
try {
if (paras != null) {
path = (paras [0]).ToString ();
AssetBundle asset = (paras [1]) as AssetBundle;
object[] org = (object[])(paras [2]);
object cb = org [0];
name = (org [1]).ToString ();
object args = org [2];
object progressCB = org [3];
if (asset == null) {
Debug.LogError("get asset is null. path =" + path);
finishSetPrefab(null);
Utl.doCallback (cb, null, args);
return;
}
GameObject go = null;
T unit = null;
if (typeof(T) == typeof(AssetBundle)) {
unit = asset as T;
unit.name = name;
} else {
if (typeof(T) == typeof(GameObject)) {
// Debug.Log ("11111name====" + name);
unit = asset.mainAsset as T;
unit.name = name;
} else {
// Debug.Log ("22222name====" + name);
go = asset.mainAsset as GameObject;
if (go != null) {
go.name = name;
unit = go.GetComponent<T> ();
} else {
// Debug.Log ("33333name====" + name);
unit = asset.mainAsset as T;
unit.name = name;
}
}
}
CLAssetsManager.self.addAsset (getAssetPath (name), name, asset, realseAsset);
sepcProc4Assets (unit, cb, args, progressCB);
} else {
Debug.LogError ("Get assetsbundle failed!");
}
} catch (System.Exception e) {
Debug.LogError ("path==" + path + "," + e + name);
}
}
/// <summary>
/// Sepcs the proc4 assets.
/// </summary>
/// <param name="unit">Unit.</param>
/// <param name="cb">Cb.</param>
/// <param name="args">Arguments.</param>
public virtual void sepcProc4Assets (T unit, object cb, object args, object progressCB)
{
GameObject go = null;
if (typeof(T) == typeof(GameObject)) {
go = unit as GameObject;
} else if (unit is MonoBehaviour) {
go = (unit as MonoBehaviour).gameObject;
}
if (go != null) {
CLSharedAssets sharedAsset = go.GetComponent<CLSharedAssets> ();
if (sharedAsset != null) {
NewList param = ObjPool.listPool.borrowObject ();
param.Add (cb);
param.Add (unit);
param.Add (args);
sharedAsset.init ((Callback)onGetSharedAssets, param, progressCB);
} else {
finishSetPrefab (unit);
Utl.doCallback (cb, unit, args);
}
} else {
finishSetPrefab (unit);
Utl.doCallback (cb, unit, args);
}
}
public virtual void onGetSharedAssets (params object[] param)
{
if (param == null) {
Debug.LogWarning ("param == null");
return;
}
NewList list = (NewList)(param [0]);
if (list.Count >= 3) {
object cb = list [0];
T obj = list [1] as T;
object orgs = list [2];
finishSetPrefab (obj);
if (cb != null) {
Utl.doCallback (cb, obj, orgs);
}
} else {
Debug.LogWarning ("list.Count ====0");
}
ObjPool.listPool.returnObject (list);
}
//释放资源
public virtual void realseAsset (params object[] paras)
{
string name = "";
try {
name = paras [0].ToString ();
object obj = poolMap [name];
ObjsPubPool pool = null;
T unit = null;
MonoBehaviour unitObj = null;
if (obj != null) {
pool = obj as ObjsPubPool;
}
if (pool != null) {
while (pool.queue.Count > 0) {
unit = pool.queue.Dequeue ();
if (unit != null) {
if (unit is MonoBehaviour) {
unitObj = unit as MonoBehaviour;
GameObject.DestroyImmediate (unitObj.gameObject, true);
} else if (unit is GameObject) {
GameObject.DestroyImmediate ((unit as GameObject), true);
}
}
unit = null;
}
pool.queue.Clear ();
}
unit = (T)(prefabMap [name]);
prefabMap.Remove (name);
if (unit != null) {
if (unit is AssetBundle) {
//do nothing, CLAssetsManager will unload assetbundle
} else {
if (unit is MonoBehaviour) {
unitObj = unit as MonoBehaviour;
CLSharedAssets sharedAsset = unitObj.GetComponent<CLSharedAssets> ();
if (sharedAsset != null) {
sharedAsset.returnAssets ();
}
GameObject.DestroyImmediate (unitObj.gameObject, true);
} else if (unit is GameObject) {
CLSharedAssets sharedAsset = (unit as GameObject).GetComponent<CLSharedAssets> ();
if (sharedAsset != null) {
sharedAsset.returnAssets ();
}
GameObject.DestroyImmediate ((unit as GameObject), true);
} else {
//UnityEngine.Resources.UnloadAsset ((Object)unit);
GameObject.DestroyImmediate (unit, true);
}
}
}
unit = null;
} catch (System.Exception e) {
Debug.LogError ("name==" + name + ":" + e);
}
}
#endregion
public ObjsPubPool getObjPool (string name)
{
object obj = poolMap [name];
ObjsPubPool pool = null;
if (obj == null) {
pool = new ObjsPubPool (prefabMap);
poolMap [name] = pool;
} else {
pool = (ObjsPubPool)obj;
}
return pool;
}
public virtual T _borrowObj (string name)
{
return _borrowObj (name, false);
}
public virtual T _borrowObj (string name, bool isSharedResource)
{
T r = null;
if (isSharedResource) {
r = (T)(prefabMap [name]);
} else {
object obj = poolMap [name];
ObjsPubPool pool = getObjPool (name);
r = pool.borrowObject (name);
poolMap [name] = pool;
}
if (_havePrefab (name)) {
CLAssetsManager.self.useAsset (getAssetPath (name));
}
return r;
}
/// <summary>
/// Borrows the texture asyn.
/// 异步取得texture
/// </summary>
/// <returns>The texture asyn.</returns>
/// <param name="path">Path.</param>
/// <param name="onGetTexture">On get texture.</param>
/// 回调函数
/// <param name="org">Org.</param>
/// 透传参数
public virtual void _borrowObjAsyn (string name, object onGetCallbak)
{
_borrowObjAsyn (name, onGetCallbak, null, null);
}
public virtual void _borrowObjAsyn (string name, object onGetCallbak, object orgs)
{
_borrowObjAsyn (name, onGetCallbak, orgs, null);
}
public virtual void _borrowObjAsyn (string name, object onGetCallbak, object orgs, object progressCB)
{
if (string.IsNullOrEmpty (name)) {
Debug.LogWarning ("The name is null");
return;
}
if (_havePrefab (name)) {
CLMainBase.self.StartCoroutine(_doBorrowObj(name, onGetCallbak, orgs));
} else {
OnSetPrefabCallbacks4Borrow.add (name, onGetCallbak, orgs);
_setPrefab (name, (Callback)onFinishSetPrefab4Borrow, name, progressCB);
}
}
IEnumerator _doBorrowObj(string name, object onGetCallbak, object orgs)
{
yield return null;
T unit = _borrowObj(name);
Utl.doCallback(onGetCallbak, name, unit, orgs);
}
public virtual void onFinishSetPrefab4Borrow (object[] paras)
{
if (paras != null && paras.Length > 1) {
T unit = paras [0] as T;
string name = paras [1].ToString ();
ArrayList list = OnSetPrefabCallbacks4Borrow.getDelegates (name);
int count = list.Count;
ArrayList cell = null;
object cb = null;
object orgs = null;
for (int i = 0; i < count; i++) {
cell = list [i] as ArrayList;
if (cell != null && cell.Count > 1) {
cb = cell [0];
orgs = cell [1];
if (cb != null) {
unit = _borrowObj (name);
Utl.doCallback (cb, name, unit, orgs);
}
}
}
list.Clear ();
OnSetPrefabCallbacks4Borrow.removeDelegates (name);
}
}
/// <summary>
/// Returns the object. 当参数unit是null时说明是共享资源
/// </summary>
/// <param name="name">Name.</param>
/// <param name="unit">Unit.</param>
public virtual void _returnObj (string name, T unit, bool inActive = true, bool setParent = true)
{
if (unit != null) {
object obj = poolMap [name];
ObjsPubPool pool = getObjPool (name);
pool.returnObject (unit);
poolMap [name] = pool;
if (unit is MonoBehaviour) {
MonoBehaviour unitObj = unit as MonoBehaviour;
if (inActive) {
unitObj.gameObject.SetActive (false);
}
if (setParent) {
unitObj.transform.parent = null;
}
} else if (unit is GameObject) {
GameObject unitObj = unit as GameObject;
if (inActive) {
unitObj.SetActive (false);
}
if (setParent) {
unitObj.transform.parent = null;
}
}
}
CLAssetsManager.self.unUseAsset (getAssetPath (name));
}
public class ObjsPubPool : AbstractObjectPool<T>
{
Hashtable prefabMap = null;
public ObjsPubPool (Hashtable prefabMap)
{
this.prefabMap = prefabMap;
}
public override T createObject (string key)
{
T unit = (prefabMap [key]) as T;
if (unit != null) {
Object go = GameObject.Instantiate (unit) as Object;
go.name = key;
T ret = null;
if (go is T) {
ret = go as T;
} else {
ret = ((GameObject)go).GetComponent<T> ();
}
return ret;
}
return null;
}
public override T resetObject (T t)
{
return t;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7d01b20707e514c6e8d5b61750fd45e9
timeCreated: 1484031732
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,414 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 子弹对象基类
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class CLBulletBase : MonoBehaviour
{
public AnimationCurve curveSpeed = new AnimationCurve (new Keyframe (0, 0, 0, 1), new Keyframe (1, 1, 1, 0));
public AnimationCurve curveHigh = new AnimationCurve (new Keyframe (0, 0, 0, 4), new Keyframe (0.5f, 1, 0, 0), new Keyframe (1, 0, -4, 0));
BoxCollider _boxCollider;
public BoxCollider boxCollider {
get {
if (_boxCollider == null) {
_boxCollider = gameObject.GetComponent<BoxCollider> ();
}
return _boxCollider;
}
}
public object attr;
//子弹悔恨
public object data = null;
//可以理解为透传参数
public bool isFireNow = false;
public bool isFollow = false;
public bool isMulHit = false;
public bool isStoped = false;
public bool needRotate = false;
// public bool isCheckTrigger = true;
public float slowdownDistance = 0;
public float arriveDistance = 0.3f;
public float turningSpeed = 1;
public int RefreshTargetMSec = 0;
float minMoveScale = 0.05F;
float curveTime = 0;
float curveTime2 = 0;
Vector3 v3Diff = Vector3.zero;
Vector3 v3Diff2 = Vector3.zero;
Vector3 subDiff = Vector3.zero;
Vector3 subDiff2 = Vector3.zero;
long lastResetTargetTime = 0;
long lastResetToPosTime = 0;
public float speed = 1;
public float high = 0;
Vector3 highV3 = Vector3.zero;
//角度偏移量
public int angleOffset = 0;
Vector3 origin = Vector3.zero;
object onFinishCallback;
Vector3 targetDirection = Vector3.zero;
public CLUnit attacker;
public CLUnit target;
public CLUnit hitTarget;
// cach transform
Transform _transform;
public Transform transform {
get {
if (_transform == null) {
_transform = gameObject.transform;
}
return _transform;
}
}
public bool haveCollider = true;
#if UNITY_EDITOR
// void Start ()
// {
// Utl.setBodyMatEdit (transform);
// }
#endif
void OnTriggerEnter (Collider collider)
{
CLUnit unit = collider.gameObject.GetComponent<CLUnit> ();
if (unit != null && unit.isOffense != attacker.isOffense && !unit.isDead) {
hitTarget = unit;
onFinishFire (!isMulHit);
}
}
public virtual void doFire(CLUnit attacker, CLUnit target, Vector3 orgPos, Vector3 dir, object attr, object data, object callbak)
{
this.attr = attr;
this.data = data;
this.attacker = attacker;
this.target = target;
onFinishCallback = callbak;
int SpeedRandomFactor = MapEx.getBytes2Int(attr, "SpeedRandomFactor");
// int SpeedRandomFactor = NumEx.bio2Int (MapEx.getBytes (attr, "SpeedRandomFactor"));
speed = MapEx.getBytes2Int(attr, "Speed") / 10.0f;
// speed = (NumEx.bio2Int (MapEx.getBytes (attr, "Speed"))) / 10.0f;
if (SpeedRandomFactor > 0) {
speed = speed + attacker.fakeRandom(-SpeedRandomFactor, SpeedRandomFactor) / 100.0f;
}
high = MapEx.getBytes2Int(attr, "High") / 10.0f;
// high = NumEx.bio2Int (MapEx.getBytes (attr, "High"));
if (MapEx.getBool(attr, "IsHighOffset")) {
high = high * (1.0f + attacker.fakeRandom(-200, 200) / 1000.0f);
}
bool isZeroY = high > 0 ? true : false;
float dis = MapEx.getBytes2Int(attr, "Range") / 10.0f;
// float dis = NumEx.bio2Int (MapEx.getBytes (attr, "Range")) / 10.0f;
isFollow = MapEx.getBool(attr, "IsFollow");
isMulHit = MapEx.getBool(attr, "IsMulHit");
needRotate = MapEx.getBool(attr, "NeedRotate");
RefreshTargetMSec = MapEx.getBytes2Int(attr, "RefreshTargetMSec");
lastResetTargetTime = DateEx.nowMS;
lastResetToPosTime = DateEx.nowMS;
//dir.y = 0;
Utl.RotateTowards(transform, dir);
origin = orgPos;
transform.position = origin;
Vector3 toPos = Vector3.zero;
if (target != null && dis <= 0) {
toPos = target.transform.position;
} else {
toPos = origin + dir.normalized * dis;
//toPos.y = 0;
}
int PosRandomFactor = MapEx.getBytes2Int(attr, "PosRandomFactor");
// int PosRandomFactor = NumEx.bio2Int (MapEx.getBytes (attr, "PosRandomFactor"));
if (PosRandomFactor > 0) {
toPos.x += attacker.fakeRandom(-PosRandomFactor, PosRandomFactor) / 100.0f;
toPos.y += attacker.fakeRandom(-PosRandomFactor, PosRandomFactor) / 100.0f;
}
//if (isZeroY) {
// toPos.y = 0;
//}
if (boxCollider != null) {
if (MapEx.getBool(attr, "CheckTrigger")) {
boxCollider.enabled = true;
} else {
boxCollider.enabled = false;
}
}
haveCollider = (boxCollider != null && boxCollider.enabled);
v3Diff = toPos - origin;
if (angleOffset != 0) {
Vector3 center = origin + v3Diff / 2.0f;
// transform.position = center + new Vector3 (0, high, 0);
Vector3 _v3 = Utl.RotateAround(center + new Vector3 (0, high, 0), center, v3Diff, angleOffset * Mathf.Sin (Mathf.Deg2Rad * Utl.getAngle (v3Diff).y));
// transform.RotateAround (center, v3Diff, angleOffset * Mathf.Sin (Mathf.Deg2Rad * Utl.getAngle (v3Diff).y));
highV3 = _v3 - center;
} else {
highV3 = new Vector3 (0, high, 0);
}
magnitude = v3Diff.magnitude <= 0.00001f ? 1 : 1.0f / v3Diff.magnitude;
hitTarget = null;
curveTime = 0;
curveTime2 = 0;
isStoped = false;
isFireNow = true;
RotateBullet ();
CancelInvoke ("timeOut");
int stayTime = MapEx.getBytes2Int (attr, "MaxStayTime");
// int stayTime = NumEx.bio2Int (MapEx.getBytes (attr, "MaxStayTime"));
if (stayTime > 0.00001) {
Invoke ("timeOut", stayTime / 10.0f);
}
}
RaycastHit hitInfor;
float magnitude = 1f;
public virtual void RotateBullet ()
{
if (needRotate) {
curveTime2 += Time.fixedDeltaTime * speed * 10 * magnitude;
subDiff2 = v3Diff * curveSpeed.Evaluate (curveTime2);
// subDiff.y += high * curveHigh.Evaluate (curveTime);
subDiff2 += highV3 * curveHigh.Evaluate (curveTime2);
if (subDiff2.magnitude > 0.01) {
Utl.RotateTowards (transform, origin + subDiff2 - transform.position);
}
}
}
// Update is called once per frame
public virtual void FixedUpdate ()
{
if (!isFireNow) {
return;
}
if (!isFollow) {
curveTime += Time.fixedDeltaTime * speed * 10 * magnitude;
subDiff = v3Diff * curveSpeed.Evaluate (curveTime);
// subDiff.y += high * curveHigh.Evaluate (curveTime);
subDiff += highV3 * curveHigh.Evaluate (curveTime);
if (!isMulHit && haveCollider) {
if (Physics.Raycast (transform.position, v3Diff, out hitInfor, 1f)) {
OnTriggerEnter (hitInfor.collider);
}
}
if (needRotate && subDiff.magnitude > 0.001f) {
Utl.RotateTowards (transform, origin + subDiff - transform.position);
}
transform.position = origin + subDiff;
if (curveTime >= 1f) {
hitTarget = null;
onFinishFire (true);
}
} else {
if (target == null || target.isDead
//|| (RefreshTargetMSec > 0 &&
//(DateEx.nowMS - lastResetTargetTime >= RefreshTargetMSec))
){
//lastResetTargetTime = DateEx.nowMS;
resetTarget ();
}
if (!isMulHit) {
if (Physics.Raycast (transform.position, v3Diff, out hitInfor, 1f)) {
OnTriggerEnter (hitInfor.collider);
}
}
subDiff = CalculateVelocity(transform.position);
//Rotate towards targetDirection (filled in by CalculateVelocity)
if (targetDirection != Vector3.zero) {
Utl.RotateTowards (transform, targetDirection, turningSpeed);
}
transform.Translate (subDiff.normalized * Time.fixedDeltaTime * speed * 10, Space.World);
}
}
/// <summary>
/// Resets the target. 当子弹是跟踪弹时,如果目标死亡,则重新设置攻击目标
/// </summary>
public virtual void resetTarget ()
{
// if (attacker == null) {
// return;
// }
// object[] list = null;
// if (attacker.isOffense) {
// list = CLBattle.self.defense.ToArray ();
// } else {
// list = CLBattle.self.offense.ToArray ();
// }
// int count = list.Length;
// if (count == 0) {
// return;
// }
// int index = attacker.fakeRandom (0, count);
// target = (CLUnit)(list [index]);
// list = null;
}
Vector3 mToPos = Vector3.zero;
Vector3 dir = Vector3.zero;
float targetDist = 0;
Vector3 forward = Vector3.zero;
float dot = 0;
float sp = 0;
Vector3 CalculateVelocity (Vector3 fromPos)
{
//mToPos = Vector3.zero;
if (isFollow){
if (target != null)
{
mToPos = target.transform.position;
}
//else
//{
//if (RefreshTargetMSec > 0 &&
//(DateEx.nowMS - lastResetToPosTime >= RefreshTargetMSec)
//){
// lastResetToPosTime = DateEx.nowMS;
// int x = attacker.fakeRandom(-10, 10);
// int z = attacker.fakeRandom2(-10, 10);
// mToPos = transform.position + new Vector3(x, 0, z);
//}
//else
//{
// mToPos = Vector3.zero;
//}
//}
}
dir = mToPos - fromPos;
targetDist = dir.magnitude;
this.targetDirection = dir;
if (targetDist <= arriveDistance) {
if (!isStoped) {
onFinishFire (true);
}
//Send a move request, this ensures gravity is applied
return Vector3.zero;
}
//forward = Vector3.zero;
forward = transform.forward;// + dir.y * Vector3.up;
dot = Vector3.Dot (dir.normalized, forward);
sp = speed * Mathf.Max (dot, minMoveScale);//* slowdown;
if (Time.fixedDeltaTime > 0) {
sp = Mathf.Clamp (sp, 0, targetDist / (Time.fixedDeltaTime));
}
return forward * sp;// + dir.y * Vector3.up * sp;
}
public void timeOut ()
{
onFinishFire (true);
}
public virtual void stop ()
{
if (isStoped) {
return;
}
CancelInvoke ("timeOut");
isStoped = true;
isFireNow = false;
NGUITools.SetActive (gameObject, false);
CLBulletPool.returnObj (this);
}
public virtual Vector3 hitPoint
{
get
{
return transform.position;
}
}
public void onFinishFire (bool needRelease)
{
if (needRelease) {
isFireNow = false;
stop ();
}
Utl.doCallback (onFinishCallback, this);
}
public static CLBulletBase fire (CLUnit attacker, CLUnit target, Vector3 orgPos,
Vector3 dir, object attr, object data, object callbak)
{
if (attr == null || attacker == null) {
Debug.LogError ("bullet attr is null");
return null;
}
string bulletName = MapEx.getString (attr, "PrefabName");
if (!CLBulletPool.havePrefab (bulletName)) {
ArrayList list = new ArrayList ();
list.Add (attacker);
list.Add (target);
list.Add (orgPos);
list.Add (dir);
list.Add (attr);
list.Add (data);
list.Add (callbak);
CLBulletPool.borrowObjAsyn (bulletName, (Callback)onFinishBorrowBullet, list, null);
return null;
}
CLBulletBase bullet = CLBulletPool.borrowObj (bulletName);
if (bullet == null) {
return null;
}
bullet.doFire (attacker, target, orgPos, dir, attr, data, callbak);
NGUITools.SetActive (bullet.gameObject, true);
// bullet.FixedUpdate();
return bullet;
}
static void onFinishBorrowBullet (params object[] args)
{
CLBulletBase bullet = (CLBulletBase)(args [1]);
if (bullet != null) {
ArrayList list = (ArrayList)(args [2]);
CLUnit attacker = (CLUnit)(list [0]);
CLUnit target = (CLUnit)(list [1]);
Vector3 orgPos = (Vector3)(list [2]);
Vector3 dir = (Vector3)(list [3]);
object attr = (list [4]);
object data = (list [5]);
object callbak = list [6];
// fire (attacker, target, orgPos, dir, attr, data, callbak);
bullet.doFire (attacker, target, orgPos, dir, attr, data, callbak);
NGUITools.SetActive (bullet.gameObject, true);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7f9143e938e5348dbac2f70be09aa48f
timeCreated: 1484115874
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 子弹对象池
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Coolape
{
public class CLBulletPool : CLAssetsPoolBase<CLBulletBase>
{
public static CLBulletPool pool = new CLBulletPool ();
public override string getAssetPath (string name)
{
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/other/bullet").e ();
return wrapPath (path, name);
}
public override bool isAutoReleaseAssetBundle
{
get
{
return base.isAutoReleaseAssetBundle;
}
}
public static void clean ()
{
pool._clean ();
}
public static bool havePrefab (string name)
{
return pool._havePrefab (name);
}
public static void setPrefab (string name, object finishCallback)
{
setPrefab (name, finishCallback, null, null);
}
public static void setPrefab (string name, object finishCallback, object orgs)
{
pool._setPrefab (name, finishCallback, orgs, null);
}
public static void setPrefab (string name, object finishCallback, object orgs, object progressCB)
{
pool._setPrefab (name, finishCallback, orgs, progressCB);
}
public static CLBulletBase borrowObj (string name)
{
return pool._borrowObj (name);
}
public static void borrowObjAsyn (string name, object onGetCallbak)
{
borrowObjAsyn (name, onGetCallbak, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, progressCB);
}
public static void returnObj (CLBulletBase unit)
{
pool._returnObj (unit.name, unit);
}
public static void returnObj (CLBulletBase unit, bool inActive, bool setParent)
{
pool._returnObj (unit.name, unit, inActive, setParent);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 441672b754db949eea16ece2ad930eea
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,349 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 特效
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
[RequireComponent (typeof(AnimationProc))]
public class CLEffect : MonoBehaviour
{
AnimationProc _animationProc;
public AnimationProc animationProc {
get {
if (_animationProc == null) {
_animationProc = GetComponent<AnimationProc> ();
}
return _animationProc;
}
}
Transform _tr;
public Transform transform {
get {
if (_tr == null) {
_tr = gameObject.transform;
}
return _tr;
}
}
// public string effectName = "";
public object willFinishCallback = null;
public object willFinishCallbackPara;
//回调数
public object finishCallback = null;
public object finishCallbackPara;
//回调数
public bool returnAuto = true;
public float willFinishTimePercent = 0;
/// <summary>
/// Plaies the delay.延迟播放特效
/// </summary>
/// <returns>The delay.</returns>
/// <param name="name">Name.</param>
/// <param name="pos">Position.</param>
/// <param name="parent">Parent.</param>
/// <param name="willFinishTimePercent">Will finish time.</param>
/// <param name="willFinishCallback">Will finish callback.</param>
/// <param name="willFinishCallbackPara">Will finish callback para.</param>
/// <param name="finishCallback">Finish callback.</param>
/// <param name="finishCallbackPara">Finish callback para.</param>
/// <param name="delaySec">Delay sec.</param>
/// <param name="returnAuto">If set to <c>true</c> return auto.</param>
public static CLEffect playDelay (string name, Vector3 pos, Transform parent, float willFinishTimePercent,
object willFinishCallback, object willFinishCallbackPara,
object finishCallback, object finishCallbackPara, float delaySec, bool returnAuto = true)
{
if (string.IsNullOrEmpty (name)) {
return null;
}
if (!CLEffectPool.havePrefab (name)) {
ArrayList list = new ArrayList ();
list.Add (name);
list.Add (pos);
list.Add (parent);
list.Add (willFinishTimePercent);
list.Add (willFinishCallback);
list.Add (willFinishCallbackPara);
list.Add (finishCallback);
list.Add (finishCallbackPara);
list.Add (delaySec);
list.Add (returnAuto);
// CLEffectPool.setPrefab (name, (Callback)onFinishSetPrefab2, list, null);
CLEffectPool.borrowObjAsyn
(name, (Callback)onFinishSetPrefab2, list);
return null;
}
CLEffect effect = CLEffectPool.borrowObj (name);
if (effect == null) {
return null;
}
NGUITools.SetActive (effect.gameObject, false);
CLMainBase.self.StartCoroutine (effect.playDelay (pos, parent, willFinishTimePercent,
willFinishCallback, willFinishCallbackPara,
finishCallback, finishCallbackPara, delaySec, returnAuto));
return effect;
}
public IEnumerator playDelay (Vector3 pos, Transform parent, float willFinishTimePercent,
object willFinishCallback, object willFinishCallbackPara,
object finishCallback, object finishCallbackPara, float delaySec, bool returnAuto)
{
yield return new WaitForSeconds (delaySec);
show (pos, parent, willFinishTimePercent, willFinishCallback, willFinishCallbackPara,
finishCallback, finishCallbackPara, returnAuto);
}
public static CLEffect play (string name, Vector3 pos, Transform parent, object finishCallback, object finishCallbackPara)
{
return play (name, pos, parent, 0, null, null, finishCallback, finishCallbackPara, true);
}
public static CLEffect play (string name, Vector3 pos, object finishCallback, object finishCallbackPara)
{
return play (name, pos, null, 0, null, null, finishCallback, finishCallbackPara, true);
}
public static CLEffect play (string name, Vector3 pos, Transform parent)
{
return play (name, pos, parent, 0, null, null, null, null, true);
}
public static CLEffect play (string name, Vector3 pos)
{
return play (name, pos, null, 0, null, null, null, null, true);
}
public static CLEffect play (string name, Vector3 pos, Transform parent, float willFinishTimePercent,
object willFinishCallback, object willFinishCallbackPara,
object finishCallback, object finishCallbackPara, bool returnAuto)
{
try {
if (string.IsNullOrEmpty (name)) {
return null;
}
if (!CLEffectPool.havePrefab (name)) {
ArrayList list = new ArrayList ();
list.Add (name);
list.Add (pos);
list.Add (parent);
list.Add (willFinishTimePercent);
list.Add (willFinishCallback);
list.Add (willFinishCallbackPara);
list.Add (finishCallback);
list.Add (finishCallbackPara);
list.Add (returnAuto);
CLEffectPool.borrowObjAsyn (name, (Callback)onFinishSetPrefab, list);
return null;
}
CLEffect effect = CLEffectPool.borrowObj (name);
if (effect == null) {
return null;
}
// effect.effectName = name;
effect.show (pos, parent, willFinishTimePercent, willFinishCallback, willFinishCallbackPara,
finishCallback, finishCallbackPara, returnAuto);
return effect;
} catch (System.Exception e) {
Debug.LogError (e);
return null;
}
}
public static void onFinishSetPrefab (params object[] args)
{
CLEffect effect = (CLEffect)(args [1]);
if (effect != null) {
ArrayList list = (ArrayList)(args [2]);
string name = list [0].ToString ();
Vector3 pos = (Vector3)(list [1]);
Transform parent = (Transform)(list [2]);
float willFinishTimePercent = (float)(list [3]);
object willFinishCallback = list [4];
object willFinishCallbackPara = list [5];
object finishCallback = list [6];
object finishCallbackPara = list [7];
bool returnAuto = (bool)(list [8]);
effect.show (pos, parent, willFinishTimePercent,
willFinishCallback, willFinishCallbackPara,
finishCallback, finishCallbackPara, returnAuto);
}
}
public static void onFinishSetPrefab2 (params object[] args)
{
// string effectName = args [0].ToString ();
CLEffect effect = (CLEffect)(args [1]);
if (effect != null) {
ArrayList list = (ArrayList)(args [2]);
string name = list [0].ToString ();
Vector3 pos = (Vector3)(list [1]);
Transform parent = (Transform)(list [2]);
float willFinishTimePercent = (float)(list [3]);
object willFinishCallback = list [4];
object willFinishCallbackPara = list [5];
object finishCallback = list [6];
object finishCallbackPara = list [7];
float delaySec = (float)(list [8]);
bool returnAuto = (bool)(list [9]);
CLMainBase.self.StartCoroutine (effect.playDelay (pos, parent, willFinishTimePercent,
willFinishCallback, willFinishCallbackPara,
finishCallback, finishCallbackPara, delaySec, returnAuto));
}
}
public void show (
Vector3 pos, Transform parent, float willFinishTimePercent,
object willFinishCallback, object willFinishCallbackPara,
object finishCallback, object finishCallbackPara, bool returnAuto = true)
{
this.willFinishTimePercent = willFinishTimePercent;
transform.parent = parent;
transform.position = pos;
transform.localScale = Vector3.one;
transform.localEulerAngles = Vector3.zero;
this.willFinishCallback = willFinishCallback;
this.willFinishCallbackPara = willFinishCallbackPara;
this.finishCallback = finishCallback;
this.finishCallbackPara = finishCallbackPara;
animationProc.callbackPara = finishCallbackPara;
this.returnAuto = returnAuto;
Callback cb = onFinish;
animationProc.onFinish = cb;
NGUITools.SetActive (gameObject, true);
if (willFinishTimePercent > 0.00001f) {
Invoke ("doWillfinishCallback", willFinishTimePercent * animationProc.timeOut);
}
}
void doWillfinishCallback ()
{
Utl.doCallback (willFinishCallback, this, willFinishCallbackPara);
}
public void onFinish (params object[] obj)
{
if (returnAuto || obj == null) {
CLEffectPool.returnObj (name, this);
NGUITools.SetActive (gameObject, false);
if (returnAuto) {
transform.parent = null;
}
}
Utl.doCallback (finishCallback, this, finishCallbackPara);
}
public void Start ()
{
#if UNITY_EDITOR
//因为是通过assetebundle加载的在真机上不需要处理只有在pc上需要重设置shader
// if (Application.isPlaying) {
// Utl.setBodyMatEdit (transform);
// }
#endif
}
ParticleSystem[] _particleSys;
public ParticleSystem[] particleSys {
get {
if (_particleSys == null) {
_particleSys = gameObject.GetComponentsInChildren<ParticleSystem> ();
}
return _particleSys;
}
}
Animator[] _animators;
public Animator[] animators {
get {
if (_animators == null) {
_animators = gameObject.GetComponentsInChildren<Animator> ();
}
return _animators;
}
}
Animation[] _animations;
public Animator[] animations {
get {
if (_animations == null) {
_animations = gameObject.GetComponentsInChildren<Animation> ();
}
return _animators;
}
}
// Hashtable particlesTimes = new Hashtable();
public void pause ()
{
if (particleSys != null && particleSys.Length > 0) {
for (int i = 0; i < particleSys.Length - 1; i++) {
particleSys [i].Pause ();
// particlesTimes[particleSys[i].GetInstanceID()] = particleSys[i].time;
}
}
if (animations != null && animations.Length > 0) {
for (int i = 0; i < animations.Length - 1; i++) {
animations [i].enabled = false;
}
}
if (animators != null && animators.Length > 0) {
for (int i = 0; i < animators.Length - 1; i++) {
animators [i].enabled = false;
}
}
}
public void regain ()
{
if (particleSys != null && particleSys.Length > 0) {
for (int i = 0; i < particleSys.Length - 1; i++) {
// particleSys[i].time = (float)(particlesTimes[particleSys[i].GetInstanceID()]);
// particleSys[i].Simulate((float)(particlesTimes[particleSys[i].GetInstanceID()]));
particleSys [i].Play ();
}
}
if (animations != null && animations.Length > 0) {
for (int i = 0; i < animations.Length - 1; i++) {
animations [i].enabled = true;
}
}
if (animators != null && animators.Length > 0) {
for (int i = 0; i < animators.Length - 1; i++) {
animators [i].enabled = true;
}
}
}
public void playSC (Vector3 pos, Transform parent, float willFinishTimePercent,
object willFinishCallback, object willFinishCallbackPara,
object finishCallback, object finishCallbackPara, float delaySec, bool returnAuto)
{
StartCoroutine (playDelay (pos, parent, willFinishTimePercent, willFinishCallback, willFinishCallbackPara, finishCallback, finishCallbackPara, delaySec, returnAuto));
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 046fe77d0e29a4b198b82e2e921648e9
timeCreated: 1484041985
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 特效对象池
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class CLEffectPool:CLAssetsPoolBase<CLEffect>
{
public static CLEffectPool pool = new CLEffectPool ();
public override string getAssetPath (string name)
{
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/other/effect").e ();
return wrapPath (path, name);
}
public override bool isAutoReleaseAssetBundle
{
get
{
return base.isAutoReleaseAssetBundle;
}
}
public static void clean ()
{
pool._clean ();
}
public static bool havePrefab (string name)
{
return pool._havePrefab (name);
}
public static void setPrefab (string name, object finishCallback)
{
setPrefab (name, finishCallback, null, null);
}
public static void setPrefab (string name, object finishCallback, object args)
{
pool._setPrefab (name, finishCallback, args, null);
}
public static void setPrefab (string name, object finishCallback, object args, object progressCB)
{
pool._setPrefab (name, finishCallback, args, progressCB);
}
public static CLEffect borrowObj (string name)
{
return pool._borrowObj (name);
}
public static void borrowObjAsyn (string name, object onGetCallbak)
{
borrowObjAsyn (name, onGetCallbak, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, progressCB);
}
public static void returnObj (CLEffect effect)
{
if (effect == null)
return;
pool._returnObj (effect.name, effect);
}
public static void returnObj (string name, CLEffect effect)
{
if (effect == null)
return;
pool._returnObj (name, effect);
}
public static void returnObj (string name, CLEffect effect, bool inActive, bool setParent)
{
if (effect == null)
return;
pool._returnObj (name, effect, inActive, setParent);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7a47afaf1b9b647faa31b597f0e14656
timeCreated: 1484041660
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,360 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 材质球对象池
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Coolape
{
public class CLMaterialPool : CLAssetsPoolBase<Material>
{
public static CLMaterialPool pool = new CLMaterialPool();
public override string getAssetPath(string name)
{
string path = PStr.b().a(CLPathCfg.self.basePath).a("/")
.a(CLPathCfg.upgradeRes).a("/other/Materials").e();
return wrapPath(path, name);
}
public override Material _borrowObj(string name)
{
ArrayList propNames = null;
ArrayList texNames = null;
ArrayList texPaths = null;
if (getMaterialTexCfg(name, ref propNames, ref texNames, ref texPaths))
{
if (texNames != null)
{
for (int i = 0; i < texNames.Count; i++)
{
CLTexturePool.borrowObj(texNames[i].ToString());
}
}
}
return base._borrowObj(name, true);
}
public override bool isAutoReleaseAssetBundle
{
get
{
return false;
}
}
public static bool havePrefab(string name)
{
return pool._havePrefab(name);
}
public static void clean()
{
pool._clean();
}
public static void setPrefab(string name, object finishCallback)
{
setPrefab(name, finishCallback, null, null);
}
public static void setPrefab(string name, object finishCallback, object args)
{
pool._setPrefab(name, finishCallback, args, null);
}
public static void setPrefab(string name, object finishCallback, object args, object progressCB)
{
pool._setPrefab(name, finishCallback, args, progressCB);
}
public static Material borrowObj(string name)
{
return pool._borrowObj(name, true);
}
public static void borrowObjAsyn(string name, object onGetCallbak)
{
borrowObjAsyn(name, onGetCallbak, null);
}
public static void borrowObjAsyn(string name, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn(name, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn(string name, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn(name, onGetCallbak, orgs, progressCB);
}
public static void returnObj(string name)
{
//return texture
ArrayList propNames = null;
ArrayList texNames = null;
ArrayList texPaths = null;
if (getMaterialTexCfg(name, ref propNames, ref texNames, ref texPaths))
{
if (texNames != null)
{
for (int i = 0; i < texNames.Count; i++)
{
CLTexturePool.returnObj(texNames[i].ToString());
}
}
}
// Then return material
pool._returnObj(name, null);
}
public static void cleanTexRef(string name, Material mat)
{
ArrayList propNames = null;
ArrayList texNames = null;
ArrayList texPaths = null;
if (CLMaterialPool.getMaterialTexCfg(name, ref propNames, ref texNames, ref texPaths))
{
if (propNames != null)
{
for (int i = 0; i < propNames.Count; i++)
{
mat.SetTexture(propNames[i].ToString(), null);
}
}
}
}
public override void sepcProc4Assets(Material mat, object cb, object args, object progressCB)
{
if (mat != null)
{
#if UNITY_EDITOR
mat.shader = Shader.Find(mat.shader.name);
#endif
resetTexRef(mat.name, mat, cb, args);
}
else
{
Debug.LogError("get mat is null.");
}
}
public static void resetTexRef(string matName, Material mat, object cb, object args)
{
ArrayList propNames = null;
ArrayList texNames = null;
ArrayList texPaths = null;
if (getMaterialTexCfg(matName, ref propNames, ref texNames, ref texPaths))
{
if (propNames != null)
{
NewList list = null;
//取得texture
int count = propNames.Count;
//for (int i = 0; i < count; i++)
if (count > 0)
{
//int i = 0;
list = ObjPool.listPool.borrowObject();
list.Add(mat);
//list.Add(propNames[i]);
//list.Add(count);
list.Add(cb);
list.Add(args);
list.Add(propNames);
list.Add(texNames);
list.Add(texPaths);
list.Add(0);
doresetTexRef(list);
}
}
else
{
Debug.LogWarning("propNames is null =====" + matName);
pool.finishSetPrefab(mat);
Utl.doCallback(cb, mat, args);
}
}
else
{
Debug.LogError("get material tex failed");
pool.finishSetPrefab(mat);
Utl.doCallback(cb, mat, args);
}
}
public static void doresetTexRef(NewList inputs)
{
ArrayList texNames = inputs[4] as ArrayList;
ArrayList texPaths = inputs[5] as ArrayList;
int i = (int)(inputs[6]);
#if UNITY_EDITOR
if (!CLCfgBase.self.isEditMode || Application.isPlaying)
{
CLTexturePool.setPrefab(texNames[i].ToString(), (Callback)onGetTexture, inputs, null);
}
else
{
string tmpPath = "Assets/" + texPaths[i];
Texture tex = AssetDatabase.LoadAssetAtPath(
tmpPath, typeof(UnityEngine.Object)) as Texture;
onGetTexture(tex, inputs);
}
#else
CLTexturePool.setPrefab(texNames [i].ToString (), (Callback)onGetTexture, inputs, null);
#endif
}
public static void onGetTexture(params object[] paras)
{
string name = "";
try
{
Texture tex = paras[0] as Texture;
NewList list = paras[1] as NewList;
Material mat = list[0] as Material;
int i = (int)(list[6]);
ArrayList propNames = list[3] as ArrayList;
string propName = propNames[i].ToString();
// name = paras [0].ToString ();
if (tex == null)
{
ArrayList texPaths = list[5] as ArrayList;
Debug.LogError("Get tex is null." + mat.name + "===" + texPaths[i]);
}
else
{
name = tex.name;
// 设置material对应属性的texture
mat.SetTexture(propName, tex);
}
int count = propNames.Count;
i++;
if (i >= count)
{
pool.finishSetPrefab(mat);
//finished
Callback cb = list[1] as Callback;
object agrs = list[2];
Utl.doCallback(cb, mat, agrs);
ObjPool.listPool.returnObject(list);
}
else
{
list[6] = i;
doresetTexRef(list);
}
}
catch (System.Exception e)
{
Debug.LogError("name==========" + name + "==" + e);
}
}
//==========================================================
// material cfg proc
//==========================================================
static Hashtable _materialTexRefCfg = null;
static string _materialTexRefCfgPath = null;
public static string materialTexRefCfgPath
{
get
{
if (string.IsNullOrEmpty(_materialTexRefCfgPath))
{
#if UNITY_EDITOR
_materialTexRefCfgPath = PStr.b().a(Application.dataPath).a("/").a(CLPathCfg.self.basePath).a("/upgradeRes4Dev/priority/cfg/materialTexRef.cfg").e();
#else
_materialTexRefCfgPath = PStr.b().a(CLPathCfg.self.basePath).a("/upgradeRes/priority/cfg/materialTexRef.cfg").e();
#endif
}
return _materialTexRefCfgPath;
}
}
public static Hashtable materialTexRefCfg
{
get
{
if (_materialTexRefCfg == null)
{
_materialTexRefCfg = readMaterialTexRefCfg();
}
return _materialTexRefCfg;
}
set
{
_materialTexRefCfg = value;
}
}
/// <summary>
/// Gets the material cfg.取得material引用图片的配置
/// </summary>
/// <returns><c>true</c>, if material cfg was gotten, <c>false</c> otherwise.</returns>
/// <param name="matName">Mat name.</param>
/// <param name="propNames">Property names.</param>
/// <param name="texNames">Tex names.</param>
/// <param name="texPaths">Tex paths.</param>
public static bool getMaterialTexCfg(string matName, ref ArrayList propNames, ref ArrayList texNames, ref ArrayList texPaths)
{
Hashtable cfg = MapEx.getMap(materialTexRefCfg, matName);
bool ret = true;
if (cfg == null)
{
Debug.LogError("Get MaterialTexCfg is null!" + matName);
ret = false;
}
else
{
propNames = cfg["pp"] as ArrayList;
texNames = cfg["tn"] as ArrayList;
texPaths = cfg["tp"] as ArrayList;
}
return ret;
}
public static Hashtable readMaterialTexRefCfg()
{
Hashtable ret = null;
#if UNITY_EDITOR
byte[] buffer = File.Exists(materialTexRefCfgPath) ? File.ReadAllBytes(materialTexRefCfgPath) : null;
#else
byte[] buffer = FileEx.readNewAllBytes (materialTexRefCfgPath);
#endif
if (buffer != null)
{
MemoryStream ms = new MemoryStream();
ms.Write(buffer, 0, buffer.Length);
ms.Position = 0;
object obj = B2InputStream.readObject(ms);
if (obj != null)
{
ret = obj as Hashtable;
}
}
ret = ret == null ? new Hashtable() : ret;
return ret;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a18a9e2748b5743eab5218a629ce6bb0
timeCreated: 1443706252
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,99 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Coolape
{
public class CLModePool : CLAssetsPoolBase<GameObject>
{
public static CLModePool pool = new CLModePool ();
public override string getAssetPath (string name)
{
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/other/model").e ();
return wrapPath (path, name);
}
public override void _returnObj (string name, GameObject unit, bool inActive = true, bool setParent = true)
{
base._returnObj (name, unit, inActive, setParent);
}
public override bool isAutoReleaseAssetBundle
{
get
{
return false;
}
}
public static void clean ()
{
pool._clean ();
}
public static bool havePrefab (string name)
{
return pool.prefabMap.Contains (name);
}
public static bool isNeedDownload (string name)
{
#if UNITY_EDITOR
if (CLCfgBase.self.isEditMode) {
return false;
}
#endif
string path = pool.getAssetPath (name);
return CLVerManager.self.checkNeedDownload (path);
}
public static void setPrefab (string name, object finishCallback)
{
pool._setPrefab (name, finishCallback, null, null);
}
public static void setPrefab (string name, object finishCallback, object args)
{
pool._setPrefab (name, finishCallback, args, null);
}
public static void setPrefab (string name, object finishCallback, object args, object progressCB)
{
pool._setPrefab (name, finishCallback, args, progressCB);
}
public override GameObject _borrowObj (string name)
{
return base._borrowObj (name, true);
}
public static GameObject borrowObj (string name)
{
return pool._borrowObj (name);
}
public static void borrowObjAsyn (string name, object onGetCallbak)
{
borrowObjAsyn (name, onGetCallbak, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, progressCB);
}
public static void returnObj (string name)
{
pool._returnObj (name, null);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 00851c579714645f58963b3ec7bb42b9
timeCreated: 1504319970
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,117 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 角色、怪物的对象池
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Coolape
{
public class CLRolePool:CLAssetsPoolBase<CLUnit>
{
public static CLRolePool pool = new CLRolePool ();
public override string getAssetPath (string name)
{
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/other/roles").e ();
return wrapPath (path, name);
}
public override void _returnObj (string name, CLUnit unit, bool inActive = true, bool setParent = true)
{
base._returnObj (name, unit, inActive, setParent);
unit.clean ();
}
public override bool isAutoReleaseAssetBundle
{
get
{
return base.isAutoReleaseAssetBundle;
}
}
public static void clean ()
{
pool._clean ();
}
public static bool havePrefab (string name)
{
return pool.prefabMap.Contains (name);
}
public static bool isNeedDownload (string roleName)
{
#if UNITY_EDITOR
if (CLCfgBase.self.isEditMode) {
return false;
}
#endif
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/other/roles").e ();
path = wrapPath (path, roleName);
return CLVerManager.self.checkNeedDownload (path);
}
public static void setPrefab (string name, object finishCallback)
{
pool._setPrefab (name, finishCallback, null, null);
}
public static void setPrefab (string name, object finishCallback, object args)
{
pool._setPrefab (name, finishCallback, args, null);
}
public static void setPrefab (string name, object finishCallback, object args, object progressCB)
{
pool._setPrefab (name, finishCallback, args, progressCB);
}
public static CLUnit borrowObj (string name)
{
return pool._borrowObj (name);
}
public static void borrowObjAsyn (string name, object onGetCallbak)
{
borrowObjAsyn (name, onGetCallbak, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, progressCB);
}
public static void returnObj (CLUnit unit)
{
pool._returnObj (unit.name, unit);
}
public static void returnObj (string name, CLUnit unit)
{
pool._returnObj (name, unit);
}
public static void returnObj (string name, CLUnit unit, bool inActive, bool setParent)
{
pool._returnObj (name, unit, inActive, setParent);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 613ac7815de5a44bc913fafd342e45dc
timeCreated: 1444005891
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,456 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description:
* 1.render ->material->texture
* 2.mesh->fbx 如何通过mesh的名字找到fbx对象(mesh fillter, SkinnedMeshRenderer.mesh)
* 3.Animator->controller->fbx
* 4.Animation->fbx
* 5.sound
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
using System.IO;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Coolape
{
public class CLSharedAssets : MonoBehaviour
{
public static CLDelegate OnFinishSetCallbacks = new CLDelegate ();
[SerializeField]
public List<CLMaterialInfor> materials = new List<CLMaterialInfor> ();
[SerializeField]
public List<CLMeshInfor> meshs = new List<CLMeshInfor> ();
bool isFinishInited = false;
bool isAllAssetsLoaded = false;
public bool isDonnotResetAssets = false;
public bool isSkipModel = true;
public object progressCallback;
public List<EventDelegate> onFinshLoad = new List<EventDelegate> ();
public void reset ()
{
isAllAssetsLoaded = false;
}
// Use this for initialization
void Start ()
{
if (isFinishInited)
return;
isFinishInited = true;
#if UNITY_EDITOR
init ((Callback)onFinishSetAsset, null, progressCallback);
#else
init ((Callback)onFinishSetAsset, null);
#endif
}
void onFinishSetAsset (params object[] paras)
{
// if (isResetShaderInEdeitorMode) {
// Utl.setBodyMatEdit (transform);
// }
EventDelegate.Execute (onFinshLoad, gameObject);
}
public bool isEmpty ()
{
return (materials == null || materials.Count == 0) && (meshs == null || meshs.Count == 0);
}
public void cleanRefOnly ()
{
foreach (var matInfor in materials) {
if (matInfor.render.sharedMaterials != null && matInfor.render.sharedMaterials.Length > matInfor.index) {
Material[] mats = matInfor.render.sharedMaterials;
mats [matInfor.index] = null;
matInfor.render.sharedMaterials = mats;
if (matInfor.index == 0) {
matInfor.render.sharedMaterial = null;
matInfor.render.material = null;
}
}
}
foreach (var meshInfor in meshs) {
if (meshInfor.meshFilter != null) {
meshInfor.meshFilter.sharedMesh = null;
}
if (meshInfor.skinnedMesh != null) {
meshInfor.skinnedMesh.sharedMesh = null;
}
if(meshInfor.animator != null) {
meshInfor.animator.avatar = null;
}
}
}
public void cleanRefAssets ()
{
#if UNITY_EDITOR
foreach (var matInfor in materials) {
string matPath = "Assets/" + CLPathCfg.self.basePath + "/upgradeRes4Dev/other/Materials/" + matInfor.materialName.Replace (".", "/") + ".mat";
Debug.Log("matPath==" + matPath);
Material mat = AssetDatabase.LoadAssetAtPath (matPath, typeof(Material)) as Material;
if (mat == null) {
continue;
}
CLMaterialPool.cleanTexRef (matInfor.materialName, mat);
if (matInfor.render.sharedMaterials != null && matInfor.render.sharedMaterials.Length > matInfor.index) {
Material[] mats = matInfor.render.sharedMaterials;
mats [matInfor.index] = null;
matInfor.render.sharedMaterials = mats;
if (matInfor.index == 0) {
matInfor.render.sharedMaterial = null;
matInfor.render.material = null;
}
}
}
foreach (var meshInfor in meshs) {
if (meshInfor.meshFilter != null) {
meshInfor.meshFilter.sharedMesh = null;
}
if (meshInfor.skinnedMesh != null) {
meshInfor.skinnedMesh.sharedMesh = null;
}
if(meshInfor.animator != null) {
meshInfor.animator.avatar = null;
}
}
#endif
}
public void init (object finishCallback, object orgs)
{
init (finishCallback, orgs, null);
}
public void init (object finishCallback, object orgs, object progressCallback)
{
this.progressCallback = progressCallback;
if (isAllAssetsLoaded || isDonnotResetAssets) {
Utl.doCallback (finishCallback, orgs);
} else {
OnFinishSetCallbacks.add (gameObject.GetInstanceID ().ToString (), finishCallback, orgs);
resetAssets ();
}
}
float _progress = 0;
//进度
public float progress {
get {
return _progress;
}
set {
_progress = value;
Utl.doCallback (progressCallback, _progress);
}
}
public void resetAssets ()
{
if (isAllAssetsLoaded)
return;
if (!isSkipModel) {
//Set model
setMesh ();
} else {
//TODO:set sound
//set Material
setMaterial ();
}
}
public void setMaterial ()
{
// cleanRefOnly ();
CLMaterialInfor clMat;
if (materials.Count > 0) {
clMat = materials [0];
clMat.setMaterial ((Callback)onFinishSetMat, 0);
} else {
callbackOnFinish ();
}
}
public void setMesh ()
{
CLMeshInfor clMesh;
if (meshs.Count > 0) {
clMesh = meshs [0];
clMesh.setMesh ((Callback)onFinishSetMesh, 0);
} else {
callbackOnFinishMesh ();
}
}
void onFinishSetMesh (params object[] paras)
{
int index = (int)paras [0];
index++;
progress = (float)index / (materials.Count + meshs.Count);
if (index < meshs.Count) {
CLMeshInfor clMat = meshs [index];
clMat.setMesh ((Callback)onFinishSetMesh, index);
} else {
//Finished
callbackOnFinishMesh ();
}
}
void onFinishSetMat (params object[] paras)
{
int index = (int)paras [0];
index++;
progress = (float)(index + meshs.Count) / (materials.Count + meshs.Count);
if (index < materials.Count) {
CLMaterialInfor clMat = materials [index];
clMat.setMaterial ((Callback)onFinishSetMat, index);
} else {
//Finished
isAllAssetsLoaded = true;
callbackOnFinish ();
}
}
void callbackOnFinishMesh ()
{
setMaterial ();
}
void callbackOnFinish ()
{
string key = gameObject.GetInstanceID ().ToString ();
ArrayList callbackList = OnFinishSetCallbacks.getDelegates (key);
int count = callbackList.Count;
ArrayList cell = null;
object cb = null;
object orgs = null;
for (int i = 0; i < count; i++) {
cell = callbackList [i] as ArrayList;
if (cell != null && cell.Count > 1) {
cb = cell [0];
orgs = cell [1];
Utl.doCallback (cb, orgs);
}
}
callbackList.Clear ();
OnFinishSetCallbacks.removeDelegates (key);
}
public void OnDestroy ()
{
if (isFinishInited) {
returnAssets ();
}
}
public void returnAssets ()
{
if (isDonnotResetAssets)
return;
CLMaterialInfor clMat;
for (int i = 0; i < materials.Count; i++) {
clMat = materials [i];
clMat.returnMaterial ();
}
CLMeshInfor clMesh;
for (int i = 0; i < meshs.Count; i++) {
clMesh = meshs [i];
clMesh.returnMesh ();
}
isFinishInited = false;
isAllAssetsLoaded = false;
}
[System.Serializable]
public class CLMeshInfor
{
public MeshFilter meshFilter;
public SkinnedMeshRenderer skinnedMesh;
// public string meshName;
public Animator animator;
public string modelName;
public string meshName;
object finishCallback;
object callbackPrgs;
public void returnMesh ()
{
CLModePool.returnObj (modelName);
}
public void setMesh (Callback onFinishCallback, object orgs)
{
finishCallback = onFinishCallback;
callbackPrgs = orgs;
#if UNITY_EDITOR
if (!CLCfgBase.self.isEditMode || Application.isPlaying) {
if (string.IsNullOrEmpty (modelName)) {
Debug.LogWarning (" then model name is null===");
} else {
CLModePool.borrowObjAsyn (modelName, (Callback)onGetModel);
}
} else {
string tmpPath = "Assets/" + CLPathCfg.self.basePath + "/upgradeRes4Dev/other/model/" + modelName.Replace (".", "/") + ".FBX";
Debug.Log (tmpPath);
GameObject model = AssetDatabase.LoadAssetAtPath (
tmpPath, typeof(UnityEngine.Object)) as GameObject;
onGetModel (modelName, model);
}
#else
CLModePool.borrowObjAsyn (modelName, (Callback)onGetModel);
#endif
}
void onGetModel (params object[] paras)
{
string name = paras [0].ToString ();
GameObject obj = paras [1] as GameObject;
if (obj == null) {
return;
}
if (obj != null) {
if (meshFilter != null) {
MeshFilter[] mfs = obj.GetComponentsInChildren<MeshFilter>();
if (mfs != null && mfs.Length > 0) {
for (int i = 0; i < mfs.Length; i++) {
if (mfs [i].sharedMesh.name == meshName) {
meshFilter.sharedMesh = mfs [i].sharedMesh;
#if UNITY_EDITOR
if (!Application.isPlaying) {
EditorUtility.SetDirty (meshFilter);
}
#endif
}
}
}
}
if (skinnedMesh != null) {
SkinnedMeshRenderer smr = obj.GetComponent<SkinnedMeshRenderer> ();
if(smr == null) {
smr = obj.GetComponentInChildren<SkinnedMeshRenderer> ();
SkinnedMeshRenderer[] smrs = obj.GetComponentsInChildren<SkinnedMeshRenderer>();
if (smrs != null) {
for (int i = 0; i < smrs.Length; i++) {
if (smrs [i].sharedMesh.name == meshName) {
skinnedMesh.sharedMesh = smr.sharedMesh;
#if UNITY_EDITOR
if (!Application.isPlaying) {
EditorUtility.SetDirty (skinnedMesh);
}
#endif
}
}
}
} else {
if (smr != null) {
skinnedMesh.sharedMesh = smr.sharedMesh;
#if UNITY_EDITOR
if (!Application.isPlaying) {
EditorUtility.SetDirty (skinnedMesh);
}
#endif
}
}
}
if (animator != null) {
Animator _animator = obj.GetComponentInChildren<Animator> ();
if (_animator != null) {
animator.avatar = _animator.avatar;
#if UNITY_EDITOR
if (!Application.isPlaying) {
EditorUtility.SetDirty (animator);
}
#endif
}
}
}
Utl.doCallback (finishCallback, callbackPrgs);
}
}
[System.Serializable]
public class CLMaterialInfor
{
public Renderer render;
public int index = 0;
public string materialName;
// public List<string> shaderPropNames = new List<string>();
// public List<string> textures = new List<string>();
// public List<string> texturesPath = new List<string> ();
object finishCallback;
object callbackPrgs;
public void returnMaterial ()
{
CLMaterialPool.returnObj (materialName);
}
public void setMaterial (Callback onFinishCallback, object orgs)
{
finishCallback = onFinishCallback;
callbackPrgs = orgs;
#if UNITY_EDITOR
if (!CLCfgBase.self.isEditMode || Application.isPlaying) {
if (string.IsNullOrEmpty (materialName)) {
Debug.LogWarning (" then materialName is null===" + render.transform.parent.parent.name);
} else {
CLMaterialPool.borrowObjAsyn (materialName, (Callback)onGetMat);
}
} else {
string tmpPath = "Assets/" + CLPathCfg.self.basePath + "/upgradeRes4Dev/other/Materials/" + materialName.Replace (".", "/") + ".mat";
Debug.Log (tmpPath);
Material mat = AssetDatabase.LoadAssetAtPath (
tmpPath, typeof(UnityEngine.Object)) as Material;
CLMaterialPool.resetTexRef (materialName, mat, null, null);
onGetMat (materialName, mat);
}
#else
CLMaterialPool.borrowObjAsyn(materialName, (Callback)onGetMat);
#endif
}
void onGetMat (params object[] paras)
{
string name = paras [0].ToString ();
Material mat = paras [1] as Material;
if (index == 0) {
render.sharedMaterial = mat;
}
Material[] mats = render.sharedMaterials;//new Material[render.sharedMaterials.Length];
mats [index] = mat;
render.sharedMaterials = mats;
#if UNITY_EDITOR
if (!Application.isPlaying) {
EditorUtility.SetDirty (render);
}
#endif
Utl.doCallback (finishCallback, callbackPrgs);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 635ed0c68a7a14a068be7753eb6e4e6f
timeCreated: 1486272645
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,90 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 音乐、音效对象池
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class CLSoundPool : CLAssetsPoolBase<AudioClip>
{
public static CLSoundPool pool = new CLSoundPool ();
public override string getAssetPath (string name)
{
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/other/sound").e ();
return wrapPath (path, name);
}
public override AudioClip _borrowObj (string name)
{
return base._borrowObj (name, true);
}
public override bool isAutoReleaseAssetBundle
{
get
{
return false;
}
}
public static bool havePrefab (string name)
{
return pool._havePrefab (name);
}
public static void clean ()
{
pool._clean ();
}
public static void setPrefab (string name, object finishCallback)
{
setPrefab (name, finishCallback, null, null);
}
public static void setPrefab (string name, object finishCallback, object orgs)
{
pool._setPrefab (name, finishCallback, orgs, null);
}
public static void setPrefab (string name, object finishCallback, object orgs, object progressCB)
{
pool._setPrefab (name, finishCallback, orgs, progressCB);
}
public static AudioClip borrowObj (string name)
{
return pool._borrowObj (name, true);
}
public static void borrowObjAsyn (string name, object onGetCallbak)
{
borrowObjAsyn (name, onGetCallbak, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, progressCB);
}
public static void returnObj (string name)
{
pool._returnObj (name, null);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 73b8eafc870b74d8988b49fe91e979d2
timeCreated: 1484055080
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,92 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 图片对象池
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class CLTexturePool : CLAssetsPoolBase<Texture>
{
public static CLTexturePool pool = new CLTexturePool ();
public override string getAssetPath (string name)
{
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/other/Textures").e ();
return wrapPath (path, name);
}
public override Texture _borrowObj (string name)
{
return base._borrowObj (name, true);
}
public override bool isAutoReleaseAssetBundle
{
get
{
return false;
}
}
public static bool havePrefab (string path)
{
return pool._havePrefab (path);
}
public static void clean ()
{
pool._clean ();
}
public static void setPrefab (string path, object finishCallback)
{
setPrefab (path, finishCallback, null, null);
}
public static void setPrefab (string path, object finishCallback, object args)
{
pool._setPrefab (path, finishCallback, args, null);
}
public static void setPrefab (string path, object finishCallback, object args, object progressCB)
{
pool._setPrefab (path, finishCallback, args, progressCB);
}
public static Texture borrowObj (string path)
{
return pool._borrowObj (path, true);
}
public static void borrowObjAsyn (string path, object onGetCallbak)
{
borrowObjAsyn (path, onGetCallbak, null);
}
public static void borrowObjAsyn (string path, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn (path, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn (string path, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn (path, onGetCallbak, orgs, progressCB);
}
public static void returnObj (string path)
{
pool._returnObj (path, null);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c18574987fe734fffa7b6ecc16b6aa7b
timeCreated: 1443877905
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,89 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 其它物件对象池
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class CLThings4LuaPool:CLAssetsPoolBase<CLBaseLua>
{
public static CLThings4LuaPool pool = new CLThings4LuaPool ();
public override string getAssetPath (string name)
{
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/other/things").e ();
return wrapPath (path, name);
}
public override bool isAutoReleaseAssetBundle
{
get
{
return base.isAutoReleaseAssetBundle;
}
}
public static void clean ()
{
pool._clean ();
}
public static bool havePrefab (string name)
{
return pool._havePrefab (name);
}
public static void setPrefab (string name, object finishCallback, object args)
{
pool._setPrefab (name, finishCallback, args, null);
}
public static void setPrefab (string name, object finishCallback, object args, object progressCB)
{
pool._setPrefab (name, finishCallback, args, progressCB);
}
public static CLBaseLua borrowObj (string name)
{
return pool._borrowObj (name);
}
public static void borrowObjAsyn (string name, object onGetCallbak)
{
borrowObjAsyn (name, onGetCallbak, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, progressCB);
}
public static void returnObj (string name, CLBaseLua go)
{
pool._returnObj (name, go);
}
public static void returnObj (CLBaseLua go)
{
pool._returnObj (go.name, go);
}
public static void returnObj (string name, CLBaseLua go, bool inActive, bool setParent)
{
pool._returnObj (name, go, inActive, setParent);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1430b72ce8c3c4257a065239bab04dc0
timeCreated: 1446172233
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,89 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: 其它物件对象池
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class CLThingsPool:CLAssetsPoolBase<GameObject>
{
public static CLThingsPool pool = new CLThingsPool ();
public override string getAssetPath (string name)
{
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/other/things").e ();
return wrapPath (path, name);
}
public override bool isAutoReleaseAssetBundle
{
get
{
return base.isAutoReleaseAssetBundle;
}
}
public static void clean ()
{
pool._clean ();
}
public static bool havePrefab (string name)
{
return pool._havePrefab (name);
}
public static void setPrefab (string name, object finishCallback, object args)
{
pool._setPrefab (name, finishCallback, args, null);
}
public static void setPrefab (string name, object finishCallback, object args, object progressCB)
{
pool._setPrefab (name, finishCallback, args, progressCB);
}
public static GameObject borrowObj (string name)
{
return pool._borrowObj (name);
}
public static void borrowObjAsyn (string name, object onGetCallbak)
{
borrowObjAsyn (name, onGetCallbak, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, progressCB);
}
public static void returnObj (string name, GameObject go)
{
pool._returnObj (name, go);
}
public static void returnObj (GameObject go)
{
pool._returnObj (go.name, go);
}
public static void returnObj (string name, GameObject go, bool inActive, bool setParent)
{
pool._returnObj (name, go, inActive, setParent);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 175a5b798de154ee0a26e6e2acc7e106
timeCreated: 1446172233
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,108 @@
/*
********************************************************************************
*Copyright(C),coolae.net
*Author: chenbin
*Version: 2.0
*Date: 2017-01-09
*Description: ui的其它物件对象池比如血条
*Others:
*History:
*********************************************************************************
*/
using UnityEngine;
using System.Collections;
namespace Coolape
{
public class CLUIOtherObjPool:CLAssetsPoolBase<GameObject>
{
public static CLUIOtherObjPool pool = new CLUIOtherObjPool ();
public override string getAssetPath (string name)
{
string path = PStr.b ().a (CLPathCfg.self.basePath).a ("/")
.a (CLPathCfg.upgradeRes).a ("/priority/ui/other").e ();
return wrapPath (path, name);
}
public override void _returnObj (string name, GameObject unit, bool inActive = true, bool setParent = true)
{
base._returnObj (name, unit, inActive, setParent);
if (unit != null && setParent) {
NGUITools.MarkParentAsChanged (unit);
}
}
public override bool isAutoReleaseAssetBundle
{
get
{
return base.isAutoReleaseAssetBundle;
}
}
public static void clean ()
{
pool._clean ();
}
public static bool havePrefab (string name)
{
return pool._havePrefab (name);
}
public static void setPrefab (string name, object finishCallback, object args)
{
pool._setPrefab (name, finishCallback, args, null);
}
public static void setPrefab (string name, object finishCallback, object args, object progressCB)
{
pool._setPrefab (name, finishCallback, args, progressCB);
}
public override GameObject _borrowObj (string name)
{
GameObject go = base._borrowObj (name);
if (go != null) {
CLUIUtl.resetAtlasAndFont (go.transform, false);
}
return go;
}
public static GameObject borrowObj (string name)
{
return pool._borrowObj (name);
}
public static void borrowObjAsyn (string name, object onGetCallbak)
{
borrowObjAsyn (name, onGetCallbak, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, null);
}
public static void borrowObjAsyn (string name, object onGetCallbak, object orgs, object progressCB)
{
pool._borrowObjAsyn (name, onGetCallbak, orgs, progressCB);
}
public static void returnObj (string name, GameObject go)
{
pool._returnObj (name, go);
}
public static void returnObj (GameObject go)
{
pool._returnObj (go.name, go);
}
public static void returnObj (string name, GameObject go, bool inActive, bool setParent)
{
pool._returnObj (name, go, inActive, setParent);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7927411782835473a835821cbb556840
timeCreated: 1484056790
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: