using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; #if UNITY_EDITOR using UnityEditor; #endif namespace SoftKitty.MasterCharacterCreator { public class DemoScript : MonoBehaviour { public CharacterEntity Player; public EquipmentAppearance[] Equipments; //This is an example for how to bind character appearance with equipments. public GameObject [] EquippedLabel; public WeaponController[] Weapons; public GameObject[] WeaponEquippedLabel; public GameObject[] WeaponStateLabel; public GameObject DevWarning; public RawImage PhotoImage; public Camera mCamera; public Text WingText; public Text WingStateText; public GameObject WingStateButton; float angle = 0F; float viewEmotion = 0F; private void Start() { Application.targetFrameRate = 60; #if UNITY_EDITOR int _found = 0; for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) { if (EditorBuildSettings.scenes[i].path.Contains("CharacterCustomization") || EditorBuildSettings.scenes[i].path.Contains("Transition")) { _found++; } } DevWarning.SetActive(_found<2); #endif } private void Update() { if(Input.GetMouseButton(1)) angle = (angle + Input.GetAxis("Mouse X")*5F) % 360F; //Hold right mouse button to rotate the player. Player.transform.localEulerAngles = new Vector3(0F, angle, 0F); if (viewEmotion > 0F) { viewEmotion -= Time.deltaTime; mCamera.fieldOfView = 15F; mCamera.transform.localPosition = new Vector3(0F, 1.6F, 3.63F); } else { mCamera.fieldOfView = Mathf.Lerp(mCamera.fieldOfView,41.1F, Time.deltaTime * 5F); mCamera.transform.localPosition = new Vector3(0F, Mathf.Lerp(mCamera.transform.localPosition.y, 1.12F,Time.deltaTime*5F), 3.63F); } } public void CloseDeveWarning() { DevWarning.SetActive(false); } public void OpenHelp() { Application.OpenURL(Application.dataPath.Replace("Assets", "") + "Assets/SoftKitty/MasterCharacterCreator/Documentation/UserGuide.pdf"); } public void TakePhoto()//Take a photo of the character. { PhotoImage.texture = Player.GetCharacterPhoto(new Vector2(256, 256), Color.red, 15F, true); PhotoImage.gameObject.SetActive(true); } public void PlayEmotion(string _emotionUid)//Play emotion with the uid. { viewEmotion = 5F; Player.SetEmotion(_emotionUid,3F); } public void ToggleWing() { WingStateButton.SetActive(!WingStateButton.activeSelf); WingText.text = WingStateButton.activeSelf ? "ON" : "OFF"; if (WingStateButton.activeSelf) Player.Equip(OutfitSlots.Back, 1); else Player.Unequip(OutfitSlots.Back); } public void SwitchWingState() { if (Player.GetBackAnimationComponent().IsPlaying("ClosedIdle")) { WingStateText.text = "Fly"; Player.GetBackAnimationComponent().CrossFade("CloseToOpen", 0.25F); Player.GetBackAnimationComponent().CrossFadeQueued("OpenFlap1", 0.25F); } else if(Player.GetBackAnimationComponent().IsPlaying("OpenFlap1")) { WingStateText.text = "Idle"; Player.GetBackAnimationComponent().CrossFade("OpenToClose", 0.3F); Player.GetBackAnimationComponent().CrossFadeQueued("ClosedIdle", 0.25F); } } public void CreateNewCharacter() { Player.ResetCharacter(); //Reset the character to default before going into character creation UI. Player.CreateCharacter(); //Switch to character creation UI (For player to use) } public void CustomizeCharacter() { Player.CustomizeCharacter();//Switch to character customization UI with this character (For player to use) } public void CustomizeCharacterDeveloper() { Player.CreateCharacterByDeveloper();//Switch to character creation UI (For developer to use) } public void Equip(int _id) { if (!Player.isEquipped(Equipments[_id])) //Check if the character is already equipped this equipment. { Player.Equip(Equipments[_id]); //If not, equip it. SoundManager.Play2D("EquipOn"); } else { Player.Unequip(Equipments[_id].Type); //If it's already equipped, then unequip it. SoundManager.Play2D("EquipOff"); } for (int i = 0; i < Equipments.Length; i++)//Update the equip mark on the interface. EquippedLabel[i].SetActive(Player.GetEquippedId(Equipments[i].Type) == Equipments[i].GetId(Player.sex)); } public void SwitchWeapon(int _id) { if (!Player.isEquippedWeapon(Weapons[_id].uid)) //Check if the character is already equipped this weapon. { Player.EquipWeapon(Weapons[_id], Player.GetWeaponState()); //If not, equip it. SoundManager.Play2D("EquipOn"); } else { Player.UnequipWeapon(Weapons[_id].Type); //If it's already equipped, then unequip it. SoundManager.Play2D("EquipOff"); } for (int i = 0; i < Weapons.Length; i++)//Update the equip mark on the interface. WeaponEquippedLabel[i].SetActive(Player.isEquippedWeapon(Weapons[i].uid)); } public void SwitchWeaponState(int _state) { Player.SwitchWeaponState((WeaponState)_state);//Switch the state of the equipped weapons for (int i = 0; i < WeaponStateLabel.Length; i++) WeaponStateLabel[i].SetActive(i== _state); } public void Quit() { Application.Quit(); } } }