/// <summary> /// 检测资源名字 /// </summary> /// <param name="name"></param> static private void CheckRes(string name) { if (gameObjPoolsMap.ContainsKey(name) == false) { gameObjPoolsMap[name] = new GameObjectRecord(name); } }
public LogEntry(List <GameObject> trackedObjects, GameObject eventOriginator, string gameEvent, bool parameter) { timestamp = Time.timeSinceLevelLoad; TrackedObjects = new GameObjectRecord[trackedObjects.Count]; for (int i = 0; i < trackedObjects.Count; i++) { TrackedObjects [i] = new GameObjectRecord(trackedObjects [i]); } this.gameEvent = gameEvent; this.gameEventOriginatorID = eventOriginator.GetInstanceID(); this.gameEventOriginatorName = eventOriginator.name; this.parameter = parameter; }
public static LogEntry Parse(LogHeader header, string line) { string[] tokens = line.Split(','); LogEntry le = new LogEntry(float.Parse(tokens [0])); le.gameEventOriginatorName = tokens [1]; le.gameEventOriginatorID = int.Parse(tokens [2]); le.gameEvent = tokens [3]; le.parameter = bool.Parse(tokens [4]); le.TrackedObjects = new GameObjectRecord[tokens.Length - 5]; for (int i = 0; i < le.TrackedObjects.Length; i++) { le.TrackedObjects [i] = GameObjectRecord.Parse(header.ObjectsNames[i], tokens [i + 5]); } return(le); }
private TypeBehaviour[] CreateObjects <TypeEnum, TypeBehaviour>(GameObjectRecord <TypeEnum>[] records, PrefabsDefinition <TypeEnum, TypeBehaviour> prefabs, string containerName = "") where TypeBehaviour : MonoBehaviour where TypeEnum : Enum { string cName = string.IsNullOrEmpty(containerName) ? "Generated " + typeof(TypeEnum).ToString() : containerName; Transform containerObjects = new GameObject(cName).transform; containerObjects.parent = container; TypeBehaviour[] instances = new TypeBehaviour[records.Length]; Dictionary <TypeEnum, Transform> dictSubContainers = new Dictionary <TypeEnum, Transform>(); for (int i = 0; i < records.Length; i++) { GameObjectRecord <TypeEnum> objectRecord = records[i]; //create container if not exist if (!dictSubContainers.ContainsKey(objectRecord.id)) { GameObject subContainer = new GameObject(objectRecord.id.ToString()); subContainer.transform.parent = containerObjects; dictSubContainers.Add(objectRecord.id, subContainer.transform); } //instance object if (prefabs.Prefabs.TryGetValue(objectRecord.id, out TypeBehaviour prefab)) { if (prefab != null) { Vector3 pos = new Vector3(objectRecord.pos.x, 0, objectRecord.pos.y); instances[i] = GameObject.Instantiate(prefab, pos, Quaternion.identity); instances[i].transform.parent = dictSubContainers[objectRecord.id]; } else { Debug.LogErrorFormat("Level Builder: Imposible to make an instance by reason - prefab with id {0} is NULL, you have to add a prefab in the inspector", objectRecord.id.ToString()); } } else { Debug.LogErrorFormat("Level Builder: Imposible to make an instance by reason - Unknown id = {0}, you have to add the id into the prefabs Dictionary", objectRecord.id.ToString()); } } return(default);