版权声明:本博客一本正经胡说八道,文章内容仅供参考。本文为博主原创文章,未经博主允许不得转载。该博客所用图片资源均作学习分享用途,仅供参考,请勿用于商业行为。传播者自负。 如果本博客所写文章侵犯到您的权益,请主动联系留言,我们将及时删除相关内容。 https://blog.csdn.net/BuladeMian/article/details/85225501
现在实现的功能较少。
当角色 进入 Cube 范围内,就可以显示 文本。
逻辑图
SimpleStoryManage.cs
using UnityEngine;
public class SimpleStoryManage : MonoBehaviour {
#region Singleton
public static SimpleStoryManage instance;
void Awake()
{
instance = this;
}
#endregion
[SerializeField]
private SimpleStoryControl storyControl;
public SimpleStory_Sentence[] _Sentence;
// Use this for initialization
void Start () {
if (storyControl == null)
{
Transform controlTrans;
controlTrans = this.transform.Find("SimpleStoryControl");
Debug.Log(" "+controlTrans.name);
if (controlTrans != null
&& controlTrans.GetComponent<SimpleStoryControl>() !=null)
{
storyControl = controlTrans.GetComponent<SimpleStoryControl>();
}
}
}
public void showUI(SimpleStoryUI_Plane simpleStoryUI_Plane)
{
_Sentence = simpleStoryUI_Plane.Sentence;
}
public void hideUI()
{
_Sentence = null;
}
}
SimpleStoryControl.cs
using UnityEngine;
public class SimpleStoryControl : MonoBehaviour {
[SerializeField]
private SimpleStoryManage storyManage;
[SerializeField]
private SimpleStoryUIManage storyUIManage;
private int time_int;
private int sentence_int;
private int _int;
private int _int_1;
// Use this for initialization
void Start () {
if (storyManage == null)
{
storyManage = SimpleStoryManage.instance;
}
if (storyUIManage == null)
{
storyUIManage = SimpleStoryUIManage.instance;
}
time_int = 50;// 1 second 30 time
sentence_int = 0;
}
// Update is called once per frame
void FixedUpdate() {
if (storyManage._Sentence == null)
{
//Debug.Log(" storyManage._Sentence:null");
_int = _int + 1;
if (_int >= time_int)
{
//Debug.Log(">>>>>>>>>>>>>>>>>>>>>>.");
_int = 0;
}
}
else if (storyManage._Sentence.Length > 0)
{
//Debug.Log(" storyManage._Sentence:!null");
storyUIManage.showText(storyManage._Sentence[sentence_int].str_sentence);
_int_1 = storyManage._Sentence[sentence_int].time_int;
_int_1 = _int_1 * time_int;
if (_int >= _int_1
&& sentence_int < storyManage._Sentence.Length
)
{
_int = 0;
sentence_int = sentence_int + 1;
}
else
{
_int = _int + 1;
}
if (sentence_int >= storyManage._Sentence.Length)
{
sentence_int = 0;
}
}
}
}
SimpleStory_Sentence.cs
using UnityEngine;
[CreateAssetMenu(fileName = "SimpleStorySentence", menuName = "SimpleStory/SimpleStory_Sentence")]
public class SimpleStory_Sentence : ScriptableObject
{
public string str_sentence;
public int time_int;
public AudioClip audioClip;
}
SimpleStory_TriggerBox.cs
using UnityEngine;
public class SimpleStory_TriggerBox : MonoBehaviour {
[SerializeField]
private SimpleStory_Sentence[] SimpleStory_Sentence_Array;
//OnTriggerEnter
void OnTriggerEnter(Collider other)
{
SimpleStoryUIManage.instance.ssStart(SimpleStory_Sentence_Array);
}
void OnTriggerExit(Collider other)
{
SimpleStoryUIManage.instance.ssEnd();
}
}
SimpleStoryUIManage.cs
using UnityEngine;
public class SimpleStoryUIManage : MonoBehaviour {
#region Singleton
public static SimpleStoryUIManage instance;
void Awake()
{
instance = this;
}
#endregion
[SerializeField]
private Transform plane;
public void ssStart(SimpleStory_Sentence[] simpleStory_)
{
if (plane != null
&& plane.GetComponent<SimpleStoryUI_Plane>() != null
)
{
SimpleStoryUI_Plane _Plane = plane.GetComponent<SimpleStoryUI_Plane>();
_Plane.showUI(simpleStory_);
}
}
public void showText( string str)
{
if (plane != null
&& plane.GetComponent<SimpleStoryUI_Plane>() != null
)
{
SimpleStoryUI_Plane _Plane = plane.GetComponent<SimpleStoryUI_Plane>();
_Plane.showText(str);
}
}
public void ssEnd()
{
if (plane != null
&& plane.GetComponent<SimpleStoryUI_Plane>() != null
)
{
SimpleStoryUI_Plane _Plane = plane.GetComponent<SimpleStoryUI_Plane>();
_Plane.hideUI();
}
}
}
SimpleStoryUI_Plane.cs
using UnityEngine;
using UnityEngine.UI;
public class SimpleStoryUI_Plane : MonoBehaviour {
[SerializeField]
private Transform plane;
[SerializeField]
private Text text;
public int _int;//用于控制 SimpleStory_Sentence[] _Sentence
[SerializeField]
private SimpleStoryManage simpleStoryManage;
public SimpleStory_Sentence[] Sentence;
// Use this for initialization
void Start () {
if (plane == null)
{
plane = this.transform;
}
if (simpleStoryManage == null)
{
simpleStoryManage = SimpleStoryManage.instance;
}
_int = 0;
}
public void showUI(SimpleStory_Sentence[] _Sentence)
{
Sentence = _Sentence;
simpleStoryManage.showUI(this);
plane.localScale = new Vector3(1,1,1);
}
public void showText(string _str)
{
plane.localScale = new Vector3(1, 1, 1);
if (text != null)
{
text.text = _str;
}
}
public void hideUI()
{
Sentence = null;
simpleStoryManage.hideUI();
plane.localScale = new Vector3(0,0,0);
}
}
参考资料:
2.