Skip to content

Commit

Permalink
修复
Browse files Browse the repository at this point in the history
  • Loading branch information
1953601435 committed Jun 1, 2024
1 parent 6b45438 commit e17db05
Show file tree
Hide file tree
Showing 86 changed files with 8,972 additions and 101 deletions.
1,560 changes: 1,482 additions & 78 deletions Assets/Scenes/Persistent.unity

Large diffs are not rendered by default.

2,452 changes: 2,452 additions & 0 deletions Assets/Scenes/SampleScene.unity

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Assets/Scenes/SampleScene.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Assets/Scripts/Character/CharacterBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ public class CharacterBehavior : MonoBehaviour
public Vector2 FaceDir => _faceDir;

private readonly Dictionary<ECommand, ICommand> _commandDictionary = new();

private ElementUI _elementUI;

private void Start()
{
_commandDictionary[ECommand.Move] = new MoveCommand(Vector2.zero, null);
_commandDictionary[ECommand.Interact] = new InteractCommand(null, this);
_elementUI = GetComponent<ElementUI>();
}

private void Update()
Expand Down Expand Up @@ -106,6 +109,7 @@ public bool AbsorbElement(Element targetElement)
if (CurrentElement is Element.Wind or >= Element.Rock)//没有元素或是融合元素
{
CurrentElement = targetElement;
_elementUI.UpdateElementBallColor();
Debug.Log(CurrentElement);
return true;
}
Expand All @@ -115,6 +119,7 @@ public bool AbsorbElement(Element targetElement)
if (Fusion.FusionMap[CurrentElement].TryGetValue(targetElement, out fusionResult))
{
CurrentElement = fusionResult;
_elementUI.UpdateElementBallColor();
Debug.Log(CurrentElement);
return true;
}
Expand All @@ -125,7 +130,7 @@ public bool AbsorbElement(Element targetElement)
}
}

Debug.Log(CurrentElement);
//Debug.Log(CurrentElement);
}

public void Die()
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Dialogue/DialogueManger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using UnityEngine;
using UnityEngine.UI;

public class DialogueManger : MonoBehaviour
public class DialogueManager : MonoBehaviour
{
public static DialogueManger instance;
public static DialogueManager instance;

public GameObject dialogueBox;
public Text dialogueText, nameText;
Expand Down
10 changes: 10 additions & 0 deletions Assets/Scripts/Dialogue/NonTalkable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UnityEngine;

public class NonTalkable : TalkInteractable
{
//protected override void Start()
//{
// base.Start();
// promptText.text = $"{gameObject.name}";
//}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Dialogue/NonTalkable.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions Assets/Scripts/Dialogue/TalkInteractable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using UnityEngine;
using UnityEngine.UI;

public abstract class TalkInteractable : MonoBehaviour
{
[SerializeField] protected bool isEntered;
public GameObject interactionPrompt;
protected Text promptText;

protected virtual void Start()
{
interactionPrompt.SetActive(false); // 确保提示框开始时是隐藏的
promptText = interactionPrompt.GetComponentInChildren<Text>(); // 获取Text组件
}

protected virtual void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
Debug.Log("Player entered trigger");
isEntered = true;
ShowPrompt();
}
}

protected virtual void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
Debug.Log("Player exited trigger");
isEntered = false;
HidePrompt();
}
}

protected virtual void Update()
{
// 基类中的Update逻辑
}

protected virtual void ShowPrompt()
{
promptText.text = gameObject.name; // 设置提示框文本为物体名称
interactionPrompt.SetActive(true);
}

