Ejemplo n.º 1
0
    // Travel down preloaded assets hierarchy to find the prefab mesh.
    private GeomController FindGeomPrefabInPrefabSet(Transform prefab_set, string part_name)
    {
        string[] split_name = part_name.Split(new char[] { ':' }, 2);

        if (split_name.Length == 2)
        {
            Transform prefab_sub_set = SceneUtils.Find <Transform>(prefab_set, split_name[0], null);
            if (prefab_sub_set != null)
            {
                return(FindGeomPrefabInPrefabSet(prefab_sub_set, split_name[1]));
            }
            else
            {
                Logger.Warning(
                    "RobotLoader::FindAssemblyPartPrefabInPrefabSet::Cannot find: {0} subset, trying default.",
                    split_name[0]);
                part_name = split_name[1];
            }
        }

        GeomController geom_prefab = SceneUtils.Find <GeomController>(prefab_set, part_name, null);

        if (geom_prefab != null)
        {
            return(geom_prefab);
        }
        Logger.Warning("RobotLoader::FindAssemblyPartPrefabInPrefabSet::Cannot find assembly part: {0}", part_name);
        return(null);
    }
Ejemplo n.º 2
0
    private bool AddCamera(KineticHierarchyController parent, XmlNode camera_xml, XmlUtils.Defaults defaults)
    {
        string camera_name = XmlUtils.GetString(camera_xml, "name", null);

        if (camera_name == null)
        {
            camera_name = string.Format("camera_{0}", camera_counter_++);
        }

        Camera camera_prototype = SceneUtils.Find <Camera>(assembly_parts_, camera_name,
                                                           SceneUtils.Find <Camera>(assembly_parts_, "__camera_template", null));

        if (camera_prototype == null)
        {
            Logger.Error("RobotLoader::AddCamera::Cannot find camera prefab for: {0}", camera_name);
            return(false);
        }

        Camera robot_camera = Instantiate(camera_prototype);

        robot_camera.name                    = camera_name;
        robot_camera.transform.parent        = parent.transform;
        robot_camera.transform.localRotation = XmlUtils.GetRotation(camera_xml, Quaternion.identity);
        robot_camera.transform.localPosition = XmlUtils.GetVector3(camera_xml, "pos", Vector3.zero);
        robot_camera.transform.LookAt(robot_camera.transform.position + robot_camera.transform.TransformDirection(Vector3.back),
                                      robot_camera.transform.TransformDirection(Vector3.up));
        robot_camera.fieldOfView = XmlUtils.GetFloat(camera_xml, "fovy", robot_camera.fieldOfView);

        return(true);
    }