skin
This commit is contained in:
BIN
Assets/Script/.DS_Store
vendored
BIN
Assets/Script/.DS_Store
vendored
Binary file not shown.
22
Assets/Script/CharSelectionManager.cs
Normal file
22
Assets/Script/CharSelectionManager.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CharSelectionManager : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private GameObject[] characterPrefabs;
|
||||
|
||||
public void ChangeCharacter(int index)
|
||||
{
|
||||
for (int i = 0; i < characterPrefabs.Length; i++)
|
||||
{
|
||||
characterPrefabs[i].SetActive(false);
|
||||
}
|
||||
characterPrefabs[index].SetActive(true);
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Script/CharSelectionManager.cs.meta
Normal file
11
Assets/Script/CharSelectionManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a566385cb2a34466a99b7610070385e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Script/CharacterCusomizationBridge.cs
Normal file
35
Assets/Script/CharacterCusomizationBridge.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class CharacterCusomizationBridge : MonoBehaviour
|
||||
{
|
||||
public Character4D character;
|
||||
|
||||
public static string characterJson;
|
||||
|
||||
public static CharacterCusomizationBridge instance;
|
||||
void Awake(){
|
||||
if(instance!=null && instance!=this){
|
||||
Destroy(instance.gameObject);
|
||||
}
|
||||
|
||||
instance=this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
void Update(){
|
||||
|
||||
// if(Input.GetKeyDown(KeyCode.Space)){
|
||||
// LoadToGame();
|
||||
// }
|
||||
}
|
||||
|
||||
public void LoadToGame(){
|
||||
CharacterSelection.selectedCharJson = character.ToJson();
|
||||
SceneManager.LoadScene("MenuScene");
|
||||
CharacterSelection.SaveCharacterSkinCloud();
|
||||
}
|
||||
}
|
||||
11
Assets/Script/CharacterCusomizationBridge.cs.meta
Normal file
11
Assets/Script/CharacterCusomizationBridge.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eacf460e0d7a143309db001657914f66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Script/CharacterSkin.meta
Normal file
8
Assets/Script/CharacterSkin.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4dc705c90c00842369b81dac75b580d8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Script/CharacterSkin/ChangeCharacterOnSelection.cs
Normal file
24
Assets/Script/CharacterSkin/ChangeCharacterOnSelection.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
|
||||
using UnityEngine;
|
||||
|
||||
public class ChangeCharacterOnSelection : MonoBehaviour
|
||||
{
|
||||
public Character4D character;
|
||||
void Start(){
|
||||
CharacterSelection.OnCharacterChanged += RefreshCharacter;
|
||||
RefreshCharacter();
|
||||
}
|
||||
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
CharacterSelection.OnCharacterChanged -= RefreshCharacter;
|
||||
}
|
||||
|
||||
void RefreshCharacter(){
|
||||
if(CharacterSelection.selectedCharJson.Length <= 0){return;}
|
||||
character.FromJson(CharacterSelection.selectedCharJson, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a01bf626125f48b38c14bb319871b4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/Script/CharacterSkin/CharacterSelection.cs
Normal file
89
Assets/Script/CharacterSkin/CharacterSelection.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Firebase.Extensions;
|
||||
using Firebase.Firestore;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CharacterSelection : MonoBehaviour
|
||||
{
|
||||
|
||||
public static string selectedCharJson;
|
||||
public List<string> predefinedCharacterJsons;
|
||||
public List<Button> predefinedCharacterButtons;
|
||||
|
||||
public static Action OnCharacterChanged;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
for(int i=0; i < predefinedCharacterButtons.Count; i++){
|
||||
int tempI = i;
|
||||
predefinedCharacterButtons[i].onClick.AddListener(()=>{OnPredefinedCharButtonPress(tempI);});
|
||||
}
|
||||
LoadCharacterSkinCloud();
|
||||
}
|
||||
|
||||
public void LoadCharacterFromString(string characterData){
|
||||
selectedCharJson = characterData;
|
||||
OnCharacterChanged.Invoke();
|
||||
}
|
||||
|
||||
void OnPredefinedCharButtonPress(int i){
|
||||
selectedCharJson = predefinedCharacterJsons[i];
|
||||
OnCharacterChanged.Invoke();
|
||||
SaveCharacterSkinCloud();
|
||||
}
|
||||
|
||||
public static void SaveCharacterSkinCloud(){
|
||||
#if UNITY_EDITOR
|
||||
PlayerPrefs.SetString("skinData", selectedCharJson);
|
||||
PlayerPrefs.Save();
|
||||
#endif
|
||||
|
||||
FirebaseFirestore db = FirebaseFirestore.DefaultInstance;
|
||||
|
||||
Dictionary<string,object> skindataDictionary = new Dictionary<string, object>();
|
||||
skindataDictionary.Add("json", selectedCharJson);
|
||||
|
||||
DocumentReference docRef = db.Collection("SkinData").Document(gplayAuth.userID);
|
||||
docRef.SetAsync(skindataDictionary).ContinueWithOnMainThread(task => {
|
||||
if(task.IsCompleted){
|
||||
Debug.Log("**** Save Completed Firestore ****");
|
||||
}
|
||||
else{
|
||||
Debug.Log("**** Failed to save data to firestore ****");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void LoadCharacterSkinCloud(){
|
||||
#if UNITY_EDITOR
|
||||
if(PlayerPrefs.HasKey("skinData")){
|
||||
LoadCharacterFromString(PlayerPrefs.GetString("skinData"));
|
||||
}
|
||||
#endif
|
||||
|
||||
FirebaseFirestore db = FirebaseFirestore.DefaultInstance;
|
||||
DocumentReference docRef = db.Collection("SkinData").Document(gplayAuth.userID);
|
||||
|
||||
docRef.GetSnapshotAsync().ContinueWithOnMainThread(task => {
|
||||
DocumentSnapshot snapshot = task.Result;
|
||||
if(snapshot.Exists){
|
||||
|
||||
LoadCharacterFromString(snapshot.GetValue<string>("json"));
|
||||
|
||||
}else{
|
||||
//show error previous data doesnt exists to load
|
||||
Debug.Log("**** No previous data to load ****");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Script/CharacterSkin/CharacterSelection.cs.meta
Normal file
11
Assets/Script/CharacterSkin/CharacterSelection.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f46cf614fdb6e410695e435f02bfcd44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -25,5 +25,9 @@ public class MenuSceneScript : MonoBehaviour
|
||||
public void LogoutBacktoLogin(){
|
||||
SceneManager.LoadScene("GameLogin");
|
||||
}
|
||||
|
||||
public void LoadCharacterCreation(){
|
||||
SceneManager.LoadScene("NewCharacter");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,12 @@ public class characterManager : MonoBehaviour
|
||||
|
||||
float xMove , yMove;
|
||||
|
||||
void Start(){
|
||||
// if(CharacterCusomizationBridge.instance!=null && CharacterCusomizationBridge.characterJson!=null){
|
||||
// GetComponent<Character4D>().FromJson(CharacterCusomizationBridge.characterJson, false);
|
||||
// }
|
||||
}
|
||||
|
||||
void Update(){
|
||||
|
||||
if(Input.GetKeyDown(KeyCode.M)){
|
||||
|
||||
@@ -20,6 +20,7 @@ public class playerNetwork : NetworkBehaviour
|
||||
public const float ATTACK_COOLDOWN = 0.6f;
|
||||
[HideInInspector]
|
||||
public StatManager statManager;
|
||||
public CharacterSelection charSelectionManager;
|
||||
|
||||
//public const int XPFORLEVEL = 10;
|
||||
[SyncVar(hook =nameof(OnHealthChanged))] public int health = 100;
|
||||
@@ -150,6 +151,8 @@ public class playerNetwork : NetworkBehaviour
|
||||
|
||||
public GameObject projectile;
|
||||
|
||||
public string selectedCharacterJson = CharacterSelection.selectedCharJson;
|
||||
|
||||
public void QuestFunction(QuestScriptable questData){
|
||||
currentQuest = questData;
|
||||
questText.text = questData.questTitle;
|
||||
@@ -243,6 +246,7 @@ public class playerNetwork : NetworkBehaviour
|
||||
{"xp", XP},
|
||||
{"completedQuest", completedQuests},
|
||||
{"playerStats", statManager.PlayerStats},
|
||||
{"characterJson", selectedCharacterJson},
|
||||
|
||||
};
|
||||
|
||||
@@ -297,8 +301,9 @@ public class playerNetwork : NetworkBehaviour
|
||||
inventory.inventoryManager.SetInventory(inventoryGetData);
|
||||
|
||||
completedQuests = snapshot.GetValue<List<string>>("completedQuest");
|
||||
|
||||
//stats
|
||||
statManager.loadFromCloudSave(snapshot.GetValue<Dictionary<string, int>>("playerStats"));
|
||||
|
||||
|
||||
isLoaded = true;
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user