protected virtual void HidePrompt()
{
interactionPrompt.SetActive(false);
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Dialogue/TalkInteractable.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Assets/Scripts/Dialogue/Talkable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ private void OnTriggerExit2D(Collider2D other)

private void Update()
{
if (isEntered && Input.GetKeyDown(KeyCode.E) && !DialogueManger.instance.dialogueBox.activeInHierarchy)
if (isEntered && Input.GetKeyDown(KeyCode.E) && !DialogueManager.instance.dialogueBox.activeInHierarchy)
{
DialogueManger.instance.ShowDialogue(lines);
DialogueManager.instance.ShowDialogue(lines);
interactionPrompt.SetActive(false); // 隐藏提示框当对话开始时
}

Expand Down
180 changes: 180 additions & 0 deletions Assets/Scripts/Dialogue/Testplayer_element.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Utility;

public class ElementUI : MonoBehaviour
{
//private List<Element> elements = new List<Element>();
public Image elementBallImage;
public Text elementInfoText;
public float colorTransitionDuration = 1.0f; // 颜色渐变持续时间
private Coroutine colorTransitionCoroutine;

private CharacterBehavior _character;

private Dictionary<Element, string> elementDescriptions = new Dictionary<Element, string>()
{
{ Element.Wind, "" },
{ Element.Fire, "" },
{ Element.Water, "" },
{ Element.Soil, "" },
{ Element.Wood, "" }
};
private Dictionary<Element, Color> elementColors = new Dictionary<Element, Color>()
{
{ Element.Wind, new Color(0.6f, 0.7f, 0.6f) },
{ Element.Fire, new Color(0.8f, 0.36f, 0.36f) },
{ Element.Water, new Color(0.3f, 0.5f, 0.8f) },
{ Element.Soil, new Color(0.8f, 0.7f, 0.4f) },
{ Element.Wood, new Color(0.1f, 0.6f, 0.2f) }
};

private Dictionary<Element, Color> fusionColors = new Dictionary<Element, Color>()
{
{ (Element.Ember), new Color(0.5f, 0.1f, 0.1f) },
{ (Element.Steam), new Color(0.3f, 0.4f, 0.4f) },
{ (Element.Rock), new Color(0.4f, 0.2f, 0.1f) },
{ (Element.Wetland), new Color(0.3f, 0.2f, 0.1f) }
};

private Dictionary<Element, string> fusionDescriptions = new Dictionary<Element, string>()
{
{ (Element.Ember), "余烬" }, // 火和木融合后的描述
{ (Element.Steam), "蒸汽" }, // 火和水融合后的描述
{ (Element.Rock), "陶瓷" }, // 火和土融合后的描述
{ (Element.Wetland), "耕土" } // 水和土融合后的描述
};

private void Start()
{
//AddElement(Element.Wind);
//Debug.Log("现在有" + elements.Count + "个元素");
_character = GetComponent<CharacterBehavior>();
}

private void Update()
{
//if (Input.GetKeyDown(KeyCode.Alpha1)&&elements.Count<3)
//{
// AddElement(Element.Fire);
// Debug.Log("吸取了火元素。现在有" + elements.Count + "个元素");
//}
//else if (Input.GetKeyDown(KeyCode.Alpha2) && elements.Count < 3)
//{
// AddElement(Element.Water);
// Debug.Log("吸取了水元素。现在有" + elements.Count + "个元素");
//}
//else if (Input.GetKeyDown(KeyCode.Alpha3) && elements.Count < 3)
//{
// AddElement(Element.Earth);
// Debug.Log("吸取了土元素。现在有" + elements.Count + "个元素");
//}
//else if (Input.GetKeyDown(KeyCode.Alpha4) && elements.Count < 3)
//{
// AddElement(Element.Wood);
// Debug.Log("吸取了木元素。现在有" + elements.Count + "个元素");
//}

//if (Input.GetKeyDown(KeyCode.Q))
//{
// ClearFusionElements();
// Debug.Log("清空了元素。现在有" + elements.Count + "个元素");
//}
}

//private void AddElement(Element newElement)
//{
// if (!elements.Contains(newElement))
// {
// elements.Add(newElement);
// UpdateElementBallColor();
// UpdateElementInfoText();
// }
//}

//private void ClearFusionElements()
//{
// elements.Clear();
// AddElement(Element.Wind);
//}

public void UpdateElementBallColor()
{
Color targetColor;
var element = _character.CurrentElement;
//if (elements.Count == 1)
//{
// targetColor = elementColors[elements[0]];
//}
//else if (elements.Count == 2)
//{
// targetColor = elementColors[elements[1]];
//}
//else if (elements.Count == 3)
//{
if (fusionColors.TryGetValue(element, out Color fusionColor) ||
fusionColors.TryGetValue(element, out fusionColor))
{
targetColor = fusionColor;
Debug.Log("触发了元素融合。融合颜色已应用。");
}
else
{
targetColor = elementColors[element];
Debug.Log("没有融合颜色,显示最新吸取元素的颜色。");
}
//}
//else
//{
// targetColor = elementBallImage.color; // 保持当前颜色
//}

//targetColor.a = 0.50f; // 设置透明度为100/255
// 开始颜色渐变协程
if (colorTransitionCoroutine != null)
{
StopCoroutine(colorTransitionCoroutine);
}
colorTransitionCoroutine = StartCoroutine(TransitionColor(elementBallImage.color, targetColor
, colorTransitionDuration));

UpdateElementInfoText();
}
private void UpdateElementInfoText()
{
var element = _character.CurrentElement;
//if (elements.Count == 1)
//{
// elementInfoText.text = elementDescriptions[elements[0]];
//}
//else if(elements.Count == 2)
//{
// elementInfoText.text = elementDescriptions[elements[1]];
//}
//else if(elements.Count == 3)
//{
if (fusionDescriptions.TryGetValue(element, out string description) ||
fusionDescriptions.TryGetValue(element, out description))
{
elementInfoText.text = description;
}
else
{
elementInfoText.text = elementDescriptions[element];
}
//}
}
private IEnumerator TransitionColor(Color fromColor, Color toColor, float duration)
{
float elapsedTime = 0f;
while (elapsedTime < duration)
{
elementBallImage.color = Color.Lerp(fromColor, toColor, elapsedTime / duration);
elapsedTime += Time.deltaTime;
yield return null;
}
elementBallImage.color = toColor;
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Dialogue/Testplayer_element.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions Assets/Scripts/Dialogue/Transformable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using UnityEngine;

public class Transformable : TalkInteractable
{
private bool isCleaned;

protected override void Start()
{
base.Start();
UpdatePromptText();
}

protected override void Update()
{
base.Update();
if (isEntered && Input.GetKeyDown(KeyCode.E))
{
if (isCleaned)
{
// 变成可对话的状态
DialogueManager.instance.ShowDialogue(new string[] { "The cleaned object is now talkable." });
interactionPrompt.SetActive(false);
}
else
{
// 执行清洗操作
isCleaned = true;
UpdatePromptText();
}
}
}

private void UpdatePromptText()
{
if (isCleaned)
{
promptText.text = $"{gameObject.name} is now clean and talkable.";
}
else
{
promptText.text = $"{gameObject.name} is covered in dust.";
}
}
}
Loading

0 comments on commit e17db05

Please sign in to comment.