public void LoadPlayerDataExp(GameObject playerObj, string loadTargetName) { GameObject playerStaticCopy = CheckPlayerDataStoraged(playerObj); if (playerStaticCopy == null) { Debug.LogWarning(GetType().Name + " warning: cannot find saved data called " + loadTargetName + ", " + "thus the data of " + playerObj.name + " will remain the same."); return; } //Data Inherition. DEV NOTE: could use interface and function to make a better / simpler code? Player d_player = playerStaticCopy.GetComponent <Player>(); Player o_player = playerObj.GetComponent <Player>(); o_player.CopyData(d_player); PropertyManager d_propertyManager = playerStaticCopy.GetComponent <PropertyManager>(); PropertyManager o_propertyManager = playerObj.GetComponent <PropertyManager>(); UnitProperty[] d_propertyList = d_propertyManager.GetPropertyList(); if (d_propertyList != null) { foreach (UnitProperty p in d_propertyList) { o_propertyManager.ApplyProperty(p); } } }
public void UpdatePlayerData(int playerListIndex, Player newPlayerData) { //this part can be customized. Player originalPlayerData = playerList[playerListIndex]; PropertyManager newPPM = newPlayerData.GetComponent <PropertyManager>(); //upload the data. //DEV NOTE: can write in a better way? such as player.sync(player); newPlayerData.UpdateHealthPoint(originalPlayerData.healthPoint); //upload the property if (newPPM == null) { Debug.LogWarning(GetType().Name + " warning: a player without PropertyManager want to be registered, which is very strange in this game. Script will automatically add one."); newPPM = newPlayerData.gameObject.AddComponent <PropertyManager>(); } UnitProperty[] originalProperty = originalPlayerData.GetComponent <PropertyManager>().GetPropertyList(); if (originalProperty != null) { foreach (UnitProperty p in originalProperty) { newPPM.ApplyProperty(p); } } //replace the stored one due to system design. Ask your programmer. playerList[playerListIndex] = newPlayerData; playerList[playerListIndex].ResetState(); Destroy(originalPlayerData.gameObject); }
private void GivePropertyTo(GameObject obj) { PropertyManager objPropertyManager = obj.GetComponent <PropertyManager>(); if (objPropertyManager == null) { Debug.LogWarning(GetType().Name + " of " + name + " warning: cannot find property manager of " + obj.name + ", which might be a bug. To make system keep running, script will add one."); objPropertyManager = obj.AddComponent <PropertyManager>(); } objPropertyManager.ApplyProperty(giveProperty, updateInfoIfPropertyExists); }
protected bool GivePropertyTo(GameObject obj, UnitProperty giveProperty, bool updateInfoIfPropertyExists) { PropertyManager objPropertyManager = obj.GetComponent <PropertyManager>(); if (objPropertyManager == null) { Debug.Log(CanNotFindPropertyManagerSoAddOne(obj)); objPropertyManager = obj.AddComponent <PropertyManager>(); } return(objPropertyManager.ApplyProperty(giveProperty, updateInfoIfPropertyExists)); }
public void SavePlayerDataExp(GameObject playerObj) { GameObject playerStaticCopy = CheckPlayerDataStoraged(playerObj); if (playerStaticCopy == null) { //didn't save before. Create a static copy. //Debug.Log(GetType().Name + ": first time to save " + playerObj.name + "."); playerStaticCopy = new GameObject(PlayerDataStorageName(playerObj.name)); DontDestroyOnLoad(playerStaticCopy); playerStaticCopy.SetActive(false); playerStaticCopy.transform.SetParent(transform); playerStaticCopySeries.Add(playerStaticCopy); } //else Debug.Log(GetType().Name + ": not the first time to save " + playerObj.name + "."); //Data Copy. DEV NOTE: could use interface and function to make a better / simpler code? Player d_player = playerStaticCopy.GetComponent <Player>(); if (d_player == null) { d_player = playerStaticCopy.AddComponent <Player>(); } Player o_player = playerObj.GetComponent <Player>(); d_player.CopyData(o_player); PropertyManager d_propertyManager = playerStaticCopy.GetComponent <PropertyManager>(); if (d_propertyManager == null) { d_propertyManager = playerStaticCopy.AddComponent <PropertyManager>(); } PropertyManager o_propertyManager = playerObj.GetComponent <PropertyManager>(); UnitProperty[] o_propertyList = o_propertyManager.GetPropertyList(); if (o_propertyList != null) { foreach (UnitProperty p in o_propertyList) { d_propertyManager.ApplyProperty(p); } } else { d_propertyManager.ClearProperty(); } }