void SaveAgents() { #if UNITY_EDITOR LSAgent [] allAgents = GameObject.FindObjectsOfType <LSAgent> (); FastList <EnvironmentAgentInfo> agentsBuffer = new FastList <EnvironmentAgentInfo> (); IAgentDataProvider database; if (LSDatabaseManager.TryGetDatabase <IAgentDataProvider> (out database)) { var agentData = database.AgentData; Dictionary <GameObject, string> prefabCodeMap = new Dictionary <GameObject, string> (); foreach (var item in agentData) { prefabCodeMap.Add(item.GetAgent().gameObject, item.Name); } foreach (var agent in allAgents) { GameObject prefab = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(agent.gameObject) as GameObject; string agentCode; if (prefabCodeMap.TryGetValue(prefab, out agentCode)) { Vector3d pos = new Vector3d(agent.transform.position); Vector2d rot = Vector2d.CreateRotation(agent.transform.eulerAngles.y * Mathf.Deg2Rad); EnvironmentAgentInfo agentInfo = new EnvironmentAgentInfo( agentCode, agent, pos, rot ); agentsBuffer.Add(agentInfo); } else { Debug.LogError(agent + " does not exist in 'Agents' database"); } } this._environmentAgents = agentsBuffer.ToArray(); } else { Debug.LogError("No database"); } #endif }
void SaveBodies() { UnityLSBody[] allBodies = GameObject.FindObjectsOfType <UnityLSBody> (); FastList <EnvironmentBodyInfo> bodiesBuffer = new FastList <EnvironmentBodyInfo>(); foreach (UnityLSBody body in allBodies) { if (IsAgent(body)) { continue; } Vector3d pos = new Vector3d(body.transform.position); Vector2d rot = Vector2d.CreateRotation(body.transform.eulerAngles.y * Mathf.Deg2Rad); EnvironmentBodyInfo bodyInfo = new EnvironmentBodyInfo( body, pos, rot ); bodiesBuffer.Add(bodyInfo); } _environmentBodies = bodiesBuffer.ToArray(); }