public static CRenderObject CreateObject(params object[] args) { EWormParts type = (EWormParts)args[0]; string path = getPrefabPath(type); if (string.IsNullOrEmpty(path)) { return(null); } Object prefab = Resources.Load(path); GameObject go = (GameObject)GameObject.Instantiate(prefab); if (go == null) { return(null); } List <object> list = args.ToList(); list.RemoveRange(0, 1); object[] restArgs = list.ToArray(); Transform dad = WorldMan.Inst.GetParent(type); string name = string.Format("{0} {1}", type, dad.childCount); go.transform.SetParent(dad); go.name = name; go.SetActive(false); CRenderObject obj = go.GetComponent <CRenderObject>(); obj.Init(restArgs); return(obj); }
public static string getPrefabPath(EWormParts type) { switch (type) { case EWormParts.point: case EWormParts.neuron: return("Prefabs/Sphere"); case EWormParts.axon: case EWormParts.spring: return("Prefabs/Line"); case EWormParts.muscle: return("Prefabs/Cone"); } return(null); }
public Transform GetParent(EWormParts type) { if (!parts.ContainsKey(type)) { Transform dad = transform.Find(type.ToString()); if (!dad) { dad = new GameObject().transform; dad.SetParent(worm); dad.name = type.ToString(); } parts.Add(type, dad); } return(parts[type]); }