DemoScript.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. #if UNITY_EDITOR
  7. using UnityEditor;
  8. #endif
  9. namespace SoftKitty.MasterCharacterCreator
  10. {
  11. public class DemoScript : MonoBehaviour
  12. {
  13. public CharacterEntity Player;
  14. public EquipmentAppearance[] Equipments; //This is an example for how to bind character appearance with equipments.
  15. public GameObject [] EquippedLabel;
  16. public WeaponController[] Weapons;
  17. public GameObject[] WeaponEquippedLabel;
  18. public GameObject[] WeaponStateLabel;
  19. public GameObject DevWarning;
  20. public RawImage PhotoImage;
  21. public Camera mCamera;
  22. public Text WingText;
  23. public Text WingStateText;
  24. public GameObject WingStateButton;
  25. float angle = 0F;
  26. float viewEmotion = 0F;
  27. private void Start()
  28. {
  29. Application.targetFrameRate = 60;
  30. #if UNITY_EDITOR
  31. int _found = 0;
  32. for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
  33. {
  34. if (EditorBuildSettings.scenes[i].path.Contains("CharacterCustomization")
  35. || EditorBuildSettings.scenes[i].path.Contains("Transition"))
  36. {
  37. _found++;
  38. }
  39. }
  40. DevWarning.SetActive(_found<2);
  41. #endif
  42. }
  43. private void Update()
  44. {
  45. if(Input.GetMouseButton(1)) angle = (angle + Input.GetAxis("Mouse X")*5F) % 360F; //Hold right mouse button to rotate the player.
  46. Player.transform.localEulerAngles = new Vector3(0F, angle, 0F);
  47. if (viewEmotion > 0F)
  48. {
  49. viewEmotion -= Time.deltaTime;
  50. mCamera.fieldOfView = 15F;
  51. mCamera.transform.localPosition = new Vector3(0F, 1.6F, 3.63F);
  52. }
  53. else
  54. {
  55. mCamera.fieldOfView = Mathf.Lerp(mCamera.fieldOfView,41.1F, Time.deltaTime * 5F);
  56. mCamera.transform.localPosition = new Vector3(0F, Mathf.Lerp(mCamera.transform.localPosition.y, 1.12F,Time.deltaTime*5F), 3.63F);
  57. }
  58. }
  59. public void CloseDeveWarning()
  60. {
  61. DevWarning.SetActive(false);
  62. }
  63. public void OpenHelp()
  64. {
  65. Application.OpenURL(Application.dataPath.Replace("Assets", "") + "Assets/SoftKitty/MasterCharacterCreator/Documentation/UserGuide.pdf");
  66. }
  67. public void TakePhoto()//Take a photo of the character.
  68. {
  69. PhotoImage.texture = Player.GetCharacterPhoto(new Vector2(256, 256), Color.red, 15F, true);
  70. PhotoImage.gameObject.SetActive(true);
  71. }
  72. public void PlayEmotion(string _emotionUid)//Play emotion with the uid.
  73. {
  74. viewEmotion = 5F;
  75. Player.SetEmotion(_emotionUid,3F);
  76. }
  77. public void ToggleWing()
  78. {
  79. WingStateButton.SetActive(!WingStateButton.activeSelf);
  80. WingText.text = WingStateButton.activeSelf ? "ON" : "OFF";
  81. if (WingStateButton.activeSelf)
  82. Player.Equip(OutfitSlots.Back, 1);
  83. else
  84. Player.Unequip(OutfitSlots.Back);
  85. }
  86. public void SwitchWingState()
  87. {
  88. if (Player.GetBackAnimationComponent().IsPlaying("ClosedIdle"))
  89. {
  90. WingStateText.text = "Fly";
  91. Player.GetBackAnimationComponent().CrossFade("CloseToOpen", 0.25F);
  92. Player.GetBackAnimationComponent().CrossFadeQueued("OpenFlap1", 0.25F);
  93. }
  94. else if(Player.GetBackAnimationComponent().IsPlaying("OpenFlap1"))
  95. {
  96. WingStateText.text = "Idle";
  97. Player.GetBackAnimationComponent().CrossFade("OpenToClose", 0.3F);
  98. Player.GetBackAnimationComponent().CrossFadeQueued("ClosedIdle", 0.25F);
  99. }
  100. }
  101. public void CreateNewCharacter()
  102. {
  103. Player.ResetCharacter(); //Reset the character to default before going into character creation UI.
  104. Player.CreateCharacter(); //Switch to character creation UI (For player to use)
  105. }
  106. public void CustomizeCharacter()
  107. {
  108. Player.CustomizeCharacter();//Switch to character customization UI with this character (For player to use)
  109. }
  110. public void CustomizeCharacterDeveloper()
  111. {
  112. Player.CreateCharacterByDeveloper();//Switch to character creation UI (For developer to use)
  113. }
  114. public void Equip(int _id)
  115. {
  116. if (!Player.isEquipped(Equipments[_id])) //Check if the character is already equipped this equipment.
  117. {
  118. Player.Equip(Equipments[_id]); //If not, equip it.
  119. SoundManager.Play2D("EquipOn");
  120. }
  121. else
  122. {
  123. Player.Unequip(Equipments[_id].Type); //If it's already equipped, then unequip it.
  124. SoundManager.Play2D("EquipOff");
  125. }
  126. for (int i = 0; i < Equipments.Length; i++)//Update the equip mark on the interface.
  127. EquippedLabel[i].SetActive(Player.GetEquippedId(Equipments[i].Type) == Equipments[i].GetId(Player.sex));
  128. }
  129. public void SwitchWeapon(int _id)
  130. {
  131. if (!Player.isEquippedWeapon(Weapons[_id].uid)) //Check if the character is already equipped this weapon.
  132. {
  133. Player.EquipWeapon(Weapons[_id], Player.GetWeaponState()); //If not, equip it.
  134. SoundManager.Play2D("EquipOn");
  135. }
  136. else
  137. {
  138. Player.UnequipWeapon(Weapons[_id].Type); //If it's already equipped, then unequip it.
  139. SoundManager.Play2D("EquipOff");
  140. }
  141. for (int i = 0; i < Weapons.Length; i++)//Update the equip mark on the interface.
  142. WeaponEquippedLabel[i].SetActive(Player.isEquippedWeapon(Weapons[i].uid));
  143. }
  144. public void SwitchWeaponState(int _state)
  145. {
  146. Player.SwitchWeaponState((WeaponState)_state);//Switch the state of the equipped weapons
  147. for (int i = 0; i < WeaponStateLabel.Length; i++) WeaponStateLabel[i].SetActive(i== _state);
  148. }
  149. public void Quit()
  150. {
  151. Application.Quit();
  152. }
  153. }
  154. }