71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class AntManTestSceneBootstrap : MonoBehaviour
|
||
|
|
{
|
||
|
|
[Header("Escena")]
|
||
|
|
[SerializeField] private string cubeName = "AntManCube";
|
||
|
|
[SerializeField] private string lightName = "Directional Light";
|
||
|
|
[SerializeField] private string cameraName = "Main Camera";
|
||
|
|
|
||
|
|
[ContextMenu("Build Test Scene")]
|
||
|
|
public void BuildTestScene()
|
||
|
|
{
|
||
|
|
GameObject cube = FindOrCreateCube();
|
||
|
|
FindOrCreateLight();
|
||
|
|
FindOrCreateCamera(cube.transform.position);
|
||
|
|
}
|
||
|
|
|
||
|
|
private GameObject FindOrCreateCube()
|
||
|
|
{
|
||
|
|
GameObject cube = GameObject.Find(cubeName);
|
||
|
|
if (cube == null)
|
||
|
|
{
|
||
|
|
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
||
|
|
cube.name = cubeName;
|
||
|
|
cube.transform.position = Vector3.zero;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (cube.GetComponent<AntManScaleController>() == null)
|
||
|
|
{
|
||
|
|
cube.AddComponent<AntManScaleController>();
|
||
|
|
}
|
||
|
|
|
||
|
|
if (cube.GetComponent<GhostTrailEmitter>() == null)
|
||
|
|
{
|
||
|
|
cube.AddComponent<GhostTrailEmitter>();
|
||
|
|
}
|
||
|
|
|
||
|
|
return cube;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void FindOrCreateLight()
|
||
|
|
{
|
||
|
|
if (GameObject.Find(lightName) != null)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
GameObject lightObject = new GameObject(lightName);
|
||
|
|
Light lightComponent = lightObject.AddComponent<Light>();
|
||
|
|
lightComponent.type = LightType.Directional;
|
||
|
|
lightComponent.intensity = 1.1f;
|
||
|
|
|
||
|
|
lightObject.transform.rotation = Quaternion.Euler(50f, -30f, 0f);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void FindOrCreateCamera(Vector3 targetPosition)
|
||
|
|
{
|
||
|
|
GameObject cameraObject = GameObject.Find(cameraName);
|
||
|
|
if (cameraObject == null)
|
||
|
|
{
|
||
|
|
cameraObject = new GameObject(cameraName);
|
||
|
|
cameraObject.tag = "MainCamera";
|
||
|
|
cameraObject.AddComponent<Camera>();
|
||
|
|
cameraObject.AddComponent<AudioListener>();
|
||
|
|
}
|
||
|
|
|
||
|
|
cameraObject.transform.position = targetPosition + new Vector3(0f, 7f, -18f);
|
||
|
|
cameraObject.transform.LookAt(targetPosition);
|
||
|
|
}
|
||
|
|
}
|