|
@@ -9,9 +9,11 @@ namespace GFGGame
|
|
{
|
|
{
|
|
private const string BODY_DEFAULT_RES_NAME = "renmo";
|
|
private const string BODY_DEFAULT_RES_NAME = "renmo";
|
|
private const string ROLE_OBJ_NAME = "Role";
|
|
private const string ROLE_OBJ_NAME = "Role";
|
|
- private const string BODY_OBJ_NAME = "Body";
|
|
|
|
|
|
+ private const string BODY_SPRITE_NAME = "Body";
|
|
|
|
+ private const string BODY_ANIMATION_NAME = "Body_a";
|
|
private const string BODY_EFFECT_OBJ_NAME = "Body_eff";
|
|
private const string BODY_EFFECT_OBJ_NAME = "Body_eff";
|
|
- private const string FORMAT_OBJ_NAME = "T{0}_{1}";
|
|
|
|
|
|
+ private const string FORMAT_SPRITE_NAME = "T{0}_s{1}";
|
|
|
|
+ private const string FORMAT_ANIMATION_NAME = "T{0}_a{1}";
|
|
private const string FORMAT_EFFECT_OBJ_NAME = "T{0}_eff";
|
|
private const string FORMAT_EFFECT_OBJ_NAME = "T{0}_eff";
|
|
private const string FORMAT_LAYER_RES_NAME_WITH_T = "{0}_t";
|
|
private const string FORMAT_LAYER_RES_NAME_WITH_T = "{0}_t";
|
|
|
|
|
|
@@ -84,34 +86,23 @@ namespace GFGGame
|
|
Transform role = sceneObj.transform.Find(ROLE_OBJ_NAME);
|
|
Transform role = sceneObj.transform.Find(ROLE_OBJ_NAME);
|
|
parentObj = role.gameObject;
|
|
parentObj = role.gameObject;
|
|
}
|
|
}
|
|
- string objName;
|
|
|
|
|
|
+ string spritObjName;
|
|
|
|
+ string aniObjName;
|
|
//默认层
|
|
//默认层
|
|
if (itemCfg.resLayer1 > 0)
|
|
if (itemCfg.resLayer1 > 0)
|
|
{
|
|
{
|
|
- objName = string.Format(FORMAT_OBJ_NAME, itemCfg.subType, 1);
|
|
|
|
- Transform transform = parentObj.transform.Find(objName);
|
|
|
|
- if (transform != null)
|
|
|
|
- {
|
|
|
|
- GameObject gameObj = transform.gameObject;
|
|
|
|
- if (gameObj != null)
|
|
|
|
- {
|
|
|
|
- GameObject.DestroyImmediate(gameObj);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, 1);
|
|
|
|
+ TryClearSpriteObj(parentObj, spritObjName);
|
|
|
|
+ aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, 1);
|
|
|
|
+ TryRemoveAnimationObj(parentObj, aniObjName);
|
|
}
|
|
}
|
|
//特殊层
|
|
//特殊层
|
|
if (itemCfg.resLayer2 > 0)
|
|
if (itemCfg.resLayer2 > 0)
|
|
{
|
|
{
|
|
- objName = string.Format(FORMAT_OBJ_NAME, itemCfg.subType, 2);
|
|
|
|
- Transform transform_t = parentObj.transform.Find(objName);
|
|
|
|
- if (transform_t != null)
|
|
|
|
- {
|
|
|
|
- GameObject gameObj_t = transform_t.gameObject;
|
|
|
|
- if (gameObj_t != null)
|
|
|
|
- {
|
|
|
|
- GameObject.DestroyImmediate(gameObj_t);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, 2);
|
|
|
|
+ TryClearSpriteObj(parentObj, spritObjName);
|
|
|
|
+ aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, 2);
|
|
|
|
+ TryRemoveAnimationObj(parentObj, aniObjName);
|
|
}
|
|
}
|
|
|
|
|
|
//特效
|
|
//特效
|
|
@@ -130,37 +121,34 @@ namespace GFGGame
|
|
public static void UpdateBody(string res, GameObject sceneObj, bool isAni = false, string effRes = null, bool needSetMask = false, GameObject parentObj = null)
|
|
public static void UpdateBody(string res, GameObject sceneObj, bool isAni = false, string effRes = null, bool needSetMask = false, GameObject parentObj = null)
|
|
{
|
|
{
|
|
//角色
|
|
//角色
|
|
- Transform roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
|
|
|
|
- GameObject roleObj = parentObj == null ? roleTf.gameObject : parentObj;
|
|
|
|
|
|
+ var roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
|
|
|
|
+ parentObj = parentObj == null ? roleTf.gameObject : parentObj;
|
|
if (res == null)
|
|
if (res == null)
|
|
{
|
|
{
|
|
res = BODY_DEFAULT_RES_NAME;
|
|
res = BODY_DEFAULT_RES_NAME;
|
|
}
|
|
}
|
|
- var objName = BODY_OBJ_NAME;
|
|
|
|
- Transform tf = roleObj.transform.Find(objName);
|
|
|
|
- if (tf != null)
|
|
|
|
- {
|
|
|
|
- GameObject.DestroyImmediate(tf.gameObject);
|
|
|
|
- tf = null;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ //清理旧的
|
|
|
|
+ TryClearSpriteObj(parentObj, BODY_SPRITE_NAME);
|
|
|
|
+ TryRemoveAnimationObj(parentObj, BODY_ANIMATION_NAME);
|
|
|
|
+
|
|
if (isAni)
|
|
if (isAni)
|
|
{
|
|
{
|
|
- AddAnimationObj(res, objName, roleObj, 0);
|
|
|
|
|
|
+ AddAnimationObj(res, BODY_ANIMATION_NAME, parentObj, 0);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- AddSpriteObj(res, "png", objName, roleObj, 0, needSetMask);
|
|
|
|
|
|
+ AddSpriteObj(res, "png", BODY_SPRITE_NAME, parentObj, 0, needSetMask);
|
|
}
|
|
}
|
|
//特效
|
|
//特效
|
|
- objName = BODY_EFFECT_OBJ_NAME;
|
|
|
|
- tf = roleObj.transform.Find(objName);
|
|
|
|
|
|
+ var tf = parentObj.transform.Find(BODY_EFFECT_OBJ_NAME);
|
|
if (tf != null)
|
|
if (tf != null)
|
|
{
|
|
{
|
|
GameObject.DestroyImmediate(tf.gameObject);
|
|
GameObject.DestroyImmediate(tf.gameObject);
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(effRes))
|
|
if (!string.IsNullOrEmpty(effRes))
|
|
{
|
|
{
|
|
- AddEffectObj(effRes, objName, roleObj, 0);
|
|
|
|
|
|
+ AddEffectObj(effRes, BODY_EFFECT_OBJ_NAME, parentObj, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -184,7 +172,7 @@ namespace GFGGame
|
|
{
|
|
{
|
|
|
|
|
|
ItemTypeCfg typeCfg = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType);
|
|
ItemTypeCfg typeCfg = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType);
|
|
- string objName = string.Format(FORMAT_OBJ_NAME, typeCfg.type, layerId);
|
|
|
|
|
|
+ //string objName = string.Format(FORMAT_SPRITE_NAME, typeCfg.type, layerId);
|
|
string res = itemCfg.res;
|
|
string res = itemCfg.res;
|
|
int sortingOrder = typeCfg.defaultLayer;
|
|
int sortingOrder = typeCfg.defaultLayer;
|
|
if (layerId == 2)
|
|
if (layerId == 2)
|
|
@@ -195,24 +183,33 @@ namespace GFGGame
|
|
{
|
|
{
|
|
res = string.Format(FORMAT_LAYER_RES_NAME_WITH_T, res);
|
|
res = string.Format(FORMAT_LAYER_RES_NAME_WITH_T, res);
|
|
}
|
|
}
|
|
- Transform tf = parentObj.transform.Find(objName);
|
|
|
|
- if (tf != null)
|
|
|
|
- {
|
|
|
|
- GameObject.DestroyImmediate(tf.gameObject);
|
|
|
|
- tf = null;
|
|
|
|
- }
|
|
|
|
|
|
+ //清理旧的
|
|
|
|
+ var spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, layerId);
|
|
|
|
+ TryClearSpriteObj(parentObj, spritObjName);
|
|
|
|
+ var aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, layerId);
|
|
|
|
+ TryRemoveAnimationObj(parentObj, aniObjName);
|
|
string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
|
|
string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
|
|
- AddSpriteObj(res, ext, objName, parentObj, sortingOrder, needSetMask);
|
|
|
|
|
|
+ AddSpriteObj(res, ext, spritObjName, parentObj, sortingOrder, needSetMask);
|
|
if (itemCfg.isAni > 0 && showAni)
|
|
if (itemCfg.isAni > 0 && showAni)
|
|
{
|
|
{
|
|
- tf = parentObj.transform.Find(objName);
|
|
|
|
- AddAnimationObj(res, objName, parentObj, sortingOrder);
|
|
|
|
|
|
+ AddAnimationObj(res, aniObjName, parentObj, sortingOrder);
|
|
Timers.inst.Add(0.03f, 1, (obj) =>
|
|
Timers.inst.Add(0.03f, 1, (obj) =>
|
|
{
|
|
{
|
|
|
|
+ Transform tf = parentObj.transform.Find(spritObjName);
|
|
if (tf != null && tf.gameObject != null && tf.gameObject.activeInHierarchy)
|
|
if (tf != null && tf.gameObject != null && tf.gameObject.activeInHierarchy)
|
|
{
|
|
{
|
|
- GameObject.DestroyImmediate(tf.gameObject);
|
|
|
|
- tf = null;
|
|
|
|
|
|
+ var assetDisposer = tf.gameObject.GetComponent<AssetReleaser>();
|
|
|
|
+ if (assetDisposer != null)
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrEmpty(assetDisposer.resPath))
|
|
|
|
+ {
|
|
|
|
+ string resPath = ResPathUtil.GetDressUpPath(res, ext);
|
|
|
|
+ if (assetDisposer.resPath == resPath)
|
|
|
|
+ {
|
|
|
|
+ TryClearSpriteObj(parentObj, spritObjName);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -223,10 +220,18 @@ namespace GFGGame
|
|
{
|
|
{
|
|
string resPath = ResPathUtil.GetDressUpPath(res, ext);
|
|
string resPath = ResPathUtil.GetDressUpPath(res, ext);
|
|
SpriteRenderer spr = null;
|
|
SpriteRenderer spr = null;
|
|
- var gameObj = new GameObject(objName);
|
|
|
|
- spr = gameObj.AddComponent<SpriteRenderer>();
|
|
|
|
- AddAssetReleaser(gameObj, resPath);
|
|
|
|
- gameObj.transform.SetParent(parentObj.transform, false);
|
|
|
|
|
|
+ var gameObj = parentObj.transform.Find(objName)?.gameObject;
|
|
|
|
+ if(gameObj == null)
|
|
|
|
+ {
|
|
|
|
+ gameObj = new GameObject(objName);
|
|
|
|
+ gameObj.transform.SetParent(parentObj.transform, false);
|
|
|
|
+ AddAssetReleaser(gameObj, resPath);
|
|
|
|
+ }
|
|
|
|
+ spr = gameObj.GetComponent<SpriteRenderer>();
|
|
|
|
+ if(spr == null)
|
|
|
|
+ {
|
|
|
|
+ spr = gameObj.AddComponent<SpriteRenderer>();
|
|
|
|
+ }
|
|
float tx, ty;
|
|
float tx, ty;
|
|
LoadSpritePos(res, out tx, out ty);
|
|
LoadSpritePos(res, out tx, out ty);
|
|
gameObj.transform.localPosition = new Vector3(tx, ty, gameObj.transform.localPosition.z);
|
|
gameObj.transform.localPosition = new Vector3(tx, ty, gameObj.transform.localPosition.z);
|
|
@@ -245,6 +250,37 @@ namespace GFGGame
|
|
return gameObj;
|
|
return gameObj;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static void TryClearSpriteObj(GameObject parentObj, string spritObjName)
|
|
|
|
+ {
|
|
|
|
+ if(parentObj == null)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Transform transform_t = parentObj.transform.Find(spritObjName);
|
|
|
|
+ if (transform_t != null)
|
|
|
|
+ {
|
|
|
|
+ GameObject gameObj_t = transform_t.gameObject;
|
|
|
|
+ if (gameObj_t != null)
|
|
|
|
+ {
|
|
|
|
+ SpriteRenderer spr = null;
|
|
|
|
+ spr = gameObj_t.GetComponent<SpriteRenderer>();
|
|
|
|
+ if(spr != null)
|
|
|
|
+ {
|
|
|
|
+ spr.sprite = null;
|
|
|
|
+ }
|
|
|
|
+ var assetDisposer = gameObj_t.GetComponent<AssetReleaser>();
|
|
|
|
+ if(assetDisposer != null)
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrEmpty(assetDisposer.resPath))
|
|
|
|
+ {
|
|
|
|
+ GFGAsset.Release(assetDisposer.resPath);
|
|
|
|
+ assetDisposer.resPath = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private static GameObject AddAnimationObj(string res, string objName, GameObject parentObj, int sortingOrder)
|
|
private static GameObject AddAnimationObj(string res, string objName, GameObject parentObj, int sortingOrder)
|
|
{
|
|
{
|
|
string resPath = ResPathUtil.GetDressUpAnimationPath(res);
|
|
string resPath = ResPathUtil.GetDressUpAnimationPath(res);
|
|
@@ -269,7 +305,25 @@ namespace GFGGame
|
|
SetParticleSortingOrder(gameObj, sortingOrder);
|
|
SetParticleSortingOrder(gameObj, sortingOrder);
|
|
return gameObj;
|
|
return gameObj;
|
|
}
|
|
}
|
|
- public static GameObject AddAnimationObj(string resPath)
|
|
|
|
|
|
+
|
|
|
|
+ private static void TryRemoveAnimationObj(GameObject parentObj, string aniObjName)
|
|
|
|
+ {
|
|
|
|
+ if (parentObj == null)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Transform transform = parentObj.transform.Find(aniObjName);
|
|
|
|
+ if (transform != null)
|
|
|
|
+ {
|
|
|
|
+ GameObject gameObj = transform.gameObject;
|
|
|
|
+ if (gameObj != null)
|
|
|
|
+ {
|
|
|
|
+ GameObject.DestroyImmediate(gameObj);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static GameObject CreateAnimationObj(string resPath)
|
|
{
|
|
{
|
|
// string resPath = ResPathUtil.GetCardAnimationPath(res);
|
|
// string resPath = ResPathUtil.GetCardAnimationPath(res);
|
|
var prefab = GFGAsset.Load<GameObject>(resPath);
|
|
var prefab = GFGAsset.Load<GameObject>(resPath);
|
|
@@ -281,6 +335,7 @@ namespace GFGGame
|
|
AddAssetReleaser(gameObj, resPath);
|
|
AddAssetReleaser(gameObj, resPath);
|
|
return gameObj;
|
|
return gameObj;
|
|
}
|
|
}
|
|
|
|
+
|
|
private static GameObject AddEffectObj(string res, string objName, GameObject parentObj, int sortingOrder)
|
|
private static GameObject AddEffectObj(string res, string objName, GameObject parentObj, int sortingOrder)
|
|
{
|
|
{
|
|
var resPath = ResPathUtil.GetDressUpEffectPath(res);
|
|
var resPath = ResPathUtil.GetDressUpEffectPath(res);
|
|
@@ -293,7 +348,7 @@ namespace GFGGame
|
|
return gameObj;
|
|
return gameObj;
|
|
}
|
|
}
|
|
|
|
|
|
- public static void LoadSpritePos(string res, out float tx, out float ty)
|
|
|
|
|
|
+ private static void LoadSpritePos(string res, out float tx, out float ty)
|
|
{
|
|
{
|
|
string resPath = ResPathUtil.GetDressUpPath(res, "bytes");
|
|
string resPath = ResPathUtil.GetDressUpPath(res, "bytes");
|
|
if (VEngine.Versions.Contains(resPath))
|
|
if (VEngine.Versions.Contains(resPath))
|