Files
AIGame/AIClient/AgentScripts/BuildLanes.cs
T

64 lines
3.9 KiB
C#

using System;
using System.IO;
using System.Linq;
using AIGame.EditorTools;
using UnityEditor;
using UnityEngine;
public static class BuildLanes
{
const string Arena = "Assets/Bundles/Scenes/Prototype/PrototypeArena.prefab";
const string Materials = "Assets/Bundles/Scenes/Prototype/Materials/";
static Transform Group(string name, Transform parent)
{
var existing = parent.Find(name); if (existing != null) return existing;
var go = new GameObject(name); go.layer = 30; go.transform.SetParent(parent, false); return go.transform;
}
static Transform Shape(string name, Transform parent, PrimitiveType primitive, Vector3 position, Vector3 scale, string material)
{
var shape = parent.Find(name);
if (shape == null)
{
var go = GameObject.CreatePrimitive(primitive); go.name = name; go.layer = 30; go.transform.SetParent(parent, false); shape = go.transform;
UnityEngine.Object.DestroyImmediate(go.GetComponent<Collider>());
}
shape.localPosition = position; shape.localScale = scale;
var mat = AssetDatabase.LoadAssetAtPath<Material>(Materials + material + ".mat");
if (mat == null) throw new Exception("Missing material " + material);
shape.GetComponent<Renderer>().sharedMaterial = mat; return shape;
}
public static string Build()
{
if (EditorApplication.isPlaying) throw new Exception("Build lanes in Edit Mode");
string repo = Directory.GetParent(Application.dataPath).Parent.FullName;
foreach (string screen in new[] { "Formation", "Pets", "Battle", "Stages" })
if (string.IsNullOrEmpty(JsonUIPrefabBuilder.BuildFromJsonFile(Path.Combine(repo, "Doc/UIPrefabCreater/UI_Prototype" + screen + ".json")))) throw new Exception("Failed " + screen);
var root = PrefabUtility.LoadPrefabContents(Arena);
try
{
var markers = Group("DeploymentMarkers", root.transform); var effects = Group("SkillEffects", root.transform);
for (int slot = 0; slot < 6; slot++)
Shape("Slot" + slot, markers, PrimitiveType.Cylinder, new Vector3(slot / 2 == 0 ? 0 : slot / 2 == 1 ? -3 : 3, .015f, slot % 2 == 0 ? 0 : -2), new Vector3(1.7f, .025f, 1.7f), "ProtoCream");
string[] colors = { "ProtoCyan", "ProtoOrange", "ProtoLeaf", "ProtoYellow", "ProtoWater", "ProtoRock", "ProtoEmber", "ProtoGrass", "ProtoViolet", "ProtoCyan" };
for (int i = 0; i < 10; i++)
{
Shape("Skill" + i, effects, PrimitiveType.Cylinder, Vector3.zero, new Vector3(1.5f, .04f, 1.5f), colors[i]).gameObject.SetActive(false);
Shape("Shield" + i, effects, PrimitiveType.Cylinder, Vector3.zero, new Vector3(1.9f, .06f, 1.9f), "ProtoCyan").gameObject.SetActive(false);
var crest = Shape("T2Crest", root.transform.Find("Heroes/Hero" + i), PrimitiveType.Cube, new Vector3(0, 2.0f, 0), Vector3.one * .24f, "ProtoYellow");
crest.localRotation = Quaternion.Euler(0, 45, 45); crest.gameObject.SetActive(false);
}
for (int i = 0; i < 9; i++)
{
var mark = root.transform.Find("Enemies/Enemy" + i);
var slow = Shape("SlowMark", mark, PrimitiveType.Cylinder, new Vector3(0, .015f, 0), new Vector3(1.1f, .03f, 1.1f), "ProtoWater"); slow.gameObject.SetActive(false);
}
foreach (Transform child in root.transform.Cast<Transform>().Where(t => t.name == "Lane" || t.name.StartsWith("LaneRoad")))
child.GetComponent<Renderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath<Material>(Materials + "ProtoPath.mat");
PrefabUtility.SaveAsPrefabAsset(root, Arena);
}
finally { PrefabUtility.UnloadPrefabContents(root); }
SetupUiBundleCollector.Setup(); AssetDatabase.SaveAssets();
return "Built four Candy pages, authored drag handles/ghost, three-lane markers, ten skill/shield slots and T2 crests.";
}
}