Unity로 3D 마크업 텍스트를 쉽게 만들 수 있는 편집기(간략판) 만들기
8594 단어 Unity
목표
텍스트 편집기에서 노력하는 것이 힘들기 때문에 간단한 느낌으로 간단하게 표시할 수 있는 구조를 먼저 만든다.
코드
훌륭한 편집자?3D 합성기로 사용하면
이런 힐러키를 만들었어요.
적당히 이렇게 된다고 가정해 봐.
코드를 쓰다.기본 클래스로 아래의 클래스를 제작합니다.
Node.csusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Node : MonoBehaviour
{
public virtual string toML()
{
string mlResult = "";
for(int i = 0; i < gameObject.transform.childCount; i++)
{
mlResult += gameObject.transform.GetChild(i).gameObject.GetComponent<Node>().toML();
}
return mlResult;
}
protected string toColorString(Color color)
{
return ((byte)(color.r * 255)).ToString("X2") + ((byte)(color.g * 255)).ToString("X2") + ((byte)(color.b * 255)).ToString("X2");
}
}
각 기본체의 종류별로 아래의 종류를 제작한다.
Cube.csusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cube : Node
{
public override string toML()
{
string ret = "";
ret += "<a-box x=" + gameObject.transform.position.x +
" y=" + gameObject.transform.position.y +
" z=" + gameObject.transform.position.z +
" size=" + gameObject.transform.localScale.x +
" color=#" + toColorString(gameObject.GetComponent<MeshRenderer>().material.color) +
">";
ret += base.toML();
ret += "</a-box>";
return ret;
}
}
생략했지만 다른 것도 마찬가지다.
그리고 루트에 연결된 다음 구성 요소 Debug를 사용합니다.일지에 토하다.
Kick.csusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Kick : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log(gameObject.GetComponent<Node>().toML());
}
}
결과
Debug.Log로 토해서 콘솔에서 복사했어요.<a-box x=0 y=0 z=0 size=1 color=#FA0303><a-sphere x=0 y=0.79 z=0.71 r=0.5 color=#000000><a-text x=0.77 y=0.79 z=-1.24 size=1 color=#FFFFFF>Hello World</a-text></a-sphere><a-cylinder x=-0.96 y=0.64 z=-1.18 height=2 r=0.5 color=#FFFFFF></a-cylinder></a-box>
완성했습니다.
긴급한 초간이판이기 때문에 더 좋은 형식을 고려한다.
Reference
이 문제에 관하여(Unity로 3D 마크업 텍스트를 쉽게 만들 수 있는 편집기(간략판) 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/oho-sugu/items/b8be003bda312cfe45a6
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
훌륭한 편집자?3D 합성기로 사용하면

이런 힐러키를 만들었어요.

적당히 이렇게 된다고 가정해 봐.
코드를 쓰다.기본 클래스로 아래의 클래스를 제작합니다.
Node.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Node : MonoBehaviour
{
public virtual string toML()
{
string mlResult = "";
for(int i = 0; i < gameObject.transform.childCount; i++)
{
mlResult += gameObject.transform.GetChild(i).gameObject.GetComponent<Node>().toML();
}
return mlResult;
}
protected string toColorString(Color color)
{
return ((byte)(color.r * 255)).ToString("X2") + ((byte)(color.g * 255)).ToString("X2") + ((byte)(color.b * 255)).ToString("X2");
}
}
각 기본체의 종류별로 아래의 종류를 제작한다.Cube.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cube : Node
{
public override string toML()
{
string ret = "";
ret += "<a-box x=" + gameObject.transform.position.x +
" y=" + gameObject.transform.position.y +
" z=" + gameObject.transform.position.z +
" size=" + gameObject.transform.localScale.x +
" color=#" + toColorString(gameObject.GetComponent<MeshRenderer>().material.color) +
">";
ret += base.toML();
ret += "</a-box>";
return ret;
}
}
생략했지만 다른 것도 마찬가지다.그리고 루트에 연결된 다음 구성 요소 Debug를 사용합니다.일지에 토하다.
Kick.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Kick : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log(gameObject.GetComponent<Node>().toML());
}
}
결과
Debug.Log로 토해서 콘솔에서 복사했어요.<a-box x=0 y=0 z=0 size=1 color=#FA0303><a-sphere x=0 y=0.79 z=0.71 r=0.5 color=#000000><a-text x=0.77 y=0.79 z=-1.24 size=1 color=#FFFFFF>Hello World</a-text></a-sphere><a-cylinder x=-0.96 y=0.64 z=-1.18 height=2 r=0.5 color=#FFFFFF></a-cylinder></a-box>
완성했습니다.
긴급한 초간이판이기 때문에 더 좋은 형식을 고려한다.
Reference
이 문제에 관하여(Unity로 3D 마크업 텍스트를 쉽게 만들 수 있는 편집기(간략판) 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/oho-sugu/items/b8be003bda312cfe45a6
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
<a-box x=0 y=0 z=0 size=1 color=#FA0303><a-sphere x=0 y=0.79 z=0.71 r=0.5 color=#000000><a-text x=0.77 y=0.79 z=-1.24 size=1 color=#FFFFFF>Hello World</a-text></a-sphere><a-cylinder x=-0.96 y=0.64 z=-1.18 height=2 r=0.5 color=#FFFFFF></a-cylinder></a-box>
Reference
이 문제에 관하여(Unity로 3D 마크업 텍스트를 쉽게 만들 수 있는 편집기(간략판) 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/oho-sugu/items/b8be003bda312cfe45a6텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)